Generate deployment events after building a Docker image. #21
This file contains 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
name: Build, test and push a Docker image | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- '*' | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
environment: build | |
permissions: | |
contents: read | |
deployments: write | |
id-token: write | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Get info | |
run: | | |
uname -v | |
docker info | |
- name: Create version.json | |
run: | | |
# create a version.json per | |
# https://github.com/mozilla-services/Dockerflow/blob/master/docs/version_object.md | |
printf '{"commit":"%s","version":"%s","source":"%s","build":"%s"}\n' \ | |
"$GITHUB_SHA" \ | |
"$GITHUB_REF_NAME" \ | |
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ | |
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" > version.json | |
- name: Output version.json | |
run: cat version.json | |
- name: Build Docker images | |
run: make build | |
- name: Verify requirements.txt contains correct dependencies | |
run: | | |
docker compose run --rm --no-deps test-ci bash ./bin/run_verify_reqs.sh | |
- name: Run lint check | |
run: | | |
make .env | |
docker compose run --rm --no-deps test-ci bash ./bin/run_lint.sh | |
- name: Run Eliot tests | |
run: | | |
docker compose up -d fakesentry statsd | |
docker compose run --rm test-ci bash ./bin/run_test.sh eliot | |
- name: Build docs | |
run: | | |
docker compose run --rm --no-deps test-ci bash make -C docs/ html | |
- name: Set Docker image tag to "latest" for updates of the main branch | |
if: github.ref == 'refs/heads/main' | |
run: | | |
echo IMAGE_TAG=latest >> "$GITHUB_ENV" | |
# Updates to the main branch are deployed to stage. | |
echo DEPLOYMENT_ENV=stage >> "$GITHUB_ENV" | |
- name: Set Docker image tag to the git tag for tagged builds | |
if: startsWith(github.ref, 'refs/tags/') | |
run: | | |
echo IMAGE_TAG="$GITHUB_REF_NAME" >> "$GITHUB_ENV" | |
if [[ $GITHUB_REF_NAME =~ ^v[0-9]{4}.[0-9]{2}.[0-9]{2} ]]; then | |
# Version tags are deployed to prod. | |
echo DEPLOYMENT_ENV=prod >> "$GITHUB_ENV" | |
else | |
# Other tags are not deployed at all. | |
echo DEPLOYMENT_ENV="" >> "$GITHUB_ENV" | |
fi | |
- name: Push the Docker image to GAR | |
if: env.IMAGE_TAG != '' | |
uses: mozilla-it/deploy-actions/docker-push@main | |
with: | |
local_image: eliot:build | |
image_repo_path: ${{ secrets.DOCKER_IMAGE_PATH }} | |
image_tag: ${{ env.IMAGE_TAG }} | |
workload_identity_pool_project_number: ${{ secrets.WORKLOAD_IDENTITY_POOL_PROJECT_NUMBER }} | |
project_id: ${{ secrets.GCP_PROJECT_ID }} | |
deployment_env: ${{ env.DEPLOYMENT_ENV }} |