ci: deploy via Komodo stack webhook, tag images with commit sha
The old deploy step POSTed to http://10.5.0.11:7777/v1/update, which no longer exists (connection refused), so every push built and pushed a new image but never reached the site. Replace it with the Komodo stack webhook for `jonbio` (/listener/github/stack/jonbio/deploy), HMAC-signed with a per-stack secret. The stack has auto_pull + webhook_force_deploy enabled, so the webhook pulls :latest and recreates the container. Also tag each build with the commit sha alongside :latest so a bad deploy can be rolled back to a known image.
This commit is contained in:
1 parent
e1f8315f17
commit
d2b77e488f
1 file changed
+43
-8
@@ -52,14 +52,49 @@ jobs:
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: 'git.jonb.io/jblu/jonbio:latest'
|
||||
tags: |
|
||||
git.jonb.io/jblu/jonbio:latest
|
||||
git.jonb.io/jblu/jonbio:${{ gitea.sha }}
|
||||
cache-from: 'type=registry,ref=git.jonb.io/jblu/jonbio:buildcache'
|
||||
cache-to: >-
|
||||
type=registry,image-manifest=true,oci-mediatypes=true,ref=git.jonb.io/jblu/jonbio:buildcache,mode=max
|
||||
- name: Deploy app
|
||||
uses: fjogeleit/http-request-action@v1
|
||||
with:
|
||||
url: 'http://10.5.0.11:7777/v1/update'
|
||||
method: GET
|
||||
bearerToken: '${{ secrets.DEPLOYTOKEN }}'
|
||||
timeout: 60000
|
||||
# Triggers the Komodo stack webhook for `jonbio`, which pulls :latest and
|
||||
# recreates the container. Replaces the old http://10.5.0.11:7777/v1/update
|
||||
# hook, which no longer exists.
|
||||
- name: Deploy via Komodo
|
||||
env:
|
||||
KOMODO_WEBHOOK_SECRET: ${{ secrets.KOMODO_JONBIO_WEBHOOK_SECRET }}
|
||||
COMMIT_SHA: ${{ gitea.sha }}
|
||||
run: |
|
||||
if [ -z "$KOMODO_WEBHOOK_SECRET" ]; then
|
||||
echo "::error::KOMODO_JONBIO_WEBHOOK_SECRET is not set on this repo"
|
||||
exit 1
|
||||
fi
|
||||
cat > /tmp/komodo-deploy.mjs <<'EOF'
|
||||
import crypto from 'node:crypto'
|
||||
|
||||
const payload = JSON.stringify({
|
||||
ref: 'refs/heads/main',
|
||||
after: process.env.COMMIT_SHA,
|
||||
repository: { full_name: 'jblu/jonbio', default_branch: 'main' },
|
||||
})
|
||||
|
||||
const signature =
|
||||
'sha256=' +
|
||||
crypto.createHmac('sha256', process.env.KOMODO_WEBHOOK_SECRET).update(payload).digest('hex')
|
||||
|
||||
const res = await fetch('http://10.5.0.3:9120/listener/github/stack/jonbio/deploy', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-GitHub-Event': 'push',
|
||||
'X-Hub-Signature-256': signature,
|
||||
},
|
||||
body: payload,
|
||||
})
|
||||
|
||||
const body = await res.text()
|
||||
console.log(`Komodo deploy -> ${res.status} ${body}`)
|
||||
if (!res.ok) process.exit(1)
|
||||
EOF
|
||||
node /tmp/komodo-deploy.mjs
|
||||
Reference in new issue
Block a user