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

Modify build-publish workflow to push to GAR #1497

Merged
merged 1 commit into from
Oct 16, 2024
Merged
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
55 changes: 44 additions & 11 deletions .github/workflows/build-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,30 @@ jobs:
build-and-publish:
runs-on: ubuntu-latest
env:
IMAGE_NAME: mozilla/telescope
DOCKERHUB_IMAGE_NAME: mozilla/telescope
TEST_CONTAINER_NAME: container-healthcheck
GAR_LOCATION: us
GCP_PROJECT_ID: telescope-prod
GAR_REPOSITORY: moz-fx-telescope-prod
IMAGE: telescope
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch everything (tags)
- name: Set tag version
run: echo "VERSION_TAG=$(git describe --tags --abbrev=4)" >> $GITHUB_ENV

- id: determine_tag
name: determine tag
run: |-
TAG=$(git describe --tags)
printf "\e[1;36m[INFO]\e[0m \$TAG=\"${TAG}\"\n"
echo TAG=${TAG} >> ${GITHUB_OUTPUT}

- name: Build `version.json` file
run: |
printf '{\n "commit": "%s",\n "version": "%s",\n "source": "%s",\n "build": "%s"\n}\n' \
"$GITHUB_SHA" \
"$VERSION_TAG" \
"${{ steps.determine_tag.outputs.TAG }}" \
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" > ./version.json
cat version.json
Expand All @@ -36,12 +46,33 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
images: |
${{ env.DOCKERHUB_IMAGE_NAME }}
${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE }}
# https://github.com/marketplace/actions/docker-metadata-action#tags-input
tags: |
type=semver,pattern={{raw}}
type=raw,value=latest,enable={{is_default_branch}}
type=sha,enable={{is_default_branch}}
type=raw,value=latest
type=raw,value=${{ steps.determine_tag.outputs.TAG }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- id: gcp_auth
name: gcp auth
if: github.event_name != 'pull_request'
uses: google-github-actions/auth@v2
with:
token_format: access_token
service_account: artifact-writer@${{ env.GCP_PROJECT_ID }}.iam.gserviceaccount.com
workload_identity_provider: ${{ vars.GCPV2_GITHUB_WORKLOAD_IDENTITY_PROVIDER }}

- name: Login to GAR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.gcp_auth.outputs.access_token }}

- name: Login to Docker Hub
if: github.event_name != 'pull_request'
Expand All @@ -56,14 +87,14 @@ jobs:
context: .
load: true
push: false
tags: ${{ env.IMAGE_NAME }}:test
tags: ${{ env.DOCKERHUB_IMAGE_NAME }}:test

- name: Test from Docker
run: |
docker run \
--name ${{ env.TEST_CONTAINER_NAME }}-test \
--user root \
${{ env.IMAGE_NAME }}:test \
${{ env.DOCKERHUB_IMAGE_NAME }}:test \
test

- name: Spin up container
Expand All @@ -73,7 +104,7 @@ jobs:
--detach \
--env CONFIG_FILE=/app/tests/checks/remotesettings/config.toml \
--publish 8000:8000 \
${{ env.IMAGE_NAME }}:test
${{ env.DOCKERHUB_IMAGE_NAME }}:test

- name: Check that container is running
run: |
Expand All @@ -90,3 +121,5 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
Loading