Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

push db-migration image to GitHub Container Registry instead of Google #1675

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .github/workflows/push-migration-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: serlo/configure-repositories/actions/setup-node@main
- uses: google-github-actions/auth@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
credentials_json: '${{ secrets.GCP_KEY_CONTAINER_REGISTRY }}'
- run: gcloud auth configure-docker
- uses: google-github-actions/setup-gcloud@v2
- run: yarn migrate:push-image
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
run: |
cd packages/db-migrations
DOCKER_REGISTRY=ghcr.io DOCKER_REPOSITORY=$(echo $GITHUB_REPOSITORY)/db-migration lerna run --stream push-image
env:
DOCKER_REGISTRY: ghcr.io
DOCKER_REPOSITORY: ${{ github.repository }}/db-migration
31 changes: 10 additions & 21 deletions packages/db-migrations/scripts/push-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void run()
async function run() {
const { version } = await fetchPackageJSON()
buildDockerImage({
name: 'api-db-migration',
name: 'db-migration',
version,
Dockerfile: path.join(root, 'Dockerfile'),
context: '.',
Expand Down Expand Up @@ -48,7 +48,9 @@ export function buildDockerImage({
throw new Error(`illegal version number ${version}`)
}

const remoteName = `eu.gcr.io/serlo-shared/${name}`
const registry = process.env.DOCKER_REGISTRY || 'ghcr.io'
const repository = process.env.DOCKER_REPOSITORY || `serlo/${name}`
const remoteName = `${registry}/${repository}`

if (!shouldBuild()) {
// eslint-disable-next-line no-console
Expand All @@ -64,25 +66,12 @@ export function buildDockerImage({
pushTags(versions)

function shouldBuild() {
const args = [
'container',
'images',
'list-tags',
remoteName,
'--filter',
`tags=${version}`,
'--format',
'json',
]

const result = spawnSync('gcloud', args, { stdio: 'pipe' })
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const images = JSON.parse(String(result.stdout))

if (!Array.isArray(images))
throw new Error('Wrong response from google cloud')

return images.length === 0
const result = spawnSync(
'docker',
['manifest', 'inspect', `${remoteName}:${version}`],
{ stdio: 'pipe' },
)
return result.status !== 0
}

function runBuild(versions: string[]) {
Expand Down