forked from Islandora-Devops/isle-buildkit
-
Notifications
You must be signed in to change notification settings - Fork 3
263 lines (262 loc) · 12.1 KB
/
main.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
setup:
name: Set up
runs-on: ubuntu-latest
outputs:
image-tag: ${{ steps.image-tag.outputs.tag }}
build-date: ${{ steps.build-date.outputs.builddate }}
ci-url: ${{ steps.ci-url.outputs.ciurl }}
isledc-commit: ${{ steps.establish-isledc-head.outputs.isledc-commit }}
buildkit-commit: ${{ steps.establish-buildkit-head.outputs.buildkit-commit }}
steps:
- name: Checkout idc-isle-dc
uses: actions/checkout@v2
with:
repository: jhu-idc/idc-isle-dc
path: idc-isle-dc
- name: Establish idc-isle-dc HEAD ref
id: establish-isledc-head
working-directory: idc-isle-dc
run: echo "::set-output name=isledc-commit::$(git log -1 --format='%H')"
- run: echo "Using idc-isle-dc ref ${{ steps.establish-isledc-head.outputs.isledc-commit }} for tests"
- name: Checkout idc-isle-buildkit
uses: actions/checkout@v2
with:
# Required for generating the Docker image tag
fetch-depth: 0
path: buildkit
- name: Establish idc-buildkit HEAD ref
id: establish-buildkit-head
working-directory: buildkit
run: echo "::set-output name=buildkit-commit::$(git log -1 --format='%H')"
- run: echo "Using idc-buildkit ref ${{ steps.establish-buildkit-head.outputs.buildkit-commit }} for images"
- name: Generate Docker image tag
working-directory: buildkit
id: image-tag
run: echo "::set-output name=tag::$(git describe --tags --always --first-parent)"
- run: echo "Using buildkit image tag ${{ steps.image-tag.outputs.tag }}"
- name: Generate build datetime
id: build-date
run: echo "::set-output name=builddate::$(jq -rn 'now|todateiso8601')"
- name: Generate CI url
id: ci-url
run: echo "::set-output name=ciurl::$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
build:
name: Build and Push Docker Images
runs-on: ubuntu-latest
timeout-minutes: 120
needs: setup
strategy:
matrix:
image-name:
- activemq
- alpaca
- cantaloupe
- crayfish
- crayfits
- dlq
- drupal
- drupal-dev
- fits
- homarus
- houdini
- hypercube
- idp
- ldap
- mariadb
- solr
steps:
- name: Checkout idc-isle-buildkit
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ needs.setup.outputs.buildkit-commit }}
- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: 8
- name: Enable buildkit
shell: bash
run: |
echo '{"experimental": "enabled"}' > ~/.docker/config.json
- name: Build & Push Image
run: ./gradlew --console plain -PregistryUrl=${{ secrets.REGISTRY_URL }} -PregistryUsername=${{ secrets.REGISTRY_USER }} -PregistryPassword=${{ secrets.REGISTRY_PASS }} -Prepository=${{ secrets.REPOSITORY }} ${{ matrix.image-name }}:push
- name: Label Image
run: |
if [ "${{github.event_name}}" == "pull_request" ] ; then
export IMAGE_DESC="IDC ${{matrix.image-name}} image (via idc-isle-buildkit PR head ${{ github.event.pull_request.head.sha }}, base ${{ github.event.pull_request.base.sha }}, merge ${{ github.sha }})"
else
export IMAGE_DESC="IDC ${{matrix.image-name}} image (via idc-isle-buildkit commit ${{ github.sha }})"
fi
echo "FROM ${{ secrets.REPOSITORY }}/${{matrix.image-name}}:${{needs.setup.outputs.image-tag}}" | \
docker build -t ${{ secrets.REPOSITORY }}/${{matrix.image-name}}:${{needs.setup.outputs.image-tag}} \
--label org.opencontainers.image.title="idc-isle-buildkit ${{matrix.image-name}}"\
--label org.opencontainers.image.description="${IMAGE_DESC}" \
--label org.opencontainers.image.url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/tree/${{github.event.repository.default_branch}}/${{matrix.image-name}} \
--label org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY \
--label org.opencontainers.image.version=${{needs.setup.outputs.image-tag}} \
--label org.opencontainers.image.created=${{needs.setup.outputs.build-date}} \
--label org.opencontainers.image.revision=${{github.sha}} \
--label org.opencontainers.image.licenses=MIT \
--label org.opencontainers.image.ref.name=${{ secrets.REPOSITORY }}/${{matrix.image-name}}:${{needs.setup.outputs.image-tag}} \
--label ci.url=${{needs.setup.outputs.ci-url}} \
-
docker inspect -f "{{json .Config.Labels }}" ${{ secrets.REPOSITORY }}/${{matrix.image-name}}:${{needs.setup.outputs.image-tag}}
docker history ${{ secrets.REPOSITORY }}/${{matrix.image-name}}:${{needs.setup.outputs.image-tag}}
docker login -u '${{ secrets.REGISTRY_USER }}' -p '${{ secrets.REGISTRY_PASS }}' '${{ secrets.REGISTRY_URL }}'
docker push ${{ secrets.REPOSITORY }}/${{matrix.image-name}}:${{needs.setup.outputs.image-tag}}
static:
name: Create and Push Drupal Static Image
needs: [ setup, build ]
runs-on: ubuntu-latest
timeout-minutes: 120
defaults:
run:
working-directory: isle-dc
steps:
- name: Checkout idc-isle-dc
uses: actions/checkout@v2
with:
repository: jhu-idc/idc-isle-dc
ref: ${{ needs.setup.outputs.isledc-commit }}
path: isle-dc
- name: Set image tag
run: |
echo "Using image tag ${{needs.setup.outputs.image-tag}}"
sed -i.bak -e 's@^TAG.*$@TAG=${{needs.setup.outputs.image-tag}}@' .env
grep TAG .env
- name: Make static image
run: make static-docker-compose.yml up || { docker-compose logs drupal && exit 1; }
- name: Drush test
run: docker-compose exec -T drupal drush -d status
- name: Label static image
run: |
if [ "${{github.event_name}}" == "pull_request" ] ; then
export IMAGE_DESC="IDC drupal-static image (via idc-isle-buildkit PR head ${{ github.event.pull_request.head.sha }}, base ${{ github.event.pull_request.base.sha }}, merge ${{ github.sha }})"
else
export IMAGE_DESC="IDC drupal-static image (via idc-isle-buildkit commit ${{ github.sha }})"
fi
export STATIC_TAG=$(docker images | grep ${{ secrets.REPOSITORY }}/drupal-static | awk '{print $2}')
echo "FROM ${{ secrets.REPOSITORY }}/drupal-static:${STATIC_TAG}" | \
docker build -t ${{ secrets.REPOSITORY }}/drupal-static:${{needs.setup.outputs.image-tag}} \
--label org.opencontainers.image.title="idc-isle-buildkit drupal-static" \
--label org.opencontainers.image.description="${IMAGE_DESC}" \
--label org.opencontainers.image.url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/tree/${{github.event.repository.default_branch}}/drupal \
--label org.opencontainers.image.source="$(git remote get-url origin)" \
--label org.opencontainers.image.version=${{needs.setup.outputs.image-tag}} \
--label org.opencontainers.image.created="$(date)" \
--label org.opencontainers.image.revision="$(git log -1 --format='%h')" \
--label org.opencontainers.image.licenses=MIT \
--label org.opencontainers.image.ref.name=${{ secrets.REPOSITORY }}/drupal-static:${{needs.setup.outputs.image-tag}} \
--label ci.url="${{needs.setup.outputs.ci-url}}" \
-
- name: Push static image
run: |
docker login -u '${{ secrets.REGISTRY_USER }}' -p '${{ secrets.REGISTRY_PASS }}' '${{ secrets.REGISTRY_URL }}'
docker push ${{ secrets.REPOSITORY }}/drupal-static:${{needs.setup.outputs.image-tag}}
test-matrix:
name: Generate idc-isle-dc test matrix
needs: setup
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.excludes-matrix.outputs.matrix }}
steps:
- name: Checkout idc-isle-dc
uses: actions/checkout@v2
with:
repository: jhu-idc/idc-isle-dc
ref: ${{ needs.setup.outputs.isledc-commit }}
- name: Generate Test Matrix
id: test-matrix
uses: jhu-idc/[email protected]
- name: Exclude nightly jobs
id: excludes-matrix
uses: jhu-idc/[email protected]
with:
glob: '*nightly*.sh'
exclude: true
matrix: ${{ steps.test-matrix.outputs.matrix }}
- name: Dump Test Matrix
env:
MATRIX: ${{ steps.excludes-matrix.outputs.matrix }}
run: echo ${MATRIX}
test:
name: Run idc-isle-dc tests
runs-on: ubuntu-latest
needs: [ build, static, test-matrix, setup ]
strategy:
matrix: ${{ fromJSON(needs.test-matrix.outputs.matrix) }}
fail-fast: false
steps:
- name: Checkout idc-isle-dc
uses: actions/checkout@v2
with:
repository: jhu-idc/idc-isle-dc
ref: ${{ needs.setup.outputs.isle-dccommit }}
- name: Set image tag
run: |
echo "Using image tag ${{needs.setup.outputs.image-tag}}"
sed -i.bak -e 's@^TAG.*$@TAG=${{needs.setup.outputs.image-tag}}@' .env
grep TAG .env
- name: Use Static Drupal Image
run: |
echo "Pulling static image ${{ secrets.REPOSITORY }}/drupal-static:${{needs.setup.outputs.image-tag}}"
docker login -u '${{ secrets.REGISTRY_USER }}' -p '${{ secrets.REGISTRY_PASS }}' '${{ secrets.REGISTRY_URL }}' && \
docker pull ${{ secrets.REPOSITORY }}/drupal-static:${{needs.setup.outputs.image-tag}} && \
make static-docker-compose.yml
- name: Run ${{ matrix.test }}
run: make up test test=${{ matrix.test }}
- name: Capture Logs
if: failure()
run: |
mkdir -p end-to-end/reports/${{ matrix.test }}
docker-compose logs drupal 2>&1 | tee end-to-end/reports/${{ matrix.test }}/docker-drupal.log
docker-compose logs 2>&1 | tee end-to-end/reports/${{ matrix.test }}/docker-allcontainers.log
- name: Upload Logs
if: failure()
uses: actions/upload-artifact@v2
with:
name: reports-${{matrix.test}}
path: end-to-end/reports
image-locations:
name: Comment with image locations
if: ${{github.event_name == 'pull_request'}}
runs-on: ubuntu-latest
needs: [ build, static, test-matrix, setup, test ]
steps:
- name: Generate idc-isle-dc commit url
id: isledc-commit-url
run: echo "::set-output name=isledc-commit-url::$GITHUB_SERVER_URL/jhu-idc/idc-isle-dc/tree/${{needs.setup.outputs.isledc-commit}}"
- name: Create comment with image tags
run: |
cat << 'EOF' > image.md
#### Images for idc-isle-buildkit commit `${{github.event.pull_request.head.sha}}`
* Buildkit images were built from idc-isle-buildkit head `${{github.head_ref}}` (`${{github.event.pull_request.head.sha}}`)
* Base ref: `${{github.base_ref}}` (`${{github.event.pull_request.base.sha}}`)
* Merge ref: `${{github.sha}}`
* All images have been pushed to `${{ secrets.REPOSITORY }}` with tag `${{needs.setup.outputs.image-tag}}`
* `drupal-static` was built from [idc-isle-dc commit `${{needs.setup.outputs.isledc-commit}}`](${{steps.isledc-commit-url.outputs.isledc-commit-url}})
* Workflow logs for these images may be viewed [here](${{needs.setup.outputs.ci-url}})
Example docker pull command:
```
docker pull ${{ secrets.REPOSITORY }}/drupal-static:${{needs.setup.outputs.image-tag}}
```
EOF
- name: Add failure warning
if: failure()
run: |
echo -e "> **Warning**: idc-isle-dc [tests failed](${{needs.setup.outputs.ci-url}}), so the images may not be useful for testing.\n\n$(cat image.md)" > image.md
- name: Post comment
uses: machine-learning-apps/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
path: image.md