Skip to content

Commit

Permalink
ci: use docker-compose stack for pytest workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Oct 15, 2023
1 parent f6a4401 commit 55165df
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 60 deletions.
95 changes: 37 additions & 58 deletions .github/workflows/r-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,67 +18,46 @@ jobs:
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment || 'test' }}
env:
ODK_CENTRAL_PASSWD: ${{ secrets.ODK_CENTRAL_PASSWD }}
OSM_CLIENT_ID: ${{ secrets.OSM_CLIENT_ID }}
OSM_CLIENT_SECRET: ${{ secrets.OSM_CLIENT_SECRET }}
OSM_SECRET_KEY: ${{ secrets.OSM_SECRET_KEY }}

container:
image: ghcr.io/hotosm/fmtm/backend:${{ inputs.image_tag }}
env:
ODK_CENTRAL_URL: ${{ vars.ODK_CENTRAL_URL }}
ODK_CENTRAL_USER: ${{ vars.ODK_CENTRAL_USER }}
ODK_CENTRAL_PASSWD: ${{ env.ODK_CENTRAL_PASSWD }}
OSM_CLIENT_ID: ${{ env.OSM_CLIENT_ID }}
OSM_CLIENT_SECRET: ${{ env.OSM_CLIENT_SECRET }}
OSM_SECRET_KEY: ${{ env.OSM_SECRET_KEY }}
FRONTEND_MAIN_URL: ${{ vars.FRONTEND_MAIN_URL }}
options: --add-host central-proxy:127.0.0.1
extract-vars:
uses: ./.github/workflows/r-extract_vars.yml
with:
environment: ${{ inputs.environment || 'test' }}

services:
# Start backend database
fmtm-db:
image: "postgis/postgis:14-3.3-alpine"
env:
POSTGRES_PASSWORD: fmtm
POSTGRES_DB: fmtm
POSTGRES_USER: fmtm
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
# Start ODK Central database
central-db:
image: "postgis/postgis:14-3.3-alpine"
env:
POSTGRES_PASSWORD: odk
POSTGRES_DB: odk
POSTGRES_USER: odk
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
run-pytest:
runs-on: ubuntu-latest
needs: [extract-vars]
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Start ODK Central
central:
image: "ghcr.io/hotosm/fmtm/odkcentral:v2023.2.1"
- name: Environment to .env
env:
SYSADMIN_EMAIL: ${{ vars.ODK_CENTRAL_USER }}
SYSADMIN_PASSWD: ${{ secrets.ODK_CENTRAL_PASSWD }}
DB_HOST: central-db

# Start proxy to access ODK Central
central-proxy:
image: "ghcr.io/hotosm/fmtm/odkcentral-proxy:latest"
ports:
- 80:80
API_VERSION: ${{ needs.extract-vars.outputs.api_version }}
FRONTEND_MAIN_VERSION: ${{ needs.extract-vars.outputs.frontend_main_version }}
FRONTEND_MAIN_URL: ${{ vars.FRONTEND_MAIN_URL }}
ODK_CENTRAL_URL: ${{ vars.ODK_CENTRAL_URL }}
ODK_CENTRAL_USER: ${{ vars.ODK_CENTRAL_USER }}
ODK_CENTRAL_PASSWD: ${{ secrets.ODK_CENTRAL_PASSWD }}
OSM_CLIENT_ID: ${{ secrets.OSM_CLIENT_ID }}
OSM_CLIENT_SECRET: ${{ secrets.OSM_CLIENT_SECRET }}
OSM_SECRET_KEY: ${{ secrets.OSM_SECRET_KEY }}
run: |
echo "APP_VERSION=${API_VERSION}" >> .env
echo "API_TAG_OVERRIDE=${{ inputs.image_tag }}" >> .env
echo "FRONTEND_MAIN_VERSION=${FRONTEND_MAIN_VERSION}" >> .env
echo "FRONTEND_MAIN_URL=${FRONTEND_MAIN_URL}" >> .env
echo "ODK_CENTRAL_URL=${ODK_CENTRAL_URL}" >> .env
echo "ODK_CENTRAL_USER=${ODK_CENTRAL_USER}" >> .env
echo "ODK_CENTRAL_PASSWD=${ODK_CENTRAL_PASSWD}" >> .env
echo "OSM_CLIENT_ID=${OSM_CLIENT_ID}" >> .env
echo "OSM_CLIENT_SECRET=${OSM_CLIENT_SECRET}" >> .env
echo "OSM_SECRET_KEY=${OSM_SECRET_KEY}" >> .env
- name: Start Services
run: |
cd src/backend
docker compose up api --detach
steps:
- uses: actions/checkout@v4
- name: Run pytest
working-directory: src/backend
run: pytest
run: docker exec fmtm_api pytest
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ services:
restart: "unless-stopped"

api:
image: "ghcr.io/hotosm/fmtm/backend:debug"
image: "ghcr.io/hotosm/fmtm/backend:${API_TAG_OVERRIDE:-debug}"
build:
context: src/backend
target: debug-with-odk
args:
APP_VERSION: debug
APP_VERSION: "${APP_VERSION:-debug}"
container_name: fmtm_api
# Uncomment these to debug with a terminal debugger like pdb
# Then `docker attach fmtm_api` to debug
Expand All @@ -61,6 +61,7 @@ services:
- fmtm_images:/opt/app/images
- fmtm_tiles:/opt/tiles
- ./src/backend/app:/opt/app
- ./src/backend/tests:/opt/tests
# - ../osm-fieldwork/osm_fieldwork:/home/appuser/.local/lib/python3.10/site-packages/osm_fieldwork
depends_on:
- fmtm-db
Expand Down

0 comments on commit 55165df

Please sign in to comment.