Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
$ANSIBLE_VAULT;1.1;AES256
35323132643564396232333034306638623934636533313039653861353465303732373131666161
6238303664356561663936333662666163323932653836360a333237396332636339303535646533
37356633353263633163646436343462626638666639346662383831616134643863363261636563
3866653936373538350a643666316365616235303036613066383030656166386166643661336534
32653662393136653133373033356130623833343831306562626662376536303237306233303638
30356538373964386164366430316465633464646132643931373232313666626535333666663466
32633537333133333838656234646537326339363633646636313234636532376133303963306638
32303734633462396330626363386530386465366565306233326430663164623236663061386330
63616562303337303933353734623535373939313363356431366264643531383761396230373338
38386364363063316163306365656533373034623734346432353230633837646266636231363264
33353937656130656335313763363762386663386236376532636265363163656337646562346632
32363761316134373363616464623030343137373338643532666138376139616431323436313063
62363137633732643830653665663333333963653532616531353064303563383334393239656465
31333332373265316336643762386432383432366130303135333362343030333537323865643036
65646639386437656365613134393936363132313639393966313162323437373236316239666631
35333961333435613139353235356637663235616261373165323031393264363965333435316331
30373238316235613937663966356438663961633336366436306235303135633362303737636338
3062666462303436613761613065623536356462616565366433
61363761383764636162396639656633356361363761373834663965303637626262383834336265
3834363165356137623130313562636366616433316666330a316535643536333638383038313838
31333133643763303530316535633934666437373834663137613337323234646265386361343763
6632373238346164650a386438373065656361623032646566613437323137353063343438393566
33646230653366343634623363366134616364373163323433613032633665613732616634363762
66346438323130396534623631326339616634663261363061363136306334386361353834333534
39336638623939323133353362323034356132623161393932386161626638313663623733353232
35656237666464646131376466353339363932666535633738333035353536306630323038353531
32313432316233653436333632326231386235643237643833326163373362306338626332393434
38633032623438636265636131666638663532393537663763633961633663633434393933663461
38333333393437373636346231306237656665393331363465353635393530396565333039366137
37333239663563376631333162373738343234336538646537353464303763633763626132346238
34326631643165393937643131323539616532663366366533386633663765303764653939396564
32383861346534633364656539316130373035303039373033363338643237393565616562393665
39363235313535306531656535623134373665386536623836666362306133343437303132653138
30396138343262613761636138616565346236353936396431336337306262383034623464366335
65643966326365353636343637613035633564666436623636613239633335633064383034393035
31363134393861623762646561656632653635653436363666643230383732363734653439373965
30623537353738643939393734303135316364376465653964623561346434653939376465663334
30643132663532613366393262656166323236633730613037383030393264626534313862376366
36303462386561316339363165396638636531333431613138613134393234666638376235333763
63373366353530613736663531336331376265303464343761333236626130313332333564616231
31333665316432386435663436373862333031373738323064316136373464653437633462663836
33313338343533373832353063626439363663383563666133353866653362343734376566316466
3632
1 change: 1 addition & 0 deletions ansible/hosts.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ srib-radio
azuracast-srib
beszel
kanidm
vt-booking
10 changes: 10 additions & 0 deletions ansible/playbook_infra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@
roles:
- kanidm
become: true

- name: VT Booking host config
hosts: vt-booking
pre_tasks:
- name: Install nginx
ansible.builtin.include_role:
name: nginxinc.nginx
roles:
- vt_booking
become: true
2 changes: 2 additions & 0 deletions ansible/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ collections:
version: "2.2.2"
- name: community.beszel
version: "2.0.0"
- name: community.docker
version: "5.4.0"
roles:
- name: nginxinc.nginx
version: "0.26.0"
1 change: 0 additions & 1 deletion ansible/roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@
- tmux
- dnsutils
- qemu-guest-agent
- podman
become: true
17 changes: 17 additions & 0 deletions ansible/roles/vt_booking/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
# Domenet. Bytter dere senere, endrer du bare denne
vt_booking_domain: booking.fribyte.no

# Hvor app-filene ligger på serveren
vt_booking_dir: /opt/vt-booking

# Hvilken versjon av imagene: latest, eller en commit-SHA
vt_booking_image_tag: latest

# Porten appens egen nginx lytter på, bare tilgjengelig fra serveren selv
vt_booking_http_port: 8080

# Fast adresseområde for Docker, så appens nettverk alltid får gateway 172.31.0.1
vt_booking_docker_bip: 172.30.0.1/24
vt_booking_docker_pool: 172.31.0.0/16
vt_booking_trusted_proxy: 172.31.0.1
Comment thread
skivdal marked this conversation as resolved.
Resolved
70 changes: 70 additions & 0 deletions ansible/roles/vt_booking/files/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Common tasks for the room booking system. Run `make help` for a list.
# Requires Docker, Java 21 and Node 22 (only Docker for `make up`).

FRONTEND := frontend
BACKEND := backend
COMPOSE := docker compose
PROD := docker compose -f compose.prod.yaml
APP_PORT ?= 8088
export APP_PORT

.PHONY: help dev test up down reset-db bootstrap-admin prod-up prod-down prod-logs prod-update prod-pull prod-bootstrap-admin

help: ## Show this list
@grep -E '^[a-z0-9-]+:.*## ' $(MAKEFILE_LIST) | awk -F ':.*## ' '{printf " make %-22s %s\n", $$1, $$2}'

$(FRONTEND)/node_modules: $(FRONTEND)/package-lock.json
cd $(FRONTEND) && npm ci
@touch $@

dev: $(FRONTEND)/node_modules ## PostgreSQL in Docker, Spring Boot and React locally with hot reload
$(COMPOSE) up -d --wait db
@echo "Starting backend (:8080) and frontend (http://localhost:5173)."
@echo "Log in with your own account (first time: 'make bootstrap-admin' in another terminal). Ctrl+C stops both."
@# `exec` makes each job the real process, so the trap's kill reaches it.
@trap 'trap - INT TERM EXIT; kill $$(jobs -p) 2>/dev/null; wait' INT TERM EXIT; \
(cd $(BACKEND) && exec ./mvnw -q spring-boot:run -Dspring-boot.run.profiles=dev) & \
(cd $(FRONTEND) && exec npm run dev -- --strictPort) & \
wait

test: $(FRONTEND)/node_modules ## Frontend and backend tests (backend needs Docker for Testcontainers)
cd $(FRONTEND) && npm test
cd $(BACKEND) && ./mvnw -q test

up: ## Build and run the complete application in Docker on http://localhost:8088 (APP_PORT to change)
$(COMPOSE) up -d --build --wait
@echo "Running on http://localhost:$(APP_PORT). First time: create an administrator with 'make bootstrap-admin'. Stop with 'make down'."

bootstrap-admin: ## Create the first system administrator (prompts for email and password; refuses if one exists)
$(COMPOSE) run --rm --build backend bootstrap-admin

down: ## Stop the containers (data is kept)
$(COMPOSE) down

reset-db: ## Delete the development database (asks first)
@printf "Delete all data in the development database? [y/N] "; read answer; \
case "$$answer" in \
[yY]*) $(COMPOSE) down -v && echo "Database deleted. It is recreated empty on the next 'make dev' or 'make up'; then run 'make bootstrap-admin'." ;; \
*) echo "Cancelled." ;; \
esac

# ── Production: compose.prod.yaml with settings in .env (see docs/DEPLOYMENT.md) ──

prod-up: ## Production: start in the background (builds the images the first time)
$(PROD) up -d --wait

prod-down: ## Production: stop the containers (the database is kept)
$(PROD) down

prod-logs: ## Production: follow the logs of all services
$(PROD) logs -f --tail=100

prod-update: ## Production: rebuild the images from this checkout and restart (back up first)
$(PROD) up -d --build --wait

prod-pull: ## Production: pull the images built by CI (IMAGE_TAG in .env) and restart (back up first)
$(PROD) pull backend frontend
$(PROD) up -d --no-build --wait

prod-bootstrap-admin: ## Production: create the first system administrator (interactive)
$(PROD) run --rm backend bootstrap-admin
66 changes: 66 additions & 0 deletions ansible/roles/vt_booking/files/compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Production: PostgreSQL, the Spring Boot API and Nginx (the built React app), behind the host's
# HTTPS reverse proxy. Settings and secrets come from .env (copy .env.example). Use the
# `make prod-*` commands, and see docs/DEPLOYMENT.md. For development, use compose.yaml instead.
name: vt-booking-prod

services:
db:
image: postgres:18-alpine
environment:
POSTGRES_DB: booking
POSTGRES_USER: booking
POSTGRES_PASSWORD: ${DB_PASSWORD:?Set DB_PASSWORD in .env}
volumes:
- pgdata:/var/lib/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U booking -d booking"]
interval: 10s
timeout: 5s
retries: 10
restart: unless-stopped
# No ports: only the API reaches the database.

backend:
# Pulled from GHCR (built by .github/workflows/images.yml), or built locally with `make prod-update`.
image: ghcr.io/fribyte-code/vt-booking-backend:${IMAGE_TAG:-latest}
build: backend
environment:
# No SPRING_PROFILES_ACTIVE: the dev profile must never run in production.
DB_URL: jdbc:postgresql://db:5432/booking
DB_USER: booking
DB_PASSWORD: ${DB_PASSWORD:?Set DB_PASSWORD in .env}
depends_on:
db:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-fsS", "-o", "/dev/null", "http://localhost:8080/api/auth/csrf"]
interval: 10s
timeout: 5s
start_period: 60s
retries: 6
restart: unless-stopped
# No ports: only Nginx reaches the API. Never publish 8080 (see docs/DEPLOYMENT.md).

frontend:
image: ghcr.io/fribyte-code/vt-booking-frontend:${IMAGE_TAG:-latest}
build: frontend
environment:
# The reverse proxy in front of Nginx, as Nginx sees it, and the header with the client address.
TRUSTED_PROXY: ${TRUSTED_PROXY:-127.0.0.1}
REAL_IP_HEADER: ${REAL_IP_HEADER:-X-Forwarded-For}
volumes:
- ./frontend/real-ip.conf.template:/etc/nginx/templates/real-ip.conf.template:ro
ports:
- "${HTTP_BIND:-127.0.0.1}:${HTTP_PORT:-8080}:80"
depends_on:
backend:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-fsS", "-o", "/dev/null", "http://localhost/"]
interval: 10s
timeout: 5s
retries: 6
restart: unless-stopped

volumes:
pgdata:
7 changes: 7 additions & 0 deletions ansible/roles/vt_booking/files/real-ip.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Mounted by compose.prod.yaml. At start, the Nginx image fills in the variables (from .env) and
# writes the result to /etc/nginx/conf.d/real-ip.conf. Requests from TRUSTED_PROXY, the reverse
# proxy in front of Nginx, carry the client address in REAL_IP_HEADER; from anywhere else the
# header is ignored. The default, 127.0.0.1, trusts no proxy.
set_real_ip_from ${TRUSTED_PROXY};
real_ip_header ${REAL_IP_HEADER};
real_ip_recursive on;
29 changes: 29 additions & 0 deletions ansible/roles/vt_booking/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- name: Restart docker
ansible.builtin.systemd_service:
name: docker
state: restarted
become: true

# Same as `make prod-pull` in the app repository
- name: Pull vt-booking images
ansible.builtin.command:
cmd: docker compose -f compose.prod.yaml pull backend frontend
chdir: "{{ vt_booking_dir }}"
changed_when: true
listen: Deploy vt-booking
become: true

- name: Start vt-booking
ansible.builtin.command:
cmd: docker compose -f compose.prod.yaml up -d --no-build --wait
chdir: "{{ vt_booking_dir }}"
changed_when: true
listen: Deploy vt-booking
become: true

- name: Restart nginx
ansible.builtin.systemd_service:
name: nginx
state: restarted
become: true
Loading