Skip to content

Feat: SBMTD infra pipeline (#349) #158

Feat: SBMTD infra pipeline (#349)

Feat: SBMTD infra pipeline (#349) #158

Workflow file for this run

name: Deploy
on:
workflow_dispatch:
push:
branches:
- dev
- test
- prod
release:
types:
- published
defaults:
run:
shell: bash
concurrency:
# this expression gives us the name of the deployment environment. It works like a ternary operation (see https://github.com/actions/runner/issues/409#issuecomment-727565588)
group: ${{ github.event_name != 'release' && github.ref_name || github.event.release.prerelease && 'test' || 'prod' }}
cancel-in-progress: true
jobs:
test:
uses: ./.github/workflows/run-tests.yml
if: github.event_name == 'release'
deploy:
needs: test
# !cancelled() is needed because if the whole workflow was cancelled, we don't want this job to run.
# (github.event_name != 'release' || needs.test.result == 'success') is needed because if `test` did run, we only want this to run if `test` succeeded.
if: (!cancelled() && (github.event_name != 'release' || needs.test.result == 'success'))
runs-on: ubuntu-latest
environment: ${{ github.event_name != 'release' && github.ref_name || github.event.release.prerelease && 'test' || 'prod' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version-file: .github/workflows/.python-version
cache: pip
cache-dependency-path: "**/pyproject.toml"
- name: Create /static directory
run: mkdir -p eligibility_server/static
- name: Write python packages to file
run: |
python -m venv .venv
source .venv/bin/activate
pip install pipdeptree
pip install -e .
pipdeptree
pipdeptree >> eligibility_server/static/requirements.txt
- name: Write commit SHA to file
run: echo "${{ github.sha }}" >> eligibility_server/static/sha.txt
- name: Docker Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Build, tag, and push image to GitHub Container Registry
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx.outputs.name }}
build-args: GIT-SHA=${{ github.sha }}
cache-from: type=gha,scope=cal-itp
cache-to: type=gha,scope=cal-itp,mode=max
context: .
file: Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ github.event_name != 'release' && github.ref_name || github.event.release.prerelease && 'test' || 'prod' }}
ghcr.io/${{ github.repository }}:${{ github.ref_name }}
ghcr.io/${{ github.repository }}:${{ github.sha }}