diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e24a8521..ec449d5c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,27 +2,47 @@ stages: - build - deploy +# ========================================================== +# ✅ Global defaults +# ========================================================== +default: + tags: + - self-hosted + interruptible: true + +# ========================================================== +# 🏗️ Build Template +# ========================================================== .build_template: &build_template stage: build image: node:20-alpine cache: key: npm-cache paths: - - node_modules/ + - .npm/ variables: - NPM_CONFIG_PRODUCTION: 'false' - NODE_ENV: '' + NPM_CONFIG_PRODUCTION: "false" + NODE_ENV: "" + NPM_CONFIG_CACHE: "$CI_PROJECT_DIR/.npm" script: - echo "Installing dependencies..." - npm ci --no-audit --no-fund + - echo "Build env used:" - echo "NEXT_PUBLIC_LTI_URL=$NEXT_PUBLIC_LTI_URL" - echo "NEXT_PUBLIC_SSO_LOGIN_URL=$NEXT_PUBLIC_SSO_LOGIN_URL" - echo "NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL" - - echo "Building Next.js static export..." + + # Build + export (untuk static hosting di S3) + - echo "Building Next.js..." - npx next build + + # Kalau project kamu pakai static export: + - echo "Exporting static site..." + - npx next export + + # Build metadata - | - mkdir -p out cat < out/build-info.json { "commit": "$CI_COMMIT_SHORT_SHA", @@ -34,11 +54,14 @@ stages: } EOF artifacts: - name: 'out-$CI_COMMIT_SHORT_SHA' + name: "out-$CI_COMMIT_SHORT_SHA" paths: - out/ expire_in: 1 week +# ========================================================== +# 🚀 Deploy Template +# ========================================================== .deploy_template: &deploy_template stage: deploy image: @@ -82,11 +105,11 @@ stages: if [ "$STATUS" = "success" ]; then COLOR=3066993 TITLE="✅ Deployment ${ENVIRONMENT_NAME} Succeeded" - DESC="Deployment job on branch \`${CI_COMMIT_REF_NAME}\` completed successfully." + DESC="Deployment job on branch \${CI_COMMIT_REF_NAME}\ completed successfully." else COLOR=15158332 TITLE="❌ Deployment ${ENVIRONMENT_NAME} Failed" - DESC="Deployment job on branch \`${CI_COMMIT_REF_NAME}\` encountered issues." + DESC="Deployment job on branch \${CI_COMMIT_REF_NAME}\ encountered issues." fi jq -n \ @@ -114,7 +137,9 @@ stages: curl -sS -H "Content-Type: application/json" -d @payload.json "$DISCORD_WEBHOOK_URL" +# ========================================================== # ==== DEVELOPMENT (Branch development) ====== +# ========================================================== build:dev: <<: *build_template rules: @@ -122,25 +147,27 @@ build:dev: environment: name: development variables: - NEXT_PUBLIC_LTI_URL: 'https://dev-lti-erp.mbugroup.id' - NEXT_PUBLIC_SSO_LOGIN_URL: 'https://dev-auth-erp.mbugroup.id' - NEXT_PUBLIC_API_BASE_URL: 'https://dev-api-lti.mbugroup.id/api' - NEXT_PUBLIC_CLIENT_ID: 'Lumbung-Telur-Indonesia' + NEXT_PUBLIC_LTI_URL: "https://dev-lti-erp.mbugroup.id" + NEXT_PUBLIC_SSO_LOGIN_URL: "https://dev-auth-erp.mbugroup.id" + NEXT_PUBLIC_API_BASE_URL: "https://dev-api-lti.mbugroup.id/api" + NEXT_PUBLIC_CLIENT_ID: "Lumbung-Telur-Indonesia" deploy:dev: <<: *deploy_template - needs: ['build:dev'] + needs: ["build:dev"] rules: - if: '$CI_COMMIT_BRANCH == "development"' variables: - S3_BUCKET: 'dev-lti-erp.mbugroup.id' - AWS_REGION: 'ap-southeast-3' - CLOUDFRONT_DISTRIBUTION_ID: 'E1Z8XTA8XF1GIV' + S3_BUCKET: "dev-lti-erp.mbugroup.id" + AWS_REGION: "ap-southeast-3" + CLOUDFRONT_DISTRIBUTION_ID: "E1Z8XTA8XF1GIV" environment: name: development url: https://dev-lti-erp.mbugroup.id +# ========================================================== # ====== STAGING (Branch staging) ====== +# ========================================================== build:staging: <<: *build_template rules: @@ -148,42 +175,20 @@ build:staging: environment: name: staging variables: - NEXT_PUBLIC_LTI_URL: 'https://stg-lti-erp.mbugroup.id' - NEXT_PUBLIC_SSO_LOGIN_URL: 'https://stg-auth-erp.mbugroup.id' - NEXT_PUBLIC_API_BASE_URL: 'https://stg-api-lti.mbugroup.id/api' - NEXT_PUBLIC_CLIENT_ID: 'Lumbung-Telur-Indonesia' + NEXT_PUBLIC_LTI_URL: "https://stg-lti-erp.mbugroup.id" + NEXT_PUBLIC_SSO_LOGIN_URL: "https://stg-auth-erp.mbugroup.id" + NEXT_PUBLIC_API_BASE_URL: "https://stg-api-lti.mbugroup.id/api" + NEXT_PUBLIC_CLIENT_ID: "Lumbung-Telur-Indonesia" deploy:staging: <<: *deploy_template - needs: ['build:staging'] + needs: ["build:staging"] rules: - if: '$CI_COMMIT_BRANCH == "staging"' variables: - S3_BUCKET: 'stg-lti-erp.mbugroup.id' - AWS_REGION: 'ap-southeast-3' - CLOUDFRONT_DISTRIBUTION_ID: 'E2V6PPO1AUIU7H' + S3_BUCKET: "stg-lti-erp.mbugroup.id" + AWS_REGION: "ap-southeast-3" + CLOUDFRONT_DISTRIBUTION_ID: "E2V6PPO1AUIU7H" environment: name: staging - url: https://stg-lti-erp.mbugroup.id -# ====== 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://stg-lti-erp.mbugroup.id \ No newline at end of file