Compare commits
67 Commits
issue-1
...
69f1fe05cf
| Author | SHA1 | Date | |
|---|---|---|---|
| 69f1fe05cf | |||
| c5172fca86 | |||
| 90c5d9a3b1 | |||
| f14abad27b | |||
| c46f127e8c | |||
| 05d3c58c3a | |||
| 3fcd04010a | |||
| ad37d148ed | |||
| c864ddd0d2 | |||
| 8979d92c00 | |||
| 17750b844b | |||
| fb2bac752a | |||
| 99acac3136 | |||
| 3b79b7e07a | |||
| 5c0ed9fbcd | |||
| 60019db7da | |||
| 2a35f97071 | |||
| d8a5d2717b | |||
| 5e17a009dc | |||
| 7e76950690 | |||
| 27f8f20275 | |||
| 98f86092a2 | |||
| 459838dfcd | |||
| 6553b4400c | |||
| b4007504b7 | |||
| a482ef9ef9 | |||
| 1bfa31acc0 | |||
| 2ab41bdce5 | |||
| 01f842323e | |||
| d6ea94f20d | |||
| 6d65f29674 | |||
| 4c098708f4 | |||
| 3301e2463e | |||
| ae289072ed | |||
| 696b328a7d | |||
| 38d2e1e965 | |||
| 1de58d4742 | |||
| 84a44f0477 | |||
| a5180ad781 | |||
| 8ba340e32f | |||
| c5538a84d1 | |||
| 81c343ddb6 | |||
| 091a9a9695 | |||
| ab0bcc25f3 | |||
| fa22a0d512 | |||
| b779817f2c | |||
| b899233138 | |||
| 7ffe1f0b34 | |||
| 75c2f21bae | |||
| 8174773cfb | |||
| 898660fd30 | |||
| b76eba3c4f | |||
| 67e9e17eab | |||
| 543be42786 | |||
| 05ef5690b1 | |||
| 1b0d53291f | |||
| f95aa89208 | |||
| c61c4d9d86 | |||
| bd6dc0a865 | |||
| a7b93e380a | |||
| ebd8b2e424 | |||
| 5e0b7e595d | |||
| 46cb1aac07 | |||
| 45dfb9b7ed | |||
| c6decd1f08 | |||
| cc290d65ff | |||
| 6f76e53e5d |
@@ -0,0 +1,83 @@
|
|||||||
|
# Builds the DevOps IT manual (manual/) into a PDF on every push to main
|
||||||
|
# that touches the manual or this workflow, and uploads it as an artifact.
|
||||||
|
name: Build IT manual
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
paths:
|
||||||
|
- "manual/**"
|
||||||
|
- ".gitea/workflows/manual.yml"
|
||||||
|
workflow_dispatch: # lets a team member re-run a build by hand from the Actions tab
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-manual:
|
||||||
|
# Runner label registered in Part 2. The label maps to the job image built
|
||||||
|
# from manual/ci/Dockerfile (TeX Live + Node.js), so each job runs in a
|
||||||
|
# fresh, temporary container -- never inside the Gitea container.
|
||||||
|
runs-on: latex
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out the triggering commit
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Generate build metadata
|
||||||
|
working-directory: manual
|
||||||
|
env:
|
||||||
|
GIT_COMMIT: ${{ github.sha }}
|
||||||
|
BUILD_NUMBER: ${{ github.run_number }}
|
||||||
|
run: |
|
||||||
|
MANUAL_VERSION="v1.5"
|
||||||
|
SHORT_SHA="${GIT_COMMIT:0:7}"
|
||||||
|
BUILD_ID="${MANUAL_VERSION}+build.${BUILD_NUMBER}.${SHORT_SHA}"
|
||||||
|
|
||||||
|
cat > build-metadata.tex <<EOF
|
||||||
|
\newcommand{\ManualVersion}{${MANUAL_VERSION}}
|
||||||
|
\newcommand{\BuildIdentifier}{${BUILD_ID}}
|
||||||
|
\newcommand{\BuildCommit}{${GIT_COMMIT}}
|
||||||
|
\newcommand{\BuildRunNumber}{${BUILD_NUMBER}}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat >> build-metadata.tex <<'EOF'
|
||||||
|
\noindent\textbf{Manual version:} \ManualVersion\\
|
||||||
|
\textbf{Build identifier:} \BuildIdentifier\\
|
||||||
|
\textbf{Commit hash:} \BuildCommit\\
|
||||||
|
\textbf{Gitea Actions run:} \BuildRunNumber
|
||||||
|
EOF
|
||||||
|
|
||||||
|
- name: Record build identity and toolchain
|
||||||
|
run: |
|
||||||
|
SHORT_SHA="${GITHUB_SHA::7}"
|
||||||
|
echo "SHORT_SHA=${SHORT_SHA}" >> "$GITHUB_ENV"
|
||||||
|
echo "Commit: ${GITHUB_SHA} (${SHORT_SHA})"
|
||||||
|
echo "Run number: ${GITHUB_RUN_NUMBER}"
|
||||||
|
pdflatex --version | head -n 1
|
||||||
|
latexmk -v | head -n 2 | tail -n 1
|
||||||
|
python3 -c "import pygments; print('Pygments', pygments.__version__)"
|
||||||
|
|
||||||
|
- name: Compile the manual
|
||||||
|
working-directory: manual
|
||||||
|
# All options live in manual/.latexmkrc; it stops with a non-zero
|
||||||
|
# exit code on the first LaTeX error, which fails this step.
|
||||||
|
run: latexmk devopsAssignment.tex
|
||||||
|
|
||||||
|
- name: Verify the PDF exists
|
||||||
|
working-directory: manual
|
||||||
|
run: |
|
||||||
|
if [ ! -s devopsAssignment.pdf ]; then
|
||||||
|
echo "ERROR: manual/devopsAssignment.pdf is missing or empty"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
ls -l devopsAssignment.pdf
|
||||||
|
|
||||||
|
- name: Upload the PDF as an artifact
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: it-manual-build-${{ github.run_number }}-${{ env.SHORT_SHA }}
|
||||||
|
path: manual/devopsAssignment.pdf
|
||||||
|
if-no-files-found: error
|
||||||
|
retention-days: 30
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
__pycache__/
|
||||||
|
security-reports/
|
||||||
@@ -0,0 +1,289 @@
|
|||||||
|
// Scrap-Web pipeline: Chapter 4 CI checks + Chapter 6 secure delivery.
|
||||||
|
//
|
||||||
|
// Trust boundary:
|
||||||
|
// * Every build (branches and pull requests) runs the Chapter 4 checks on the
|
||||||
|
// controller's built-in node. No credentials, no Docker socket.
|
||||||
|
// * Delivery stages run only for trusted branches, on the 'delivery' agent,
|
||||||
|
// which holds the Docker socket and the registry/deploy credentials.
|
||||||
|
// TODO before submission: remove the feature branch from TRUSTED_BRANCH so
|
||||||
|
// only reviewed code on main can deliver.
|
||||||
|
//
|
||||||
|
// Two kinds of run:
|
||||||
|
// * Normal run (DEPLOY_RECORD empty): test, scan, build once, publish, deploy
|
||||||
|
// staging, prove idempotence, human approval, promote the SAME digest.
|
||||||
|
// * Redeploy run (DEPLOY_RECORD = a committed release record, e.g.
|
||||||
|
// releases/v1-production.yml): no build; redeploys exactly that record with
|
||||||
|
// this commit's Ansible files. Used for rollback and failed-deploy recovery.
|
||||||
|
// Production redeploys need the same approval.
|
||||||
|
|
||||||
|
def TRUSTED_BRANCH = 'main|feature/issue-24-delivery'
|
||||||
|
// Jenkins user IDs allowed to approve production. Anonymous users cannot.
|
||||||
|
def APPROVERS = 'samahk,kaylah7'
|
||||||
|
|
||||||
|
def deployRecord(String record) {
|
||||||
|
withCredentials([sshUserPrivateKey(credentialsId: 'deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) {
|
||||||
|
withEnv(["RECORD=${record}"]) {
|
||||||
|
sh '''
|
||||||
|
export PATH=/opt/ansible-venv/bin:$PATH
|
||||||
|
ansible-playbook -i ansible/inventory.ini ansible/deploy.yml --syntax-check
|
||||||
|
ansible-playbook -i ansible/inventory.ini ansible/deploy.yml \
|
||||||
|
--private-key "$DEPLOY_KEY" -e @"$RECORD"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pipeline {
|
||||||
|
agent none
|
||||||
|
|
||||||
|
parameters {
|
||||||
|
string(name: 'DEPLOY_RECORD', defaultValue: '',
|
||||||
|
description: 'Leave EMPTY for a normal release. For rollback/recovery, the path of a committed release record, e.g. releases/v1-production.yml')
|
||||||
|
}
|
||||||
|
|
||||||
|
options {
|
||||||
|
skipDefaultCheckout()
|
||||||
|
disableConcurrentBuilds() // no competing releases
|
||||||
|
timeout(time: 60, unit: 'MINUTES')
|
||||||
|
buildDiscarder(logRotator(numToKeepStr: '50'))
|
||||||
|
}
|
||||||
|
|
||||||
|
environment {
|
||||||
|
REGISTRY = 'git.ssw590-08.me'
|
||||||
|
IMAGE = 'git.ssw590-08.me/ssw-590-08/pricing'
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
// ---------------- Chapter 4 CI (all builds, controller) ----------------
|
||||||
|
stage('CI checks') {
|
||||||
|
agent { label 'built-in' }
|
||||||
|
steps {
|
||||||
|
checkout scm
|
||||||
|
sh 'git rev-parse HEAD'
|
||||||
|
sh 'python3 --version'
|
||||||
|
sh 'python3 -m py_compile pricing.py tests/test_pricing.py'
|
||||||
|
sh 'python3 -m unittest discover -s tests -v'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------- Chapter 6 delivery (trusted branches, agent) ---------
|
||||||
|
stage('Delivery') {
|
||||||
|
when {
|
||||||
|
beforeAgent true
|
||||||
|
branch pattern: TRUSTED_BRANCH, comparator: 'REGEXP'
|
||||||
|
expression { (params.DEPLOY_RECORD ?: '').trim() == '' }
|
||||||
|
}
|
||||||
|
agent { label 'delivery' }
|
||||||
|
stages {
|
||||||
|
stage('Checkout') {
|
||||||
|
steps {
|
||||||
|
checkout scm
|
||||||
|
script {
|
||||||
|
env.APP_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
|
||||||
|
env.IMAGE_TAG = "${env.IMAGE}:${env.APP_COMMIT}"
|
||||||
|
}
|
||||||
|
echo "Source commit: ${env.APP_COMMIT}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Unit tests') {
|
||||||
|
steps {
|
||||||
|
dir('pricing') {
|
||||||
|
sh '''
|
||||||
|
python3 -m venv .venv
|
||||||
|
.venv/bin/pip install -q --require-hashes -r requirements.txt
|
||||||
|
.venv/bin/python -m py_compile app.py test_app.py
|
||||||
|
.venv/bin/python -m unittest -v
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6.4.5: dependency and secret checks on the source. Fails closed:
|
||||||
|
// a missing script, a scanner error, or a finding stops the run.
|
||||||
|
stage('Security scan: source') {
|
||||||
|
steps { sh 'bash security/scan.sh source' }
|
||||||
|
post { always { archiveArtifacts artifacts: 'security-reports/**', allowEmptyArchive: true } }
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build image') {
|
||||||
|
steps {
|
||||||
|
dir('pricing') {
|
||||||
|
sh 'docker build --build-arg APP_COMMIT="$APP_COMMIT" -t "$IMAGE_TAG" .'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6.4.5: image vulnerability scan before publishing. Fails closed.
|
||||||
|
stage('Security scan: image') {
|
||||||
|
steps { sh 'bash security/scan.sh image "$IMAGE_TAG"' }
|
||||||
|
post { always { archiveArtifacts artifacts: 'security-reports/**', allowEmptyArchive: true } }
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Publish') {
|
||||||
|
steps {
|
||||||
|
withCredentials([usernamePassword(credentialsId: 'gitea-registry-push',
|
||||||
|
usernameVariable: 'REG_USER',
|
||||||
|
passwordVariable: 'REG_TOKEN')]) {
|
||||||
|
// Push, then delete the local copy and pull it back from the
|
||||||
|
// registry, so the recorded digest is the registry's, not a local ID.
|
||||||
|
sh '''
|
||||||
|
printf '%s' "$REG_TOKEN" | docker login "$REGISTRY" -u "$REG_USER" --password-stdin
|
||||||
|
docker push "$IMAGE_TAG"
|
||||||
|
docker image rm "$IMAGE_TAG"
|
||||||
|
docker pull "$IMAGE_TAG"
|
||||||
|
docker logout "$REGISTRY"
|
||||||
|
docker image inspect "$IMAGE_TAG" --format '{{index .RepoDigests 0}}' > image-digest.txt
|
||||||
|
echo "Published: $(cat image-digest.txt)"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
script { env.IMAGE_DIGEST = readFile('image-digest.txt').trim() }
|
||||||
|
writeFile file: 'build-record.txt', text: """source_commit: ${env.APP_COMMIT}
|
||||||
|
image_tag: ${env.IMAGE_TAG}
|
||||||
|
image_digest: ${env.IMAGE_DIGEST}
|
||||||
|
jenkins_build: ${env.BUILD_URL}
|
||||||
|
"""
|
||||||
|
archiveArtifacts artifacts: 'image-digest.txt, build-record.txt', fingerprint: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6.4.6: deploy the digest just published to staging with Ansible,
|
||||||
|
// then rerun unchanged and require changed=0 (idempotence).
|
||||||
|
stage('Deploy staging') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
// Expected behaviour comes from the source, not from config.
|
||||||
|
env.APP_VERSION = sh(script: "sed -n 's/^VERSION = \"\\(.*\\)\"/\\1/p' pricing/app.py", returnStdout: true).trim()
|
||||||
|
def unit = sh(script: "sed -n 's/^UNIT_PRICE = //p' pricing/app.py", returnStdout: true).trim()
|
||||||
|
env.EXPECTED_TOTAL = "${3 * (unit as Integer)}"
|
||||||
|
writeFile file: "release-${env.APP_VERSION}-staging.yml", text: """target_env: staging
|
||||||
|
release_image: ${env.IMAGE_DIGEST}
|
||||||
|
expected_version: ${env.APP_VERSION}
|
||||||
|
expected_commit: ${env.APP_COMMIT}
|
||||||
|
expected_total: ${env.EXPECTED_TOTAL}
|
||||||
|
public_url: https://staging.ssw590-08.me
|
||||||
|
proxy_network: gitea-net
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
archiveArtifacts artifacts: "release-${env.APP_VERSION}-staging.yml", fingerprint: true
|
||||||
|
deployRecord("release-${env.APP_VERSION}-staging.yml")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Staging idempotence') {
|
||||||
|
steps {
|
||||||
|
withCredentials([sshUserPrivateKey(credentialsId: 'deploy-ssh', keyFileVariable: 'DEPLOY_KEY')]) {
|
||||||
|
sh '''
|
||||||
|
export PATH=/opt/ansible-venv/bin:$PATH
|
||||||
|
ansible-playbook -i ansible/inventory.ini ansible/deploy.yml \
|
||||||
|
--private-key "$DEPLOY_KEY" -e @release-$APP_VERSION-staging.yml | tee rerun.log
|
||||||
|
grep -E 'startup +: .*changed=0 +unreachable=0 +failed=0' rerun.log \
|
||||||
|
|| { echo "Second run changed something: not idempotent"; exit 1; }
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6.4.7: restricted human approval, then promote the SAME digest.
|
||||||
|
stage('Approve production') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
def scan = fileExists('security-reports/image-summary.txt') ?
|
||||||
|
readFile('security-reports/image-summary.txt').trim() : 'see security-reports'
|
||||||
|
// Only APPROVERS can approve; Abort or the timeout stops the run.
|
||||||
|
timeout(time: 30, unit: 'MINUTES') {
|
||||||
|
env.APPROVER = input(
|
||||||
|
message: """Promote ${env.APP_VERSION} to production (https://app.ssw590-08.me)?
|
||||||
|
Source commit: ${env.APP_COMMIT}
|
||||||
|
Image digest: ${env.IMAGE_DIGEST}
|
||||||
|
Security scans: source and image gates PASSED (fixable HIGH/CRITICAL block).
|
||||||
|
${scan}
|
||||||
|
Staging: deployed, HTTPS health/version/commit/total ${env.EXPECTED_TOTAL} passed, rerun changed=0.""",
|
||||||
|
ok: 'Approve and deploy to production',
|
||||||
|
submitter: APPROVERS,
|
||||||
|
submitterParameter: 'APPROVER')
|
||||||
|
}
|
||||||
|
env.APPROVED_AT = sh(script: 'date -Is', returnStdout: true).trim()
|
||||||
|
echo "APPROVED by ${env.APPROVER} at ${env.APPROVED_AT}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Deploy production') {
|
||||||
|
steps {
|
||||||
|
// Same digest and commit as staging; only environment and URL change. No rebuild.
|
||||||
|
writeFile file: "release-${env.APP_VERSION}-production.yml", text: """target_env: production
|
||||||
|
release_image: ${env.IMAGE_DIGEST}
|
||||||
|
expected_version: ${env.APP_VERSION}
|
||||||
|
expected_commit: ${env.APP_COMMIT}
|
||||||
|
expected_total: ${env.EXPECTED_TOTAL}
|
||||||
|
public_url: https://app.ssw590-08.me
|
||||||
|
proxy_network: gitea-net
|
||||||
|
approved_by: ${env.APPROVER}
|
||||||
|
approved_at: ${env.APPROVED_AT}
|
||||||
|
"""
|
||||||
|
archiveArtifacts artifacts: "release-${env.APP_VERSION}-production.yml", fingerprint: true
|
||||||
|
deployRecord("release-${env.APP_VERSION}-production.yml")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------- Rollback / recovery: redeploy a committed record -----
|
||||||
|
stage('Redeploy release record') {
|
||||||
|
when {
|
||||||
|
beforeAgent true
|
||||||
|
branch pattern: TRUSTED_BRANCH, comparator: 'REGEXP'
|
||||||
|
expression { (params.DEPLOY_RECORD ?: '').trim() != '' }
|
||||||
|
}
|
||||||
|
agent { label 'delivery' }
|
||||||
|
stages {
|
||||||
|
stage('Load record') {
|
||||||
|
steps {
|
||||||
|
checkout scm
|
||||||
|
script {
|
||||||
|
env.RECORD = params.DEPLOY_RECORD.trim()
|
||||||
|
if (!(env.RECORD ==~ /releases\/[A-Za-z0-9._-]+\.yml/) || !fileExists(env.RECORD)) {
|
||||||
|
error "No committed release record at ${env.RECORD}"
|
||||||
|
}
|
||||||
|
env.TARGET_ENV = sh(script: 'sed -n "s/^target_env: //p" "$RECORD"', returnStdout: true).trim()
|
||||||
|
env.CONFIG_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
|
||||||
|
}
|
||||||
|
echo "Redeploying ${env.RECORD} to ${env.TARGET_ENV} with configuration commit ${env.CONFIG_COMMIT}"
|
||||||
|
sh 'cat "$RECORD"'
|
||||||
|
archiveArtifacts artifacts: "${env.RECORD}", fingerprint: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Approve redeploy') {
|
||||||
|
when { environment name: 'TARGET_ENV', value: 'production' }
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
timeout(time: 30, unit: 'MINUTES') {
|
||||||
|
env.APPROVER = input(
|
||||||
|
message: "Redeploy ${env.RECORD} to PRODUCTION (configuration commit ${env.CONFIG_COMMIT})?",
|
||||||
|
ok: 'Approve redeploy',
|
||||||
|
submitter: APPROVERS,
|
||||||
|
submitterParameter: 'APPROVER')
|
||||||
|
}
|
||||||
|
echo "APPROVED by ${env.APPROVER} at ${sh(script: 'date -Is', returnStdout: true).trim()}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Redeploy') {
|
||||||
|
steps {
|
||||||
|
sh 'echo "Redeploy start: $(date -Is)"'
|
||||||
|
deployRecord(env.RECORD)
|
||||||
|
sh 'echo "Redeploy verified: $(date -Is)"'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
success { echo 'All stages passed.' }
|
||||||
|
failure { echo 'A stage failed: see the stage view for which one.' }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
# Scrap-Web
|
# Scrap-Web
|
||||||
|
|
||||||
This Repo is here to act as Group 8's repo for the SSW590 course
|
This Repo is here to act as Group 8's repo for the SSW590 course
|
||||||
|
|
||||||
|
In the 10/2 assignment, we added a domain, reverse proxy, https, and created our repo in Gitea
|
||||||
|
|
||||||
|
In the 10/10 assignment, we added an automation workflow for compiling a LaTeX artifact upon git pushes
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Secrets and host-specific values stay on the Droplet
|
||||||
|
jenkins-agent.secret
|
||||||
|
agent.secrets.env
|
||||||
|
.env
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
# Trusted Jenkins delivery agent for Chapter 6.
|
||||||
|
# Build context is the repository root (see agent/compose.yaml).
|
||||||
|
FROM jenkins/inbound-agent:latest-jdk21
|
||||||
|
|
||||||
|
USER root
|
||||||
|
|
||||||
|
# Python 3 + venv for tests, pip-audit and Ansible; curl for checks
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends python3 python3-venv python3-pip ca-certificates curl \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Docker CLI + buildx plugin (client only; the daemon is the host's, via the mounted socket)
|
||||||
|
COPY --from=docker:cli /usr/local/bin/docker /usr/local/bin/docker
|
||||||
|
COPY --from=docker/buildx-bin /buildx /usr/libexec/docker/cli-plugins/docker-buildx
|
||||||
|
|
||||||
|
# Trivy scanner (image vulnerabilities + secret scanning)
|
||||||
|
COPY --from=aquasec/trivy:latest /usr/local/bin/trivy /usr/local/bin/trivy
|
||||||
|
|
||||||
|
# Ansible in its own virtual environment, plus the community.docker collection
|
||||||
|
ENV ANSIBLE_COLLECTIONS_PATH=/opt/ansible-collections
|
||||||
|
COPY ansible/requirements.yml /tmp/ansible-requirements.yml
|
||||||
|
RUN python3 -m venv /opt/ansible-venv \
|
||||||
|
&& /opt/ansible-venv/bin/pip install --no-cache-dir ansible-core \
|
||||||
|
&& /opt/ansible-venv/bin/ansible-galaxy collection install -r /tmp/ansible-requirements.yml -p /opt/ansible-collections \
|
||||||
|
&& rm /tmp/ansible-requirements.yml
|
||||||
|
|
||||||
|
# pip-audit in a separate tools venv
|
||||||
|
RUN python3 -m venv /opt/tools-venv \
|
||||||
|
&& /opt/tools-venv/bin/pip install --no-cache-dir pip-audit
|
||||||
|
|
||||||
|
USER jenkins
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
# Trusted delivery agent. Connects to the existing Jenkins controller over the
|
||||||
|
# internal gitea-net network (WebSocket), so no new port is published.
|
||||||
|
services:
|
||||||
|
jenkins-agent:
|
||||||
|
build:
|
||||||
|
context: ..
|
||||||
|
dockerfile: agent/Dockerfile
|
||||||
|
image: ssw590/jenkins-delivery-agent:1
|
||||||
|
container_name: jenkins-agent
|
||||||
|
restart: unless-stopped
|
||||||
|
# Start agent.jar directly. The secret is read from a file (-secret @file),
|
||||||
|
# so it never appears in the process list, docker inspect, or Git.
|
||||||
|
entrypoint:
|
||||||
|
- java
|
||||||
|
- -jar
|
||||||
|
- /usr/share/jenkins/agent.jar
|
||||||
|
- -url
|
||||||
|
- http://jenkins:8080/
|
||||||
|
- -webSocket
|
||||||
|
- -name
|
||||||
|
- delivery-agent
|
||||||
|
- -workDir
|
||||||
|
- /home/jenkins/agent
|
||||||
|
- -secret
|
||||||
|
- "@/run/secrets/jenkins-agent-secret"
|
||||||
|
# Host Docker socket: needed to build/push images. This is effectively root
|
||||||
|
# on the Droplet, so only reviewed main-branch delivery jobs may use this agent.
|
||||||
|
group_add: ["${DOCKER_GID:?set DOCKER_GID in .env}"]
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
- ./jenkins-agent.secret:/run/secrets/jenkins-agent-secret:ro
|
||||||
|
- agent_home:/home/jenkins # workspace, known_hosts, registry login
|
||||||
|
networks: [gitea-net]
|
||||||
|
|
||||||
|
networks:
|
||||||
|
gitea-net:
|
||||||
|
external: true
|
||||||
|
name: gitea-net
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
agent_home:
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Print tool versions inside the agent. From the repo root on the Droplet:
|
||||||
|
# docker exec -i jenkins-agent sh -s < agent/versions.sh
|
||||||
|
echo "== java"; java -version 2>&1 | head -1
|
||||||
|
echo "== python"; python3 --version
|
||||||
|
echo "== docker"; docker version --format 'client {{.Client.Version}} / server {{.Server.Version}}'
|
||||||
|
echo "== buildx"; docker buildx version
|
||||||
|
echo "== trivy"; trivy --version | head -1
|
||||||
|
echo "== pip-audit"; /opt/tools-venv/bin/pip-audit --version
|
||||||
|
echo "== ansible"; /opt/ansible-venv/bin/ansible --version | head -3
|
||||||
|
echo "== collections"; /opt/ansible-venv/bin/ansible-galaxy collection list community.docker 2>/dev/null | tail -2
|
||||||
|
echo "== os"; . /etc/os-release; echo "$PRETTY_NAME $(uname -m)"
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
- name: Deploy a selected immutable pricing release
|
||||||
|
hosts: delivery
|
||||||
|
become: true
|
||||||
|
vars:
|
||||||
|
project_dir: "/opt/startup/pricing-{{ target_env }}"
|
||||||
|
tasks:
|
||||||
|
- name: Validate release selection
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- target_env in ['staging', 'production']
|
||||||
|
- "'@sha256:' in release_image"
|
||||||
|
- expected_version in ['v1', 'v2']
|
||||||
|
- expected_total | int > 0
|
||||||
|
- public_url.startswith('https://')
|
||||||
|
- proxy_network | length > 0
|
||||||
|
- name: Create deployment directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ project_dir }}"
|
||||||
|
state: directory
|
||||||
|
mode: '0750'
|
||||||
|
- name: Render selected Compose configuration
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: compose.yaml.j2
|
||||||
|
dest: "{{ project_dir }}/compose.yaml"
|
||||||
|
mode: '0640'
|
||||||
|
- name: Converge application without rebuilding
|
||||||
|
community.docker.docker_compose_v2:
|
||||||
|
project_src: "{{ project_dir }}"
|
||||||
|
project_name: "pricing-{{ target_env }}"
|
||||||
|
state: present
|
||||||
|
build: never
|
||||||
|
pull: missing
|
||||||
|
wait: true
|
||||||
|
wait_timeout: 90
|
||||||
|
- name: Verify health through public TLS endpoint
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "{{ public_url }}/health"
|
||||||
|
return_content: true
|
||||||
|
validate_certs: true
|
||||||
|
register: health
|
||||||
|
until: health.status == 200 and health.json.status == 'ok'
|
||||||
|
retries: 12
|
||||||
|
delay: 5
|
||||||
|
changed_when: false
|
||||||
|
- name: Read release identity
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "{{ public_url }}/"
|
||||||
|
return_content: true
|
||||||
|
register: identity
|
||||||
|
changed_when: false
|
||||||
|
- name: Exercise business behavior
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "{{ public_url }}/price?quantity=3"
|
||||||
|
return_content: true
|
||||||
|
register: price
|
||||||
|
changed_when: false
|
||||||
|
- name: Check release identity and calculation
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- identity.json.version == expected_version
|
||||||
|
- identity.json.commit == expected_commit
|
||||||
|
- price.json.total | int == expected_total | int
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
[delivery]
|
||||||
|
# Target: the existing Droplet, reached over SSH as the dedicated deploy account.
|
||||||
|
# Host key must be verified and pinned in the agent's known_hosts before first use.
|
||||||
|
startup ansible_host=147.182.179.191 ansible_user=deploy
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
collections:
|
||||||
|
- name: community.docker
|
||||||
|
version: ">=4.8.0,<6.0.0"
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
services:
|
||||||
|
app:
|
||||||
|
image: "{{ release_image }}"
|
||||||
|
restart: unless-stopped
|
||||||
|
read_only: true
|
||||||
|
tmpfs:
|
||||||
|
- /tmp
|
||||||
|
cap_drop:
|
||||||
|
- ALL
|
||||||
|
security_opt:
|
||||||
|
- no-new-privileges:true
|
||||||
|
networks:
|
||||||
|
edge:
|
||||||
|
aliases:
|
||||||
|
- "pricing-{{ target_env }}"
|
||||||
|
networks:
|
||||||
|
edge:
|
||||||
|
external: true
|
||||||
|
name: "{{ proxy_network }}"
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
services:
|
||||||
|
jenkins:
|
||||||
|
build: .
|
||||||
|
image: custom-jenkins:lts-jdk21-python3
|
||||||
|
container_name: jenkins
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
JAVA_OPTS: "-Xms256m -Xmx512m"
|
||||||
|
volumes:
|
||||||
|
- jenkins-home:/var/jenkins_home
|
||||||
|
networks:
|
||||||
|
- gitea-net
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
jenkins-home:
|
||||||
|
name: jenkins_home
|
||||||
|
|
||||||
|
networks:
|
||||||
|
gitea-net:
|
||||||
|
external: true
|
||||||
|
name: gitea-net
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# LaTeX build output: generated by every compile, never committed.
|
||||||
|
# The PDF is produced by the Gitea Actions workflow and downloaded as an artifact.
|
||||||
|
*.pdf
|
||||||
|
*.aux
|
||||||
|
*.log
|
||||||
|
*.out
|
||||||
|
*.toc
|
||||||
|
*.lof
|
||||||
|
*.lot
|
||||||
|
*.bbl
|
||||||
|
*.blg
|
||||||
|
*.idx
|
||||||
|
*.ilg
|
||||||
|
*.ind
|
||||||
|
*.glo
|
||||||
|
*.gls
|
||||||
|
*.glg
|
||||||
|
*.acn
|
||||||
|
*.acr
|
||||||
|
*.alg
|
||||||
|
*.ist
|
||||||
|
*.fls
|
||||||
|
*.fdb_latexmk
|
||||||
|
*.synctex.gz
|
||||||
|
_minted*/
|
||||||
|
|
||||||
|
# Exception: PDFs used as figures inside the manual must stay tracked.
|
||||||
|
# Uncomment and adjust if you ever include a PDF image:
|
||||||
|
# !images/**/*.pdf
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Build configuration for the SSW 590 DevOps IT manual.
|
||||||
|
# Usage (from the repository root): latexmk devopsAssignment.tex
|
||||||
|
|
||||||
|
# Produce a PDF with pdflatex.
|
||||||
|
$pdf_mode = 1;
|
||||||
|
|
||||||
|
# -shell-escape : required by the minted package (calls Python Pygments)
|
||||||
|
# -interaction=nonstopmode, -halt-on-error : stop on the first LaTeX error
|
||||||
|
# instead of waiting for input, so CI fails clearly
|
||||||
|
# -file-line-error : print errors as file:line:message
|
||||||
|
$pdflatex = 'pdflatex -shell-escape -interaction=nonstopmode -halt-on-error -file-line-error %O %S';
|
||||||
|
|
||||||
|
# Run makeglossaries when the glossary or acronym inputs change.
|
||||||
|
# (bibtex and makeindex are handled by latexmk automatically.)
|
||||||
|
add_cus_dep('glo', 'gls', 0, 'run_makeglossaries');
|
||||||
|
add_cus_dep('acn', 'acr', 0, 'run_makeglossaries');
|
||||||
|
sub run_makeglossaries {
|
||||||
|
return system("makeglossaries \"$_[0]\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
push @generated_exts, 'glo', 'gls', 'glg', 'acn', 'acr', 'alg', 'ist';
|
||||||
|
After Width: | Height: | Size: 232 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 107 KiB |
|
After Width: | Height: | Size: 111 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 91 KiB |
|
After Width: | Height: | Size: 584 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 142 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 138 KiB |
|
After Width: | Height: | Size: 327 KiB |
|
After Width: | Height: | Size: 216 KiB |
|
After Width: | Height: | Size: 146 KiB |
|
After Width: | Height: | Size: 192 KiB |
|
After Width: | Height: | Size: 159 KiB |
|
After Width: | Height: | Size: 194 KiB |
|
After Width: | Height: | Size: 220 KiB |
|
After Width: | Height: | Size: 617 KiB |
|
After Width: | Height: | Size: 169 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 422 KiB |
|
After Width: | Height: | Size: 157 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 174 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 53 KiB |
|
After Width: | Height: | Size: 264 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 2.0 MiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 67 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 123 KiB |
|
After Width: | Height: | Size: 84 KiB |
|
After Width: | Height: | Size: 131 KiB |
|
After Width: | Height: | Size: 160 KiB |
|
After Width: | Height: | Size: 65 KiB |
|
After Width: | Height: | Size: 432 KiB |
|
After Width: | Height: | Size: 235 KiB |
|
After Width: | Height: | Size: 151 KiB |
|
After Width: | Height: | Size: 188 KiB |
|
After Width: | Height: | Size: 522 KiB |
|
After Width: | Height: | Size: 84 KiB |
|
After Width: | Height: | Size: 134 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 472 KiB |
|
After Width: | Height: | Size: 257 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 281 KiB |
|
After Width: | Height: | Size: 104 KiB |
|
After Width: | Height: | Size: 172 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 149 KiB |
|
After Width: | Height: | Size: 105 KiB |
|
After Width: | Height: | Size: 142 KiB |
|
After Width: | Height: | Size: 98 KiB |
|
After Width: | Height: | Size: 85 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 181 KiB |