Skip to content

Commit

Permalink
#77: improve GitHub workflow ci-tests to reuse images and test deploy…
Browse files Browse the repository at this point in the history
… docker-compose
  • Loading branch information
Wolkenfarmer committed Mar 16, 2024
1 parent 1d58beb commit 39f3a65
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
51 changes: 44 additions & 7 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ jobs:
cd ./frontend/
docker-compose up -d
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push frontend Docker images
run: |
docker tag dps_training_k-frontend ghcr.io/hpi-sam/dps_training_k-frontend:dev
docker push ghcr.io/hpi-sam/dps_training_k-frontend:dev
build-and-test-backend:
runs-on: ubuntu-latest
steps:
Expand All @@ -34,6 +46,27 @@ jobs:
docker pull redis:latest
docker-compose up -d
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push backend Docker images
run: |
docker tag dps_training_k-django ghcr.io/hpi-sam/dps_training_k-django:dev
docker push ghcr.io/hpi-sam/dps_training_k-django:dev
docker tag dps_training_k-celeryworker ghcr.io/hpi-sam/dps_training_k-celeryworker:dev
docker push ghcr.io/hpi-sam/dps_training_k-celeryworker:dev
docker tag dps_training_k-celerybeat ghcr.io/hpi-sam/dps_training_k-celerybeat:dev
docker push ghcr.io/hpi-sam/dps_training_k-celerybeat:dev
docker tag dps_training_k-nginx ghcr.io/hpi-sam/dps_training_k-nginx:dev
docker push ghcr.io/hpi-sam/dps_training_k-nginx:dev
docker tag dps_training_k-postgres ghcr.io/hpi-sam/dps_training_k-postgres:dev
docker push ghcr.io/hpi-sam/dps_training_k-postgres:dev
# Skip redis as it is just the public Docker Hub image anyway and therefore should be directly pulled from there
- name: Run backend tests
run: docker exec K-dPS-django python3 manage.py test

Expand All @@ -47,15 +80,19 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build frontend Docker container
run: |
cd ./frontend/
docker-compose up -d
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build backend Docker containers
- name: Run docker containers with deploy configuration
run: |
cd ./backend/dps_training_k/
docker pull redis:latest
cp ./backend/dps_training_k/.env ./
cp ./frontend/env.d.ts ./
IMAGE_TAG=dev
envsubst < docker-compose.template.yml > docker-compose.yml
docker-compose up -d
- name: Run integration tests
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

# Build and push frontend images
- name: Build and push frontend Docker images
run: |
cd ./frontend/
docker-compose build
docker tag dps_training_k-frontend ghcr.io/hpi-sam/dps_training_k-frontend:latest
docker push ghcr.io/hpi-sam/dps_training_k-frontend:latest
# Build and push backend images
- name: Build and push backend Docker images
run: |
cd ./backend/dps_training_k/
Expand All @@ -50,7 +48,7 @@ jobs:
- name: Prepare deployment files
run: |
mkdir deployment_files
cp docker-compose.yml deployment_files/
cp docker-compose.template.yml deployment_files/
cp frontend/env.d.ts deployment_files/
cp backend/dps_training_k/.env deployment_files/
Expand Down
12 changes: 6 additions & 6 deletions docker-compose.yml → docker-compose.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ volumes:

services:
web:
image: ghcr.io/hpi-sam/dps_training_k-frontend:latest
image: ghcr.io/hpi-sam/dps_training_k-frontend:${IMAGE_TAG}
container_name: K-dPS-frontend
ports:
- "5173:5173"

django:
image: ghcr.io/hpi-sam/dps_training_k-django:latest
image: ghcr.io/hpi-sam/dps_training_k-django:${IMAGE_TAG}
container_name: K-dPS-django
restart: unless-stopped
depends_on:
Expand All @@ -31,7 +31,7 @@ services:


postgres:
image: ghcr.io/hpi-sam/dps_training_k-postgres:latest
image: ghcr.io/hpi-sam/dps_training_k-postgres:${IMAGE_TAG}
container_name: K-dPS-postgres
volumes:
- local_postgres_data:/var/lib/postgresql/data:Z
Expand All @@ -51,7 +51,7 @@ services:
celeryworker:
env_file:
- .env
image: ghcr.io/hpi-sam/dps_training_k-celeryworker:latest
image: ghcr.io/hpi-sam/dps_training_k-celeryworker:${IMAGE_TAG}
container_name: K-dPS-celeryworker
command: /start-celeryworker
depends_on:
Expand All @@ -60,14 +60,14 @@ services:
celerybeat:
env_file:
- .env
image: ghcr.io/hpi-sam/dps_training_k-celerybeat:latest
image: ghcr.io/hpi-sam/dps_training_k-celerybeat:${IMAGE_TAG}
container_name: K-dPS-celerybeat
command: /start-celerybeat
depends_on:
- django

nginx:
image: ghcr.io/hpi-sam/dps_training_k-nginx:latest
image: ghcr.io/hpi-sam/dps_training_k-nginx:${IMAGE_TAG}
container_name: K-dPS-nginx
volumes:
- static_volume:/app/staticfiles
Expand Down

0 comments on commit 39f3a65

Please sign in to comment.