mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 05:22:02 +00:00
Update .gitlab-ci.yml file
This commit is contained in:
+16
-47
@@ -3,33 +3,16 @@ stages:
|
||||
- deploy
|
||||
|
||||
variables:
|
||||
# 🔧 Docker BuildKit lebih cepat
|
||||
DOCKER_BUILDKIT: "1"
|
||||
COMPOSE_DOCKER_CLI_BUILD: "1"
|
||||
DOCKER_DRIVER: overlay2
|
||||
|
||||
# 🧠 Tag image berdasarkan commit
|
||||
BUILDKIT_PROGRESS: plain
|
||||
IMAGE_NAME: "$CI_REGISTRY_IMAGE/web-lti:development_${CI_COMMIT_SHORT_SHA}"
|
||||
|
||||
# 📦 Cache npm antar pipeline
|
||||
NPM_CACHE_DIR: "$CI_PROJECT_DIR/.npm"
|
||||
|
||||
# 🌐 Environment default untuk Next.js
|
||||
NODE_ENV: "production"
|
||||
HUSKY_SKIP_INSTALL: "1"
|
||||
|
||||
# ⚙️ Inject ENV dari GitLab CI Variables ke Dockerfile
|
||||
NEXT_PUBLIC_API_BASE_URL: "${NEXT_PUBLIC_API_BASE_URL}"
|
||||
NEXT_PUBLIC_LTI_API_START_URL: "${NEXT_PUBLIC_LTI_API_START_URL}"
|
||||
|
||||
cache:
|
||||
key: npm-cache
|
||||
paths:
|
||||
- .npm/
|
||||
|
||||
# =========================
|
||||
# 🏗️ BUILD STAGE
|
||||
# =========================
|
||||
build-image:
|
||||
stage: build
|
||||
image: docker:27.0.3
|
||||
@@ -37,56 +20,42 @@ build-image:
|
||||
- docker:dind
|
||||
|
||||
before_script:
|
||||
- echo "🔐 Logging in to GitLab Container Registry..."
|
||||
- echo "Login to registry"
|
||||
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY"
|
||||
|
||||
script:
|
||||
- echo "🚧 Building optimized Docker image..."
|
||||
- >
|
||||
docker build
|
||||
--build-arg NEXT_PUBLIC_API_BASE_URL="$NEXT_PUBLIC_API_BASE_URL"
|
||||
--build-arg NEXT_PUBLIC_LTI_API_START_URL="$NEXT_PUBLIC_LTI_API_START_URL"
|
||||
--build-arg NODE_ENV="$NODE_ENV"
|
||||
--build-arg HUSKY_SKIP_INSTALL="$HUSKY_SKIP_INSTALL"
|
||||
--build-arg BUILDKIT_INLINE_CACHE=1
|
||||
--cache-from "$CI_REGISTRY_IMAGE/web-lti:latest"
|
||||
-t "$IMAGE_NAME" .
|
||||
- docker build \
|
||||
--build-arg NEXT_PUBLIC_API_BASE_URL="$NEXT_PUBLIC_API_BASE_URL" \
|
||||
--build-arg NEXT_PUBLIC_LTI_API_START_URL="$NEXT_PUBLIC_LTI_API_START_URL" \
|
||||
--build-arg NODE_ENV="$NODE_ENV" \
|
||||
--build-arg HUSKY_SKIP_INSTALL="$HUSKY_SKIP_INSTALL" \
|
||||
--cache-from "$CI_REGISTRY_IMAGE/web-lti:latest" \
|
||||
-t "$IMAGE_NAME" .
|
||||
- docker push "$IMAGE_NAME"
|
||||
- echo "🧹 Cleaning old images..."
|
||||
- docker image prune -af --filter "until=72h"
|
||||
|
||||
after_script: "echo 'Build complete: $IMAGE_NAME' && docker system prune -af || true && docker volume prune -f || true"
|
||||
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == "development"'
|
||||
|
||||
# =========================
|
||||
# 🚀 DEPLOY STAGE
|
||||
# =========================
|
||||
deploy-dev:
|
||||
stage: deploy
|
||||
image: alpine:3.20
|
||||
|
||||
before_script:
|
||||
- echo "📦 Installing dependencies..."
|
||||
- apk add --no-cache openssh curl
|
||||
- mkdir -p ~/.ssh
|
||||
- echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
||||
- echo \"$SSH_PRIVATE_KEY\" > ~/.ssh/id_rsa
|
||||
- chmod 600 ~/.ssh/id_rsa
|
||||
- eval $(ssh-agent -s)
|
||||
- ssh-add ~/.ssh/id_rsa
|
||||
- ssh-keyscan -H "$SERVER_IP" >> ~/.ssh/known_hosts
|
||||
- ssh-keyscan -H \"$SERVER_IP\" >> ~/.ssh/known_hosts
|
||||
|
||||
script:
|
||||
- echo "🚀 Deploying image to $SERVER_USER@$SERVER_IP"
|
||||
- >
|
||||
ssh -o StrictHostKeyChecking=no "$SERVER_USER@$SERVER_IP" "
|
||||
docker pull $CI_REGISTRY_IMAGE/web-lti:development_${CI_COMMIT_SHORT_SHA} &&
|
||||
docker stop dev-web-lti || true &&
|
||||
docker rm dev-web-lti || true &&
|
||||
docker run -d --name dev-web-lti \
|
||||
--network dev-lti-network \
|
||||
-p 3002:3000 \
|
||||
$CI_REGISTRY_IMAGE/web-lti:development_${CI_COMMIT_SHORT_SHA}
|
||||
"
|
||||
- ssh -o StrictHostKeyChecking=no \"$SERVER_USER@$SERVER_IP\" \"docker stop dev-web-lti || true && docker rm dev-web-lti || true && docker pull $CI_REGISTRY_IMAGE/web-lti:development_${CI_COMMIT_SHORT_SHA} && docker run -d --name dev-web-lti --network dev-lti-network -p 3002:3000 $CI_REGISTRY_IMAGE/web-lti:development_${CI_COMMIT_SHORT_SHA}\"
|
||||
|
||||
after_script: "echo 'Deploy finished for $IMAGE_NAME'"
|
||||
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == "development"'
|
||||
Reference in New Issue
Block a user