From 1596460d887498884469e10e49c86c1a5eff4c6a Mon Sep 17 00:00:00 2001 From: popcorn9499 <6319808+popcorn9499@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:03:03 -0600 Subject: [PATCH 1/5] removed some extra cruft --- deploy/ansible/group_vars/all.yml | 4 --- deploy/ansible/site.yml | 54 +++---------------------------- 2 files changed, 5 insertions(+), 53 deletions(-) diff --git a/deploy/ansible/group_vars/all.yml b/deploy/ansible/group_vars/all.yml index a59795d..9e52a51 100644 --- a/deploy/ansible/group_vars/all.yml +++ b/deploy/ansible/group_vars/all.yml @@ -2,8 +2,4 @@ ansible_become: true ansible_python_interpreter: /usr/bin/python3 apache_manage_vhost: true -apache_legacy_sites: [] -apache_legacy_sites_reviewed: false -legacy_backend_services: [] -legacy_backend_services_reviewed: false apache_tls_options_file: /etc/letsencrypt/options-ssl-apache.conf diff --git a/deploy/ansible/site.yml b/deploy/ansible/site.yml index 578e003..6f2f3d4 100644 --- a/deploy/ansible/site.yml +++ b/deploy/ansible/site.yml @@ -32,11 +32,9 @@ - mail_password is defined and mail_password | length > 0 and not mail_password.startswith('REPLACE_') - ghcr_username is defined and ghcr_username | length > 0 and not ghcr_username.startswith('REPLACE_') - ghcr_read_token is defined and ghcr_read_token | length > 0 and not ghcr_read_token.startswith('REPLACE_') - - (not apache_manage_vhost | bool) or apache_legacy_sites_reviewed | bool - - legacy_backend_services_reviewed | bool fail_msg: >- Deployment is not configured. Review the Supabase connection details and encrypted vault, - then explicitly review the existing Apache sites and legacy backend services. + then verify the deployment inputs before continuing. - name: Check the configured Apache certificate and key ansible.builtin.stat: @@ -215,19 +213,8 @@ - "{{ backend_image }}" - "{{ frontend_image }}" - - name: Check whether the legacy service units are present - ansible.builtin.service_facts: - - - name: Switch from the legacy deployment to containers + - name: Deploy the container stack block: - - name: Stop and disable reviewed legacy backend services - ansible.builtin.service: - name: "{{ item }}" - state: stopped - enabled: false - loop: "{{ legacy_backend_services }}" - when: item in ansible_facts.services - - name: Start the selected Compose stack and wait for healthy services community.docker.docker_compose_v2: project_src: "{{ stack_directory }}" @@ -282,16 +269,6 @@ changed_when: "'Enabling site' in apache_site_enabled.stdout" when: apache_manage_vhost | bool - - name: Disable the reviewed legacy Apache vhosts - ansible.builtin.command: - argv: - - a2dissite - - "{{ item }}" - loop: "{{ apache_legacy_sites }}" - register: apache_legacy_site_disabled - changed_when: "'disabling site' in apache_legacy_site_disabled.stdout or 'To activate the new configuration' in apache_legacy_site_disabled.stdout" - when: apache_manage_vhost | bool - - name: Validate the Apache configuration ansible.builtin.command: argv: @@ -387,17 +364,6 @@ - apache_manage_vhost | bool - not previous_stack_environment.stat.exists - - name: Restore reviewed legacy Apache vhosts during rollback - ansible.builtin.command: - argv: - - a2ensite - - "{{ item }}" - loop: "{{ apache_legacy_sites }}" - failed_when: false - when: - - apache_manage_vhost | bool - - not previous_stack_environment.stat.exists - - name: Check whether the restored Apache configuration is valid ansible.builtin.command: argv: @@ -438,21 +404,11 @@ wait_timeout: 180 when: previous_stack_environment.stat.exists - - name: Restore reviewed legacy backend services during rollback - ansible.builtin.service: - name: "{{ item }}" - state: started - enabled: true - loop: "{{ legacy_backend_services }}" - when: - - not previous_stack_environment.stat.exists - - item in ansible_facts.services - - - name: Report that cutover failed and rollback was attempted + - name: Report that container deployment failed and rollback was attempted ansible.builtin.fail: msg: >- - Container cutover failed. Ansible attempted to restore the reviewed Apache sites - and systemd backend services; inspect the preceding errors and server state. + Container deployment failed. Ansible attempted to restore the previous container + stack and managed Apache vhost; inspect the preceding errors and server state. - name: Remove the previous Compose environment backup after successful cutover ansible.builtin.file: From b89edde8338c1ccf56fee2f0ed634ab7c9d6a55c Mon Sep 17 00:00:00 2001 From: popcorn9499 <6319808+popcorn9499@users.noreply.github.com> Date: Fri, 4 Dec 2026 18:46:18 -0600 Subject: [PATCH 2/5] change to /DockerContainers instead of /opt --- deploy/ansible/group_vars/production/vars.yml | 4 +-- deploy/ansible/group_vars/test/vars.yml | 2 +- docs/ContainerizedDeployment.md | 25 +++++++++++++------ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/deploy/ansible/group_vars/production/vars.yml b/deploy/ansible/group_vars/production/vars.yml index 421fbff..6008b1a 100644 --- a/deploy/ansible/group_vars/production/vars.yml +++ b/deploy/ansible/group_vars/production/vars.yml @@ -1,9 +1,9 @@ --- compose_project_name: gobison-production -stack_directory: /opt/gobison/production +stack_directory: /DockerContainers/gobison/production apache_site_name: gobison-production-containers.conf domain_name: gobison.popicraft.net nginx_host_port: 8081 -supabase_db_url: "jdbc:postgresql://REPLACE_WITH_SUPABASE_SESSION_POOLER_HOST:5432/postgres?sslmode=require" +supabase_db_url: "jdbc:postgresql://aws-2-us-east-1.pooler.supabase.com:5432/postgres?sslmode=require" apache_tls_certificate_file: /etc/letsencrypt/live/popicraft.net-0001/fullchain.pem apache_tls_certificate_key_file: /etc/letsencrypt/live/popicraft.net-0001/privkey.pem diff --git a/deploy/ansible/group_vars/test/vars.yml b/deploy/ansible/group_vars/test/vars.yml index 8405da7..d9a9ea2 100644 --- a/deploy/ansible/group_vars/test/vars.yml +++ b/deploy/ansible/group_vars/test/vars.yml @@ -1,6 +1,6 @@ --- compose_project_name: gobison-test -stack_directory: /opt/gobison/test +stack_directory: /DockerContainers/gobison/test apache_site_name: gobison-test-containers.conf domain_name: test.gobison.popicraft.net nginx_host_port: 8082 diff --git a/docs/ContainerizedDeployment.md b/docs/ContainerizedDeployment.md index fb63cbe..0cb8b13 100644 --- a/docs/ContainerizedDeployment.md +++ b/docs/ContainerizedDeployment.md @@ -93,16 +93,25 @@ Keep test and production data isolated; separate Supabase projects are preferred Environment defaults are in: -| Environment | Compose project | Nginx host port | Supabase JDBC URL | -| --- | --- | ---: | --- | -| Production | `gobison-production` | `8081` | `deploy/ansible/group_vars/production/vars.yml` | -| Test | `gobison-test` | `8082` | `deploy/ansible/group_vars/test/vars.yml` | +| Environment | Compose project | Stack directory on VPS | Nginx host port | Supabase JDBC URL | +| --- | --- | --- | ---: | --- | +| Production | `gobison-production` | `/DockerContainers/gobison/production` | `8081` | `deploy/ansible/group_vars/production/vars.yml` | +| Test | `gobison-test` | `/DockerContainers/gobison/test` | `8082` | `deploy/ansible/group_vars/test/vars.yml` | -Replace the placeholder pooler host before deployment. Review the Apache certificate paths, existing vhost names, and backend systemd service names on the VPS; Ansible intentionally requires explicit review flags before disabling legacy sites or services. +Replace the placeholder pooler host before deployment. Check that the Apache certificate paths exist and that the managed vhost names do not conflict with existing configuration. ## Ansible and Vault setup -The inventory targets `popicraft.net` as `deploybot` over SSH port `2525`. Confirm the account has narrowly scoped non-interactive sudo access and that Docker Engine plus the Docker Compose v2 plugin are already installed. Ansible does not install or replace Docker Engine. +The inventory targets `popicraft.net` as `deploybot` over SSH port `2525`. Docker Engine and the Docker Compose v2 plugin must already be installed; Ansible does not install or replace Docker Engine. + +The current playbook uses `become: true` for tasks that write root-owned files, manage Apache, and control Docker. A straightforward sudoers rule that supports those Ansible tasks is: + +```sudoers +# /etc/sudoers.d/ansible-deploybot +deploybot ALL=(root) NOPASSWD: ALL +``` + +On Ubuntu, create or edit the file with `sudo visudo -f /etc/sudoers.d/ansible-deploybot`, then validate it with `sudo visudo -cf /etc/sudoers.d/ansible-deploybot` and inspect the effective permissions with `sudo -l -U deploybot`. `NOPASSWD: ALL` grants `deploybot` unrestricted root-level command execution through sudo; it is convenient for automation but is not least privilege. For a tighter policy, redesign the playbook to use narrowly scoped root-owned helper scripts and allow only those scripts in sudoers. 1. From `deploy/ansible`, install the collection and check playbook syntax: @@ -111,7 +120,7 @@ The inventory targets `popicraft.net` as `deploybot` over SSH port `2525`. Confi ansible-playbook -i inventory.ini site.yml --syntax-check ``` -2. Set each environment's real Supabase JDBC URL and confirm the Apache TLS paths, exact legacy site names, and exact legacy backend service names in `group_vars/`. +2. Set each environment's real Supabase JDBC URL and confirm the Apache TLS paths in `group_vars/`. 3. Copy the appropriate example Vault files, replace placeholders, and encrypt them. Ansible prompts for a Vault password; use the same password for both environment files and store it in a password manager: ```sh @@ -127,7 +136,7 @@ The inventory targets `popicraft.net` as `deploybot` over SSH port `2525`. Confi Vault files contain the Supabase username/password, mail password, and read-only GHCR credentials. Never commit unencrypted secrets. The repository ignores `vault.yml`; verify encrypted files begin with `$ANSIBLE_VAULT;` before force-adding them for CI. 4. Configure GitHub Actions secrets `DEPLOY_SSH_KEY`, `DEPLOY_KNOWN_HOSTS`, and `ANSIBLE_VAULT_PASSWORD`. The deployment workflow uses GitHub Environments named `test` and `production`; add secrets there or as repository secrets, and consider required reviewers for production. -Ansible writes protected host-side password files under `/opt/gobison//secrets/`, pulls exact application images, starts the Compose stack, verifies Nginx, then updates and validates Apache. Review the playbook and server state before the first cutover; keep the old deployment available for rollback. +Ansible writes the Compose files, environment, and protected password files under each environment's stack directory in `/DockerContainers/gobison/`, pulls exact application images, starts the Compose stack, verifies Nginx, then updates and validates Apache. The playbook and inventory stay on the Ansible control machine; only the configured stack files and runtime data are placed on the VPS. ## GitHub Actions status From fb7bc79530ecbf907fbbcee8449563c3da8bb981 Mon Sep 17 00:00:00 2001 From: popcorn9499 <6319808+popcorn9499@users.noreply.github.com> Date: Fri, 4 Dec 2026 18:52:48 -0600 Subject: [PATCH 3/5] add encrypted vault to store some of configuration for deployment --- .../ansible/group_vars/production/vault.yml | 20 +++++++++++++++++++ deploy/ansible/group_vars/test/vault.yml | 19 ++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 deploy/ansible/group_vars/production/vault.yml create mode 100644 deploy/ansible/group_vars/test/vault.yml diff --git a/deploy/ansible/group_vars/production/vault.yml b/deploy/ansible/group_vars/production/vault.yml new file mode 100644 index 0000000..c21c857 --- /dev/null +++ b/deploy/ansible/group_vars/production/vault.yml @@ -0,0 +1,20 @@ +$ANSIBLE_VAULT;1.1;AES256 +62616330326365636466663133623331356135393961356334336635663565373939323433366261 +3636613631366437333734643630663665313561666466370a346138636536393463363662643764 +33393465373663623938623966373836643930393465383630353263626265383734383131643565 +3832626439343363610a623231613063356264633737623732343036306635333833663564326434 +65393164366234633736333939323538656333336435323336316364326431366639663265326265 +38393237633934373766613837616237306433656265343830313161313536313932643961393565 +63326166376638303361663337363137613234373630633238383031396137623633336362316534 +34343530666366376461616332616563393231363936623239393265613735326433376130306566 +66346134373630363530323831326233373735623066333638393237656630336630616235663238 +35313537653839313261646430326331356635613365356231303163333262643264663638313532 +34346361663331623664616564666362303730656536393639643531313631356466353861656266 +30633935393838663935393130353031373132353063376138323966663063666536366632373365 +33666362643062616637303435306434383431623362626434656465393166646131353865616135 +31623736643164333365636137366363386336616635306437663138303137396338613538383536 +33666261393361666562363062306564323039323239303030663566653335346661336361666235 +33613337663461373062623730346266333235376562313736633438333764396163353835313331 +65316162376137373635626135656331666335326338636232303563333733353934363362336436 +31616463633035383165353138386133616662653433366531373230646232356361656466366438 +663263316436633135356430613436363438 diff --git a/deploy/ansible/group_vars/test/vault.yml b/deploy/ansible/group_vars/test/vault.yml new file mode 100644 index 0000000..ea69bd4 --- /dev/null +++ b/deploy/ansible/group_vars/test/vault.yml @@ -0,0 +1,19 @@ +$ANSIBLE_VAULT;1.1;AES256 +65343838353136663233366435333763386266656134383131633666343662313161343933623439 +3933653363656137303138613539633931616463666439360a396262373231353333633230663063 +64646666666233323966636334303235633862656332613061303935316633366436366333646130 +6339633232386362660a396533366464653632656166343437623631363864303764366162306664 +39363330336536313561306232393038353438613362353233363138636231656637363034383834 +31353831616630343937313532643830623464653861313239633435393138633138393639373436 +32306331663933356665313538653436643632396662643031633961616366613237353766386566 +32346434666631613866346462663530386631383962323931396332623833666631646262306134 +39363234373331656665613539333866616430353363653131376232323838323662626434336632 +61663733366262653536316634356362363766623438386661333963616237336366366539313730 +35396339653333383161343265613562633963373438363331653363333765663135613630376336 +39313862373032306339333131333933396139613535373031396661633163333635653339333235 +35623266333765333562666539343963643363326262626633343830353431666237393831613237 +33663264383139653336303833373738613861396234363665323465343931386532366334613538 +31356235343561653433663033303830653366386261333334653136373566326331346436613466 +35313833326663396131613935356235386331656638633636333732333132656631353933393062 +37303134356632326636316434313962303265373934323662336462623838323536333665323331 +6534623861373564626533306465636165616332613435303464 From 2bcfcf4383f01d6a88ecefd47e76c24501169643 Mon Sep 17 00:00:00 2001 From: popcorn9499 <6319808+popcorn9499@users.noreply.github.com> Date: Fri, 4 Dec 2026 18:55:54 -0600 Subject: [PATCH 4/5] setup container deployment to build the prod image --- .github/workflows/container-deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/container-deploy.yml b/.github/workflows/container-deploy.yml index cba3d46..18666a6 100644 --- a/.github/workflows/container-deploy.yml +++ b/.github/workflows/container-deploy.yml @@ -10,7 +10,7 @@ on: types: - completed branches: -# - master + - master - dev permissions: @@ -99,7 +99,7 @@ jobs: uses: docker/build-push-action@v6 with: context: source - file: ${{ github.workspace }}/source/deploy/backend.Dockerfile + file: ${{ githubAPI_BASE_URL.workspace }}/source/deploy/backend.Dockerfile push: true tags: ghcr.io/${{ github.repository_owner }}/gobison-backend:${{ github.event.workflow_run.head_sha }} From efaa0383e09cb0918b4b9f2a4eefae7bcc5f3878 Mon Sep 17 00:00:00 2001 From: popcorn9499 <6319808+popcorn9499@users.noreply.github.com> Date: Fri, 4 Dec 2026 18:58:23 -0600 Subject: [PATCH 5/5] fix a typo --- .github/workflows/container-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/container-deploy.yml b/.github/workflows/container-deploy.yml index 18666a6..aee60a7 100644 --- a/.github/workflows/container-deploy.yml +++ b/.github/workflows/container-deploy.yml @@ -99,7 +99,7 @@ jobs: uses: docker/build-push-action@v6 with: context: source - file: ${{ githubAPI_BASE_URL.workspace }}/source/deploy/backend.Dockerfile + file: ${{ github.workspace }}/source/deploy/backend.Dockerfile push: true tags: ghcr.io/${{ github.repository_owner }}/gobison-backend:${{ github.event.workflow_run.head_sha }}