-
Notifications
You must be signed in to change notification settings - Fork 1
389 lines (339 loc) · 14.2 KB
/
docker_action.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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# docker_action.yml
name: Docker-ubuntu-build
on:
push:
branches:
- '*'
tags:
- '*'
pull_request:
branches:
- 'main'
- 'develop'
- 'releases/**'
- 'release/**'
- 'release'
# only allow one copy of this workflow to run at a time (the group specified by workflow name)
# cancel current workflows if they are running, so that we just run the latest queue'd.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }} # github.repository as <account>/<repo> "abcucberkeley/opticalaberrations"
DO_SIGNING: ${{ false }}
BRANCH: ${{ github.head_ref || github.ref_name }} # 'latest-tf' or 'develop'
PYTEST: python -m pytest --cache-clear -vvv --color=yes --disable-warnings
jobs:
cleanup-job:
runs-on: self-hosted
container:
image: ghcr.io/catthehacker/ubuntu:act-22.04
defaults:
run:
shell: bash
steps:
- name: 'Cleanup build folder'
run: |
ls -la ./
rm -rf ./* || true
rm -rf ./.??* || true
ls -la ./
build-docker:
needs: cleanup-job
if: always()
name: docker_image_build
runs-on: self-hosted
strategy:
matrix:
include:
- CUDA_VERSION: "Torch_CUDA_12_3"
- CUDA_VERSION: "TF_CUDA_12_3"
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Show default environment variables
run: |
echo "The job_id is: $GITHUB_JOB" # reference the default environment variables
echo "The id of this action is: $GITHUB_ACTION" # reference the default environment variables
echo "The run id is: $GITHUB_RUN_ID"
echo "The GitHub Actor's username is: $GITHUB_ACTOR"
echo "GitHub SHA: $GITHUB_SHA"
# The repo gets volume mapped into the container automatically in test-docker
- name: Checkout whole repo
uses: actions/checkout@v4
with:
lfs: 'true'
submodules: 'recursive'
- name: List files in the repository
run: |
ls -lhXR ${{ github.workspace }}
- name: Set file permissions in the repository
run: |
chmod -R 777 ${{ github.workspace }}
ls -lhXR ${{ github.workspace }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }} # aka ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}
labels: |
org.opencontainers.image.title=OpticalNet_ubuntu
org.opencontainers.image.description=Docker image for a transformer network to perform sensorless detection of aberrations in adaptive optics. https://github.com/abcucberkeley/opticalaberrations
org.opencontainers.image.vendor=Advanced Bioimaging Center at UC Berkeley and Janelia Research Campus
tags: |
type=schedule
type=ref,suffix=_${{ matrix.CUDA_VERSION }},event=branch
type=ref,suffix=_${{ matrix.CUDA_VERSION }},event=tag
type=ref,suffix=_${{ matrix.CUDA_VERSION }},event=pr
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BRANCH_NAME=${{ env.BRANCH }}
target: ${{ matrix.CUDA_VERSION }}
build-apptainer:
needs: build-docker
runs-on: self-hosted
strategy:
matrix:
include:
- CUDA_VERSION: "Torch_CUDA_12_3"
- CUDA_VERSION: "TF_CUDA_12_3"
steps:
- name: List files in the directory
run: |
ls -lhXR
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }} # aka ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull latest docker
run: |
docker pull ghcr.io/${{ github.repository }}:${{ github.head_ref || github.ref_name }}_${{ matrix.CUDA_VERSION }}
- name: Build Apptainer from local docker image we just pulled to a local .sif
run: |
apptainer build --nv --force ${{ github.workspace }}/${{ github.head_ref || github.ref_name }}_${{ matrix.CUDA_VERSION }}.sif docker-daemon:ghcr.io/${{ github.repository }}:${{ github.head_ref || github.ref_name }}_${{ matrix.CUDA_VERSION }}
- name: Login and Push Apptainer SIF to github
run: |
ls *.si*
apptainer remote login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io
apptainer push ${{ github.workspace }}/${{ github.head_ref || github.ref_name }}_${{ matrix.CUDA_VERSION }}.sif oras://ghcr.io/${{ github.repository }}:${{ github.head_ref || github.ref_name }}_${{ matrix.CUDA_VERSION }}_sif
# singularity push container.sif oras://ghcr.io/abcucberkeley/opticalaberrations:develop_sif
# singularity remote login -u ${{ secrets.GHCR_USERNAME }} --password-stdin oras://${{ env.REGISTRY }}
# apptainer pull --force --disable-cache develop.sif oras://ghcr.io/abcucberkeley/opticalaberrations:develop_sif
test-apptainer:
needs: build-apptainer
runs-on: self-hosted
strategy:
matrix:
include:
- CUDA_VERSION: "TF_CUDA_12_3"
test_framework: "tensorflow"
- CUDA_VERSION: "Torch_CUDA_12_3"
test_framework: "pytorch"
fail-fast: false # do the other tests in the matrix even if one of them fails
env:
APPTAINER_RUN: apptainer exec --nv ${{ github.workspace }}/${{ github.head_ref || github.ref_name }}_${{ matrix.CUDA_VERSION }}.sif
steps:
- name: investigate
run: |
pwd
id
id -u
ls -lhXR
- name: pip list
run: ${{ env.APPTAINER_RUN }} pip list
- name: Test NVIDIA-SMI
run: ${{ env.APPTAINER_RUN }} nvidia-smi
- name: Test ${{ matrix.test_framework }}
run: ${{ env.APPTAINER_RUN }} ${{ env.PYTEST }} ${{ github.workspace }}/tests/test_${{ matrix.test_framework }}.py
- name: Test Cupy
run: ${{ env.APPTAINER_RUN }} ${{ env.PYTEST }} ${{ github.workspace }}/tests/test_cupy.py
- name: Test IO
run: ${{ env.APPTAINER_RUN }} ${{ env.PYTEST }} ${{ github.workspace }}/tests/test_io.py
- name: Test preprocessing
run: ${{ env.APPTAINER_RUN }} ${{ env.PYTEST }} ${{ github.workspace }}/tests/test_preprocessing.py
- name: Test embeddings
run: ${{ env.APPTAINER_RUN }} ${{ env.PYTEST }} ${{ github.workspace }}/tests/test_embeddings.py
- name: Test synthetic datasets
run: ${{ env.APPTAINER_RUN }} ${{ env.PYTEST }} ${{ github.workspace }}/tests/test_datasets.py
- name: Test AO # requires test data generated by previous step: Test synthetic datasets. Seems to fail on aggregate_rois plotting. Try this in a separate call.
run: ${{ env.APPTAINER_RUN }} ${{ env.PYTEST }} --deselect=tests/test_ao.py::test_aggregate_rois ${{ github.workspace }}/tests/test_ao.py
- name: Test aggregate_rois
run: ${{ env.APPTAINER_RUN }} ${{ env.PYTEST }} ${{ github.workspace }}/tests/test_ao.py::test_aggregate_rois
test_train-apptainer:
strategy:
matrix:
include:
- CUDA_VERSION: "TF_CUDA_12_3"
- CUDA_VERSION: "Torch_CUDA_12_3"
needs: test-apptainer # need to wait for test-docker to finish otherwise GPU will be utilized.
runs-on: self-hosted
env:
APPTAINER_RUN: apptainer exec --nv ${{ github.workspace }}/${{ github.head_ref || github.ref_name }}_${{ matrix.CUDA_VERSION }}.sif
steps:
- name: Test training
run: ${{ env.APPTAINER_RUN }} ${{ env.PYTEST }} ${{ github.workspace }}/tests/test_train.py
# cleanup-job2:
# runs-on: self-hosted
# needs: test_train-apptainer # needs to run after apptainer because this is going to write root files.
# container:
# image: ghcr.io/catthehacker/ubuntu:act-22.04
# defaults:
# run:
# shell: bash
# steps:
# - name: 'Cleanup build folder'
# run: |
# ls -la ./
# rm -rf ./* || true
# rm -rf ./.??* || true
# ls -la ./
# setup-job2:
# needs: cleanup-job2
# runs-on: self-hosted
# steps:
# # The repo gets volume mapped into the container automatically in test-docker
# - name: Checkout whole repo
# uses: actions/checkout@v4
# with:
# lfs: 'true'
# submodules: 'recursive'
# - name: List files in the repository
# run: |
# ls -lhXR ${{ github.workspace }}
# - name: Set file permissions in the repository
# run: |
# chmod -R 777 ${{ github.workspace }}
# ls -lhXR ${{ github.workspace }}
# test-docker:
# needs: setup-job2 # needs to run after apptainer because this is going to write root files.
# runs-on: self-hosted
# strategy:
# matrix:
# include:
# - CUDA_VERSION: "TF_CUDA_12_3"
# container:
# image: ghcr.io/${{ github.repository }}:${{ github.head_ref || github.ref_name }}_${{ matrix.CUDA_VERSION }} # pull image 'latest-tf' or 'develop' that we just built
# credentials:
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# ports:
# - 80
# options: --gpus all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 # --user 1000 Needs to run as 'root' not 'vscode' for cupy cache to work.
# defaults:
# run:
# shell: bash
# steps:
# - name: investigate
# run: |
# pwd
# id
# id -u
# ls -lhXR
# - name: pip list
# run: pip list
# - name: Test NVIDIA-SMI
# run: nvidia-smi
# - name: Test TensorFlow
# run: ${{ env.PYTEST }} tests/test_tensorflow.py
# - name: Test Cupy
# run: ${{ env.PYTEST }} tests/test_cupy.py
# - name: Test IO
# run: ${{ env.PYTEST }} tests/test_io.py
# - name: Test preprocessing
# run: ${{ env.PYTEST }} tests/test_preprocessing.py
# - name: Test embeddings
# run: ${{ env.PYTEST }} tests/test_embeddings.py
# - name: Test synthetic datasets
# run: ${{ env.PYTEST }} tests/test_datasets.py
# - name: Test AO # requires test data generated by previous step: Test synthetic datasets
# run: ${{ env.PYTEST }} tests/test_ao.py
# test_train-docker:
# needs: test-docker
# runs-on: self-hosted
# strategy:
# matrix:
# include:
# - CUDA_VERSION: "TF_CUDA_12_3"
# container:
# image: ghcr.io/${{ github.repository }}:${{ github.head_ref || github.ref_name }}_${{ matrix.CUDA_VERSION }} # pull image 'latest-tf' or 'develop' that we just built
# credentials:
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# ports:
# - 80
# options: --gpus all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 # --user 1000 Needs to run as 'root' not 'vscode' for cupy cache to work.
# defaults:
# run:
# shell: bash
# steps:
# - name: Test training
# run: ${{ env.PYTEST }} tests/test_train.py
# build-native-apptainer:
# needs: build-docker
# if: always()
# runs-on: self-hosted
# strategy:
# matrix:
# include:
# - CUDA_VERSION: "TF_CUDA_12_3"
# steps:
# # Login against a Docker registry except on PR
# # https://github.com/docker/login-action
# - name: Log into registry ${{ env.REGISTRY }}
# if: github.event_name != 'pull_request'
# uses: docker/login-action@v3
# with:
# registry: ${{ env.REGISTRY }} # aka ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# - name: Build Apptainer from Recipe to a local .sif
# run: |
# apptainer build --nv --force --build-arg BRANCH_NAME=${{ env.BRANCH }} ${{ github.workspace }}/${{ github.head_ref || github.ref_name }}_${{ matrix.CUDA_VERSION }}_native.sif Apptainerfile_${{ matrix.CUDA_VERSION }}
# - name: Login and Push Apptainer SIF to github
# run: |
# ls *.si*
# apptainer remote login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io
# apptainer push ${{ github.workspace }}/${{ github.head_ref || github.ref_name }}_${{ matrix.CUDA_VERSION }}_native.sif oras://ghcr.io/${{ github.repository }}:${{ github.head_ref || github.ref_name }}_${{ matrix.CUDA_VERSION }}_native_sif