Revert "ci: add Docker build + GitLab Container Registry push before deploy"
This reverts commit 90b317731b.
This commit is contained in:
+16
-93
@@ -1,126 +1,49 @@
|
|||||||
# ─── BETE GitLab CI/CD Pipeline ───────────────────────────────────────────────
|
# ─── BETE GitLab CI/CD Pipeline ───────────────────────────────────────────────
|
||||||
# 1. Build 4 Docker images (frontend, backend, discord-gateway, proxy)
|
# Simply SSH into VPS → git pull → docker compose up -d --build
|
||||||
# 2. Push to GitLab Container Registry
|
|
||||||
# 3. Deploy to VPS — pull images, docker compose up
|
|
||||||
#
|
#
|
||||||
# Required CI/CD Variables (set in GitLab → Settings → CI/CD → Variables):
|
# Required CI/CD Variables (set in GitLab → Settings → CI/CD → Variables):
|
||||||
#
|
#
|
||||||
# VPS_HOST - VPS IP/hostname
|
# VPS_HOST - VPS IP/hostname (e.g. 45.127.35.244)
|
||||||
# VPS_USERNAME - SSH user
|
# VPS_USERNAME - SSH user (e.g. root)
|
||||||
# VPS_SSH_KEY - SSH private key (type: file)
|
# VPS_SSH_KEY - SSH private key (type: file)
|
||||||
# ENV_FILE - Full .env file content (type: env_var) — optional if .env already on VPS
|
#
|
||||||
|
# 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:
|
stages:
|
||||||
- build
|
|
||||||
- deploy
|
- deploy
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
REGISTRY: $CI_REGISTRY
|
|
||||||
REGISTRY_PROJECT: $CI_REGISTRY/$CI_PROJECT_PATH
|
|
||||||
IMAGE_TAG_COMMIT: $CI_COMMIT_SHA
|
|
||||||
IMAGE_TAG_LATEST: latest
|
|
||||||
|
|
||||||
# Frontend build args
|
|
||||||
VITE_BE_API_URL: https://imphnen.asepharyana.my.id
|
|
||||||
VITE_BE_WS_URL: wss://imphnen.asepharyana.my.id
|
|
||||||
|
|
||||||
# Deploy target
|
|
||||||
SSH_HOST: "${VPS_USERNAME}@${VPS_HOST}"
|
|
||||||
APP_DIR: /opt/imphenbot
|
APP_DIR: /opt/imphenbot
|
||||||
|
SSH_HOST: "${VPS_USERNAME}@${VPS_HOST}"
|
||||||
|
|
||||||
# ── Build stage ───────────────────────────────────────────────────────────────
|
|
||||||
.docker-build:
|
|
||||||
stage: build
|
|
||||||
image: docker:27-cli
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
services:
|
|
||||||
- docker:27-dind
|
|
||||||
before_script:
|
|
||||||
- echo "$CI_JOB_TOKEN" | docker login "$CI_REGISTRY" -u "$CI_REGISTRY_USER" --password-stdin
|
|
||||||
script:
|
|
||||||
# Build image
|
|
||||||
- |
|
|
||||||
docker build \
|
|
||||||
--file infra/docker/Dockerfile.$SERVICE_NAME \
|
|
||||||
--tag $REGISTRY_PROJECT/bete-$SERVICE_NAME:$IMAGE_TAG_COMMIT \
|
|
||||||
--tag $REGISTRY_PROJECT/bete-$SERVICE_NAME:$IMAGE_TAG_LATEST \
|
|
||||||
--build-arg BUILDKIT_INLINE_CACHE=1 \
|
|
||||||
--build-arg VITE_BE_API_URL=$VITE_BE_API_URL \
|
|
||||||
--build-arg VITE_BE_WS_URL=$VITE_BE_WS_URL \
|
|
||||||
--cache-from $REGISTRY_PROJECT/bete-$SERVICE_NAME:latest \
|
|
||||||
.
|
|
||||||
# Push to GitLab Container Registry
|
|
||||||
- docker push $REGISTRY_PROJECT/bete-$SERVICE_NAME:$IMAGE_TAG_COMMIT
|
|
||||||
- docker push $REGISTRY_PROJECT/bete-$SERVICE_NAME:$IMAGE_TAG_LATEST
|
|
||||||
|
|
||||||
build-frontend:
|
|
||||||
extends: .docker-build
|
|
||||||
variables:
|
|
||||||
SERVICE_NAME: frontend
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
|
|
||||||
build-backend:
|
|
||||||
extends: .docker-build
|
|
||||||
variables:
|
|
||||||
SERVICE_NAME: backend
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
|
|
||||||
build-discord-gateway:
|
|
||||||
extends: .docker-build
|
|
||||||
variables:
|
|
||||||
SERVICE_NAME: discord-gateway
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
|
|
||||||
build-proxy:
|
|
||||||
extends: .docker-build
|
|
||||||
variables:
|
|
||||||
SERVICE_NAME: proxy
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
|
|
||||||
# ── Deploy stage ──────────────────────────────────────────────────────────────
|
|
||||||
deploy-vps:
|
deploy-vps:
|
||||||
stage: deploy
|
stage: deploy
|
||||||
image: debian:stable-slim
|
image: debian:stable-slim
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
needs:
|
|
||||||
- build-frontend
|
|
||||||
- build-backend
|
|
||||||
- build-discord-gateway
|
|
||||||
- build-proxy
|
|
||||||
before_script:
|
before_script:
|
||||||
- apt-get update -qq && apt-get install -y -qq openssh-client
|
- apt-get update -qq && apt-get install -y -qq openssh-client git
|
||||||
- mkdir -p ~/.ssh
|
- mkdir -p ~/.ssh
|
||||||
- cp "$VPS_SSH_KEY" ~/.ssh/id_rsa
|
- cp "$VPS_SSH_KEY" ~/.ssh/id_rsa
|
||||||
- chmod 600 ~/.ssh/id_rsa
|
- chmod 600 ~/.ssh/id_rsa
|
||||||
- ssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hosts 2>/dev/null
|
- ssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hosts 2>/dev/null
|
||||||
script:
|
script:
|
||||||
# Login to GitLab Container Registry, pull images, update docker-compose, restart
|
|
||||||
- |
|
- |
|
||||||
ssh "$SSH_HOST" "
|
ssh "$SSH_HOST" "
|
||||||
set -eu
|
set -eu
|
||||||
|
echo '→ Pulling latest code...'
|
||||||
cd $APP_DIR
|
cd $APP_DIR
|
||||||
|
git fetch --depth 1 origin master
|
||||||
|
git checkout master
|
||||||
|
git reset --hard origin/master
|
||||||
|
|
||||||
echo '→ Logging in to GitLab Container Registry...'
|
echo '→ Rebuilding and restarting containers...'
|
||||||
echo '$CI_JOB_TOKEN' | docker login $CI_REGISTRY -u '$CI_REGISTRY_USER' --password-stdin
|
docker compose -f infra/docker/docker-compose.yml up -d --build --remove-orphans
|
||||||
|
|
||||||
echo '→ Updating docker-compose image references...'
|
|
||||||
sed -i 's|ghcr.io/\${OWNER:-mytheclipse}|$REGISTRY_PROJECT|g' infra/docker/docker-compose.yml
|
|
||||||
sed -i 's|\${OWNER:-mytheclipse}|$CI_PROJECT_NAMESPACE|g' infra/docker/docker-compose.yml
|
|
||||||
|
|
||||||
echo '→ Pulling latest images...'
|
|
||||||
docker compose -f infra/docker/docker-compose.yml pull
|
|
||||||
|
|
||||||
echo '→ Restarting containers...'
|
|
||||||
docker compose -f infra/docker/docker-compose.yml up -d --remove-orphans
|
|
||||||
|
|
||||||
echo '→ Cleaning up...'
|
echo '→ Cleaning up...'
|
||||||
docker image prune -f
|
docker image prune -f
|
||||||
|
|||||||
Reference in New Issue
Block a user