All work

Entry 07 of 11

Work

Deployments

CI/CD and cloud hosting

  • Docker
  • GitHub Actions
  • Nginx
Read the walkthrough
  1. Build the release
  2. Run the tests
  3. Deploy the release

Overview

Automated pipelines, SSL, monitoring, and rollbacks.

What it covers

  • Automated pipelines
  • SSL
  • Monitoring
  • Rollbacks

Deploy a tested release

  1. Build a Docker image for a specific commit and tag the image with that commit's identifier.
  2. Run the application's tests against that image in GitHub Actions before promoting it.
  3. Deploy the same image behind Nginx and request a known HTTPS page to verify the release.

Keep a Python automation running on a Linux VPS

On a Linux VPS you manage with systemd, a continuously listening worker can start at boot and restart after a failure. A script that finishes each run, such as a catalog export, can run hourly under a timer. Both continue after you disconnect from SSH.

  1. Create an unprivileged service account named catalog and place your authorized script and its Python virtual environment under /opt/catalog-job. Adapt the account, paths and example-shop argument to your host. StateDirectory=catalog-job gives the service a writable /var/lib/catalog-job directory for results or checkpoints.
  2. For a worker that stays in the foreground, save catalog-worker.service under /etc/systemd/system. Run sudo systemctl daemon-reload and sudo systemctl enable --now catalog-worker.service. Restart=on-failure waits ten seconds before restarting a failed worker. Check sudo systemctl status catalog-worker.service and sudo journalctl -u catalog-worker.service -n 50.
  3. For an hourly export that exits, install catalog-export.service and catalog-export.timer under /etc/systemd/system. Run sudo systemctl daemon-reload and sudo systemctl enable --now catalog-export.timer. Check systemctl list-timers catalog-export.timer for its next run. Trigger one test with sudo systemctl start catalog-export.service and inspect sudo journalctl -u catalog-export.service -n 50 and the CSV.
  4. Use one scheduler for each job. A timer skips a second start while its service is active. Persistent=true catches up once after downtime. For jobs with external side effects, record completed item IDs and use an idempotency key at the destination so replaying a job after a crash is safe.
catalog-worker.service
[Unit]
Description=Continuous Python worker
Wants=network-online.target
After=network-online.target

[Service]
Type=exec
User=catalog
WorkingDirectory=/opt/catalog-job
StateDirectory=catalog-job
ExecStart=/opt/catalog-job/.venv/bin/python -u /opt/catalog-job/worker.py
Restart=on-failure
RestartSec=10s

[Install]
WantedBy=multi-user.target
catalog-export.service
[Unit]
Description=Export the published product catalog
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
User=catalog
WorkingDirectory=/opt/catalog-job
StateDirectory=catalog-job
ExecStart=/opt/catalog-job/.venv/bin/python /opt/catalog-job/export_catalog.py example-shop /var/lib/catalog-job/products.csv
catalog-export.timer
[Unit]
Description=Run the catalog export hourly

[Timer]
OnCalendar=hourly
Persistent=true
Unit=catalog-export.service

[Install]
WantedBy=timers.target

Documentation