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

Update build workflows to use image caching, multi-arch, auto-tag #925

Merged
merged 69 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
07d4678
refactor: move scripts & josm to contrib dir
spwoodcock Oct 19, 2023
b263ef4
ci: add contrib label to labeler.yml
spwoodcock Oct 19, 2023
e316941
ci: separate frontend and backend tests during pr
spwoodcock Oct 19, 2023
de42945
ci: remove extract-vars (use auto-tagging)
spwoodcock Oct 19, 2023
0fc06ee
build: update dockerfiles and compose to use COMMIT_REFs
spwoodcock Oct 19, 2023
4156fd6
ci: build backend images on tag and release events
spwoodcock Oct 19, 2023
1d9c022
ci: publish docs on changes to development branch
spwoodcock Oct 19, 2023
962752e
build: set default S3_ENDPOINT for entrypoint (if not set)
spwoodcock Oct 19, 2023
65acea7
build: add healthchecks to dockerfiles
spwoodcock Oct 19, 2023
d0fb4c6
ci: enable backend smoketest using compose --wait
spwoodcock Oct 19, 2023
f95787f
build: update odkcentral --> v2023.4.0
spwoodcock Oct 19, 2023
8b80645
build: healthcheck for minio service
spwoodcock Oct 19, 2023
ab8ce15
ci(pytest): update pytest workflow to use img artifacts
spwoodcock Oct 19, 2023
37c1796
build: update odkcentral img, add entrypoint + healthcheck
spwoodcock Oct 19, 2023
ae16d40
ci: fix pytest img tar downloading
spwoodcock Oct 19, 2023
293f2df
ci(pytest): fix cached image loading from /tmp
spwoodcock Oct 19, 2023
995f7f7
ci(pytest): simplify image caching and loading
spwoodcock Oct 19, 2023
fdacf0a
ci(pytest): remove image cache upload
spwoodcock Oct 19, 2023
fd0053f
ci(pytest): add image cache job to end of workflow
spwoodcock Oct 19, 2023
349316c
ci(pytest): set cache loading based on needs outputs
spwoodcock Oct 19, 2023
426a84f
ci(pytest): cache images if download was unsuccessful
spwoodcock Oct 19, 2023
2b59aef
ci(pytest): fix operator !=
spwoodcock Oct 19, 2023
d2c870f
build: use env vars for all image versions
spwoodcock Oct 20, 2023
bca417c
build: ODK_CENTRAL_VERSION --> ODK_CENTRAL_TAG
spwoodcock Oct 20, 2023
6923ca0
ci(pytest): set image tags for caching from github vars
spwoodcock Oct 20, 2023
871f07b
ci: replace deploy workflow with reusable
spwoodcock Oct 20, 2023
884a78f
ci(pytest): image caching cache_name --> artifact_name
spwoodcock Oct 20, 2023
e91ea5c
ci(deploy): set .env from var and secrets context (not manual)
spwoodcock Oct 20, 2023
6f76e2a
ci(pytest): increase timeout for central wait-for-it 30s
spwoodcock Oct 20, 2023
ba1d995
ci(pytest): fix timeout syntax
spwoodcock Oct 20, 2023
c83a3b3
build: add shebang to odkcentral entrypoint script
spwoodcock Oct 20, 2023
542ff18
ci: update env to .env for pytest
spwoodcock Oct 20, 2023
6d2802e
ci(pytest): remove additional -alpine from postgis img
spwoodcock Oct 20, 2023
cd8da20
build: redact password in odk-central entrypoint
spwoodcock Oct 20, 2023
222aa39
ci: fix to_envs single .env file parsing
spwoodcock Oct 20, 2023
d64ba4c
ci: pass env var directly to jq, not github var
spwoodcock Oct 20, 2023
2b7c3b9
ci(pytest): fix by using scalar over literal syntax
spwoodcock Oct 20, 2023
79b2d26
build: hardcode WORKER_COUNT=1 for odk-central start
spwoodcock Oct 20, 2023
894cfce
ci: update docs workflow to use new cahcing
spwoodcock Oct 20, 2023
be175c3
docs: update info for testing workflows via act
spwoodcock Oct 20, 2023
70ff49d
ci(pytest): add caching img steps directly to workflow (no reuse)
spwoodcock Oct 20, 2023
3b1ae5e
ci(pytest): typo image --> images for cache key
spwoodcock Oct 20, 2023
8e57e49
refactor: pydantic deprecation FIeldValidationInfo --> ValidationInfo
spwoodcock Oct 20, 2023
2c0b2db
ci: rewrite pytest to build pr image prior to test
spwoodcock Oct 20, 2023
83b5c2c
ci: don't push,cache,multi_arch PR image builds
spwoodcock Oct 20, 2023
d1aa451
ci: add permissions: write to pytest build + scan=false
spwoodcock Oct 20, 2023
78f054a
ci: remove permissions from pytest (handle downstream)
spwoodcock Oct 20, 2023
663ad01
ci: update conditionals for building pr images
spwoodcock Oct 20, 2023
cfe9c1f
ci: update pytest cache-hit output
spwoodcock Oct 20, 2023
14ea453
ci: get image_tag instead of image_name from output
spwoodcock Oct 20, 2023
149c154
ci(pytest): fix case where cache hit, skip build
spwoodcock Oct 20, 2023
2b3c540
ci(pytest): set BACKEND_IMG_TAG in all if cases
spwoodcock Oct 20, 2023
5779aa6
ci(pytest): replace BACKEND_IMG_TAG --> API_TAG_OVERRIDE
spwoodcock Oct 20, 2023
8c0118c
ci(pytest): fix getting backend image tag from docker img ls
spwoodcock Oct 22, 2023
f18ad1a
ci(pytest): only run image caching steps if explicity cache=false
spwoodcock Oct 22, 2023
9f8f8b9
ci(pytest): revert ==false to !=true negation
spwoodcock Oct 22, 2023
33123ee
ci: replace all refs to repo with gh vars
spwoodcock Oct 22, 2023
406dd72
ci(pytest): prep pytest for moving to gh-workflows
spwoodcock Oct 22, 2023
3ec3c0d
ci(pytest): test with caching off
spwoodcock Oct 22, 2023
814b5e0
ci(pytest): remove redundant var build_test_img
spwoodcock Oct 22, 2023
afc3188
ci(pytest): fix "" workflow syntax --> ''
spwoodcock Oct 22, 2023
0b5c008
ci(pytest): quote ci-development fallback
spwoodcock Oct 22, 2023
4aa8451
ci(pytest): move where default ci-development tag is set
spwoodcock Oct 22, 2023
9ec6cee
ci(pytest): reenable caching for workflow images
spwoodcock Oct 22, 2023
99dd6cb
ci(pytest): inputs.cache_imgs to array
spwoodcock Oct 22, 2023
9cc4c79
ci(pytest): allow passing of image_tag to image build stage
spwoodcock Oct 22, 2023
35cdf24
ci: replace all reusable workflows with hotosm/gh-workflows
spwoodcock Oct 22, 2023
f8cd157
ci(pytest): use new format of reusable pytest workflow
spwoodcock Oct 22, 2023
d82cb13
build: rename API_TAG_OVERRIDE --> TAG_OVERRIDE
spwoodcock Oct 22, 2023
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
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
### copy to .env and set variables

### ODK Central ###
ODK_CENTRAL_VERSION=v2023.2.1
ODK_CENTRAL_URL=https://central-proxy
ODK_CENTRAL_USER=dev@fmtm.hotosm.org
ODK_CENTRAL_PASSWD=testuserpassword
Expand Down
3 changes: 2 additions & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
- "**/Dockerfile"
- "**/*.dockerfile"
- "**/*entrypoint.sh"
- "josm/**/*"
"migration":
- "src/backend/migrations/**/*"
"documentation":
Expand All @@ -20,3 +19,5 @@
- "INSTALL.md"
"ODK":
- "odkcentral/**/*"
"contrib":
- "contrib/**/*"
131 changes: 36 additions & 95 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Workflow for build and auto-deploy of branches

name: Build and Deploy

on:
Expand All @@ -15,52 +17,47 @@ on:

jobs:
pytest:
uses: ./.github/workflows/r-pytest.yml
uses: hotosm/gh-workflows/.github/workflows/test_pytest_compose.yml@main
with:
image_tag: ci-${{ github.ref_name }}
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: ./.github/workflows/r-frontend_tests.yml

extract-vars:
needs:
- pytest
- frontend-tests
uses: ./.github/workflows/r-extract_vars.yml
uses: hotosm/gh-workflows/.github/workflows/test_pnpm.yml@main
with:
environment: ${{ github.ref_name }}
working_dir: src/frontend

backend-build:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@main
needs: [extract-vars]
with:
context: src/backend
build_target: prod
image_tags: |
"ghcr.io/hotosm/fmtm/backend:${{ needs.extract-vars.outputs.api_version }}-${{ github.ref_name }}"
"ghcr.io/hotosm/fmtm/backend:latest"
image_name: ghcr.io/${{ github.repository }}/backend
build_args: |
APP_VERSION=${{ needs.extract-vars.outputs.api_version }}
APP_VERSION=${{ github.ref_name }}
COMMIT_REF=${{ github.sha }}

frontend-main-build:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@main
needs: [extract-vars]
with:
context: src/frontend
dockerfile: prod.dockerfile
build_target: prod
image_tags: |
"ghcr.io/hotosm/fmtm/frontend:${{ needs.extract-vars.outputs.frontend_main_version }}-${{ github.ref_name }}"
"ghcr.io/hotosm/fmtm/frontend:latest"
image_name: ghcr.io/${{ github.repository }}/frontend
build_args: |
APP_VERSION=${{ needs.extract-vars.outputs.frontend_main_version }}
VITE_API_URL=${{ needs.extract-vars.outputs.api_url }}
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:
- extract-vars
- backend-build
environment:
name: ${{ github.ref_name }}
Expand All @@ -69,55 +66,28 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Environment to .env
- name: Vars and Secrets to Env
env:
GIT_BRANCH: ${{ github.ref_name }}
API_VERSION: ${{ needs.extract-vars.outputs.api_version }}
FRONTEND_MAIN_VERSION: ${{ needs.extract-vars.outputs.frontend_main_version }}
VARS_CONTEXT: ${{ toJson(vars) }}
SECRETS_CONTEXT: ${{ toJson(secrets) }}
run: |
echo "${{ secrets.DOTENV }}" > .env
echo "GIT_BRANCH=${GIT_BRANCH}" >> .env
echo "API_VERSION=${API_VERSION}" >> .env
echo "FRONTEND_MAIN_VERSION=${FRONTEND_MAIN_VERSION}" >> .env
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: |
echo "Not implemented"
# source .env
# docker network create fmtm

# docker pull "postgis/postgis:14-3.3-alpine"
# docker run --rm -d \
# --name=fmtm-db \
# --network=fmtm \
# -e POSTGRES_USER=fmtm \
# -e POSTGRES_PASSWORD=fmtm \
# -e POSTGRES_DB=fmtm \
# "postgis/postgis:14-3.3-alpine"

# docker pull "ghcr.io/hotosm/fmtm/backend:${API_VERSION}-${GIT_BRANCH}"
# docker run --rm -d \
# --network=fmtm \
# -p 8080:8080 \
# -e OSM_CLIENT_ID="test" \
# -e OSM_CLIENT_SECRET="test" \
# -e OSM_SECRET_KEY="test" \
# -e S3_ACCESS_KEY="fmtm" \
# -e S3_SECRET_KEY="somelongpassword" \
# "ghcr.io/hotosm/fmtm/backend:${API_VERSION}-${GIT_BRANCH}"

# # First wait 10 seconds for API
# sleep 10
# # Check the exit status of curl and exit the job if it fails
# if ! curl -f http://localhost:8080/docs; then
# echo "curl failed to access http://localhost:8080/docs"
# exit 1
# fi
docker compose up -d api --wait --wait-timeout 60

smoke-test-frontend:
runs-on: ubuntu-latest
needs:
- extract-vars
- frontend-main-build
environment:
name: ${{ github.ref_name }}
Expand All @@ -130,40 +100,11 @@ jobs:
run: echo "Not implemented"

deploy-containers:
runs-on: ubuntu-latest
needs:
- extract-vars
- smoke-test-backend
- smoke-test-frontend
environment:
name: ${{ github.ref_name }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Environment to .env
env:
GIT_BRANCH: ${{ github.ref_name }}
API_VERSION: ${{ needs.extract-vars.outputs.api_version }}
FRONTEND_MAIN_VERSION: ${{ needs.extract-vars.outputs.frontend_main_version }}
run: |
echo "${{ secrets.DOTENV }}" > .env
echo "GIT_BRANCH=${GIT_BRANCH}" >> .env
echo "API_VERSION=${API_VERSION}" >> .env
echo "FRONTEND_MAIN_VERSION=${FRONTEND_MAIN_VERSION}" >> .env

- uses: webfactory/ssh-agent@v0.7.0
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Disable Host key verification
# Hack to prevent "Host key verification failed". Should be replaced with a ssh-keyscan based solution
run: echo "StrictHostKeyChecking no" >> ~/.ssh/config

- name: Deploy
run: |
docker compose --file "docker-compose.${{ github.ref_name }}.yml" pull
docker compose --file "docker-compose.${{ github.ref_name }}.yml" up --detach --remove-orphans
env:
DOCKER_HOST: ${{ vars.DOCKER_HOST }}
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
10 changes: 3 additions & 7 deletions .github/workflows/build_ci_img.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ on:
workflow_dispatch:

jobs:
extract-vars:
uses: ./.github/workflows/r-extract_vars.yml

backend-ci-build:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@main
needs: [extract-vars]
with:
context: src/backend
build_target: ci
image_tags: |
"ghcr.io/hotosm/fmtm/backend:${{ needs.extract-vars.outputs.api_version }}-ci-${{ github.ref_name }}"
"ghcr.io/hotosm/fmtm/backend:ci-${{ github.ref_name }}"
"ghcr.io/${{ github.repository }}/backend:ci-${{ github.ref_name }}"
build_args: |
APP_VERSION=${{ needs.extract-vars.outputs.api_version }}
APP_VERSION=${{ github.ref_name }}
COMMIT_REF=${{ github.sha }}
10 changes: 5 additions & 5 deletions .github/workflows/build_odk_imgs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
with:
context: odkcentral/api
image_tags: |
"ghcr.io/hotosm/fmtm/odkcentral:${{ vars.ODK_CENTRAL_VERSION }}"
"ghcr.io/hotosm/fmtm/odkcentral:latest"
"ghcr.io/${{ github.repository }}/odkcentral:${{ vars.ODK_CENTRAL_TAG }}"
"ghcr.io/${{ github.repository }}/odkcentral:latest"
build_args: |
ODK_CENTRAL_VERSION=${{ vars.ODK_CENTRAL_VERSION }}
ODK_CENTRAL_TAG=${{ vars.ODK_CENTRAL_TAG }}

build-proxy:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@main
with:
context: odkcentral/proxy
image_tags: |
"ghcr.io/hotosm/fmtm/odkcentral-proxy:${{ vars.ODK_CENTRAL_VERSION }}"
"ghcr.io/hotosm/fmtm/odkcentral-proxy:latest"
"ghcr.io/${{ github.repository }}/odkcentral-proxy:${{ vars.ODK_CENTRAL_TAG }}"
"ghcr.io/${{ github.repository }}/odkcentral-proxy:latest"
22 changes: 7 additions & 15 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,29 @@ on:
- docs/**
- src/**
- mkdocs.yml
branches: [main]
branches: [development]
# Allow manual trigger (workflow_dispatch)
workflow_dispatch:

jobs:
build_doxygen:
uses: hotosm/gh-workflows/.github/workflows/doxygen_build.yml@main
with:
cache_paths: |
docs/apidocs
docs/openapi.json
cache_key: docs-build
output_path: docs/apidocs

build_openapi_json:
uses: hotosm/gh-workflows/.github/workflows/openapi_build.yml@main
with:
image: ghcr.io/hotosm/fmtm/backend:ci-${{ github.ref_name }}
image: ghcr.io/${{ github.repository }}/backend:ci-${{ github.ref_name }}
example_env_file_path: ".env.example"
cache_paths: |
docs/apidocs
docs/openapi.json
cache_key: docs-build
output_path: docs/openapi.json

publish_docs:
uses: hotosm/gh-workflows/.github/workflows/mkdocs_build.yml@main
needs:
- build_doxygen
- build_openapi_json
with:
image: ghcr.io/hotosm/fmtm/backend:ci-${{ github.ref_name }}
cache_paths: |
docs/apidocs
docs/openapi.json
cache_key: docs-build
image: ghcr.io/${{ github.repository }}/backend:ci-${{ github.ref_name }}
doxygen: true
openapi: true
23 changes: 0 additions & 23 deletions .github/workflows/pr_test.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/pr_test_backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: PR Test Backend

on:
pull_request:
branches:
- main
- staging
- development
# Workflow is triggered only if src/backend changes
paths:
- src/backend/**
# Allow manual trigger (workflow_dispatch)
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
cache_extra_imgs: |
"docker.io/postgis/postgis:${{ vars.POSTGIS_TAG }}"
"docker.io/minio/minio:${{ vars.MINIO_TAG }}"
# For caching odk central images, add:
# "ghcr.io/${{ github.repository }}/odkcentral:${{ vars.ODK_CENTRAL_TAG }}"
# "ghcr.io/${{ github.repository }}/odkcentral-proxy:${{ vars.ODK_CENTRAL_TAG }}"
secrets: inherit
19 changes: 19 additions & 0 deletions .github/workflows/pr_test_frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: PR Tests Frontend

on:
pull_request:
branches:
- main
- staging
- development
# Workflow is triggered only if src/frontend changes
paths:
- src/frontend/**
# Allow manual trigger (workflow_dispatch)
workflow_dispatch:

jobs:
frontend-tests:
uses: hotosm/gh-workflows/.github/workflows/test_pnpm.yml@main
with:
working_dir: src/frontend
Loading
Loading