diff --git a/infra/deploy-playbook.yaml b/infra/deploy-playbook.yaml index d5232ae..5019b41 100644 --- a/infra/deploy-playbook.yaml +++ b/infra/deploy-playbook.yaml @@ -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 \ No newline at end of file + command: ./manage.py migrate + + handlers: + - name: Restart nginx + ansible.builtin.service: + name: nginx + state: restarted + become: true \ No newline at end of file diff --git a/infra/nginx.conf.j2 b/infra/nginx.conf.j2 new file mode 100644 index 0000000..e0b6d0d --- /dev/null +++ b/infra/nginx.conf.j2 @@ -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; + } +} \ No newline at end of file diff --git a/requirements.dev.txt b/requirements.dev.txt index 5c17466..4d42320 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -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 diff --git a/requirements.txt b/requirements.txt index 097df52..f95ac92 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/src/apps/dashboard/static/apps/scripts/dashboard.js b/src/apps/dashboard/static/apps/scripts/dashboard.js index acc43c1..704d5bf 100644 --- a/src/apps/dashboard/static/apps/scripts/dashboard.js +++ b/src/apps/dashboard/static/apps/scripts/dashboard.js @@ -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"); }; }; \ No newline at end of file diff --git a/src/core/settings.py b/src/core/settings.py index 1630cec..939f013 100644 --- a/src/core/settings.py +++ b/src/core/settings.py @@ -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', diff --git a/src/functional_tests/container_commands.py b/src/functional_tests/container_commands.py index fb74014..d781406 100644 --- a/src/functional_tests/container_commands.py +++ b/src/functional_tests/container_commands.py @@ -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()