-
Notifications
You must be signed in to change notification settings - Fork 1.8k
197 lines (178 loc) · 6.53 KB
/
docker-crawlab.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: "Docker Image CI: crawlab"
on:
push:
branches: [ develop, main ]
#pull_request:
# branches: [ main ]
release:
types: [ published ]
workflow_dispatch:
repository_dispatch:
types: [ docker-crawlab ]
env:
IMAGE_PATH_CRAWLAB_BACKEND: backend
IMAGE_PATH_CRAWLAB_FRONTEND: frontend
IMAGE_NAME_CRAWLAB: crawlabteam/crawlab
IMAGE_NAME_CRAWLAB_BACKEND: crawlabteam/crawlab-backend
IMAGE_NAME_CRAWLAB_FRONTEND: crawlabteam/crawlab-frontend
jobs:
setup:
runs-on: ubuntu-latest
outputs:
is_matched_backend: ${{ steps.check_changed_files.outputs.is_matched_backend }}
is_matched_frontend: ${{ steps.check_changed_files.outputs.is_matched_frontend }}
is_matched_dockerfile: ${{ steps.check_changed_files.outputs.is_matched_dockerfile }}
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v2
- name: Get changed files
id: changed_files
uses: tj-actions/[email protected]
- id: check_changed_files
name: Check changed files
run: |
# check changed files
is_matched_backend=0
is_matched_frontend=0
is_matched_dockerfile=0
for file in ${{ steps.changed_files.outputs.all_changed_files }}; do
if [[ $file =~ ^${IMAGE_PATH_CRAWLAB_BACKEND}/.* ]]; then
file_backend=$file
is_matched_backend=1
fi
if [[ $file =~ ^${IMAGE_PATH_CRAWLAB_FRONTEND}/.* ]]; then
file_frontend=$file
is_matched_frontend=1
fi
if [[ $file == Dockerfile ]]; then
file_dockerfile=$file
is_matched_dockerfile=1
fi
done
# set outputs
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
is_matched_backend=1
is_matched_frontend=1
is_matched_dockerfile=1
fi
echo "::set-output name=is_matched_backend::$is_matched_backend"
echo "::set-output name=is_matched_frontend::$is_matched_frontend"
echo "::set-output name=is_matched_dockerfile::$is_matched_dockerfile"
# echo outputs
echo "is_matched_backend=$is_matched_backend, file_backend=$file_backend"
echo "is_matched_frontend=$is_matched_frontend, file_frontend=$file_frontend"
echo "is_matched_dockerfile=$is_matched_dockerfile, file_dockerfile=$file_dockerfile"
- id: version
name: Get version
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo "::set-output name=version::$VERSION"
build-backend:
needs: [ setup ]
if: needs.setup.outputs.is_matched_backend == '1'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get changed files
id: changed-files
uses: tj-actions/[email protected]
- name: Build image
run: |
cd $IMAGE_PATH_CRAWLAB_BACKEND
docker build . --file Dockerfile --tag image
- name: Log into registry
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Push image
run: |
IMAGE_VERSION=${{needs.setup.outputs.version}}
IMAGE_NAME=$IMAGE_NAME_CRAWLAB_BACKEND
docker tag image $IMAGE_NAME:$IMAGE_VERSION
docker push $IMAGE_NAME:$IMAGE_VERSION
build-frontend:
needs: [ setup ]
if: needs.setup.outputs.is_matched_frontend == '1'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get changed files
id: changed-files
uses: tj-actions/[email protected]
- name: Build image
run: |
cd $IMAGE_PATH_CRAWLAB_FRONTEND
docker build . --file Dockerfile --tag image
- name: Log into registry
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Push image
run: |
IMAGE_VERSION=${{needs.setup.outputs.version}}
IMAGE_NAME=$IMAGE_NAME_CRAWLAB_FRONTEND
docker tag image $IMAGE_NAME:$IMAGE_VERSION
docker push $IMAGE_NAME:$IMAGE_VERSION
build-crawlab:
if: ${{ always() }}
needs: [ setup, build-backend, build-frontend ]
runs-on: ubuntu-latest
services:
mongo:
image: mongo:4.2
ports:
- 27017:27017
steps:
- uses: actions/checkout@v2
- name: Update Dockerfile
run: |
IMAGE_VERSION=${{needs.setup.outputs.version}}
if [[ $IMAGE_VERSION != "latest" ]]; then
for n in crawlab-backend crawlab-frontend; do
IMAGE_NAME=$n
sed -i "s/${IMAGE_NAME}:latest/${IMAGE_NAME}:${IMAGE_VERSION}/" Dockerfile
done
fi
- name: Build image
run: docker build . --file Dockerfile --tag image
- name: Test image
run: |
docker run --rm -d --name crawlab_master \
-e CRAWLAB_NODE_MASTER=true \
-e CRAWLAB_DEMO=true \
-e CRAWLAB_MONGO_HOST=localhost \
-e CRAWLAB_MONGO_PORT=27017 \
-p 8080:8080 \
--network host \
image
docker exec crawlab_master env
docker logs -f crawlab_master &
sleep 10
docker ps
cmd='curl http://localhost:8080/api/system-info -s'
echo "cmd: ${cmd}"
res=`${cmd}`
echo "res: ${res}"
if [[ $res =~ "success" ]]; then
:
else
exit 1
fi
docker stop crawlab_master
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.8'
- name: Test demo
run: |
pip install crawlab-demo
crawlab-demo validate
- name: Log into registry
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Push image
run: |
IMAGE_VERSION=${{needs.setup.outputs.version}}
IMAGE_ID=$IMAGE_NAME_CRAWLAB
docker tag image $IMAGE_ID:$IMAGE_VERSION
docker push $IMAGE_ID:$IMAGE_VERSION