stages: - build - deploy # ====== template untuk build job (DRY) ====== .build_template: &build_template stage: build image: node:20 cache: key: npm-cache paths: - 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 # ====== template untuk deploy job (DRY) ====== .deploy_template: &deploy_template stage: deploy image: name: amazon/aws-cli:2.15.39 entrypoint: [""] # matiin entrypoint "aws" script: - 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