Deploy #2
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 | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Login to Amazon ECR | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Build | |
uses: docker/build-push-action@v2 | |
with: | |
push: true | |
file: Dockerfile.Prod | |
tags: "${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.AWS_REPOSITORY }}:${{ github.sha }}" | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.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_NAME="${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com" | |
export DOCKER_REGISTRY_TOKEN="$(aws ecr get-login-password --region ${{ secrets.AWS_REGION }})" | |
ssh ${{ secrets.DEPLOY_USERNAME }}@${{ secrets.DEPLOY_IP }} -i ~/.ssh/key DOCKER_REGISTRY_TOKEN=$DOCKER_REGISTRY_TOKEN DOCKER_REGISTRY_NAME=$DOCKER_REGISTRY_NAME DOCKER_TAG=${{ github.sha }} CONTAINER_NAME=${{ secrets.AWS_REPOSITORY }} 'bash -s' < .github/workflows/deploy.sh |