-
Notifications
You must be signed in to change notification settings - Fork 1
132 lines (129 loc) · 5.36 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Continuous Integration
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build-backend:
name: Generate and Push Backend Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Prepare Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Check and Build All
run: ./scripts/build-all
- name: Docker Login
run: docker login --username=$DOCKER_USERNAME --password=$DOCKER_PASSWORD
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker Image
run: docker build -t $DOCKER_ADDRESS/$DOCKER_REPO_NAME:$(date "+%Y%m%d") .
env:
DOCKER_ADDRESS: ${{ secrets.DOCKER_ADDRESS }}
DOCKER_REPO_NAME: ${{secrets.DOCKER_REPO_NAME}}
- name: Push Docker Image
run: docker push $DOCKER_ADDRESS/$DOCKER_REPO_NAME:$(date "+%Y%m%d")
env:
DOCKER_ADDRESS: ${{ secrets.DOCKER_ADDRESS }}
DOCKER_REPO_NAME: ${{secrets.DOCKER_REPO_NAME}}
deploy-backend:
name: Deploy Backend
runs-on: ubuntu-latest
needs: build-backend
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set Secret Key for Publish
run: |
sudo tee /home/id_rsa <<- EOF
$DEPLOY_KEY
EOF
env:
DEPLOY_KEY: ${{secrets.DEPLOY_KEY}}
- name: Remove Previous Docker Container
run: ssh -i /home/id_rsa -p 1022 $TARGET_MACHINE -o "StrictHostKeyChecking no" "docker rm -f hare.backend||true"
env:
TARGET_MACHINE: ${{ secrets.TARGET_MACHINE }}
- name: Pull Docker Image
run: ssh -i /home/id_rsa -p 1022 $TARGET_MACHINE -o "StrictHostKeyChecking no" "docker pull $DOCKER_ADDRESS/$DOCKER_REPO_NAME:$(date "+%Y%m%d")"
env:
TARGET_MACHINE: ${{ secrets.TARGET_MACHINE }}
DOCKER_ADDRESS: ${{ secrets.DOCKER_ADDRESS }}
DOCKER_REPO_NAME: ${{secrets.DOCKER_REPO_NAME }}
- name: Run Docker Container
run: ssh -i /home/id_rsa -p 1022 $TARGET_MACHINE -o "StrictHostKeyChecking no" "docker run --name hare.backend -d -p 21000:8080 -e spring.profiles.active=prod -e spring.datasource.url='$DB_URL' -e spring.datasource.username=$DB_USERNAME -e spring.datasource.password=$DB_PW --restart always $DOCKER_ADDRESS/$DOCKER_REPO_NAME:$(date "+%Y%m%d")"
env:
TARGET_MACHINE: ${{ secrets.TARGET_MACHINE }}
DB_URL: ${{secrets.DB_URL }}
DOCKER_ADDRESS: ${{ secrets.DOCKER_ADDRESS }}
DOCKER_REPO_NAME: ${{secrets.DOCKER_REPO_NAME }}
DB_USERNAME: ${{secrets.DB_USERNAME }}
DB_PW: ${{secrets.DB_PW }}
build-frontend:
name: Generate and Push Frontend Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Dependencies
run: yarn install
working-directory: frontends/hare.webui
- name: Check all
run: yarn test:unit:coverage
working-directory: frontends/hare.webui
- name: Build all
run: yarn build
working-directory: frontends/hare.webui
- name: Docker Login
run: docker login --username=$DOCKER_USERNAME --password=$DOCKER_PASSWORD
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker Image
run: docker build -t $DOCKER_ADDRESS/$DOCKER_REPO_NAME_FE:$(date "+%Y%m%d") .
working-directory: frontends/hare.webui
env:
DOCKER_ADDRESS: ${{ secrets.DOCKER_ADDRESS }}
DOCKER_REPO_NAME_FE: ${{secrets.DOCKER_REPO_NAME_FE}}
- name: Push Docker Image
run: docker push $DOCKER_ADDRESS/$DOCKER_REPO_NAME_FE:$(date "+%Y%m%d")
env:
DOCKER_ADDRESS: ${{ secrets.DOCKER_ADDRESS }}
DOCKER_REPO_NAME_FE: ${{secrets.DOCKER_REPO_NAME_FE}}
deploy-frontend:
name: Deploy Frontend
runs-on: ubuntu-latest
needs: build-frontend
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set Secret Key for Publish
run: |
sudo tee /home/id_rsa <<- EOF
$DEPLOY_KEY
EOF
env:
DEPLOY_KEY: ${{secrets.DEPLOY_KEY}}
- name: Remove Previous Docker Container
run: ssh -i /home/id_rsa -p 1022 $TARGET_MACHINE -o "StrictHostKeyChecking no" "docker rm -f hare.frontend||true"
env:
TARGET_MACHINE: ${{ secrets.TARGET_MACHINE }}
- name: Pull Docker Image
run: ssh -i /home/id_rsa -p 1022 $TARGET_MACHINE -o "StrictHostKeyChecking no" "docker pull $DOCKER_ADDRESS/$DOCKER_REPO_NAME_FE:$(date "+%Y%m%d")"
env:
TARGET_MACHINE: ${{ secrets.TARGET_MACHINE }}
DOCKER_ADDRESS: ${{ secrets.DOCKER_ADDRESS }}
DOCKER_REPO_NAME_FE: ${{secrets.DOCKER_REPO_NAME_FE}}
- name: Run Docker Container
run: ssh -i /home/id_rsa -p 1022 $TARGET_MACHINE -o "StrictHostKeyChecking no" "docker run --name hare.frontend -d -p 11001:80 --restart always $DOCKER_ADDRESS/$DOCKER_REPO_NAME_FE:$(date "+%Y%m%d")"
env:
TARGET_MACHINE: ${{ secrets.TARGET_MACHINE }}
DOCKER_ADDRESS: ${{ secrets.DOCKER_ADDRESS }}
DOCKER_REPO_NAME_FE: ${{secrets.DOCKER_REPO_NAME_FE}}