diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1e2cfcef..147eb7ea 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,9 +14,9 @@ stages: NPM_CONFIG_PRODUCTION: "false" NODE_ENV: "" script: - - echo "๐Ÿงฉ Installing dependencies..." + - echo "Installing dependencies..." - npm ci --no-audit --no-fund - - echo "โš™๏ธ Building Next.js static export..." + - echo "Building Next.js static export..." - npx next build artifacts: name: "out-$CI_COMMIT_SHORT_SHA" @@ -24,44 +24,43 @@ stages: - out/ expire_in: 1 week -# ====== TEMPLATE: DEPLOY KE S3 + CLOUDFRONT + NOTICE DISCORD ====== .deploy_template: &deploy_template stage: deploy image: name: amazon/aws-cli:latest entrypoint: ["/bin/sh", "-c"] script: + - set -e - aws --version - - echo "๐Ÿงน Cleaning up newline characters in AWS credentials..." + - echo "Cleaning up newline characters in AWS credentials..." - export AWS_ACCESS_KEY_ID=$(echo $AWS_ACCESS_KEY_ID | tr -d '\r\n') - export AWS_SECRET_ACCESS_KEY=$(echo $AWS_SECRET_ACCESS_KEY | tr -d '\r\n') - - echo "๐Ÿš€ Deploying to s3://$S3_BUCKET in region $AWS_REGION" + - echo "Deploying to s3://$S3_BUCKET in region $AWS_REGION" - aws s3api head-bucket --bucket "$S3_BUCKET" --region "$AWS_REGION" || aws s3api create-bucket --bucket "$S3_BUCKET" --region "$AWS_REGION" --create-bucket-configuration LocationConstraint="$AWS_REGION" - aws s3 sync ./out "s3://$S3_BUCKET" --delete --region "$AWS_REGION" --endpoint-url "https://s3.ap-southeast-3.amazonaws.com" + # CloudFront invalidation - | + STATUS="success" if [ -n "$CLOUDFRONT_DISTRIBUTION_ID" ]; then - echo "๐Ÿ“ฆ Invalidating CloudFront cache..." - aws cloudfront create-invalidation \ - --distribution-id "$CLOUDFRONT_DISTRIBUTION_ID" \ - --paths "/*" + echo "Invalidating CloudFront cache..." + if ! aws cloudfront create-invalidation --distribution-id "$CLOUDFRONT_DISTRIBUTION_ID" --paths "/*"; then + echo "CloudFront invalidation failed." + STATUS="failed" + fi else - echo "โ„น๏ธ No CloudFront distribution specified โ€” skipping invalidation" + echo "No CloudFront distribution specified โ€” skipping invalidation" fi - if [ "$CI_JOB_STATUS" = "success" ]; then - STATUS='success' - else - STATUS='failed' - fi - # ๐Ÿ”” Notifikasi Discord + + # Notifikasi Discord - | RUN_URL="${CI_PROJECT_URL}/-/pipelines/${CI_PIPELINE_ID}" - # Tentukan nama environment untuk pesan + # Tentukan nama environment if [ "$CI_COMMIT_BRANCH" = "devops-s3" ]; then ENVIRONMENT_NAME="WEB-LTI-DEV" elif [ "$CI_COMMIT_BRANCH" = "master" ]; then - ENVIRONMENT_NAME="WEB-LTI-DEV" + ENVIRONMENT_NAME="WEB-LTI-PROD" else ENVIRONMENT_NAME="UNKNOWN" fi