Skip to content
76 changes: 76 additions & 0 deletions .github/workflows/_unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Run unit tests

on:
workflow_call:
inputs:
command:
required: true
type: string
image:
required: true
type: string
environment:
type: string

jobs:
vars:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
outputs:
token: ${{ steps.vars.outputs.token }}
environment:
name: ${{ inputs.environment }}
steps:
- name: GCP Auth
id: auth
uses: google-github-actions/auth@v2
with:
token_format: 'access_token'
workload_identity_provider: ${{ vars.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.SERVICE_ACCOUNT }}
- id: vars
run: |
echo "token=$(gcloud auth print-access-token)" >> $GITHUB_OUTPUT
unit-tests:
runs-on: ubuntu-latest
needs: [vars]
container:
image: ${{ inputs.image }}
credentials:
username: oauth2accesstoken
password: ${{ needs.vars.outputs.token }}
services:
postgis:
image: postgis/postgis:16-3.4-alpine
env:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: fancypassword
POSTGRES_DB: testdb
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Setup
run: |
cd /var/www/app
python3 -m pip install -r requirements-dev.txt

- name: Run Tests
run: |
cd /var/www/app
${{ inputs.command }}
# export PYTHONPATH=/var/www/app:$PYTHONPATH
env:
DB_HOST: postgis
DB_NAME: testdb
DB_USER: testuser
DB_PASSWORD: fancypassword
DB_PORT: 5432
FQDN: testing.pamdas.org
GCP_ENVIRONMENT_ENABLED: false
TRACING_ENABLED: false
CELERY_TASK_ALWAYS_EAGER: true
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
- gundi-3054 # remove this line before merge
- 'release-**'

jobs:
Expand All @@ -26,6 +27,15 @@ jobs:
repository: ${{ needs.vars.outputs.repository }}
tag: ${{ needs.vars.outputs.tag }}

unit-test:
uses: ./.github/workflows/_unit-test.yml
needs: [vars, build]
with:
environment: stage
image: "${{ needs.vars.outputs.repository }}:${{ needs.vars.outputs.tag }}"
command: |
pytest

deploy_dev:
uses: PADAS/gundi-workflows/.github/workflows/deploy_k8s.yml@v2
if: startsWith(github.ref, 'refs/heads/main')
Expand Down
63 changes: 19 additions & 44 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
FROM ubuntu:20.04
MAINTAINER chrisdo@vulcan.com

# use apt-get update and install in the same RUN command: http://lenguyenthedat.com/docker-cache/
EXPOSE 8000
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8
ENV LANGUAGE C.UTF-8
ENV DJANGO_SETTINGS_MODULE=cdip_admin.settings
ENV DEBUG=False
ENV SERVICE_NAME=cdip_portal
ENV DB_HOST=host.docker.internal
ENV DJANGO_SILK_ENABLED=True

RUN apt-get update && \
apt-get -y upgrade && \
DEBIAN_FRONTEND=noninteractive \
Expand All @@ -18,57 +27,23 @@ RUN apt-get update && \
software-properties-common \
postgresql-client-12 \
vim \
&& apt-get autoremove


# Use ubuntugis/ppa for bionic since it's not available for 20.04 (focal) yet.
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 089EBE08314DF160
RUN /bin/sh -c 'echo "deb http://ppa.launchpad.net/ubuntugis/ppa/ubuntu bionic main" >> /etc/apt/sources.list.d/ubuntugis.list'

#RUN apt-get update
RUN apt-get update && \
apt-get -y install gdal-bin libgdal-dev
RUN export CPLUS_INCLUDE_PATH=/usr/include/gdal
RUN export C_INCLUDE_PATH=/usr/include/gdal
RUN pip3 install GDAL==$(gdal-config --version)

WORKDIR /workspace

ADD dependencies/requirements.txt /workspace/requirements.txt

RUN pip3 install -U "pip"

RUN pip3 install -r /workspace/requirements.txt --no-cache-dir

ARG built_version=""

ADD ./cdip_admin /var/www/app
ADD ./swagger-fix/index.html /usr/local/lib/python3.8/dist-packages/rest_framework_swagger/templates/rest_framework_swagger/

EXPOSE 8000

ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8
ENV LANGUAGE C.UTF-8

ENV BUILT_VERSION=${built_version}

ENV DJANGO_SETTINGS_MODULE=cdip_admin.settings
ENV DEBUG=False

# Default service name
ENV SERVICE_NAME=cdip_portal

# if connecting to db running on localhost
ENV DB_HOST=host.docker.internal
gdal-bin libgdal-dev && \
apt-get autoremove && \
pip3 install -U "pip"

WORKDIR /var/www/app
COPY dependencies .
RUN pip3 install -r requirements.txt --no-cache-dir

COPY ./cdip_admin .
COPY ./swagger-fix/index.html /usr/local/lib/python3.8/dist-packages/rest_framework_swagger/templates/rest_framework_swagger/
RUN mkdir -p /var/www/static

# Collect static files (using a stub database)
ENV DJANGO_SILK_ENABLED=True
RUN python3 manage.py collectstatic --noinput --settings=cdip_admin.local_settings_nodb
ENV DJANGO_SILK_ENABLED=False

RUN mkdir -p /var/www/static && \
python3 manage.py collectstatic --noinput --settings=cdip_admin.local_settings_nodb
CMD ["/var/www/app/start_scripts/start.sh"]