-
Notifications
You must be signed in to change notification settings - Fork 4
216 lines (183 loc) · 6.74 KB
/
ci.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
name: Run tests, publish docker image
on:
push:
paths-ignore:
- "swagger/**"
pull_request:
paths-ignore:
- "swagger/**"
env:
# TODO: Change variable to your image's name.
IMAGE_NAME: workbench-server
DOCKER_BUILDKIT: 1
jobs:
# blocked by https://github.com/docker/build-push-action/issues/493
# # Build the image and cache it for later use
# build:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v2
# with:
# lfs: true
# - name: Ensure buildkit is used
# uses: docker/setup-buildx-action@v1
# id: buildx
# with:
# install: true
# - name: Build and cache
# uses: docker/build-push-action@v2
# with:
# context: .
# push: false
# cache-from: type=gha
# cache-to: type=gha,mode=max
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
lfs: true
- uses: docker/setup-buildx-action@v1
id: buildx
with:
install: true
# by default the user on GH seems to have the UID 1001
# however our docker container expects a uid of 1000.
# This is not an issue in Docker since we chown files when they are added.
# However when docker compose bind mounts the volumes for development
# the permissions of the files reflect those that are on the host, in the
# GH action case uid 1001 and gid 116.
# The easiest way I can think of to get this working is to just set the
# uid to 1000.
# - name: Set permissions for checked out files
# run: sudo chown -R 1000 .
# there is a bug where docker build and docker compose don't produce the
# same results
# see https://github.com/docker/compose/issues/883
# So we use docker-compose build instead
- name: Build image
#run: docker build .
run: docker compose build
- name: Start docker compose
run: docker compose up --detach --wait --timeout 60
- name: Debugging
run: |
ls -la
docker compose ps
docker ps
if: ${{ always() }}
- name: prepare test database
run: docker compose run web echo 'database created'
env:
RAILS_ENV: test
- name: Run tests
run: docker compose run web rspec --format progress --format html --out rspec_results.html
env:
RAILS_ENV: test
- name: Upload test results
uses: actions/upload-artifact@v2
if: ${{ always() }}
with:
name: rspec test results
path: rspec_results.html
- name: Upload test logs
uses: actions/upload-artifact@v2
if: ${{ always() }}
with:
name: rspec test results
path: log/*test.log
# update api docs
- name: Generate API docs
run: docker compose run web generate_docs.sh
- name: Stop docker compose
if: ${{ always() }}
run: docker compose stop
# Undo permissions change
# - name: Undo Set permissions for checked out files
# run: sudo chown -R $(id -u) .
- name: Commit swagger doc changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: |
Update API docs
[skip_ci]
file_pattern: swagger/**
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || contains(github.ref, 'refs/tag'))
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 200
- name: Calculate git describe
id: tagger
shell: pwsh
# the `@()` forces array output (even for single line) and the `[-1]` selects the last line
run: |
$result = @( git fetch --prune && git describe 'HEAD~' )
$last_line = $result[-1]
if ([string]::IsNullOrWhiteSpace($last_line)) {
Write-Output "failed to get git describe, result was: $result"
exit 1
}
echo "::set-output name=tag::$last_line"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: atruskie
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
build-args: |
trimmed=true
version=${{steps.tagger.outputs.tag}}
context: .
push: true
tags: user/app:latest
labels: |
version:${{steps.tagger.outputs.tag}}
- name: Build and push Docker image
uses: docker/build-push-action@v1.1.0
with:
# Username used to log in to a Docker registry. If not set then no login will occur
username: atruskie
# Password or personal access token used to log in to a Docker registry. If not set then no login will occur
password: ${{ secrets.DOCKER_HUB_TOKEN }}
# Server address of Docker registry. If not set then will default to Docker Hub
#registry: # optional
# Docker repository to tag the image with
repository: qutecoacoustics/workbench-server
# Comma-delimited list of tags. These will be added to the registry/repository to form the image's tags
tags: "${{steps.tagger.outputs.tag}}"
# Automatically tags the built image with the git reference as per the readme
tag_with_ref: true
# Automatically tags the built image with the git short SHA as per the readme
#tag_with_sha: true
# Path to the build context
path: .
# Path to the Dockerfile (Default is '{path}/Dockerfile')
#dockerfile: # optional
# Sets the target stage to build
#target:
# Always attempt to pull a newer version of the image
always_pull: true
# Comma-delimited list of build-time variables
build_args: "version=${{steps.tagger.outputs.tag}},trimmed=true"
# Comma-delimited list of images to consider as cache sources
#cache_froms: # optional
# Comma-delimited list of labels to add to the built image
labels: "version=${{steps.tagger.outputs.tag}}"
# Adds labels with git repository information to the built image
add_git_labels: true
# Whether to push the image
push: true