Created
March 16, 2022 00:08
-
-
Save joeyslalom/3a3b4783ea9f2e7fa3493c13bcf68e0a to your computer and use it in GitHub Desktop.
GitHub Action - docker build and push to Artifact Registry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Create service account | |
#. * Service Account Token Creator | |
#. * Artifact Registry Writer | |
# 2. Generate service account key | |
#. * In GitHub project -> Settings -> Secrets -> Actions -> New Repository Secret | |
#. Name: GCP_CREDENTIALS | |
#. Value: key.json contents | |
# 3. Create repo in artifact repository | |
#. * Name: $env.REPOSITORY below | |
#. * Region: $env.GAR_LOCATION below | |
name: Docker build and push to Artifact Registry | |
on: | |
push: | |
branches: | |
- main | |
- github-action | |
env: | |
PROJECT_ID: slalom-2020-293920 | |
GAR_LOCATION: us-west1 | |
REPOSITORY: reimagined-couscous | |
IMAGE: main | |
jobs: | |
login-build-push: | |
name: Docker login, build, and push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: 'Docker build' | |
run: |- | |
docker build \ | |
--tag "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA" \ | |
app/ | |
- id: 'auth' | |
name: 'Authenticate to Google Cloud' | |
uses: 'google-github-actions/[email protected]' | |
with: | |
credentials_json: '${{ secrets.GCP_CREDENTIALS }}' | |
token_format: 'access_token' | |
- uses: 'docker/login-action@v1' | |
name: 'Docker login' | |
with: | |
registry: '${{ env.GAR_LOCATION }}-docker.pkg.dev' | |
username: 'oauth2accesstoken' | |
password: '${{ steps.auth.outputs.access_token }}' | |
- name: 'Docker push' | |
run: |- | |
docker push "$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
corresponding tf: