generated from pieceowater-dev/openAPI-frontend-template
-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (51 loc) · 2.42 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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