# Deploy the newest published release, if there is one.
#
#   install: /etc/systemd/system/pig-autodeploy.service
#
# Oneshot, driven by pig-autodeploy.timer. It exits 0 within a second or two on
# the overwhelming majority of runs, because the running digest already matches
# the newest release-* tag.
#
# Runs as root because it drives docker and writes the checkout at /opt/pig.
# The escalation this avoids is the one that matters: no key on the CI runner
# can reach this machine. The credential travels the other way — a pull-only
# registry token in /etc/pig/registry-token.

[Unit]
Description=PIG — deploy the newest published release
Documentation=https://git.karti.ai/PIG/pig/src/branch/main/deploy/README.md
After=network-online.target docker.service
Wants=network-online.target
Requires=docker.service

[Service]
Type=oneshot
# Optional: PIG_REGISTRY_USER, PIG_REPO_DIR, PIG_DEPLOY_PUBLIC_URL and friends.
# The leading '-' means a missing file is not an error, so the defaults in the
# script stand on a host that never needed to override anything.
EnvironmentFile=-/etc/pig/autodeploy.env
ExecStart=/bin/bash /opt/pig/scripts/autodeploy.sh
# A build, a migration, a pull and two health waits. Generous, but a deploy cut
# off halfway is worse than a slow one.
TimeoutStartSec=1800
# No Restart=. A failed release must not be retried automatically — the script
# records the failed digest and refuses it on the next tick for the same
# reason.
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
