variables:

stages:
  - build

before_script:
  - IMAGE_TAG=git-${CI_COMMIT_SHA:0:8}
  - IMAGE_NAME="enterprise-integrations/iics_secure_agent:${IMAGE_TAG}"
  - ECR_IMAGE_NAME="${AWS_ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/enterprise-integrations/iics_secure_agent:${IMAGE_TAG}"
  - apk update && apk add groff less && apk add python3
  - pip3 install awscli
  - $(aws ecr get-login --no-include-email --region us-east-1)

after_script:
  - docker logout "$AWS_ACCOUNT_ID".dkr.ecr.us-east-1.amazonaws.com

image: docker:latest

build-master:
  stage: build
  tags:
    - docker
  script:
    - docker build --pull --rm -t ${IMAGE_NAME} .
    - docker tag ${IMAGE_NAME} ${ECR_IMAGE_NAME}
    - docker push ${ECR_IMAGE_NAME}
  only:
    refs:
      - master
    changes:
      - Dockerfile
      - .gitlab-ci.yml
      - run-agent.sh
