Skip to content

updates Dockerfile

updates Dockerfile #85

Workflow file for this run

name: Test
on:
push:
branches:
- develop
- master
- staging
- release/*
- feature/*
- bugfix/*
- hotfix/*
# pull_request:
# branches: [ develop, master ]
# types: [ synchronize, opened, reopened, ready_for_review ]
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
defaults:
run:
shell: bash
permissions:
id-token: write
attestations: write
jobs:
changes:
if: (github.event_name != 'pull_request'
|| github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name)
|| github.event_name == 'create'
runs-on: ubuntu-latest
timeout-minutes: 1
defaults:
run:
shell: bash
outputs:
run_tests: ${{ steps.changes.outputs.run_tests }}
steps:
- name: Checkout code
uses: actions/checkout@v4.1.7
- id: changes
name: Check for file changes
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
with:
base: ${{ github.ref }}
token: ${{ github.token }}
filters: .github/file-filters.yml
test:
needs: [ changes ]
if: needs.changes.outputs.run_tests == 'true'
runs-on: ubuntu-latest
services:
redis:
image: redis
ports:
- 16379:6379
db:
image: postgres:14
env:
POSTGRES_DATABASE: country_workspace
POSTGRES_PASSWORD: postgres
POSTGRES_USERNAME: postgres
ports:
- 15432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
DOCKER_DEFAULT_PLATFORM: linux/amd64
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
DATABASE_URL: postgres://postgres:postgres@localhost:15432/country_workspace
CELERY_BROKER_URL: redis://localhost:16379/0"
CACHE_URL: redis://localhost:16379/0
DOCKER_BUILDKIT: 1
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Hack container for local development
if: ${{ env.ACT }}
run: |
echo /home/runner/externals/node20/bin >> $GITHUB_PATH
- name: Hack container for local development
run: |
echo BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5.5.1
with:
images: "unicef/hope-country-workspace"
flavor: |
prefix=test
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{raw}}
- name: DockerHub login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- id: last_commit
uses: ./.github/actions/last_commit
- id: calc
shell: bash
run: |
set -x
LOCK_SHA=$(sha1sum uv.lock docker/bin/* docker/conf/* docker/Dockerfile | sha1sum | awk '{print $1}' | cut -c 1-8)
echo "checksum=$LOCK_SHA" >> "$GITHUB_ENV"
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "BUILD_DATE=$(date +"%Y-%m-%d %H:%M" )" >> $GITHUB_ENV
- name: Build Test Image
run: |
docker build \
--target tests \
-t "unicef/hope-country-workspace:${{env.BRANCH}}-test-${{env.checksum}}" \
--cache-from "type=gha" \
--cache-to "type=gha,mode=max" \
-f docker/Dockerfile .
- name: Run Test suite
run: |
mkdir output
docker run --rm \
--network host \
-e PYTHONPATH=/app/src \
-e DATABASE_URL=${DATABASE_URL} \
-v "./output/:/app/output" \
-v "./src/:/app/src" \
-v "./tests:/app/tests" \
-v "./pytest.ini:/app/pytest.ini" \
-t "unicef/hope-country-workspace:${{env.BRANCH}}-test-${{env.checksum}}" \
pytest -c /app/pytest.ini tests/ -v --maxfail=5 --migrations --cov --cov-report xml:output/coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
continue-on-error: true
with:
env_vars: OS,PYTHON
fail_ci_if_error: true
files: /app/output/coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
verbose: false
name: codecov-${{env.GITHUB_REF_NAME}}
- name: Build Distro
run: |
docker build \
--target dist \
--cache-from "type=gha" \
--cache-to "type=gha,mode=max" \
--build-arg "VERSION=${{env.sha_short}}" \
--build-arg "BUILD_DATE=${{env.BUILD_DATE}}" \
--build-arg "BRANCH=${{env.BRANCH}}" \
-t "unicef/hope-country-workspace:${{env.BRANCH}}" \
-f docker/Dockerfile .
docker push "unicef/hope-country-workspace:${{env.BRANCH}}"
docker inspect unicef/hope-country-workspace:${{env.BRANCH}} | jq -r '.[0].Config.Labels'