Deploy #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy | |
on: workflow_dispatch | |
env: | |
AWS_REGION: ${{ vars.AWS_REGION }} | |
DOCKER_TAG: ${{ github.sha }} | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Login to Amazon ECR | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
file: Dockerfile.Prod | |
tags: "${{ secrets.DOCKER_REGISTRY_NAME }}/terremotibot:${{ env.DOCKER_TAG }}" | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Prepare deploy | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "${{ secrets.DEPLOY_KNOWN_HOSTS }}" > ~/.ssh/known_hosts | |
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/key | |
chmod 0600 ~/.ssh/* | |
- name: Deploy | |
run: | | |
export DOCKER_REGISTRY_TOKEN="$(aws ecr get-login-password)" | |
ssh ${{ secrets.DEPLOY_USERNAME }}@${{ secrets.DEPLOY_HOSTNAME }} \ | |
-i ~/.ssh/key \ | |
DOCKER_REGISTRY_TOKEN=$DOCKER_REGISTRY_TOKEN \ | |
DOCKER_REGISTRY_NAME=${{ secrets.DOCKER_REGISTRY_NAME }} \ | |
DOCKER_TAG=$DOCKER_TAG \ | |
CONTAINER_NAME=terremotibot \ | |
'bash -s' < .github/workflows/deploy.sh |