Skip to content

Commit

Permalink
⬆️ Update Adventure Log
Browse files Browse the repository at this point in the history
  • Loading branch information
anarion80 committed Nov 14, 2024
1 parent 71062d5 commit 1b9bbb3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 53 deletions.
6 changes: 1 addition & 5 deletions roles/adventure_log/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ adventure_log_network_name: "adventurelog"
adventure_log_web_memory: 1g
adventure_log_db_memory: 1g
adventure_log_server_memory: 1g
adventure_log_nginx_memory: 1g
# docker
adventure_log_web_container_name: adventure-log-web
adventure_log_web_image_name: ghcr.io/seanmorley15/adventurelog-frontend
Expand All @@ -26,17 +25,14 @@ adventure_log_db_image_version: 15-3.3
adventure_log_server_container_name: adventure-log-server
adventure_log_server_image_name: ghcr.io/seanmorley15/adventurelog-backend
adventure_log_server_image_version: latest
adventure_log_nginx_container_name: adventure-log-nginx
adventure_log_nginx_image_name: nginx
adventure_log_nginx_image_version: stable-alpine
adventure_log_user_id: "1000"
adventure_log_group_id: "1000"


# adventure_log
adventure_log_public_server_url: "http://{{ adventure_log_server_container_name }}:8000"
adventure_log_origin: "https://{{ adventure_log_hostname }}.{{ ansible_nas_domain }}"
adventure_log_body_size_limit: "Infinity"
adventure_log_body_size_limit: "100000"
adventure_log_postgres_port: "5432"
adventure_log_postgres_db: "adventure_log"
adventure_log_postgres_user: "adventure_log"
Expand Down
9 changes: 1 addition & 8 deletions roles/adventure_log/molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@
name: "{{ adventure_log_web_container_name }}"
register: result_web

- name: Get Adventure Log dashboard container state
- name: Get Adventure Log server container state
community.docker.docker_container:
name: "{{ adventure_log_server_container_name }}"
register: result_server

- name: Get Adventure Log nginx container state
community.docker.docker_container:
name: "{{ adventure_log_nginx_container_name }}"
register: result_nginx

- name: Check if Adventure Log containers are running
ansible.builtin.assert:
that:
Expand All @@ -36,5 +31,3 @@
- result_web.container['State']['Restarting'] == false
- result_server.container['State']['Status'] == "running"
- result_server.container['State']['Restarting'] == false
- result_nginx.container['State']['Status'] == "running"
- result_nginx.container['State']['Restarting'] == false
7 changes: 0 additions & 7 deletions roles/adventure_log/molecule/default/verify_stopped.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,9 @@
state: absent
register: result_db

- name: Try and stop and remove Adventure Log nginx
community.docker.docker_container:
name: "{{ adventure_log_nginx_container_name }}"
state: absent
register: result_nginx

- name: Check if Adventure Log is stopped
ansible.builtin.assert:
that:
- not result_server.changed
- not result_web.changed
- not result_db.changed
- not result_nginx.changed
42 changes: 9 additions & 33 deletions roles/adventure_log/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
state: directory
with_items:
- "{{ adventure_log_data_directory }}"
- "{{ adventure_log_data_directory }}/config"
- "{{ adventure_log_data_directory }}/media"
- "{{ adventure_log_data_directory }}/proxy"

- name: Create Adventure Log network
community.docker.docker_network:
name: "{{ adventure_log_network_name }}"

- name: Copy Adventure Log Nginx config
ansible.builtin.template:
src: nginx.conf.j2
dest: "{{ adventure_log_data_directory }}/config/nginx.conf"

- name: Create Adventure Log Db Docker Container
community.docker.docker_container:
name: "{{ adventure_log_db_container_name }}"
Expand All @@ -36,11 +42,12 @@
name: "{{ adventure_log_server_container_name }}"
image: "{{ adventure_log_server_image_name }}:{{ adventure_log_server_image_version }}"
pull: true
# ports:
# - "{{ adventure_log_port }}:8501"
ports:
- "{{ adventure_log_port }}:80"
env: "{{ adventure_log_server_env }}"
volumes:
- "{{ adventure_log_data_directory }}/media:/code/media/"
- "{{ adventure_log_data_directory }}/config/nginx.conf:/etc/nginx/nginx.conf:ro"
networks:
- name: "{{ adventure_log_network_name }}"
network_mode: "{{ adventure_log_network_name }}"
Expand Down Expand Up @@ -70,32 +77,6 @@
traefik.http.routers.adventure_log.tls.domains[0].sans: "*.{{ ansible_nas_domain }}"
traefik.http.services.adventure_log.loadbalancer.server.port: "3000"
memory: "{{ adventure_log_web_memory }}"

- name: Create Adventure Log Nginx Container
community.docker.docker_container:
name: "{{ adventure_log_nginx_container_name }}"
image: "{{ adventure_log_nginx_image_name }}:{{ adventure_log_nginx_image_version }}"
pull: true
ports:
- "{{ adventure_log_port }}:80"
volumes:
- "{{ adventure_log_data_directory }}/media:/usr/share/nginx/html"
networks:
- name: "{{ adventure_log_network_name }}"
network_mode: "{{ adventure_log_network_name }}"
container_default_behavior: no_defaults
labels:
traefik.enable: "{{ adventure_log_available_externally | string }}"
traefik.http.routers.adventure_log_nginx.rule: "Host(`{{ adventure_log_hostname }}.{{ ansible_nas_domain }}`) && PathPrefix(`/media`)"
traefik.http.routers.adventure_log_nginx.tls.certresolver: "letsencrypt"
traefik.http.routers.adventure_log_nginx.tls.domains[0].main: "{{ ansible_nas_domain }}"
traefik.http.routers.adventure_log_nginx.tls.domains[0].sans: "*.{{ ansible_nas_domain }}"
traefik.http.middlewares.adventure_log_nginx-stripprefix.stripprefix.prefixes: "/media"
traefik.http.routers.adventure_log_nginx.middlewares: "adventure_log_nginx-stripprefix"
traefik.http.services.adventure_log_nginx.loadbalancer.server.port: "80"
restart_policy: always
memory: "{{ adventure_log_nginx_memory }}"

when: adventure_log_enabled is true

- name: Stop Adventure Log
Expand All @@ -114,9 +95,4 @@
community.docker.docker_container:
name: "{{ adventure_log_db_container_name }}"
state: absent

- name: Stop Adventure Log Nginx
community.docker.docker_container:
name: "{{ adventure_log_nginx_container_name }}"
state: absent
when: adventure_log_enabled is false
38 changes: 38 additions & 0 deletions roles/adventure_log/templates/nginx.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
worker_processes 1;
events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 65;

upstream django {
server {{ adventure_log_server_container_name}}:8000; # Use the internal Docker networking
}

server {
listen 80; # NGINX always listens on port 80 inside the container
server_name localhost;

location / {
proxy_pass http://{{ adventure_log_server_container_name}}:8000; # Explicitly forward to Django service
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}


location /static/ {
alias /code/staticfiles/; # Serve static files directly
}

location /media/ {
alias /code/media/; # Serve media files directly
}
}
}

0 comments on commit 1b9bbb3

Please sign in to comment.