Skip to content

Commit

Permalink
feat: push Docker images to GAR (#746)
Browse files Browse the repository at this point in the history
I took a stab at updating the CircleCI config to push images to GAR
after they're pushed to Docker Hub. This approach requires the
[circleci/gcp-gcr
orb](https://circleci.com/developer/orbs/orb/circleci/gcp-gcr).

Requirements:

- [x] New environment variables added to CircleCI project
- [x] Workload Identity configured for service account
- [ ] New workflows tested
  • Loading branch information
emaydeck-mozilla committed Sep 3, 2024
1 parent 9fb9fb3 commit 97e9193
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@
# DOCKERHUB_LOAD_TEST_REPO - Docker Hub repo for load tests, format: <username>/<repo>
# DOCKER_LOAD_TEST_PASS - Docker Hub load test repo password
# DOCKER_LOAD_TEST_USER - Docker Hub load test repo user
#
# These environment variables are necessary to authenticate with GCP and upload images to GAR
# GCP_GAR_REPO - Name of GAR repo
# GCP_PROJECT_ID - GCP project ID
# GCP_SERVICE_ACCOUNT_EMAIL - GCP service account email
# GCP_WIP_ID - GCP Workload Identity Pool ID
# GCP_WIP_PROVIDER_ID - GCP Workload Identity Pool Provider ID

version: 2.1

orbs:
gcp-gcr: circleci/gcp-gcr@0.16.3

commands:
docker_login:
parameters:
Expand Down Expand Up @@ -402,6 +412,43 @@ jobs:
docker push "${DOCKERHUB_LOAD_TEST_REPO}:${CIRCLE_SHA1}"
docker push "${DOCKERHUB_LOAD_TEST_REPO}:latest"
deploy-to-gar:
executor: gcp-gcr/default
parameters:
build_tag:
type: string
default: build
image:
type: string
registry-url:
type: string
default: us-docker.pkg.dev
steps:
- gcp-gcr/gcr-auth:
gcp_cred_config_file_path: ~/gcp_cred_config.json
google-project-id: GCP_PROJECT_ID
registry-url: <<parameters.registry-url>>
service_account_email: GCP_SERVICE_ACCOUNT_EMAIL
workload_identity_pool_id: GCP_WIP_ID
workload_identity_pool_provider_id: GCP_WIP_PROVIDER_ID
- run:
name: Tag image
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
echo 'export GAR_TAG=master' >> $BASH_ENV
elif [ ! -z "${CIRCLE_TAG}" ]; then
echo "export GAR_TAG=$CIRCLE_TAG" >> $BASH_ENV
fi
echo "export GAR_IMAGE=\"<<parameters.registry-url>>/${GCP_PROJECT_ID}/${GCP_GAR_REPO}/<<parameters.image>>\"" >> $BASH_ENV
source $BASH_ENV
docker tag <<parameters.image>>:<<parameters.build_tag>> $GAR_IMAGE:$GAR_TAG
docker tag <<parameters.image>>:<<parameters.build_tag>> $GAR_IMAGE:latest
- gcp-gcr/push-image:
image: $GAR_IMAGE
google-project-id: GCP_PROJECT_ID
registry-url: <<parameters.registry-url>>
tag: $GAR_TAG,latest

workflows:
build-test-deploy:
jobs:
Expand Down Expand Up @@ -452,7 +499,7 @@ workflows:
tags:
only: /.*/

# Comment out the following two sections for local CircleCI testing.
# Comment out the following four sections for local CircleCI testing.
- deploy:
name: deploy-autoconnect
image: autoconnect:build
Expand Down Expand Up @@ -483,6 +530,34 @@ workflows:
branches:
only: master

- deploy-to-gar:
name: deploy-autoconnect-gar
image: autoconnect
requires:
- build-autoconnect
- Integration Tests
- Rust Unit Tests
- Rust Formatting Check
filters:
tags:
only: /.*/
branches:
only: master

- deploy-to-gar:
name: deploy-autoendpoint-gar
image: autoendpoint
requires:
- build-autoendpoint
- Integration Tests
- Rust Unit Tests
- Rust Formatting Check
filters:
tags:
only: /.*/
branches:
only: master

- deploy-load-test:
requires:
- build-load-test
Expand Down

0 comments on commit 97e9193

Please sign in to comment.