added Makefile and docker compose

This commit is contained in:
2024-05-24 18:21:21 +02:00
commit d6ee1c8a47
3 changed files with 197 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
/SWA-*/
/.*-env
/*-db

78
Makefile Normal file
View File

@@ -0,0 +1,78 @@
ROOT_DIR := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
DOCKER_REGISTRY=hub.anxietyprime.de/
KEYCLOAK_BASE=quay.io/keycloak/keycloak:24.0.4
KEYCLOAK_DB_BASE=postgres:alpine3.18
KEYCLOAK=swa-jodel/keycloak:latest
KEYCLOAK_DB=swa-jodel/keycloak-db:latest
FRONTEND=swa-jodel/frontend:latest
BACKEND=swa-jodel/backend:latest
DATABASE=swa-jodel/database:latest
help:
@echo "[HELP]"
@echo "usage: make <command>"
@echo " help this page"
@echo " env create the env files"
@echo " build build the docker images"
@echo " clean remove for the build required data"
@echo " uninstall remove the docker images"
.PHONY = env
env:
@echo -e "POSTGRES_USER=\nPOSTGRES_PASSWORD=\n\n\nPOSTGRES_IP=database\nPOSTGRES_DB=Jodel" \
> .backend-env
@echo -e "POSTGRES_USER=\nPOSTGRES_PASSWORD=\n\nKEYCLOAK_ADMIN=\nKEYCLOAK_ADMIN_PASSWORD=\n\n\nPOSTGRES_IP=keycloak-db\nPOSTGRES_DB=keycloak\nKC_DB_URL_DATABASE=\$$POSTGRES_IP\nKC_DB_USERNAME=\$$POSTGRES_USER\nKC_DB_PASSWORD=\$$POSTGRES_PASSWORD" \
> .keycloak-env
.PHONY = gitsync
gitsync:
git --git-dir=$(ROOT_DIR)SWA-frontend/.git pull --quiet || git --git-dir=ROOT_DIR clone https://git.anxietyprime.de/SWA-Project/SWA-frontend.git --quiet
git --git-dir=$(ROOT_DIR)SWA-backend/.git pull --quiet || git --git-dir=ROOT_DIR clone https://git.anxietyprime.de/SWA-Project/SWA-backend.git --quiet
git --git-dir=$(ROOT_DIR)SWA-database/.git pull --quiet || git --git-dir=ROOT_DIR clone https://git.anxietyprime.de/SWA-Project/SWA-database.git --quiet
@echo "done"
.PHONY = build
build: uninstall frontend backend database keycloak
.PHONY = frontend
frontend: gitsync
docker buildx build --tag $(DOCKER_REGISTRY)$(FRONTEND) $(ROOT_DIR)SWA-frontend
.PHONY = backend
backend: gitsync
docker buildx build --tag $(DOCKER_REGISTRY)$(BACKEND) $(ROOT_DIR)SWA-backend
.PHONY = database
database: gitsync
docker buildx build --tag $(DOCKER_REGISTRY)$(DATABASE) $(ROOT_DIR)SWA-database
.PHONY = keycloak
keycloak:
docker pull $(KEYCLOAK_BASE) --quiet
@docker tag $(KEYCLOAK_BASE) $(DOCKER_REGISTRY)$(KEYCLOAK)
docker pull $(KEYCLOAK_DB_BASE) --quiet
@docker tag $(KEYCLOAK_DB_BASE) $(DOCKER_REGISTRY)$(KEYCLOAK_DB)
.PHONY = clean
clean:
@rm -fr $(ROOT_DIR)SWA-frontend $(ROOT_DIR)SWA-backend $(ROOT_DIR)SWA-database
@docker image rm $(KEYCLOAK_BASE) || true
@docker image rm $(KEYCLOAK_DB_BASE) || true
.PHONY = uninstall
uninstall:
@docker image rm $(KEYCLOAK) || true
@docker image rm $(KEYCLOAK_DB) || true
@docker image rm $(FRONTEND) || true
@docker image rm $(BACKEND) || true
@docker image rm $(DATABASE) || true
.PHONY = yeet
yeet: uninstall build clean
@rm $(ROOT_DIR)Makefile

116
docker-compose.yaml Normal file
View File

@@ -0,0 +1,116 @@
services:
keycloak:
image: hub.anxietyprime.de/swa-jodel/keycloak:latest
container_name: swa-keycloak
command:
- start-dev
env_file:
- ./.keycloak-env
environment:
KC_DB: postgres
KC_DB_SCHEMA: public
KC_DB_URL: jdbc:postgresql://keycloak-db/keycloak
KC_HTTP_RELATIVE_PATH: /auth
ports:
- 8080:8080
networks:
- swa-keycloak
- swa-keycloak-db
healthcheck:
test: echo ""
interval: 5s
timeout: 5s
retries: 30
depends_on:
keycloak-db:
condition: service_healthy
keycloak-db:
image: hub.anxietyprime.de/swa-jodel/keycloak-db:latest
container_name: swa-keycloak-db
env_file:
- ./.keycloak-env
volumes:
- ./keycloak-db/:/var/lib/postgresql/data
expose:
- 5432
networks:
- swa-keycloak-db
healthcheck:
test: pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB
start_period: 5s
interval: 5s
timeout: 5s
retries: 30
frontend:
image: hub.anxietyprime.de/swa-jodel/frontend:latest
container_name: swa-frontend
ports:
- 80:80
networks:
- swa-public
healthcheck:
test: ["CMD", "service", "nginx", "status"]
interval: 5s
timeout: 5s
retries: 30
depends_on:
backend:
condition: service_healthy
backend:
image: hub.anxietyprime.de/swa-jodel/backend:latest
container_name: swa-backend
env_file:
- ./.backend-env
ports:
- 3000:8080
networks:
- swa-public
- swa-keycloak
- swa-database
healthcheck:
test: echo ""
interval: 5s
timeout: 5s
retries: 30
depends_on:
keycloak:
condition: service_healthy
database:
condition: service_healthy
database:
image: hub.anxietyprime.de/swa-jodel/database:latest
container_name: swa-database
env_file:
- ./.backend-env
volumes:
- ./backend-db/:/var/lib/postgresql/data
expose:
- 5432
networks:
- swa-database
healthcheck:
test: pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB
start_period: 5s
interval: 5s
timeout: 5s
retries: 30
networks:
default:
external: false
swa-keycloak:
name: swa-keycloak
swa-keycloak-db:
name: swa-keycloak-db
swa-public:
name: swa-public
swa-database:
name: swa-database