-
Notifications
You must be signed in to change notification settings - Fork 50
85 lines (75 loc) · 3.42 KB
/
deploy-aws-us-docker-update-v2.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Docker Build and Push deploy
on:
push:
branches:
- main
jobs:
build-and-push-deploy:
runs-on: ubuntu-latest
env:
IMAGE_TAG: ${{ github.run_number }}
ECR_REPOSITORY: ref-ui
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Configure AWS CLI
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_V2 }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_V2 }}
aws-region: us-east-1
- name: Login to Amazon ECR
run: |
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 151564965346.dkr.ecr.us-east-1.amazonaws.com
- name: Build Docker image
run: |
docker build -t 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} .
- name: Push Docker image
run: |
docker push 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: Execute SSH commmands on remote server[52.54.49.247]
uses: appleboy/ssh-action@master
with:
host: 52.54.49.247
username: root
key: ${{ secrets.SSH_PRIVATE_KEY_PROD_01 }}
port: 60022
script: |
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 151564965346.dkr.ecr.us-east-1.amazonaws.com
docker stop ref-ui || true
docker rm ref-ui || true
docker pull 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
timeout=300
elapsed=0
while ! docker pull 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | grep -q "Image is up to date"; do
sleep 10
elapsed=$((elapsed+10))
if [ "$elapsed" -ge "$timeout" ]; then
echo "Timeout waiting for Docker pull."
exit 1
fi
done
docker run -d -p 8080:80 --name ref-ui 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: Execute SSH commmands on remote server[34.224.251.142]
uses: appleboy/ssh-action@master
with:
host: 34.224.251.142
username: root
key: ${{ secrets.SSH_PRIVATE_KEY_PROD_02 }}
port: 60022
script: |
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 151564965346.dkr.ecr.us-east-1.amazonaws.com
docker stop ref-ui || true
docker rm ref-ui || true
docker pull 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
timeout=300
elapsed=0
while ! docker pull 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | grep -q "Image is up to date"; do
sleep 10
elapsed=$((elapsed+10))
if [ "$elapsed" -ge "$timeout" ]; then
echo "Timeout waiting for Docker pull."
exit 1
fi
done
docker run -d -p 8080:80 --name ref-ui 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}