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:
@@ -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
|
||||
|
||||
handlers:
|
||||
- name: Restart nginx
|
||||
ansible.builtin.service:
|
||||
name: nginx
|
||||
state: restarted
|
||||
become: true
|
||||
16
infra/nginx.conf.j2
Normal file
16
infra/nginx.conf.j2
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -27,4 +27,5 @@ typing_extensions==4.15.0
|
||||
tzdata==2025.3
|
||||
urllib3==2.6.2
|
||||
websocket-client==1.9.0
|
||||
whitenoise==6.11.0
|
||||
wsproto==1.3.2
|
||||
|
||||
@@ -3,3 +3,4 @@ django-stubs==5.2.8
|
||||
django-stubs-ext==5.2.8
|
||||
gunicorn==23.0.0
|
||||
requests==2.31.0
|
||||
whitenoise==6.11.0
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
console.log("apps/scripts/dashboard.js loading");
|
||||
// console.log("apps/scripts/dashboard.js loading");
|
||||
const initialize = (inputSelector) => {
|
||||
console.log("initialize called!");
|
||||
// console.log("initialize called!");
|
||||
const textInput = document.querySelector(inputSelector);
|
||||
textInput.oninput = () => {
|
||||
console.log("oninput triggered");
|
||||
// console.log("oninput triggered");
|
||||
textInput.classList.remove("is-invalid");
|
||||
};
|
||||
};
|
||||
@@ -57,6 +57,7 @@ INSTALLED_APPS = [
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'whitenoise.middleware.WhiteNoiseMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
|
||||
@@ -20,7 +20,7 @@ def _exec_in_container(host, commands):
|
||||
return _exec_in_container_on_server(host, commands)
|
||||
|
||||
def _exec_in_container_locally(commands):
|
||||
print(f"Running {commands} on inside local docker container")
|
||||
# print(f"Running {commands} on inside local docker container")
|
||||
return _run_commands(["docker", "exec", _get_container_id()] + commands)
|
||||
|
||||
def _exec_in_container_on_server(host, commands):
|
||||
@@ -52,5 +52,5 @@ def _run_commands(commands):
|
||||
result = process.stdout.decode()
|
||||
if process.returncode != 0:
|
||||
raise Exception(result)
|
||||
print(f"Result: {result!r}")
|
||||
# print(f"Result: {result!r}")
|
||||
return result.strip()
|
||||
|
||||
Reference in New Issue
Block a user