Add Docker Compose installation step to zoo_django_actions workflow #97
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Zoo Django Actions | |
on: [push] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
max-parallel: 4 | |
matrix: | |
python-version: ["3.10", "3.11", "3.12"] | |
database-name: | |
- zoo_django_actions | |
database-password: | |
- postgres | |
database-user: | |
- postgres | |
database-host: | |
- 127.0.0.1 | |
database-port: | |
- 5432 | |
services: | |
postgres: | |
image: postgres:latest | |
env: | |
POSTGRES_DB: ${{ matrix.database-name }} | |
POSTGRES_USER: ${{ matrix.database-user }} | |
POSTGRES_PASSWORD: ${{ matrix.database-password }} | |
ports: | |
- 5432:5432 | |
# Set health checks to wait until postgres has started | |
options: | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- uses: actions/[email protected] | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/[email protected] | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Install Docker Compose | |
run: | | |
sudo curl -L "https://github.com/docker/compose/releases/download/v2.0.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
sudo chmod +x /usr/local/bin/docker-compose | |
- name: Format with black | |
run: | | |
pip install black | |
# format the files with black | |
black . | |
- name: Lint with flake8 | |
run: | | |
pip install flake8 | |
# stop the build if there are Python syntax errors or undefined names | |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
- name: Sort imports | |
run: | | |
pip install isort | |
# stop the build if there are Python syntax errors or undefined names | |
isort . | |
isort --check --diff . | |
- name: Setup test database | |
env: | |
POSTGRES_DB_NAME: ${{ matrix.database-name }} | |
POSTGRES_USER: ${{ matrix.database-user }} | |
POSTGRES_PASSWORD: ${{ matrix.database-password }} | |
POSTGRES_DB_HOST: ${{ matrix.database-host }} | |
POSTGRES_DB_PORT: ${{ matrix.database-port }} | |
POSTGRES_DB: ${{ matrix.database-name }} | |
run: | | |
export DATABASE_URL=postgres://${{ matrix.database-user }}:${{ matrix.database-password }}@${{ matrix.database-host }}:${{ matrix.database-port }}/${{ matrix.database-name }} | |
export SECRET_KEY=test-secret-key | |
export DEBUG=1 | |
- name: Run migrations | |
run: | | |
export DATABASE_URL=postgres://${{ matrix.database-user }}:${{ matrix.database-password }}@${{ matrix.database-host }}:${{ matrix.database-port }}/${{ matrix.database-name }} | |
export SECRET_KEY=test-secret-key | |
export DEBUG=1 | |
export ALLOWED_HOSTS=localhost | |
export GITHUB_WORKFLOW=True | |
export MODE=workflow | |
python manage.py makemigrations | |
python manage.py migrate | |
python manage.py migrate --run-syncdb | |
python manage.py check | |
- name: Run tests | |
run: | | |
python manage.py test | |
env: | |
DATABASE_URL: postgres://${{ matrix.database-user }}:${{ matrix.database-password }}@${{ matrix.database-host }}:${{ matrix.database-port }}/${{ matrix.database-name }} | |
SECRET_KEY: test-secret-key | |
DEBUG: 1 | |
ALLOWED_HOSTS: localhost | |
GITHUB_WORKFLOW: True | |
MODE: workflow | |
- uses: actions/[email protected] | |
- name: Build the images and start the containers | |
run: | | |
export GITHUB_WORKFLOW=True | |
export MODE="Test" | |
docker-compose -f docker-compose.yml build | |
docker-compose -f docker-compose.yml up -d | |
# run: docker-compose up -d --build | |
- name: Stop containers | |
if: always() | |
run: docker-compose -f "docker-compose.yml" down | |