-
Notifications
You must be signed in to change notification settings - Fork 4
96 lines (83 loc) · 2.9 KB
/
sample-deployment.yaml
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
name: Sample service deployment
on:
workflow_dispatch:
inputs:
host:
description: 'Target host IP or hostname'
required: true
sshPort:
description: 'SSH port of Target host'
required: true
default: '22'
sshUser:
description: 'SSH user of Target host'
required: true
default: 'ubuntu'
jobs:
test:
name: 'Run tests'
runs-on: ubuntu-latest
steps:
- name: Setup timezone
run: sudo timedatectl set-timezone "Asia/Shanghai"
- uses: actions/checkout@v2
- name: Setup Java JDK
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-package: 'jdk'
java-version: '11'
check-latest: true
- name: Create dependency folder
run: mkdir lib
working-directory: sample
- name: Fetch latest release
uses: dsaltares/fetch-gh-release-asset@master
with:
file: "com.thoughtworks.inspac.sdk.jar"
target: "sample/lib/com.thoughtworks.inspac.sdk.jar"
token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('sample/build.gradle.kts', 'sample/**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Run tests
run: ./gradlew build
working-directory: sample
- name: Build Docker image
run: |
docker build --build-arg DEMO_HOSTNAME=${{ github.event.inputs.host }} -f Dockerfile -t thoughtworks/inspac-sample:latest .
docker save thoughtworks/inspac-sample:latest | gzip > inspac-sample.tgz
working-directory: sample
- name: Transfer Docker image
uses: appleboy/[email protected]
with:
host: ${{ github.event.inputs.host }}
username: ${{ github.event.inputs.sshUser }}
port: ${{ github.event.inputs.sshPort }}
key: ${{ secrets.SSH_KEY }}
source: "sample/inspac-sample.tgz"
target: "/home/ubuntu/inspac"
strip_components: 1
- name: Deploy inSpac sample service
uses: appleboy/[email protected]
with:
host: ${{ github.event.inputs.host }}
username: ${{ github.event.inputs.sshUser }}
port: ${{ github.event.inputs.sshPort }}
key: ${{ secrets.SSH_KEY }}
script: |
docker stop inspac-sample
docker system prune -a -f
gunzip -c /home/ubuntu/inspac/inspac-sample.tgz | docker load
docker-compose -f /home/ubuntu/inspac/docker-compose.yaml up -d
rm -f /home/ubuntu/inspac/inspac-sample.t*
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
# with:
# sudo: true