54 lines
1.8 KiB
YAML
54 lines
1.8 KiB
YAML
# ─── BETE GitLab CI/CD Pipeline ───────────────────────────────────────────────
|
|
# Simply SSH into VPS → git pull → docker compose up -d --build
|
|
#
|
|
# Required CI/CD Variables (set in GitLab → Settings → CI/CD → Variables):
|
|
#
|
|
# VPS_HOST - VPS IP/hostname (e.g. 45.127.35.244)
|
|
# VPS_USERNAME - SSH user (e.g. root)
|
|
# VPS_SSH_KEY - SSH private key (type: file)
|
|
#
|
|
# Notes:
|
|
# - VPS must have git access to this repo (deploy key or SSH agent)
|
|
# - .env file must already exist on VPS at $APP_DIR/.env
|
|
# - VPS_SSH_KEY must be "File" type so GitLab writes it to disk
|
|
#
|
|
# ──────────────────────────────────────────────────────────────────────────────
|
|
|
|
stages:
|
|
- deploy
|
|
|
|
variables:
|
|
APP_DIR: /opt/imphenbot
|
|
SSH_HOST: "${VPS_USERNAME}@${VPS_HOST}"
|
|
|
|
deploy-vps:
|
|
stage: deploy
|
|
image: alpine:latest
|
|
only:
|
|
- master
|
|
before_script:
|
|
- apk add --no-cache openssh-client git
|
|
- mkdir -p ~/.ssh
|
|
- cp "$VPS_SSH_KEY" ~/.ssh/id_rsa
|
|
- chmod 600 ~/.ssh/id_rsa
|
|
- ssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hosts 2>/dev/null
|
|
script:
|
|
- |
|
|
ssh "$SSH_HOST" "
|
|
set -eu
|
|
echo '→ Pulling latest code...'
|
|
cd $APP_DIR
|
|
git fetch --depth 1 origin master
|
|
git checkout master
|
|
git reset --hard origin/master
|
|
|
|
echo '→ Rebuilding and restarting containers...'
|
|
docker compose -f infra/docker/docker-compose.yml up -d --build --remove-orphans
|
|
|
|
echo '→ Cleaning up...'
|
|
docker image prune -f
|
|
echo '✓ Deploy complete'
|
|
"
|
|
after_script:
|
|
- rm -f ~/.ssh/id_rsa
|