|
| 1 | +name: Build, test and push a Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - v20[0-9][0-9].[01][0-9].[0-3][0-9] # e.g. v2023.12.04 |
| 9 | + - v20[0-9][0-9].[01][0-9].[0-3][0-9]-[0-9] # e.g. v2023.12.04-2 |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - main |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + permissions: |
| 17 | + contents: read |
| 18 | + deployments: write |
| 19 | + id-token: write |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + - name: Get info |
| 24 | + run: | |
| 25 | + uname -v |
| 26 | + docker info |
| 27 | + - name: Create version.json |
| 28 | + run: | |
| 29 | + # create a version.json per |
| 30 | + # https://github.com/mozilla-services/Dockerflow/blob/master/docs/version_object.md |
| 31 | + printf '{"commit":"%s","version":"%s","source":"%s","build":"%s"}\n' \ |
| 32 | + "$GITHUB_SHA" \ |
| 33 | + "$GITHUB_REF_NAME" \ |
| 34 | + "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ |
| 35 | + "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" > version.json |
| 36 | + - name: Output version.json |
| 37 | + run: cat version.json |
| 38 | + - name: Build Docker images |
| 39 | + run: | |
| 40 | + make build |
| 41 | + docker compose images |
| 42 | + - name: Verify requirements.txt contains correct dependencies |
| 43 | + run: | |
| 44 | + docker run --rm local/socorro_app shell ./bin/run_verify_reqs.sh |
| 45 | + - name: Run lint check |
| 46 | + run: | |
| 47 | + docker run --rm local/socorro_app shell ./bin/lint.sh |
| 48 | + - name: Run tests |
| 49 | + run: | |
| 50 | + make my.env |
| 51 | + docker compose run --rm test-ci shell ./bin/test.sh |
| 52 | +
|
| 53 | + - name: Set Docker image tag to "latest" for updates of the main branch |
| 54 | + if: github.ref == 'refs/heads/main' |
| 55 | + run: | |
| 56 | + echo IMAGE_TAG=latest >> "$GITHUB_ENV" |
| 57 | + # Updates to the main branch are deployed to stage. |
| 58 | + echo DEPLOYMENT_ENV=stage >> "$GITHUB_ENV" |
| 59 | + - name: Set Docker image tag to the git tag for tagged builds |
| 60 | + if: startsWith(github.ref, 'refs/tags/') |
| 61 | + run: | |
| 62 | + echo IMAGE_TAG="$GITHUB_REF_NAME" >> "$GITHUB_ENV" |
| 63 | + # Version tags are deployed to prod. |
| 64 | + echo DEPLOYMENT_ENV=prod >> "$GITHUB_ENV" |
| 65 | + - name: Push the Docker image to GAR |
| 66 | + if: env.IMAGE_TAG != '' |
| 67 | + uses: mozilla-it/deploy-actions/docker-push@v3.11.1 |
| 68 | + with: |
| 69 | + local_image: local/socorro_app:latest |
| 70 | + image_repo_path: ${{ secrets.DOCKER_IMAGE_PATH }} |
| 71 | + image_tag: ${{ env.IMAGE_TAG }} |
| 72 | + workload_identity_pool_project_number: ${{ secrets.WORKLOAD_IDENTITY_POOL_PROJECT_NUMBER }} |
| 73 | + project_id: ${{ secrets.GCP_PROJECT_ID }} |
| 74 | + deployment_env: ${{ env.DEPLOYMENT_ENV }} |
0 commit comments