Skip to content

ci: update build workflows to use image caching, multi-arch, auto-tag… #437

ci: update build workflows to use image caching, multi-arch, auto-tag…

ci: update build workflows to use image caching, multi-arch, auto-tag… #437

# Workflow for build and auto-deploy of branches
name: Build and Deploy
on:
# Push includes PR merge
push:
branches:
- main
- staging
- development
paths:
# Workflow is triggered only if src changes
- src/**
# Allow manual trigger
workflow_dispatch:
jobs:
pytest:
uses: hotosm/gh-workflows/.github/workflows/test_pytest_compose.yml@main
with:
image_name: ghcr.io/${{ github.repository }}/backend
build_context: src/backend
build_args: |
APP_VERSION=${{ github.ref_name }}
COMMIT_REF=${{ github.sha }}
docker_compose_service: api
tag_override: ci-${{ github.ref_name }}
secrets: inherit
frontend-tests:
uses: hotosm/gh-workflows/.github/workflows/test_pnpm.yml@main
with:
working_dir: src/frontend
backend-build:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@main
with:
context: src/backend
build_target: prod
image_name: ghcr.io/${{ github.repository }}/backend
build_args: |
APP_VERSION=${{ github.ref_name }}
COMMIT_REF=${{ github.sha }}
frontend-main-build:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@main
with:
context: src/frontend
dockerfile: prod.dockerfile
build_target: prod
image_name: ghcr.io/${{ github.repository }}/frontend
build_args: |
APP_VERSION=${{ github.ref_name }}
COMMIT_REF=${{ github.sha }}
VITE_API_URL=${{ vars.URL_SCHEME }}://${{ vars.API_URL }}"
smoke-test-backend:
runs-on: ubuntu-latest
needs:
- backend-build
environment:
name: ${{ github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Vars and Secrets to Env
env:
GIT_BRANCH: ${{ github.ref_name }}
VARS_CONTEXT: ${{ toJson(vars) }}
SECRETS_CONTEXT: ${{ toJson(secrets) }}
run: |
to_envs() { jq -r "to_entries[] | \"\(.key)=\(.value)\""; }
echo "GIT_BRANCH=${GIT_BRANCH}" >> $GITHUB_ENV
echo "${VARS_CONTEXT}" | to_envs >> $GITHUB_ENV
echo "${SECRETS_CONTEXT}" | to_envs >> $GITHUB_ENV
- name: Create .env file
run: env > .env
- name: Backend smoke test
run: |
docker compose up -d api --wait --wait-timeout 60
smoke-test-frontend:
runs-on: ubuntu-latest
needs:
- frontend-main-build
environment:
name: ${{ github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Frontend smoke test
run: echo "Not implemented"
deploy-containers:
needs:
- smoke-test-backend
- smoke-test-frontend
uses: hotosm/gh-workflows/.github/workflows/remote_deploy.yml@main
with:
environment: ${{ github.ref_name }}
docker_compose_file: "docker-compose.${{ github.ref_name }}.yml"
secrets: inherit