Skip to content

Instantly share code, notes, and snippets.

@bobleujr
Created June 1, 2023 18:23
Show Gist options
  • Save bobleujr/ef8284df6e2fb841dec430f4a9f19037 to your computer and use it in GitHub Desktop.
Save bobleujr/ef8284df6e2fb841dec430f4a9f19037 to your computer and use it in GitHub Desktop.
Connect to GCP's Artifact Registry via Github Actions

If you're also about to migrate from Container Registry into Artifact Registry and has to adapt your Github Actions pipelines to do so, the migration itself is very simple

  steps:
      ...
      - id: 'auth'
        uses: 'google-github-actions/auth@v1'
        with:
          # if you're using a .json for a service account
          credentials_json: '${{ secrets.your-service-account-json }}'
          # if you are using workload identity
          token_format: access_token
          workload_identity_provider: <provider-id>
          service_account: <service-account>@<project-id>.iam.gserviceaccount.com
          access_token_lifetime: 600s

      - name: 'Set up Cloud SDK'
        uses: 'google-github-actions/setup-gcloud@v1'

      - name: Use gcloud CLI
        run: gcloud info
      
      # if you're using a .json for a service account
      - name: Login to Artifact Registry
        run: |
          gcloud auth configure-docker us-central1-docker.pkg.dev
      # if you are using workload identity
      - name: Login to Artifact Registry
        uses: docker/login-action@v1
        with:
          registry: us-central1-docker.pkg.dev
          username: oauth2accesstoken
          password: ${{ steps.auth.outputs.access_token }}
      
      - name: Docker build & push
        run: | 
          # Build & push
          docker build -t us-central1-docker.pkg.dev/<project-id>/<registry-name>/<image-name>:<tag> .
          docker push us-central1-docker.pkg.dev/<project-id>/<registry-name>/<image-name>:<tag>
        shell: bash
      
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment