-
Notifications
You must be signed in to change notification settings - Fork 4
179 lines (143 loc) · 5.16 KB
/
open-state-ci-cd.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: Open State CI/CD
on:
push:
branches:
- '*'
release:
types: [published]
env:
IMAGE_TAG: latest
jobs:
tests:
name: Run tests
runs-on: ubuntu-latest
continue-on-error: false
services:
mongodb:
image: mongo:4.4.0
ports:
- 27017:27017
env:
MONGO_INITDB_ROOT_USERNAME: open_state
MONGO_INITDB_ROOT_PASSWORD: open_state
MONGO_INITDB_DATABASE: open_state
redis:
image: redis:6.0.7
ports:
- 6379:6379
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Prepare Java SDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Execute tests
run: ./gradlew check
- name: Save test results
uses: actions/upload-artifact@v2
with:
name: test_results_${{ github.sha }}
path: build/reports/tests/test/**
- name: Execute test coverage report
run: ./gradlew jacocoTestReport
- name: Save test coverage results
uses: actions/upload-artifact@v2
with:
name: test_coverage_results_${{ github.sha }}
path: build/reports/jacoco/test/html/**
build:
name: Build project
runs-on: ubuntu-latest
continue-on-error: false
needs: [tests]
if: github.event.action == 'published'
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Prepare Java SDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Build project
run: ./gradlew assemble
- name: Save executables
uses: actions/upload-artifact@v2
with:
name: assembles_${{ github.sha }}
path: build/libs/*.jar
package:
name: Packaging
runs-on: ubuntu-latest
continue-on-error: false
needs: [tests, build]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: assembles_${{ github.sha }}
path: build/libs
- name: Define image tag
run:
if [[ ${{ github.ref }} == refs/heads/master || ${{ github.ref }} == refs/heads/2.x.x-REACTIVE ]]; then export IMAGE_TAG=latest; else export IMAGE_TAG=${{ github.ref }}#refs/heads/; fi;
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USER_NAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: openplatform/open-state:${{ env.IMAGE_TAG }}
file: docker/Dockerfile
deploy-production:
name: Deploy Production
runs-on: ubuntu-latest
continue-on-error: false
needs: [tests, build, package]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Deploy server
run: |
sudo apt install openssh-client
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
eval $(ssh-agent -s)
echo "${{ secrets.PROD_DEPLOY_SSH_KEY }}" | tr -d '\r' | ssh-add - > /dev/null
mkdir -p ~/.ssh
chmod 700 ~/.ssh
ssh-keyscan ${{ secrets.PROD_SERVER }} >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
export DOCKER_HOST="ssh://gitlab@${{ secrets.PROD_SERVER }}"
export MONGODB_PASSWORD="${{ secrets.PROD_MONGO_PASSWORD }}"
export BITCOIN_NODE_ADDRESS="${{ secrets.PROD_BITCOIN_NODE }}"
export BITCOIN_USERNAME="${{ secrets.PROD_BITCOIN_USERNAME }}"
export BITCOIN_PASSWORD="${{ secrets.PROD_BITCOIN_PASSWORD }}"
export OPEN_API_URL="${{ secrets.OPEN_API_URL_PROD }}"
export ETHEREUM_NODE_ADDRESS="${{ secrets.PROD_ETHEREUM_NODE_ADDRESS }}"
export ETHEREUM_ROPSTEN_NODE_ADDRESS="${{ secrets.PROD_ETHEREUM_ROPSTEN_NODE_ADDRESS }}"
export DOCKER_IMAGE_TAG="openplatform/open-state:${{ env.IMAGE_TAG }}"
docker login -u ${{ secrets.DOCKERHUB_USER_NAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
ssh -i /dev/null gitlab@${{ secrets.PROD_SERVER }} "
docker stop open-state && \
IMG=\$(docker ps -a --filter='name=^/open-state$' --format='{{.Image}}') && \
docker rm -f open-state && \
docker rmi \$IMG; \
exit 0
"
docker-compose -f docker-compose.yml up -d