From a01ea4f3a36c5ef30be1ec05d3d5f460580ce406 Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Sat, 13 Jan 2024 13:12:28 +0000 Subject: [PATCH 1/5] chore: Remove workflow as it's not really doing a lot --- .github/workflows/pythonpackage.yml | 61 ----------------------------- 1 file changed, 61 deletions(-) delete mode 100644 .github/workflows/pythonpackage.yml diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml deleted file mode 100644 index de51596..0000000 --- a/.github/workflows/pythonpackage.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: Python application - -on: [push, pull_request] - -jobs: - build: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - python-version: [3.9, "3.10", "3.11", pypy3] - os: [ - ubuntu-20.04, - ] - - services: - postgres: - image: postgres:12 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: postgres - ports: - - 5432:5432 - # needed because the postgres container does not provide a healthcheck - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - - steps: - - uses: actions/checkout@v1 - - name: Set up Python 3.11 - uses: actions/setup-python@v2 - with: - python-version: 3.11 - - name: Configure sysctl limits - run: | - sudo swapoff -a - sudo sysctl -w vm.swappiness=1 - sudo sysctl -w fs.file-max=262144 - sudo sysctl -w vm.max_map_count=262144 - - - uses: getong/elasticsearch-action@v1.2 - with: - elasticsearch version: '2.3' - host port: 9200 - container port: 9200 - host node port: 9300 - node port: 9300 - discovery type: 'single-node' - - name: psycopg2 prerequisites - run: sudo apt-get install python-dev libpq-dev - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install pytest-django - - name: Run migrations - run: python manage.py migrate - - name: Validate Project - run: python manage.py check - - name: Run Tests - run: python manage.py test From d86c518c04abca24703dd08dde6d1ff8744e4475 Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Sat, 13 Jan 2024 13:17:04 +0000 Subject: [PATCH 2/5] chore: Some good practice updates to Dockerfile --- Dockerfile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d84425b..0445706 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,12 @@ FROM python:3.11 + WORKDIR /app -COPY . /app -RUN pip install -r requirements.txt + +COPY . . + +RUN python -m pip install --upgrade pip +RUN python -m pip install -r requirements.txt + RUN python manage.py collectstatic --noinput + CMD uwsgi --http=0.0.0.0:80 --module=backend.wsgi From d48615de8ad828f2a121dd1c1a356d9824170e02 Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Sat, 13 Jan 2024 13:17:23 +0000 Subject: [PATCH 3/5] test: Run the docker processes that people need to be able to run --- .github/workflows/docker.yml | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..0a561ff --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,54 @@ +name: Docker test suite + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + +jobs: + pytest: + name: Docker test build + # List of supported runners: + # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Pre-build container images + run: | + docker network create djangocmsnet + docker compose build --force-rm + + - name: Run the containers + run: | + docker compose build web + docker compose up database_default -d + docker compose run web python manage.py migrate + docker compose up -d + - name: Wait for 5 seconds + run: sleep 5s + shell: bash + + - name: 'debug: Display state and logs' + if: always() + run: | + docker compose ps + docker compose logs web + docker compose logs database_default + + - name: Execute django check + run: docker compose exec -w /app web python manage.py check --deploy + + - name: Execute test suite + run: docker compose exec -w /app web python manage.py test + + - name: Terminate all components + if: always() + run: docker compose down -v From 0060af2d5b669b1d28ae25e230685af8993c8cbf Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Sat, 13 Jan 2024 18:02:51 +0000 Subject: [PATCH 4/5] test: Give timeout for database to start --- .github/workflows/docker.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0a561ff..6cf4366 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -30,11 +30,9 @@ jobs: run: | docker compose build web docker compose up database_default -d + sleep 5s docker compose run web python manage.py migrate docker compose up -d - - name: Wait for 5 seconds - run: sleep 5s - shell: bash - name: 'debug: Display state and logs' if: always() From 76cdcefd3b38685160562a1fe53ce3ece803cd57 Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Sat, 13 Jan 2024 18:06:02 +0000 Subject: [PATCH 5/5] test: Is 2 seconds enough? --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 6cf4366..6460d96 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -30,7 +30,7 @@ jobs: run: | docker compose build web docker compose up database_default -d - sleep 5s + sleep 2s docker compose run web python manage.py migrate docker compose up -d