-
Notifications
You must be signed in to change notification settings - Fork 10
125 lines (121 loc) · 4.7 KB
/
prod_workflow.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
name: Minimal CI/CD
on: [push]
jobs:
tests:
name: Testing
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Run docker-compose
run: docker-compose up -d
- name: Set up Open JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Test backend
run: mvn -B clean test -pl :backend-server
- name: Set up Node 14
uses: actions/setup-node@v2-beta
with:
node-version: '14'
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Test frontend
run: |
npm install frontend-client --prefix ./frontend-client
npm --prefix frontend-client run test:unit
deploy:
name: Deploy on server
runs-on: ubuntu-latest
needs: tests
if: github.ref == 'refs/heads/master'
env:
KILL_JAVA_SH: ${{ github.workspace }}/ci/kill_java_process.sh
JAVA_CMD_PATH: ~/jdk/bin/java
JAR_NAME: backend-server-
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Set up Node 14
uses: actions/setup-node@v2-beta
with:
node-version: '14'
- name: Cache node modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Build frontend
run: |
npm install frontend-client --prefix ./frontend-client
npm --prefix frontend-client run build
- name: Create version
run: |
APP_RELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
APP_RELEASE_VERSION=${APP_RELEASE_VERSION%"-SNAPSHOT"}
APP_RELEASE_VERSION_ARRAY=(${APP_RELEASE_VERSION//./ })
APP_RELEASE_VERSION_MINOR=APP_RELEASE_VERSION_ARRAY[2]
APP_RELEASE_VERSION_MINOR=$((APP_RELEASE_VERSION_MINOR + 1))
APP_RELEASE_VERSION="${APP_RELEASE_VERSION_ARRAY[0]}.${APP_RELEASE_VERSION_ARRAY[1]}.${APP_RELEASE_VERSION_MINOR}"
echo "JAR_NAME=$JAR_NAME$APP_RELEASE_VERSION-SNAPSHOT.jar" >> $GITHUB_ENV
echo "RELEASE VERSION: ${APP_RELEASE_VERSION}-SNAPSHOT"
mvn -B --batch-mode release:update-versions -DdevelopmentVersion=$APP_RELEASE_VERSION-SNAPSHOT
- name: Cache maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build backend
run: mvn -B clean package -Dmaven.test.skip=true -pl :backend-server
- name: Prepare SSH Keys
run: |
mkdir -p ~/.ssh
echo "${{ secrets.CLIENT_PRIV_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "${{ secrets.SERVER_PUB_KEY }}" > ~/.ssh/known_hosts
chmod 600 ~/.ssh/known_hosts
- name: Kill java process
run: |
ssh -p ${{ secrets.PORT }} ${{ secrets.USERNAME }}@${{ secrets.HOST }} 'bash -s' < $KILL_JAVA_SH
- name: Remove old artifacts
run: |
ssh -p ${{ secrets.PORT }} ${{ secrets.USERNAME }}@${{ secrets.HOST }} "rm -rf backend-server-*.jar"
- name: Copy jar to server
run: |
rsync -avzhe 'ssh -p ${{ secrets.PORT }}' ${{ github.workspace }}/backend-server/target/$JAR_NAME ${{ secrets.USERNAME }}@${{ secrets.HOST }}:~
- name: Launch app
run: |
ssh -f -p ${{ secrets.PORT }} ${{ secrets.USERNAME }}@${{ secrets.HOST }} "$JAVA_CMD_PATH -Xms64M -Xmx256M -jar $JAR_NAME &"
- name: Commit version
run: |
git config --global user.name 'Nicolas Vargas Ortega'
git config --global user.email 'soasada@users.noreply.github.com'
git commit -am "CI/CD: $JAR_NAME artifact deployed"
git push