Skip to content

Commit

Permalink
Merge pull request #103 from hpi-sam/77-setup-ci
Browse files Browse the repository at this point in the history
77 setup ci
  • Loading branch information
Wolkenfarmer authored Apr 15, 2024
2 parents a422b1a + 20c24f0 commit ad15e5a
Show file tree
Hide file tree
Showing 23 changed files with 2,224 additions and 178 deletions.
96 changes: 93 additions & 3 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,102 @@
name: CI Tests

on:
push:
workflow_dispatch:

jobs:
hello-world:
build-and-test-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- 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: 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:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build backend Docker containers
run: |
cd ./backend/dps_training_k/
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

test-integration:
needs: [build-and-test-frontend, build-and-test-backend]
runs-on: ubuntu-latest
steps:
- name: print hello world
run: echo "Hello World!"
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run docker containers with deploy configuration
run: |
cp ./backend/dps_training_k/.env ./
cp ./frontend/env.d.ts ./
export IMAGE_TAG=dev
envsubst '${IMAGE_TAG}' < docker-compose.template.yml > docker-compose.yml
docker-compose up -d
- name: Run integration tests
run: |
cd ./frontend/
npm install cypress --save-dev
npx cypress run --e2e
57 changes: 52 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,59 @@
name: Build and Push Docker Images
name: Deploy

on:
release:
types: [published]
workflow_dispatch:

jobs:
hello-world:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: print hello world
run: echo "Hello World!"
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- 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 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
- name: Build and push backend Docker images
run: |
cd ./backend/dps_training_k/
docker-compose build
docker tag dps_training_k-django ghcr.io/hpi-sam/dps_training_k-django:latest
docker push ghcr.io/hpi-sam/dps_training_k-django:latest
docker tag dps_training_k-celeryworker ghcr.io/hpi-sam/dps_training_k-celeryworker:latest
docker push ghcr.io/hpi-sam/dps_training_k-celeryworker:latest
docker tag dps_training_k-celerybeat ghcr.io/hpi-sam/dps_training_k-celerybeat:latest
docker push ghcr.io/hpi-sam/dps_training_k-celerybeat:latest
docker tag dps_training_k-nginx ghcr.io/hpi-sam/dps_training_k-nginx:latest
docker push ghcr.io/hpi-sam/dps_training_k-nginx:latest
docker tag dps_training_k-postgres ghcr.io/hpi-sam/dps_training_k-postgres:latest
docker push ghcr.io/hpi-sam/dps_training_k-postgres:latest
# Skip redis as it is just the public Docker Hub image anyway and therefore should be directly pulled from there
- name: Prepare deployment files
run: |
mkdir deployment_files
cp docker-compose.template.yml deployment_files/
cp frontend/env.d.ts deployment_files/
cp backend/dps_training_k/.env deployment_files/
- name: Archive deployment files
uses: actions/upload-artifact@v2
with:
name: deployment-files
path: deployment_files/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode/settings.json
backend/.vscode/settings.json
.idea/
.vscode/launch.json
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
# dps.training_k
The K-dPS (the clinic variant of the dynamic patient simulation) simulation software for training medical personal on how to act during medical surges / during mass casualty incidents.
# K-dPS
The K-dPS (the clinic variant of the dynamic patient simulation) simulation software for training medical personal on how to act during medical
surges / during mass casualty incidents.
The Frontend website and backend server are two different projects. For setup instructions see the Readmes in the respective folders.

For a common understanding we use this [Code Glossary Notion page](https://k-dps.notion.site/9e82c16b6d9248679b87e0403bbf81a9?v=06e889f90e834b7baf2f879f9ad9551b&pvs=4) (note that this is an internal document and therefore neither formulated for others to understand nor written in English)
For a common understanding we use this
[Code Glossary Notion page](https://k-dps.notion.site/9e82c16b6d9248679b87e0403bbf81a9?v=06e889f90e834b7baf2f879f9ad9551b&pvs=4) (note that this
is an internal document and therefore neither formulated for others to understand nor
written in English)

## Deployment process
The deployment process is automatically started on each release and can be manually triggered by running the GitHub action `deploy`.
This uploads the needed images to [GitHub Packages](https://github.com/orgs/hpi-sam/packages?repo_name=dps.training_k) and saves the needed
environment variables as well as the docker-compose file as
[Actions Artifacts](https://github.com/hpi-sam/dps.training_k/actions/workflows/deploy.yml).
For deployment on the server following steps are needed:
1. Download the action artifacts and extract them in a folder
2. Run following commands in that folder:
```bash
export IMAGE_TAG=latest
envsubst '${IMAGE_TAG}' < docker-compose.template.yml > docker-compose.yml
docker-compose up -d
```
The website should now be running on port 5173.

## MoSCoW and future plans
We follow this [MoSCoW Notion page](https://k-dps.notion.site/MoSCoW-78d8a9b852f7499bb7fb47a770c30723?pvs=4) (note that this is an internal document and therefore neither formulated for others to understand nor written in English)
We follow this [MoSCoW Notion page](https://k-dps.notion.site/MoSCoW-78d8a9b852f7499bb7fb47a770c30723?pvs=4) (note that this is an internal
document and therefore neither formulated for others to understand nor written in English)

In addition to that we aim to always incorporate following non-functional requirements into our development:

Expand All @@ -29,4 +48,6 @@ In addition to that we aim to always incorporate following non-functional requir
- A backend should be able to handle a single exercise with 30 clients.

## Interface Definition
The communication between the frontend and backend uses an Interface as defined in our [interface definition Notion page](https://k-dps.notion.site/Interface-Definition-6852697ae02f41b29544550f84e1049a) (note that this is an internal document and therefore not necessarily formulated for others to understand)
The communication between the frontend and backend uses an Interface as defined in our
[interface definition Notion page](https://k-dps.notion.site/Interface-Definition-6852697ae02f41b29544550f84e1049a)(note that this is an internal
document and therefore not necessarily formulated for others to understand)
2 changes: 1 addition & 1 deletion backend/dps_training_k/deployment/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nginx:1.21-alpine
FROM nginx:latest

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
2 changes: 1 addition & 1 deletion backend/dps_training_k/deployment/postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM postgres:14.1
FROM postgres:14

COPY ./deployment/postgres/maintenance /usr/local/bin/maintenance
RUN chmod +x /usr/local/bin/maintenance/*
Expand Down
9 changes: 7 additions & 2 deletions backend/dps_training_k/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ services:
build:
context: .
dockerfile: ./deployment/django/Dockerfile
image: dps_training_k-django
container_name: K-dPS-django
restart: unless-stopped
depends_on:
- postgres
- redis
Expand All @@ -32,6 +34,7 @@ services:
build:
context: .
dockerfile: ./deployment/postgres/Dockerfile
image: dps_training_k-postgres
container_name: K-dPS-postgres
volumes:
- local_postgres_data:/var/lib/postgresql/data:Z
Expand All @@ -44,9 +47,8 @@ services:
timeout: 5s
retries: 5


redis:
image: redis:6
image: redis:latest
container_name: K-dPS-redis

celeryworker:
Expand All @@ -55,6 +57,7 @@ services:
dockerfile: ./deployment/django/Dockerfile
env_file:
- .env
image: dps_training_k-celeryworker
container_name: K-dPS-celeryworker
command: /start-celeryworker
depends_on:
Expand All @@ -66,13 +69,15 @@ services:
dockerfile: ./deployment/django/Dockerfile
env_file:
- .env
image: dps_training_k-celerybeat
container_name: K-dPS-celerybeat
command: /start-celerybeat
depends_on:
- django

nginx:
build: deployment/nginx
image: dps_training_k-nginx
container_name: K-dPS-nginx
volumes:
- static_volume:/app/staticfiles
Expand Down
77 changes: 77 additions & 0 deletions docker-compose.template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
version: '3.8'

volumes:
local_postgres_data: { }
local_postgres_data_backups: { }
static_volume: { }

services:
web:
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:${IMAGE_TAG}
container_name: K-dPS-django
restart: unless-stopped
depends_on:
- postgres
- redis
env_file:
- .env
environment:
- RUN_MIGRATIONS=1
volumes:
- static_volume:/app/staticfiles
expose:
- 8000
command: uvicorn configuration.asgi:application --host 0.0.0.0 --reload


postgres:
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
- local_postgres_data_backups:/backups:z
env_file:
- .env
healthcheck:
test: [ "CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}" ]
interval: 10s
timeout: 5s
retries: 5

redis:
image: redis:latest
container_name: K-dPS-redis

celeryworker:
env_file:
- .env
image: ghcr.io/hpi-sam/dps_training_k-celeryworker:${IMAGE_TAG}
container_name: K-dPS-celeryworker
command: /start-celeryworker
depends_on:
- django

celerybeat:
env_file:
- .env
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:${IMAGE_TAG}
container_name: K-dPS-nginx
volumes:
- static_volume:/app/staticfiles
ports:
- "8000:80"
depends_on:
- django
2 changes: 1 addition & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20
FROM node:latest
LABEL authors="Wolkenfarmer, Joshua Riewesell"
WORKDIR /app
RUN npm install -g vite
Expand Down
9 changes: 9 additions & 0 deletions frontend/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "cypress"

export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
})
Loading

0 comments on commit ad15e5a

Please sign in to comment.