Skip to content

Merge branch 'main' into deployment #80

Merge branch 'main' into deployment

Merge branch 'main' into deployment #80

Workflow file for this run

name: CI/CD for Django with Docker Compose
on:
push:
branches: [ "deployment" ]
jobs:
build-test-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_PAT }}
logout: true
- name: Create docker.env File
run: |
echo "DJANGO_SECRET_KEY=test_secret_key" >> docker.env
echo "DB_HOST=db" >> docker.env
echo "DJANGO_DEBUG=False" >> docker.env
echo "POSTGRES_DB=vis_phewas_db" >> docker.env
echo "DB_NAME=vis_phewas_db" >> docker.env
echo "POSTGRES_PASSWORD=default_secure_password" >> docker.env
echo "DB_PASS=default_secure_password" >> docker.env
echo "DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1" >> docker.env
echo "POSTGRES_USER=postgres" >> docker.env
echo "DB_USER=postgres" >> docker.env
cat docker.env
- name: Build and Run with Docker Compose
run: |
docker compose --env-file docker.env -f docker-compose-build.yml up -d --build
- name: Health Check
run: |
sleep 10 # Give the containers some time to start
curl --fail http://localhost:8000 || (docker compose -f docker-compose-build.yml logs web && \
docker compose -f docker-compose-build.yml exec web cat /app/vis_phewas/debug.log && exit 1)
- name: Wait for DB to Start
run: |
sleep 20 # Give the DB some time to start
docker compose -f docker-compose-build.yml logs db
docker compose -f docker-compose-build.yml exec -T db pg_isready -U postgres
- name: Run Integration Tests
run: |
docker compose -f docker-compose-build.yml exec -T web python manage.py test
- name: Stop and Remove Containers
run: |
docker compose -f docker-compose-build.yml down
- name: Tag and Push Web Image to Docker Hub
run: |
docker tag vis-phewas-web tnaccarato/vis-phewas:web
docker push tnaccarato/vis-phewas:web
- name: Tag and Push DB Image to Docker Hub
run: |
docker tag vis-phewas-db tnaccarato/vis-phewas:db
docker push tnaccarato/vis-phewas:db