-
Notifications
You must be signed in to change notification settings - Fork 11
71 lines (63 loc) · 2.35 KB
/
deploy.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
name: Deploy mazacofo
on:
push:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Create .env file
run: |
touch .env
echo "MYSQL_HOST=$MYSQL_HOST" >> .env
echo "MYSQL_USER=$MYSQL_USER" >> .env
echo "MYSQL_PW=$MYSQL_PW" >> .env
echo "MYSQL_DB=$MYSQL_DB" >> .env
echo "WEBHOOK_URL=$WEBHOOK_URL" >> .env
env:
MYSQL_HOST: ${{ secrets.MYSQL_HOST }}
MYSQL_USER: ${{ secrets.MYSQL_USER }}
MYSQL_PW: ${{ secrets.MYSQL_PW }}
MYSQL_DB: ${{ secrets.MYSQL_DB }}
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ap-northeast-2
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build and Push image to ECR - client
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: mazacofo
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f ./Dockerfile .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
- name: Deploy to server
uses: appleboy/[email protected]
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
TAG: ${{ github.sha }}
REPOSITORY: mazacofo
PORT_: 2021
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
envs: REGISTRY, TAG, REPOSITORY, PORT_
script: |
if [ "$( docker container inspect -f '{{.State.Status}}' $REPOSITORY )" == "running" ]; then
docker container stop $REPOSITORY
docker container rm $REPOSITORY
fi
docker image rmi $(docker images '$REGISTRY/$REPOSITORY')
aws ecr get-login-password --region ap-northeast-2 \
| docker login --username AWS --password-stdin 889566267001.dkr.ecr.ap-northeast-2.amazonaws.com
docker pull $REGISTRY/$REPOSITORY:$TAG
docker run -d --name $REPOSITORY -p $PORT_:$PORT_ $REGISTRY/$REPOSITORY:$TAG