Update .gitlab-ci.yml file

This commit is contained in:
kris
2025-11-10 08:22:49 +00:00
parent 8912a82dba
commit 90de8f4e4d
+28 -19
View File
@@ -2,62 +2,71 @@ stages:
- build
- deploy
# ====== template untuk build job (DRY) ======
# ====== TEMPLATE: BUILD STATIC NEXT.JS ======
.build_template: &build_template
stage: build
image: node:20
image: node:20-alpine
cache:
key: npm-cache
paths:
- node_modules/
variables:
NPM_CONFIG_PRODUCTION: "false" # install devDeps (tailwind/postcss)
NODE_ENV: "" # kosongin supaya devDeps ikut
NPM_CONFIG_PRODUCTION: "false"
NODE_ENV: ""
script:
- echo "🧩 Installing dependencies..."
- npm ci --no-audit --no-fund
- npm install && npm run build # hasil export -> ./out
- echo "⚙️ Building Next.js static export..."
- npx next build
artifacts:
name: "out-$CI_COMMIT_SHORT_SHA"
paths: ["out/"]
paths:
- out/
expire_in: 1 week
# ====== template untuk deploy job (DRY) ======
# ====== TEMPLATE: DEPLOY KE S3 + CLOUDFRONT ======
.deploy_template: &deploy_template
stage: deploy
image:
name: amazon/aws-cli:2.15.39
entrypoint: [""] # matiin entrypoint "aws"
name: amazon/aws-cli:latest
entrypoint: ["/bin/sh", "-c"]
script:
- aws --version
- echo "Deploying to s3://$S3_BUCKET in region $AWS_REGION"
- aws s3 sync ./out "s3://$S3_BUCKET" --delete
- echo "🚀 Deploying to s3://$S3_BUCKET in region $AWS_REGION"
- aws s3 sync ./out "s3://$S3_BUCKET" --delete --region "$AWS_REGION"
- |
if [ -n "$CLOUDFRONT_DISTRIBUTION_ID" ]; then
echo "📦 Invalidating CloudFront cache..."
aws cloudfront create-invalidation \
--distribution-id "$CLOUDFRONT_DISTRIBUTION_ID" \
--paths "/*"
else
echo "️ No CloudFront distribution specified — skipping invalidation"
fi
# ====== DEVELOPMENT ======
build:development:
# ====== DEVELOPMENT (Branch devops-s3) ======
build:dev:
<<: *build_template
rules:
- if: '$CI_COMMIT_BRANCH == "development"'
- if: '$CI_COMMIT_BRANCH == "devops-s3"'
environment:
name: development
name: devops-s3
variables:
NEXT_PUBLIC_API_BASE_URL: "https://dev-api-lti.mbugroup.id"
NEXT_PUBLIC_SSO_LOGIN_URL: "https://dev-api-sso.mbugroup.id"
deploy:development:
deploy:dev:
<<: *deploy_template
needs: ["build:devops-s3"]
rules:
- if: '$CI_COMMIT_BRANCH == "devops-s3"'
variables:
# pakai variable scoped ke job ini
S3_BUCKET: "dev-lti-erp.mbugroup.id"
S3_BUCKET: "web-lti-dev"
AWS_DEFAULT_REGION: "ap-southeast-1"
CLOUDFRONT_DISTRIBUTION_ID: "E1Z8XTA8XF1GIV"
environment:
name: devops-s3
# url: https://<cloudfront-dev-domain-atau-staging-domain-kamu>
url: dev-lti-erp.mbugroup.id.s3.ap-southeast-3.amazonaws.com
# ====== PRODUCTION ======
build:production: