version: v1.0

name: Deploy

agent:
  machine:
    type: e1-standard-2
    os_image: ubuntu2004

execution_time_limit:
  minutes: 3

blocks:
  - name: Dockerize
    task:
      secrets:
        - name: gcloud
        - name: terremotibot
      prologue:
        commands:
          - gcloud auth activate-service-account --key-file=.secrets/gcloud.json
          - gcloud auth configure-docker -q

          - checkout

          - export DOCKER_BUILDKIT=1
      jobs:
        - name: Build and push
          commands:
            - docker build -t "$REPOSITORY/terremotibot:$SEMAPHORE_GIT_SHA" -f Dockerfile.Prod .
            - docker images
            - docker push "$REPOSITORY/terremotibot:$SEMAPHORE_GIT_SHA"

  - name: tb5@hetzner
    task:
      secrets:
        - name: terremotibot
        - name: tb5@hetzner
      prologue:
        commands:
          - chmod 0600 ~/.keys/*
          - ssh-add ~/.keys/*

          - checkout
      jobs:
        - name: SSH
          commands:
            - ssh deploy@$IP DOCKER_TAG=$SEMAPHORE_GIT_SHA CONTAINER_NAME=terremotibot 'bash -s' < .semaphore/deploy.sh

version: v1.0

name: Deploy

agent:
  machine:
    type: e1-standard-2
    os_image: ubuntu2004

execution_time_limit:
  minutes: 3

blocks:
  - name: Dockerize
    task:
      secrets:
        - name: aws_ecr
        - name: terremotibot
      prologue:
        commands:
          - aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com"

          - checkout

          - export DOCKER_BUILDKIT=1
      jobs:
        - name: Build and push
          commands:
            - export REPOSITORY="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com"

            - docker build -t "$REPOSITORY/terremotibot:$SEMAPHORE_GIT_SHA" -f Dockerfile.Prod .
            - docker images
            - docker push "$REPOSITORY/terremotibot:$SEMAPHORE_GIT_SHA"

  - name: tb5@hetzner
    task:
      secrets:
        - name: terremotibot
        - name: tb5@hetzner
      prologue:
        commands:
          - chmod 0600 ~/.keys/*
          - ssh-add ~/.keys/*

          - checkout
      jobs:
        - name: SSH
          commands:
            - ssh deploy@$IP DOCKER_TAG=$SEMAPHORE_GIT_SHA CONTAINER_NAME=terremotibot 'bash -s' < .semaphore/deploy.sh

Move Docker image to AWS
Move Docker image to AWS
