From 55165df5e3bebf8507349937deb358c8e188e086 Mon Sep 17 00:00:00 2001 From: spwoodcock Date: Sun, 15 Oct 2023 17:50:46 +0100 Subject: [PATCH] ci: use docker-compose stack for pytest workflow --- .github/workflows/r-pytest.yml | 95 +++++++++++++--------------------- docker-compose.yml | 5 +- 2 files changed, 40 insertions(+), 60 deletions(-) diff --git a/.github/workflows/r-pytest.yml b/.github/workflows/r-pytest.yml index 8253090da4..cb8bd9b541 100644 --- a/.github/workflows/r-pytest.yml +++ b/.github/workflows/r-pytest.yml @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 887c1bd490..ebfecc6cf3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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