Deploy per Portainer-Webhook statt Polling
Nach erfolgreichem Push in findr/infrastructure den Stack-Webhook aufrufen (PORTAINER_WEBHOOK-Secret), damit der Redeploy sofort statt auf einen Timer passiert. Signed-off-by: Peter Siegmund <mars3142@noreply.mars3142.dev>
This commit is contained in:
+19
-13
@@ -104,16 +104,12 @@ jobs:
|
|||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
run: docker push "$IMAGE:latest"
|
run: docker push "$IMAGE:latest"
|
||||||
|
|
||||||
# The stack lives in the infrastructure repo and Portainer deploys it from
|
# The stack lives in the infrastructure repo, so a rollout is a commit in that
|
||||||
# there, so a rollout is a commit in that repo: it pins the findr-api image to
|
# repo: it pins the findr-api image to this build's commit. Then the Portainer
|
||||||
# this build's commit. Compose then recreates the one service whose image
|
# stack webhook is called, which re-pulls the repo and recreates the one
|
||||||
# changed. Leaving the stack on ":latest" and only re-pulling would drag
|
# service whose image changed. Leaving the stack on ":latest" and only
|
||||||
# findr-web and postgres along with every api deploy, and nothing in Git would
|
# re-pulling would drag findr-web and postgres along with every api deploy, and
|
||||||
# say which version is running.
|
# nothing in Git would say which version is running.
|
||||||
#
|
|
||||||
# Pushing the commit is the whole job - Portainer polls the repo and redeploys
|
|
||||||
# once it sees a new head. A green job therefore means the rollout was handed
|
|
||||||
# over, not that it has happened yet.
|
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
@@ -122,9 +118,10 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
# The token goes into the remote URL, so it must not be echoed - it can
|
# The token goes into the remote URL, so it must not be echoed - it can
|
||||||
# write to the whole infrastructure repo. No "set -x" here either.
|
# write to the whole infrastructure repo. No "set -x" here either.
|
||||||
- name: Pin findr-api image in the stack
|
- name: Pin findr-api image and trigger the stack
|
||||||
env:
|
env:
|
||||||
INFRA_TOKEN: ${{ secrets.INFRA_TOKEN }}
|
INFRA_TOKEN: ${{ secrets.INFRA_TOKEN }}
|
||||||
|
PORTAINER_WEBHOOK: ${{ secrets.PORTAINER_WEBHOOK }}
|
||||||
TAG: ${{ needs.build-and-push.outputs.tag }}
|
TAG: ${{ needs.build-and-push.outputs.tag }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -160,8 +157,17 @@ jobs:
|
|||||||
# findr-web writes to the same file, so a push can lose a race.
|
# findr-web writes to the same file, so a push can lose a race.
|
||||||
# Rebasing and retrying beats failing a build whose image is already in
|
# Rebasing and retrying beats failing a build whose image is already in
|
||||||
# the registry.
|
# the registry.
|
||||||
|
pushed=
|
||||||
for attempt in 1 2 3; do
|
for attempt in 1 2 3; do
|
||||||
git push && exit 0
|
if git push; then pushed=1; break; fi
|
||||||
git pull --rebase
|
git pull --rebase
|
||||||
done
|
done
|
||||||
exit 1
|
[ -n "$pushed" ] || exit 1
|
||||||
|
|
||||||
|
# No polling: tell Portainer to redeploy now. -k because :9443 serves a
|
||||||
|
# self-signed cert. The URL carries a secret, so it comes from a secret
|
||||||
|
# and is never printed.
|
||||||
|
if [ -z "${PORTAINER_WEBHOOK:-}" ]; then
|
||||||
|
echo "::error::PORTAINER_WEBHOOK secret is not set" && exit 1
|
||||||
|
fi
|
||||||
|
curl -fsS -k -X POST "$PORTAINER_WEBHOOK"
|
||||||
|
|||||||
Reference in New Issue
Block a user