diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..6460d96 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,52 @@ +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 + sleep 2s + docker compose run web python manage.py migrate + docker compose up -d + + - 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 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 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