feat: complete secure pricing delivery and rollback documentation
startup-product-gitea-ci/pipeline/pr-main There was a failure building this commit
startup-product-gitea-ci/pipeline/head There was a failure building this commit

This commit is contained in:
2026-11-13 21:07:53 -05:00
parent c6a53349ee
commit 36cec81744
52 changed files with 1716 additions and 5 deletions
@@ -0,0 +1,40 @@
---
- name: Check staging release before deployment
hosts: staging
gather_facts: false
vars:
container_name: startup-pricing-staging
release_image: startup-pricing:release-v2-20261113
tasks:
- name: Get desired release image ID
ansible.builtin.command:
argv:
- docker
- image
- inspect
- "{{ release_image }}"
- --format
- "{{ '{{.Id}}' }}"
register: desired_image
changed_when: false
- name: Get current container image ID
ansible.builtin.command:
argv:
- docker
- inspect
- "{{ container_name }}"
- --format
- "{{ '{{.Image}}' }}"
register: current_image
changed_when: false
failed_when: false
- name: Report whether image replacement is needed
ansible.builtin.debug:
msg: >-
Replacement needed:
{{ current_image.rc != 0 or
current_image.stdout != desired_image.stdout }}
+169
View File
@@ -0,0 +1,169 @@
---
- name: Deploy secure pricing service to staging
hosts: staging
gather_facts: false
vars:
container_name: startup-pricing-staging
release_image: startup-pricing:release-v2-20261113
expected_version: v2
tasks:
- name: Inspect current staging container
ansible.builtin.command:
argv:
- docker
- inspect
- "{{ container_name }}"
register: current_container
changed_when: false
failed_when: false
check_mode: false
- name: Confirm release image exists
ansible.builtin.command:
argv:
- docker
- image
- inspect
- "{{ release_image }}"
changed_when: false
check_mode: false
- name: Get desired release image ID
ansible.builtin.command:
argv:
- docker
- image
- inspect
- "{{ release_image }}"
- --format
- "{{ '{{.Id}}' }}"
register: desired_image
changed_when: false
check_mode: false
- name: Get current staging image ID
ansible.builtin.command:
argv:
- docker
- inspect
- "{{ container_name }}"
- --format
- "{{ '{{.Image}}' }}"
register: current_image
changed_when: false
failed_when: false
check_mode: false
- name: Determine whether staging replacement is required
ansible.builtin.set_fact:
replace_staging: >-
{{
current_image.rc != 0
or current_image.stdout != desired_image.stdout
or not (
(current_container.stdout | from_json | first).State.Running
if current_container.rc == 0
else false
)
}}
- name: Display replacement decision
ansible.builtin.debug:
msg: "Replacement needed: {{ replace_staging }}"
- name: Stop existing staging container if present
ansible.builtin.command:
argv:
- docker
- stop
- "{{ container_name }}"
when:
- not ansible_check_mode
- current_container.rc == 0
- replace_staging
- name: Remove existing staging container if present
ansible.builtin.command:
argv:
- docker
- rm
- "{{ container_name }}"
when:
- not ansible_check_mode
- current_container.rc == 0
- replace_staging
- name: Start secure staging container
ansible.builtin.command:
argv:
- docker
- run
- -d
- --name
- "{{ container_name }}"
- --memory=64m
- --memory-swap=128m
- --cpus=0.5
- --pids-limit=64
- --read-only
- --tmpfs
- /tmp:rw,nosuid,nodev,size=16m
- --security-opt
- no-new-privileges:true
- --cap-drop
- ALL
- -p
- 127.0.0.1:5062:5000
- "{{ release_image }}"
- gunicorn
- --workers
- "1"
- --bind
- 0.0.0.0:5000
- app:app
when:
- not ansible_check_mode
- replace_staging
- name: Wait for staging health endpoint
ansible.builtin.uri:
url: http://127.0.0.1:5062/health
method: GET
status_code: 200
return_content: true
register: staging_health
retries: 10
delay: 2
until: staging_health.status == 200
check_mode: false
when: not (ansible_check_mode and replace_staging)
- name: Verify staging health response
ansible.builtin.assert:
that:
- staging_health.json.status == "healthy"
success_msg: "Staging health check passed."
when: not (ansible_check_mode and replace_staging)
- name: Check staging pricing endpoint
ansible.builtin.uri:
url: http://127.0.0.1:5062/pricing
method: GET
status_code: 200
return_content: true
register: staging_pricing
retries: 10
delay: 2
until: staging_pricing.status == 200
check_mode: false
when: not (ansible_check_mode and replace_staging)
- name: Verify staging application version
ansible.builtin.assert:
that:
- staging_pricing.json.version == expected_version
success_msg: "Secure staging deployment succeeded."
when: not (ansible_check_mode and replace_staging)
+7
View File
@@ -0,0 +1,7 @@
[staging]
digitalocean ansible_host=143.244.173.110
[staging:vars]
ansible_user=root
ansible_ssh_private_key_file=~/.ssh/ssw590_digitalocean
ansible_python_interpreter=/usr/bin/python3
@@ -0,0 +1,33 @@
---
- name: Verify secure pricing staging deployment
hosts: staging
gather_facts: false
tasks:
- name: Inspect staging container
ansible.builtin.command:
argv:
- docker
- inspect
- startup-pricing-staging
register: staging_inspect
changed_when: false
- name: Check staging health endpoint
ansible.builtin.uri:
url: http://127.0.0.1:5062/health
method: GET
status_code: 200
return_content: true
register: staging_health
- name: Assert staging is healthy and running v2
ansible.builtin.assert:
that:
- staging_health.json.status == "healthy"
- staging_health.json.version == "v2"
success_msg: "Staging is healthy and running v2"
- name: Display verification result
ansible.builtin.debug:
msg: "Ansible verified the existing staging deployment successfully."