Update .gitlab-ci.yml file

This commit is contained in:
kris
2025-11-10 08:04:37 +00:00
parent caf406a383
commit 2aaaf9a442
+73 -17
View File
@@ -2,26 +2,82 @@ stages:
- build - build
- deploy - deploy
build_static: # ====== template untuk build job (DRY) ======
.build_template: &build_template
stage: build stage: build
image: node:18-alpine image: node:20
script: cache:
- env | grep NEXT_PUBLIC_ key: npm-cache
- npm ci
- npx next build
artifacts:
paths: paths:
- out/ - node_modules/
expire_in: 1 hour variables:
only: NPM_CONFIG_PRODUCTION: "false" # install devDeps (tailwind/postcss)
- devops-s3 NODE_ENV: "" # kosongin supaya devDeps ikut
script:
- npm ci --no-audit --no-fund
- npm install && npm run build # hasil export -> ./out
artifacts:
name: "out-$CI_COMMIT_SHORT_SHA"
paths: ["out/"]
expire_in: 1 week
deploy_s3: # ====== template untuk deploy job (DRY) ======
.deploy_template: &deploy_template
stage: deploy stage: deploy
image: image:
name: amazon/aws-cli:latest name: amazon/aws-cli:2.15.39
entrypoint: ["/bin/sh", "-c"] entrypoint: [""] # matiin entrypoint "aws"
script: script:
- aws s3 sync out/ s3://$(echo $S3_BUCKET | tr -d '\r\n')/ --delete --region $(echo $AWS_DEFAULT_REGION | tr -d '\r\n') - aws --version
only: - echo "Deploying to s3://$S3_BUCKET in region $AWS_REGION"
- devops-s3 - aws s3 sync ./out "s3://$S3_BUCKET" --delete
- |
if [ -n "$CLOUDFRONT_DISTRIBUTION_ID" ]; then
aws cloudfront create-invalidation \
--distribution-id "$CLOUDFRONT_DISTRIBUTION_ID" \
--paths "/*"
fi
# ====== DEVELOPMENT ======
build:development:
<<: *build_template
rules:
- if: '$CI_COMMIT_BRANCH == "development"'
environment:
name: development
deploy:development:
<<: *deploy_template
needs: ["build:development"]
rules:
- if: '$CI_COMMIT_BRANCH == "development"'
variables:
# pakai variable scoped ke job ini
S3_BUCKET: "dev-lti-erp.mbugroup.id"
CLOUDFRONT_DISTRIBUTION_ID: "E1Z8XTA8XF1GIV"
environment:
name: development
# url: https://<cloudfront-dev-domain-atau-staging-domain-kamu>
# ====== PRODUCTION ======
build:production:
<<: *build_template
rules:
# pilih salah satu: pakai branch master ATAU pakai tags rilis
- if: '$CI_COMMIT_BRANCH == "master"'
# - if: '$CI_COMMIT_TAG' # kalau mau rilis via tag, uncomment ini dan hapus baris di atas
environment:
name: production
deploy:production:
<<: *deploy_template
needs: ["build:production"]
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
# - if: '$CI_COMMIT_TAG' # selaras dengan rule di build:production
variables:
S3_BUCKET: "lti-erp.mbugroup.id"
CLOUDFRONT_DISTRIBUTION_ID: "ddfd"
environment:
name: production
# url: https://royalgoldcapital.com