diff --git a/.gitea/workflows/manual-build.yml b/.gitea/workflows/manual-build.yml index 8634b47..e00d2ac 100644 --- a/.gitea/workflows/manual-build.yml +++ b/.gitea/workflows/manual-build.yml @@ -21,7 +21,7 @@ jobs: run: | set -eu SHORT_SHA="$(printf '%s' "$GITHUB_SHA" | cut -c1-7)" - BUILD_ID="v1.4+build.${GITHUB_RUN_NUMBER}.${SHORT_SHA}" + BUILD_ID="v1.5+build.${GITHUB_RUN_NUMBER}.${SHORT_SHA}" cat > manual/build_metadata.tex <- + Replacement needed: + {{ current_image.rc != 0 or + current_image.stdout != desired_image.stdout }} diff --git a/pricing-service/ansible/deploy-staging.yml b/pricing-service/ansible/deploy-staging.yml new file mode 100644 index 0000000..11d81ef --- /dev/null +++ b/pricing-service/ansible/deploy-staging.yml @@ -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) diff --git a/pricing-service/ansible/inventory.ini b/pricing-service/ansible/inventory.ini new file mode 100644 index 0000000..97f7942 --- /dev/null +++ b/pricing-service/ansible/inventory.ini @@ -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 diff --git a/pricing-service/ansible/verify-staging.yml b/pricing-service/ansible/verify-staging.yml new file mode 100644 index 0000000..9206fcc --- /dev/null +++ b/pricing-service/ansible/verify-staging.yml @@ -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." diff --git a/pricing-service/app.py b/pricing-service/app.py new file mode 100644 index 0000000..54343ec --- /dev/null +++ b/pricing-service/app.py @@ -0,0 +1,25 @@ +from flask import Flask, jsonify + +app = Flask(__name__) + + +@app.get("/health") +def health(): + return jsonify({"status": "healthy"}), 200 + + +@app.get("/pricing") +def pricing(): + return jsonify({ + "service": "Startup Pricing Service", + "version": "v1", + "plans": [ + {"name": "Basic", "price": 10}, + {"name": "Pro", "price": 25}, + {"name": "Enterprise", "price": 50} + ] + }), 200 + + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=5000) diff --git a/pricing-service/chapter6-evidence/03-release-integrity/digitalocean-release-images.txt b/pricing-service/chapter6-evidence/03-release-integrity/digitalocean-release-images.txt new file mode 100644 index 0000000..e477a3f --- /dev/null +++ b/pricing-service/chapter6-evidence/03-release-integrity/digitalocean-release-images.txt @@ -0,0 +1,2 @@ +Image=startup-pricing:release-v1-20261113 ID=sha256:d0d0a2c2052b01a33ce12fd2b278e906552ea9797b5b918f44e5065f444d3027 Platform=linux/amd64 User=appuser +Image=startup-pricing:release-v2-20261113 ID=sha256:008f4481d5cff032ceef48a45acb0cc7c17c2e99c1e4830e62205bc75e8e4707 Platform=linux/amd64 User=appuser diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/ansible-connectivity.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/ansible-connectivity.txt new file mode 100644 index 0000000..8f73fe0 --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/ansible-connectivity.txt @@ -0,0 +1,4 @@ +digitalocean | SUCCESS => { + "changed": false, + "ping": "pong" +} diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/ansible-staging-verification.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/ansible-staging-verification.txt new file mode 100644 index 0000000..b5e7f1d --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/ansible-staging-verification.txt @@ -0,0 +1,22 @@ + +PLAY [Verify secure pricing staging deployment] ******************************** + +TASK [Inspect staging container] *********************************************** +ok: [digitalocean] + +TASK [Check staging health endpoint] ******************************************* +ok: [digitalocean] + +TASK [Assert staging is healthy and running v2] ******************************** +ok: [digitalocean] => { + "changed": false, + "msg": "Staging is healthy and running v2" +} + +TASK [Display verification result] ********************************************* +ok: [digitalocean] => { + "msg": "Ansible verified the existing staging deployment successfully." +} + +PLAY RECAP ********************************************************************* +digitalocean : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-check-mode-after-fix.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-check-mode-after-fix.txt new file mode 100644 index 0000000..247df10 --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-check-mode-after-fix.txt @@ -0,0 +1,50 @@ + +PLAY [Deploy secure pricing service to staging] ******************************** + +TASK [Inspect current staging container] *************************************** +skipping: [digitalocean] + +TASK [Confirm release image exists] ******************************************** +skipping: [digitalocean] + +TASK [Get desired release image ID] ******************************************** +skipping: [digitalocean] + +TASK [Get current staging image ID] ******************************************** +skipping: [digitalocean] + +TASK [Determine whether staging replacement is required] *********************** +[ERROR]: Task failed: Finalization of task args for 'ansible.builtin.set_fact' failed: Error while resolving value for 'replace_staging': The filter plugin 'ansible.builtin.from_json' failed: Expecting value: line 1 column 1 (char 0) + +Task failed. +Origin: /Users/nageshwaranmanikumar/Desktop/SSW590/startup-product/pricing-service/ansible/deploy-staging.yml:54:7 + +52 failed_when: false +53 +54 - name: Determine whether staging replacement is required + ^ column 7 + +<<< caused by >>> + +Finalization of task args for 'ansible.builtin.set_fact' failed. +Origin: /Users/nageshwaranmanikumar/Desktop/SSW590/startup-product/pricing-service/ansible/deploy-staging.yml:55:7 + +53 +54 - name: Determine whether staging replacement is required +55 ansible.builtin.set_fact: + ^ column 7 + +<<< caused by >>> + +Error while resolving value for 'replace_staging': The filter plugin 'ansible.builtin.from_json' failed: Expecting value: line 1 column 1 (char 0) +Origin: /Users/nageshwaranmanikumar/Desktop/SSW590/startup-product/pricing-service/ansible/deploy-staging.yml:56:26 + +54 - name: Determine whether staging replacement is required +55 ansible.builtin.set_fact: +56 replace_staging: >- + ^ column 26 + +fatal: [digitalocean]: FAILED! => {"changed": false, "msg": "Task failed: Finalization of task args for 'ansible.builtin.set_fact' failed: Error while resolving value for 'replace_staging': The filter plugin 'ansible.builtin.from_json' failed: Expecting value: line 1 column 1 (char 0)"} + +PLAY RECAP ********************************************************************* +digitalocean : ok=0 changed=0 unreachable=0 failed=1 skipped=4 rescued=0 ignored=0 diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-check-mode-fixed.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-check-mode-fixed.txt new file mode 100644 index 0000000..99e4e44 --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-check-mode-fixed.txt @@ -0,0 +1,38 @@ + +PLAY [Deploy secure pricing service to staging] ******************************** + +TASK [Inspect current staging container] *************************************** +skipping: [digitalocean] + +TASK [Confirm release image exists] ******************************************** +skipping: [digitalocean] + +TASK [Get desired release image ID] ******************************************** +skipping: [digitalocean] + +TASK [Get current staging image ID] ******************************************** +skipping: [digitalocean] + +TASK [Determine whether staging replacement is required] *********************** +ok: [digitalocean] + +TASK [Stop existing staging container if present] ****************************** +skipping: [digitalocean] + +TASK [Remove existing staging container if present] **************************** +skipping: [digitalocean] + +TASK [Start secure staging container] ****************************************** +skipping: [digitalocean] + +TASK [Wait for staging health endpoint] **************************************** +ok: [digitalocean] + +TASK [Verify staging version] ************************************************** +ok: [digitalocean] => { + "changed": false, + "msg": "Secure staging deployment succeeded." +} + +PLAY RECAP ********************************************************************* +digitalocean : ok=3 changed=0 unreachable=0 failed=0 skipped=7 rescued=0 ignored=0 diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-check-mode.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-check-mode.txt new file mode 100644 index 0000000..51dfa47 --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-check-mode.txt @@ -0,0 +1,55 @@ + +PLAY [Deploy secure pricing service to staging] ******************************** + +TASK [Inspect current staging container] *************************************** +skipping: [digitalocean] + +TASK [Confirm release image exists] ******************************************** +skipping: [digitalocean] + +TASK [Get desired release image ID] ******************************************** +skipping: [digitalocean] + +TASK [Get current staging image ID] ******************************************** +skipping: [digitalocean] + +TASK [Determine whether staging replacement is required] *********************** +ok: [digitalocean] + +TASK [Stop existing staging container if present] ****************************** +skipping: [digitalocean] + +TASK [Remove existing staging container if present] **************************** +skipping: [digitalocean] + +TASK [Start secure staging container] ****************************************** +skipping: [digitalocean] + +TASK [Wait for staging health endpoint] **************************************** +skipping: [digitalocean] + +TASK [Verify staging version] ************************************************** +[ERROR]: Task failed: Error while evaluating conditional: object of type 'dict' has no attribute 'json' + +Task failed. +Origin: /Users/nageshwaranmanikumar/Desktop/SSW590/startup-product/pricing-service/ansible/deploy-staging.yml:118:7 + +116 until: staging_health.status == 200 +117 +118 - name: Verify staging version + ^ column 7 + +<<< caused by >>> + +Error while evaluating conditional: object of type 'dict' has no attribute 'json' +Origin: /Users/nageshwaranmanikumar/Desktop/SSW590/startup-product/pricing-service/ansible/deploy-staging.yml:121:13 + +119 ansible.builtin.assert: +120 that: +121 - staging_health.json.status == "healthy" + ^ column 13 + +fatal: [digitalocean]: FAILED! => {"changed": false, "msg": "Task failed: Error while evaluating conditional: object of type 'dict' has no attribute 'json'"} + +PLAY RECAP ********************************************************************* +digitalocean : ok=1 changed=0 unreachable=0 failed=1 skipped=8 rescued=0 ignored=0 diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-execution.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-execution.txt new file mode 100644 index 0000000..8834b63 --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-execution.txt @@ -0,0 +1,38 @@ + +PLAY [Deploy secure pricing service to staging] ******************************** + +TASK [Inspect current staging container] *************************************** +ok: [digitalocean] + +TASK [Confirm release image exists] ******************************************** +ok: [digitalocean] + +TASK [Get desired release image ID] ******************************************** +ok: [digitalocean] + +TASK [Get current staging image ID] ******************************************** +ok: [digitalocean] + +TASK [Determine whether staging replacement is required] *********************** +ok: [digitalocean] + +TASK [Stop existing staging container if present] ****************************** +changed: [digitalocean] + +TASK [Remove existing staging container if present] **************************** +changed: [digitalocean] + +TASK [Start secure staging container] ****************************************** +changed: [digitalocean] + +TASK [Wait for staging health endpoint] **************************************** +ok: [digitalocean] + +TASK [Verify staging version] ************************************************** +ok: [digitalocean] => { + "changed": false, + "msg": "Secure staging deployment succeeded." +} + +PLAY RECAP ********************************************************************* +digitalocean : ok=10 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-final-check.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-final-check.txt new file mode 100644 index 0000000..412247a --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-final-check.txt @@ -0,0 +1,50 @@ + +PLAY [Deploy secure pricing service to staging] ******************************** + +TASK [Inspect current staging container] *************************************** +ok: [digitalocean] + +TASK [Confirm release image exists] ******************************************** +ok: [digitalocean] + +TASK [Get desired release image ID] ******************************************** +ok: [digitalocean] + +TASK [Get current staging image ID] ******************************************** +ok: [digitalocean] + +TASK [Determine whether staging replacement is required] *********************** +[ERROR]: Task failed: Finalization of task args for 'ansible.builtin.set_fact' failed: Error while resolving value for 'replace_staging': object of type 'list' has no attribute 'State' + +Task failed. +Origin: /Users/nageshwaranmanikumar/Desktop/SSW590/startup-product/pricing-service/ansible/deploy-staging.yml:59:7 + +57 check_mode: false +58 +59 - name: Determine whether staging replacement is required + ^ column 7 + +<<< caused by >>> + +Finalization of task args for 'ansible.builtin.set_fact' failed. +Origin: /Users/nageshwaranmanikumar/Desktop/SSW590/startup-product/pricing-service/ansible/deploy-staging.yml:60:7 + +58 +59 - name: Determine whether staging replacement is required +60 ansible.builtin.set_fact: + ^ column 7 + +<<< caused by >>> + +Error while resolving value for 'replace_staging': object of type 'list' has no attribute 'State' +Origin: /Users/nageshwaranmanikumar/Desktop/SSW590/startup-product/pricing-service/ansible/deploy-staging.yml:61:26 + +59 - name: Determine whether staging replacement is required +60 ansible.builtin.set_fact: +61 replace_staging: >- + ^ column 26 + +fatal: [digitalocean]: FAILED! => {"changed": false, "msg": "Task failed: Finalization of task args for 'ansible.builtin.set_fact' failed: Error while resolving value for 'replace_staging': object of type 'list' has no attribute 'State'"} + +PLAY RECAP ********************************************************************* +digitalocean : ok=4 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-idempotency-test.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-idempotency-test.txt new file mode 100644 index 0000000..3af9b8c --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-idempotency-test.txt @@ -0,0 +1,43 @@ + +PLAY [Deploy secure pricing service to staging] ******************************** + +TASK [Inspect current staging container] *************************************** +ok: [digitalocean] + +TASK [Confirm release image exists] ******************************************** +ok: [digitalocean] + +TASK [Get desired release image ID] ******************************************** +ok: [digitalocean] + +TASK [Get current staging image ID] ******************************************** +ok: [digitalocean] + +TASK [Determine whether staging replacement is required] *********************** +ok: [digitalocean] + +TASK [Display replacement decision] ******************************************** +ok: [digitalocean] => { + "msg": "Replacement needed: False" +} + +TASK [Stop existing staging container if present] ****************************** +skipping: [digitalocean] + +TASK [Remove existing staging container if present] **************************** +skipping: [digitalocean] + +TASK [Start secure staging container] ****************************************** +skipping: [digitalocean] + +TASK [Wait for staging health endpoint] **************************************** +ok: [digitalocean] + +TASK [Verify staging version] ************************************************** +ok: [digitalocean] => { + "changed": false, + "msg": "Secure staging deployment succeeded." +} + +PLAY RECAP ********************************************************************* +digitalocean : ok=8 changed=0 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0 diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-json-list-fixed.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-json-list-fixed.txt new file mode 100644 index 0000000..3af9b8c --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-json-list-fixed.txt @@ -0,0 +1,43 @@ + +PLAY [Deploy secure pricing service to staging] ******************************** + +TASK [Inspect current staging container] *************************************** +ok: [digitalocean] + +TASK [Confirm release image exists] ******************************************** +ok: [digitalocean] + +TASK [Get desired release image ID] ******************************************** +ok: [digitalocean] + +TASK [Get current staging image ID] ******************************************** +ok: [digitalocean] + +TASK [Determine whether staging replacement is required] *********************** +ok: [digitalocean] + +TASK [Display replacement decision] ******************************************** +ok: [digitalocean] => { + "msg": "Replacement needed: False" +} + +TASK [Stop existing staging container if present] ****************************** +skipping: [digitalocean] + +TASK [Remove existing staging container if present] **************************** +skipping: [digitalocean] + +TASK [Start secure staging container] ****************************************** +skipping: [digitalocean] + +TASK [Wait for staging health endpoint] **************************************** +ok: [digitalocean] + +TASK [Verify staging version] ************************************************** +ok: [digitalocean] => { + "changed": false, + "msg": "Secure staging deployment succeeded." +} + +PLAY RECAP ********************************************************************* +digitalocean : ok=8 changed=0 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0 diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-safe-syntax.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-safe-syntax.txt new file mode 100644 index 0000000..1e41a43 --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-safe-syntax.txt @@ -0,0 +1,2 @@ + +playbook: ansible/deploy-staging.yml diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-syntax-check.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-syntax-check.txt new file mode 100644 index 0000000..1e41a43 --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/deploy-staging-syntax-check.txt @@ -0,0 +1,2 @@ + +playbook: ansible/deploy-staging.yml diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/playbook-syntax-check.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/playbook-syntax-check.txt new file mode 100644 index 0000000..9f902e8 --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/playbook-syntax-check.txt @@ -0,0 +1,2 @@ + +playbook: ansible/verify-staging.yml diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/pre-deployment-resources.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/pre-deployment-resources.txt new file mode 100644 index 0000000..6396d27 --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/pre-deployment-resources.txt @@ -0,0 +1,11 @@ + total used free shared buff/cache available +Mem: 458Mi 334Mi 7.7Mi 3.0Mi 140Mi 124Mi +Swap: 1.0Gi 756Mi 267Mi +CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS +50fb5110c6d3 grafana 10.67% 25.88MiB / 192MiB 13.48% 113MB / 447MB 2.96TB / 714GB 31 +2d22225910a8 prometheus 8.27% 20.63MiB / 128MiB 16.12% 632MB / 122MB 1.32TB / 444GB 8 +d480acd19bde blackbox-exporter 1.89% 9.273MiB / 32MiB 28.98% 1.17GB / 241MB 425GB / 109GB 8 +7b33270bc99a node-exporter 0.00% 652KiB / 32MiB 1.99% 31.1MB / 463MB 463GB / 139GB 4 +58e75ecb35c7 caddy 1.60% 13.61MiB / 458.2MiB 2.97% 3.66GB / 4.05GB 819GB / 171GB 8 +9f243097358c jenkins 0.48% 139.3MiB / 384MiB 36.29% 69.7MB / 163MB 330GB / 88.1GB 46 +e45237a53503 gitea 13.53% 31.66MiB / 458.2MiB 6.91% 125MB / 2.79GB 3.8TB / 1.71TB 51 diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/release-check-execution.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/release-check-execution.txt new file mode 100644 index 0000000..8637dcf --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/release-check-execution.txt @@ -0,0 +1,16 @@ + +PLAY [Check staging release before deployment] ********************************* + +TASK [Get desired release image ID] ******************************************** +ok: [digitalocean] + +TASK [Get current container image ID] ****************************************** +ok: [digitalocean] + +TASK [Report whether image replacement is needed] ****************************** +ok: [digitalocean] => { + "msg": "Replacement needed: False" +} + +PLAY RECAP ********************************************************************* +digitalocean : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/release-check-syntax.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/release-check-syntax.txt new file mode 100644 index 0000000..4a509a2 --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/release-check-syntax.txt @@ -0,0 +1,2 @@ + +playbook: ansible/check-staging-release.yml diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/staging-before-ansible.json b/pricing-service/chapter6-evidence/05-ansible-deployment/staging-before-ansible.json new file mode 100644 index 0000000..3e24510 --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/staging-before-ansible.json @@ -0,0 +1,231 @@ +[ + { + "Id": "d6fee4b0ca309694dc1a40e4e143d243e5fd465c5c59b20fbe6c7b0df2f2a03e", + "Created": "2026-11-14T00:10:40.598265925Z", + "Path": "gunicorn", + "Args": [ + "--workers", + "1", + "--bind", + "0.0.0.0:5000", + "app:app" + ], + "State": { + "Status": "running", + "Running": true, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 286251, + "ExitCode": 0, + "Error": "", + "StartedAt": "2026-11-14T00:10:41.260368681Z", + "FinishedAt": "0001-01-01T00:00:00Z" + }, + "Image": "sha256:008f4481d5cff032ceef48a45acb0cc7c17c2e99c1e4830e62205bc75e8e4707", + "ResolvConfPath": "/var/lib/docker/containers/d6fee4b0ca309694dc1a40e4e143d243e5fd465c5c59b20fbe6c7b0df2f2a03e/resolv.conf", + "HostnamePath": "/var/lib/docker/containers/d6fee4b0ca309694dc1a40e4e143d243e5fd465c5c59b20fbe6c7b0df2f2a03e/hostname", + "HostsPath": "/var/lib/docker/containers/d6fee4b0ca309694dc1a40e4e143d243e5fd465c5c59b20fbe6c7b0df2f2a03e/hosts", + "LogPath": "/var/lib/docker/containers/d6fee4b0ca309694dc1a40e4e143d243e5fd465c5c59b20fbe6c7b0df2f2a03e/d6fee4b0ca309694dc1a40e4e143d243e5fd465c5c59b20fbe6c7b0df2f2a03e-json.log", + "Name": "/startup-pricing-staging", + "RestartCount": 0, + "Driver": "overlayfs", + "Platform": "linux", + "MountLabel": "", + "ProcessLabel": "", + "AppArmorProfile": "docker-default", + "ExecIDs": null, + "HostConfig": { + "Binds": null, + "ContainerIDFile": "", + "LogConfig": { + "Type": "json-file", + "Config": {} + }, + "NetworkMode": "bridge", + "PortBindings": { + "5000/tcp": [ + { + "HostIp": "127.0.0.1", + "HostPort": "5062" + } + ] + }, + "RestartPolicy": { + "Name": "no", + "MaximumRetryCount": 0 + }, + "AutoRemove": false, + "VolumeDriver": "", + "VolumesFrom": null, + "ConsoleSize": [ + 0, + 0 + ], + "CapAdd": null, + "CapDrop": [ + "ALL" + ], + "CgroupnsMode": "private", + "Dns": null, + "DnsOptions": [], + "DnsSearch": [], + "ExtraHosts": null, + "GroupAdd": null, + "IpcMode": "private", + "Cgroup": "", + "Links": null, + "OomScoreAdj": 0, + "PidMode": "", + "Privileged": false, + "PublishAllPorts": false, + "ReadonlyRootfs": true, + "SecurityOpt": [ + "no-new-privileges:true" + ], + "Tmpfs": { + "/tmp": "rw,nosuid,nodev,size=16m" + }, + "UTSMode": "", + "UsernsMode": "", + "ShmSize": 67108864, + "Runtime": "runc", + "Isolation": "", + "CpuShares": 0, + "Memory": 67108864, + "NanoCpus": 500000000, + "CgroupParent": "", + "BlkioWeight": 0, + "BlkioWeightDevice": [], + "BlkioDeviceReadBps": [], + "BlkioDeviceWriteBps": [], + "BlkioDeviceReadIOps": [], + "BlkioDeviceWriteIOps": [], + "CpuPeriod": 0, + "CpuQuota": 0, + "CpuRealtimePeriod": 0, + "CpuRealtimeRuntime": 0, + "CpusetCpus": "", + "CpusetMems": "", + "Devices": [], + "DeviceCgroupRules": null, + "DeviceRequests": null, + "MemoryReservation": 0, + "MemorySwap": 134217728, + "MemorySwappiness": null, + "OomKillDisable": null, + "PidsLimit": 64, + "Ulimits": [], + "CpuCount": 0, + "CpuPercent": 0, + "IOMaximumIOps": 0, + "IOMaximumBandwidth": 0, + "MaskedPaths": [ + "/proc/acpi", + "/proc/asound", + "/proc/interrupts", + "/proc/kcore", + "/proc/keys", + "/proc/latency_stats", + "/proc/sched_debug", + "/proc/scsi", + "/proc/timer_list", + "/proc/timer_stats", + "/sys/devices/virtual/powercap", + "/sys/firmware" + ], + "ReadonlyPaths": [ + "/proc/bus", + "/proc/fs", + "/proc/irq", + "/proc/sys", + "/proc/sysrq-trigger" + ] + }, + "Storage": { + "RootFS": { + "Snapshot": { + "Name": "overlayfs" + } + } + }, + "Mounts": [], + "Config": { + "Hostname": "d6fee4b0ca30", + "Domainname": "", + "User": "appuser", + "AttachStdin": false, + "AttachStdout": false, + "AttachStderr": false, + "ExposedPorts": { + "5000/tcp": {} + }, + "Tty": false, + "OpenStdin": false, + "StdinOnce": false, + "Env": [ + "PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", + "LANG=C.UTF-8", + "GPG_KEY=7169605F62C751356D054A26A821E680E5FA6305", + "PYTHON_VERSION=3.13.18", + "PYTHON_SHA256=abb0102e6d4ae027509bcb82327d9dd85515b44a3ba8ad538cfc5e9847029f68", + "PYTHONDONTWRITEBYTECODE=1", + "PYTHONUNBUFFERED=1" + ], + "Cmd": [ + "gunicorn", + "--workers", + "1", + "--bind", + "0.0.0.0:5000", + "app:app" + ], + "Image": "startup-pricing:release-v2-20261113", + "Volumes": null, + "WorkingDir": "/app", + "Entrypoint": null, + "Labels": {} + }, + "NetworkSettings": { + "SandboxID": "f9bb6a75eb59bb42120d9d7ad2c6b43da4e0253b2704f37b8b300f4a3accc3b8", + "SandboxKey": "/var/run/docker/netns/f9bb6a75eb59", + "Ports": { + "5000/tcp": [ + { + "HostIp": "127.0.0.1", + "HostPort": "5062" + } + ] + }, + "Networks": { + "bridge": { + "IPAMConfig": null, + "Links": null, + "Aliases": null, + "DriverOpts": null, + "GwPriority": 0, + "NetworkID": "dcc4503fc49e15773f240848c06ef6380ae3e4fbcfd4c8bdd316c6199cfcab63", + "EndpointID": "66c439997e5e4e43ae2883761373c6a81838ab77be13221127c2a34ef5a494d2", + "Gateway": "172.17.0.1", + "IPAddress": "172.17.0.2", + "MacAddress": "c2:40:1e:46:99:2d", + "IPPrefixLen": 16, + "IPv6Gateway": "", + "GlobalIPv6Address": "", + "GlobalIPv6PrefixLen": 0, + "DNSNames": null + } + } + }, + "ImageManifestDescriptor": { + "mediaType": "application/vnd.oci.image.manifest.v1+json", + "digest": "sha256:e8c9b28b2cb30e27f138d95bdd14ade4ea56202156b9761ae57ecfbef51a36ef", + "size": 1999, + "platform": { + "architecture": "amd64", + "os": "linux" + } + } + } +] diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/staging-before-safe-deployment.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/staging-before-safe-deployment.txt new file mode 100644 index 0000000..6bdaa58 --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/staging-before-safe-deployment.txt @@ -0,0 +1 @@ +ImageID=sha256:008f4481d5cff032ceef48a45acb0cc7c17c2e99c1e4830e62205bc75e8e4707 Status=running RestartCount=0 diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/staging-idempotency-verification.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/staging-idempotency-verification.txt new file mode 100644 index 0000000..8555944 --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/staging-idempotency-verification.txt @@ -0,0 +1,7 @@ +Chapter 6 - Ansible Staging Idempotency Verification +Verified after real Ansible deployment + +ContainerID=49b27eaa9b37d8929165de042bbcfee85953e1038ea8b0f8df6c2d7cdd590377 Status=running RestartCount=0 ImageID=sha256:008f4481d5cff032ceef48a45acb0cc7c17c2e99c1e4830e62205bc75e8e4707 + +Health endpoint: +{"status":"healthy","version":"v2"} diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/staging-security-configuration.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/staging-security-configuration.txt new file mode 100644 index 0000000..6af24ac --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/staging-security-configuration.txt @@ -0,0 +1 @@ +Image=startup-pricing:release-v2-20261113 Memory=67108864 MemorySwap=134217728 NanoCPUs=500000000 PidsLimit=64 ReadOnly=true CapDrop=["ALL"] Security=["no-new-privileges:true"] Restart=no Ports={"5000/tcp":[{"HostIp":"127.0.0.1","HostPort":"5062"}]} Tmpfs={"/tmp":"rw,nosuid,nodev,size=16m"} Cmd=["gunicorn","--workers","1","--bind","0.0.0.0:5000","app:app"] diff --git a/pricing-service/chapter6-evidence/05-ansible-deployment/staging-v2-verification.txt b/pricing-service/chapter6-evidence/05-ansible-deployment/staging-v2-verification.txt new file mode 100644 index 0000000..3adc6ff --- /dev/null +++ b/pricing-service/chapter6-evidence/05-ansible-deployment/staging-v2-verification.txt @@ -0,0 +1,41 @@ +=== STAGING HEALTH === + % Total % Received % Xferd Average Speed Time Time Time Current + Dload Upload Total Spent Left Speed + + 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 +1HTTP/1.1 200 OK +Server: gunicorn +Date: Sat, 14 Nov 2026 00:11:31 GMT +Connection: close +Content-Type: application/json +Content-Length: 36 + +{"status":"healthy","version":"v2"} +00 36 100 36 0 0 5268 0 --:--:-- --:--:-- --:--:-- 6000 + +=== STAGING PRICING === + % Total % Received % Xferd Average Speed Time Time Time Current + Dload Upload Total Spent Left Speed + + 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 +1HTTP/1.1 200 OK +Server: gunicorn +Date: Sat, 14 Nov 2026 00:11:31 GMT +Connection: close +Content-Type: application/json +Content-Length: 179 + +{"plans":[{"name":"Starter","price":5},{"name":"Basic","price":12},{"name":"Pro","price":30},{"name":"Enterprise","price":60}],"service":"Startup Pricing Service","version":"v2"} +00 179 100 179 0 0 53673 0 --:--:-- --:--:-- --:--:-- 59666 + +=== CONTAINER STATUS === +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +d6fee4b0ca30 startup-pricing:release-v2-20261113 "gunicorn --workers …" 52 seconds ago Up 50 seconds 127.0.0.1:5062->5000/tcp startup-pricing-staging +=== RESOURCE USAGE === +CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS +d6fee4b0ca30 startup-pricing-staging 0.05% 8.047MiB / 64MiB 12.57% 3.07kB / 2.66kB 54.1MB / 48.3MB 2 +=== STARTUP LOGS === +[2026-11-14 00:10:44 +0000] [1] [INFO] Starting gunicorn 23.0.0 +[2026-11-14 00:10:44 +0000] [1] [INFO] Listening at: http://0.0.0.0:5000 (1) +[2026-11-14 00:10:44 +0000] [1] [INFO] Using worker: sync +[2026-11-14 00:10:44 +0000] [8] [INFO] Booting worker with pid: 8 diff --git a/pricing-service/chapter6-evidence/06-rollback-recovery/final-v2-recovery.txt b/pricing-service/chapter6-evidence/06-rollback-recovery/final-v2-recovery.txt new file mode 100644 index 0000000..bfb5e4f --- /dev/null +++ b/pricing-service/chapter6-evidence/06-rollback-recovery/final-v2-recovery.txt @@ -0,0 +1,11 @@ +Chapter 6 - Final v2 Recovery Verification +Date: Fri Nov 13 20:56:52 EST 2026 + +=== Container === +Status=running Image=startup-pricing:release-v2-20261113 RestartCount=0 ImageID=sha256:008f4481d5cff032ceef48a45acb0cc7c17c2e99c1e4830e62205bc75e8e4707 + +=== Health === +{"status":"healthy","version":"v2"} + +=== Pricing === +{"plans":[{"name":"Starter","price":5},{"name":"Basic","price":12},{"name":"Pro","price":30},{"name":"Enterprise","price":60}],"service":"Startup Pricing Service","version":"v2"} diff --git a/pricing-service/releases/SHA256SUMS b/pricing-service/releases/SHA256SUMS new file mode 100644 index 0000000..8724aa4 --- /dev/null +++ b/pricing-service/releases/SHA256SUMS @@ -0,0 +1,2 @@ +d9f8a6e420728b45c5ad56e80e0b7189d79cb9e09b9eddebec8aea2501c2d536 releases/startup-pricing-v1-20261113.tar +b7bfe31fbfdfd0d706503a3119d14cc6c21d3d377fb58588004ed571ddfae2ae releases/startup-pricing-v2-20261113.tar diff --git a/pricing-service/releases/startup-pricing-v1-20261113.tar b/pricing-service/releases/startup-pricing-v1-20261113.tar new file mode 100644 index 0000000..7debec8 Binary files /dev/null and b/pricing-service/releases/startup-pricing-v1-20261113.tar differ diff --git a/pricing-service/releases/startup-pricing-v2-20261113.tar b/pricing-service/releases/startup-pricing-v2-20261113.tar new file mode 100644 index 0000000..2ab1e28 Binary files /dev/null and b/pricing-service/releases/startup-pricing-v2-20261113.tar differ diff --git a/pricing-service/requirements-production.txt b/pricing-service/requirements-production.txt new file mode 100644 index 0000000..e9b38fe --- /dev/null +++ b/pricing-service/requirements-production.txt @@ -0,0 +1,2 @@ +Flask>=3.1,<4.0 +gunicorn>=23,<24 diff --git a/pricing-service/requirements.txt b/pricing-service/requirements.txt new file mode 100644 index 0000000..fdecb8e --- /dev/null +++ b/pricing-service/requirements.txt @@ -0,0 +1 @@ +Flask>=3.1,<4.0 diff --git a/pricing-service/test_app.py b/pricing-service/test_app.py new file mode 100644 index 0000000..eae0739 --- /dev/null +++ b/pricing-service/test_app.py @@ -0,0 +1,33 @@ +import unittest +from app import app + + +class PricingServiceTests(unittest.TestCase): + + def setUp(self): + self.client = app.test_client() + + def test_health_endpoint(self): + response = self.client.get("/health") + + self.assertEqual(response.status_code, 200) + self.assertEqual( + response.get_json()["status"], + "healthy" + ) + + def test_pricing_endpoint(self): + response = self.client.get("/pricing") + + self.assertEqual(response.status_code, 200) + + data = response.get_json() + + self.assertEqual(data["version"], "v1") + self.assertEqual(len(data["plans"]), 3) + self.assertEqual(data["plans"][0]["name"], "Basic") + self.assertEqual(data["plans"][0]["price"], 10) + + +if __name__ == "__main__": + unittest.main() diff --git a/pricing-service/versions/v1/app.py b/pricing-service/versions/v1/app.py new file mode 100644 index 0000000..54343ec --- /dev/null +++ b/pricing-service/versions/v1/app.py @@ -0,0 +1,25 @@ +from flask import Flask, jsonify + +app = Flask(__name__) + + +@app.get("/health") +def health(): + return jsonify({"status": "healthy"}), 200 + + +@app.get("/pricing") +def pricing(): + return jsonify({ + "service": "Startup Pricing Service", + "version": "v1", + "plans": [ + {"name": "Basic", "price": 10}, + {"name": "Pro", "price": 25}, + {"name": "Enterprise", "price": 50} + ] + }), 200 + + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=5000) diff --git a/pricing-service/versions/v2/.dockerignore b/pricing-service/versions/v2/.dockerignore new file mode 100644 index 0000000..4feb913 --- /dev/null +++ b/pricing-service/versions/v2/.dockerignore @@ -0,0 +1,7 @@ +.venv/ +__pycache__/ +*.pyc +.pytest_cache/ +.git/ +.env +.gitignore diff --git a/pricing-service/versions/v2/Dockerfile b/pricing-service/versions/v2/Dockerfile new file mode 100644 index 0000000..1ced772 --- /dev/null +++ b/pricing-service/versions/v2/Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.13-slim + +WORKDIR /app + +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 + +COPY requirements.txt . + +RUN pip install --no-cache-dir -r requirements.txt + +COPY app.py . + +RUN useradd --create-home appuser +USER appuser + +EXPOSE 5000 + +CMD ["python", "app.py"] diff --git a/pricing-service/versions/v2/Dockerfile.production b/pricing-service/versions/v2/Dockerfile.production new file mode 100644 index 0000000..9a5972e --- /dev/null +++ b/pricing-service/versions/v2/Dockerfile.production @@ -0,0 +1,20 @@ +FROM python:3.13-slim + +WORKDIR /app + +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 + +COPY requirements-production.txt . + +RUN pip install --no-cache-dir -r requirements-production.txt + +RUN useradd --create-home appuser + +COPY --chown=appuser:appuser app.py . + +USER appuser + +EXPOSE 5000 + +CMD ["gunicorn", "--workers", "2", "--bind", "0.0.0.0:5000", "app:app"] diff --git a/pricing-service/versions/v2/app.py b/pricing-service/versions/v2/app.py new file mode 100644 index 0000000..a909f57 --- /dev/null +++ b/pricing-service/versions/v2/app.py @@ -0,0 +1,26 @@ +from flask import Flask, jsonify + +app = Flask(__name__) + + +@app.get("/health") +def health(): + return jsonify({"status": "healthy", "version": "v2"}), 200 + + +@app.get("/pricing") +def pricing(): + return jsonify({ + "service": "Startup Pricing Service", + "version": "v2", + "plans": [ + {"name": "Starter", "price": 5}, + {"name": "Basic", "price": 12}, + {"name": "Pro", "price": 30}, + {"name": "Enterprise", "price": 60} + ] + }), 200 + + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=5000) diff --git a/pricing-service/versions/v2/requirements-production.txt b/pricing-service/versions/v2/requirements-production.txt new file mode 100644 index 0000000..e9b38fe --- /dev/null +++ b/pricing-service/versions/v2/requirements-production.txt @@ -0,0 +1,2 @@ +Flask>=3.1,<4.0 +gunicorn>=23,<24 diff --git a/pricing-service/versions/v2/requirements.txt b/pricing-service/versions/v2/requirements.txt new file mode 100644 index 0000000..fdecb8e --- /dev/null +++ b/pricing-service/versions/v2/requirements.txt @@ -0,0 +1 @@ +Flask>=3.1,<4.0 diff --git a/pricing-service/versions/v2/test_app.py b/pricing-service/versions/v2/test_app.py new file mode 100644 index 0000000..f15a2e9 --- /dev/null +++ b/pricing-service/versions/v2/test_app.py @@ -0,0 +1,32 @@ +import unittest +from app import app + + +class PricingServiceV2Tests(unittest.TestCase): + + def setUp(self): + self.client = app.test_client() + + def test_health_endpoint(self): + response = self.client.get("/health") + + self.assertEqual(response.status_code, 200) + + data = response.get_json() + self.assertEqual(data["status"], "healthy") + self.assertEqual(data["version"], "v2") + + def test_pricing_endpoint(self): + response = self.client.get("/pricing") + + self.assertEqual(response.status_code, 200) + + data = response.get_json() + self.assertEqual(data["version"], "v2") + self.assertEqual(len(data["plans"]), 4) + self.assertEqual(data["plans"][0]["name"], "Starter") + self.assertEqual(data["plans"][0]["price"], 5) + + +if __name__ == "__main__": + unittest.main()