From 2aaaf9a4423976433a522c637b95bfd1a09f10a5 Mon Sep 17 00:00:00 2001 From: kris Date: Mon, 10 Nov 2025 08:04:37 +0000 Subject: [PATCH] Update .gitlab-ci.yml file --- .gitlab-ci.yml | 90 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 17 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8791d4ed..9a0676ef 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 \ No newline at end of file + - 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:// + +# ====== 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