tambah webhook
This commit is contained in:
27
deploy.sh
Normal file
27
deploy.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
# eCert MBIP — Production Deploy Script
|
||||
# Dipanggil oleh webhook selepas git push ke GitHub
|
||||
set -e
|
||||
|
||||
PROJECT_DIR="/srv/ecert"
|
||||
LOG="$PROJECT_DIR/deploy.log"
|
||||
|
||||
log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG"; }
|
||||
|
||||
log "=== Deploy dimulakan ==="
|
||||
|
||||
cd "$PROJECT_DIR"
|
||||
|
||||
log "git pull..."
|
||||
git pull origin main
|
||||
|
||||
log "migrate database..."
|
||||
docker exec ecert_app php artisan migrate --force
|
||||
|
||||
log "optimize cache..."
|
||||
docker exec ecert_app php artisan optimize
|
||||
|
||||
log "restart queue worker..."
|
||||
docker restart ecert_queue
|
||||
|
||||
log "=== Deploy selesai ==="
|
||||
@@ -62,6 +62,22 @@ services:
|
||||
APP_ENV: production
|
||||
extra_hosts: []
|
||||
|
||||
# ── Webhook Deploy (GitHub → auto pull + migrate) ──────────────────────────
|
||||
webhook:
|
||||
build:
|
||||
context: ./docker/webhook
|
||||
container_name: ecert_webhook
|
||||
restart: always
|
||||
environment:
|
||||
WEBHOOK_SECRET: ${WEBHOOK_SECRET}
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- /root/.ssh:/root/.ssh:ro
|
||||
- ./docker/webhook/hooks.json:/etc/webhook/hooks.json:ro
|
||||
- ./deploy.sh:/deploy.sh:ro
|
||||
- .:/srv/ecert
|
||||
command: -hooks=/etc/webhook/hooks.json -template -verbose
|
||||
|
||||
###############################################################################
|
||||
volumes:
|
||||
storage_data:
|
||||
|
||||
@@ -62,6 +62,13 @@ server {
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
# ── GitHub Webhook Deploy ─────────────────────────────────────────────────
|
||||
location /hooks/ {
|
||||
proxy_pass http://ecert_webhook:9000/hooks/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_read_timeout 60s;
|
||||
}
|
||||
|
||||
# ── Halang akses fail tersembunyi ─────────────────────────────────────────
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
|
||||
6
docker/webhook/Dockerfile
Normal file
6
docker/webhook/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM alpine:3.21
|
||||
RUN apk add --no-cache git docker-cli curl && \
|
||||
curl -fsSL https://github.com/adnanh/webhook/releases/download/2.8.1/webhook-linux-amd64.tar.gz \
|
||||
| tar xz -C /usr/local/bin --strip-components=1
|
||||
EXPOSE 9000
|
||||
ENTRYPOINT ["/usr/local/bin/webhook"]
|
||||
18
docker/webhook/hooks.json
Normal file
18
docker/webhook/hooks.json
Normal file
@@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"id": "deploy",
|
||||
"execute-command": "/deploy.sh",
|
||||
"command-working-directory": "/srv/ecert",
|
||||
"response-message": "Deploy dimulakan.",
|
||||
"trigger-rule": {
|
||||
"match": {
|
||||
"type": "payload-hmac-sha256",
|
||||
"secret": "{{ .Env.WEBHOOK_SECRET }}",
|
||||
"parameter": {
|
||||
"source": "header",
|
||||
"name": "X-Hub-Signature-256"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user