nginx compatibility added to serve static files on server; whitenoise installed to catch static file serving in local docker container, also added to core.settings middleware; console logs & print statements removed from dashboard.js & functional_tests.container_commands; ansible playbook and nginx config file support nginx w.in deployment workflow

This commit is contained in:
Disco DeDisco
2026-02-08 17:55:09 -05:00
parent 07a76cb32d
commit 8190317c21
7 changed files with 75 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
- hosts: staging
- hosts: all
tasks:
- name: Debug django_allowed_host
@@ -12,6 +12,34 @@
update_cache: true
become: true
- name: Install nginx
ansible.builtin.apt:
name: nginx
state: latest
become: true
- name: Deploy nginx config
ansible.builtin.template:
src: nginx.conf.j2
dest: /etc/nginx/sites-available/gamearray
become: true
notify: Restart nginx
- name: Enable nginx site
ansible.builtin.file:
src: /etc/nginx/sites-available/gamearray
dest: /etc/nginx/sites-enabled/gamearray
state: link
become: true
notify: Restart nginx
- name: Remove default nginx site
ansible.builtin.file:
path: /etc/nginx/sites-enabled/default
state: absent
become: true
notify: Restart nginx
- name: Add our user to the docker group, so we don't need sudo/become
ansible.builtin.user:
name: '{{ ansible_user }}'
@@ -88,9 +116,29 @@
EMAIL_HOST_PASSWORD: "{{ email_host_password }}"
MAILGUN_API_KEY: "{{ mailgun_api_key }}"
ports:
80:8888 # container port 80 (standard http port) maps to server port 8888 (arbitrary internal port)
127.0.0.1:8888:8888
- name: Create static files directory
ansible.builtin.file:
path: /var/www/gamearray/static
state: directory
owner: www-data
group: www-data
become: true
- name: Copy static files from container to host
ansible.builtin.command:
cmd: docker cp gamearray:/src/static/. /var/www/gamearray/static/
become: true
- name: Run migration inside container
community.docker.docker_container_exec:
container: gamearray
command: ./manage.py migrate
command: ./manage.py migrate
handlers:
- name: Restart nginx
ansible.builtin.service:
name: nginx
state: restarted
become: true

16
infra/nginx.conf.j2 Normal file
View File

@@ -0,0 +1,16 @@
server {
listen 80;
server_name {{ django_allowed_host }};
location /static/ {
alias /var/www/gamearray/static/;
}
location / {
proxy_pass http://127.0.0.1:8888;
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;
}
}