image: docker:20.10.7

services:
  - docker:20.10.7-dind

variables:
  AWS_REGION: "ap-southeast-1" # AWS Region
  AWS_DEFAULT_REGION: "ap-southeast-1" # AWS Region
  ECR_REGISTRY: "957131694835.dkr.ecr.ap-southeast-1.amazonaws.com"
  ECR_REPOSITORY: "nuxtjs-app"
  ECS_CLUSTER: "development-ecs-cluster" # Replace with your ECS cluster name
  ECS_SERVICE: "ebrochure-fe" # Replace with your ECS service name

  #### STAGING ####
  STAGING_ECR_REGISTRY: "038462767923.dkr.ecr.ap-southeast-1.amazonaws.com"
  STAGING_ECR_REPOSITORY: "ebrochure-fe"
  STAGING_ECS_CLUSTER: "staging-ecs-cluster" # Replace with your ECS cluster name
  STAGING_ECS_SERVICE: "ebrochure-fe" # Replace with your ECS service name

# stages:
#   - build_and_public
#   - deploy

# build_and_public_staging:
#   stage: build_and_public
#   script:
#     - apk add --no-cache python3 py3-pip
#     - pip3 install awscli
#     - echo $STAGING_AWS_ACCESS_KEY_ID
#     - echo $STAGING_AWS_SECRET_ACCESS_KEY
#     - aws configure set aws_access_key_id $STAGING_AWS_ACCESS_KEY_ID
#     - aws configure set aws_secret_access_key $STAGING_AWS_SECRET_ACCESS_KEY
#     - aws configure set default.region $AWS_REGION
#     - aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $STAGING_ECR_REGISTRY
#     - docker build -t $STAGING_ECR_REGISTRY/$STAGING_ECR_REPOSITORY:latest --no-cache .
#     - docker push $STAGING_ECR_REGISTRY/$STAGING_ECR_REPOSITORY:latest
#   rules:
#     - if: '$CI_COMMIT_BRANCH == "staging"'

# build_and_public_main:
#   stage: build_and_public
#   script:
#     - apk add --no-cache python3 py3-pip
#     - pip3 install awscli
#     - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
#     - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
#     - aws configure set default.region $AWS_REGION
#     - aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_REGISTRY
#     - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:latest --no-cache .
#     - docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
#   rules:
#     - if: '$CI_COMMIT_BRANCH == "main"'

# deploy_staging:
#   stage: deploy
#   script:
#     - apk add --no-cache python3 py3-pip
#     - pip3 install awscli
#     - aws configure set aws_access_key_id $STAGING_AWS_ACCESS_KEY_ID
#     - aws configure set aws_secret_access_key $STAGING_AWS_SECRET_ACCESS_KEY
#     - aws configure set default.region $AWS_REGION
#     - aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $STAGING_ECR_REGISTRY
#     - aws ecs update-service --cluster $STAGING_ECS_CLUSTER --service $STAGING_ECS_SERVICE --force-new-deployment
#   rules:
#     - if: '$CI_COMMIT_BRANCH == "staging"'

# deploy_main:
#   stage: deploy
#   script:
#     - apk add --no-cache python3 py3-pip
#     - pip3 install awscli
#     - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
#     - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
#     - aws configure set default.region $AWS_REGION
#     - aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_REGISTRY
#     - aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --force-new-deployment
#   rules:
#     - if: '$CI_COMMIT_BRANCH == "main"'
