Skip to content

Update prod-update.yml #31

Update prod-update.yml

Update prod-update.yml #31

Workflow file for this run

name: Build and Push Docker Image to AWS ECR
on:
push:
branches:
# - main
jobs:
build_and_push:
name: Build and Push
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Configure AWS credentials
timeout-minutes: 1
run: |
aws configure set aws_access_key_id ${{ vars.AWS_ACCESS_KEY_ID }}
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws configure set region ${{ vars.AWS_REGION }}
- name: Login to AWS ECR
timeout-minutes: 1
run: aws ecr get-login-password --region ${{ vars.AWS_REGION }} | docker login --username AWS --password-stdin ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com
- name: Build Docker image
timeout-minutes: 3
run: |
docker build \
-t ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com/${{ vars.ECR_REPOSITORY }}:${{ github.sha }} \
--build-arg BUILD_MODE=main \
--build-arg API_ADDRESS=https://api.grands-pay.com \
.
- name: Push Docker image to ECR
timeout-minutes: 2
run: |
docker push ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com/${{ vars.ECR_REPOSITORY }}:${{ github.sha }}
- name: Logout of AWS ECR
timeout-minutes: 1
run: docker logout ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com
- name: SSH into EC2 instance and run ls
timeout-minutes: 5
uses: appleboy/ssh-action@master
with:
host: ${{ vars.EC2_PUBLIC_DNS }}
username: ec2-user
key: ${{ secrets.EC2_SSH_KEY }}
port: 22
script: |
cp docker-compose-sample.yml docker-compose.yml
sed -i 's|{{ IMAGE_URI }}|${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com/${{ vars.ECR_REPOSITORY }}:${{ github.sha }}|g' docker-compose.yml
aws ecr get-login-password --region ${{ vars.AWS_REGION }} | sudo docker login --username AWS --password-stdin ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com
sudo docker pull ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com/${{ vars.ECR_REPOSITORY }}:${{ github.sha }}
sudo docker stack deploy -c docker-compose.yml qpay
rm docker-compose.yml