mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
Update .gitlab-ci.yml file
This commit is contained in:
+73
-17
@@ -2,26 +2,82 @@ stages:
|
||||
- build
|
||||
- deploy
|
||||
|
||||
build_static:
|
||||
# ====== template untuk build job (DRY) ======
|
||||
.build_template: &build_template
|
||||
stage: build
|
||||
image: node:18-alpine
|
||||
script:
|
||||
- env | grep NEXT_PUBLIC_
|
||||
- npm ci
|
||||
- npx next build
|
||||
artifacts:
|
||||
image: node:20
|
||||
cache:
|
||||
key: npm-cache
|
||||
paths:
|
||||
- out/
|
||||
expire_in: 1 hour
|
||||
only:
|
||||
- devops-s3
|
||||
- node_modules/
|
||||
variables:
|
||||
NPM_CONFIG_PRODUCTION: "false" # install devDeps (tailwind/postcss)
|
||||
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
|
||||
image:
|
||||
name: amazon/aws-cli:latest
|
||||
entrypoint: ["/bin/sh", "-c"]
|
||||
name: amazon/aws-cli:2.15.39
|
||||
entrypoint: [""] # matiin entrypoint "aws"
|
||||
script:
|
||||
- aws s3 sync out/ s3://$(echo $S3_BUCKET | tr -d '\r\n')/ --delete --region $(echo $AWS_DEFAULT_REGION | tr -d '\r\n')
|
||||
only:
|
||||
- devops-s3
|
||||
- aws --version
|
||||
- echo "Deploying to s3://$S3_BUCKET in region $AWS_REGION"
|
||||
- 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
|
||||
|
||||
Reference in New Issue
Block a user