Skip to content

Commit 5c411d1

Browse files
authored
1956 - docker image building pipelines (#1957)
* refactor docker building Signed-off-by: Wenqi Li <[email protected]>
1 parent 81cfbf0 commit 5c411d1

File tree

5 files changed

+154
-49
lines changed

5 files changed

+154
-49
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ docs/
88
.coverage/
99
coverage.xml
1010
.readthedocs.yml
11-
*.md
1211
*.toml
1312

1413
!README.md

.github/workflows/docker.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: docker
2+
# versioning: compute a static version file
3+
# local_docker: use the version file to build docker images
4+
# docker_test_latest: test the latest internal docker image (has flake)
5+
# docker_test_dockerhub: test the latest dockerhub release (no flake)
6+
on:
7+
# master only docker deployment and quick tests
8+
push:
9+
branches:
10+
- master
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
jobs:
15+
versioning:
16+
# compute versioning file from python setup.py
17+
# upload as artifact
18+
# (also used in release.yml)
19+
if: github.repository == 'Project-MONAI/MONAI'
20+
container:
21+
image: localhost:5000/local_monai:latest
22+
runs-on: [self-hosted, linux, x64, build_only]
23+
steps:
24+
- uses: actions/checkout@v2
25+
# full history so that we can git describe
26+
with:
27+
ref: master
28+
fetch-depth: 0
29+
- shell: bash
30+
run: |
31+
git describe
32+
python setup.py build
33+
cat build/lib/monai/_version.py
34+
- name: Upload version
35+
uses: actions/upload-artifact@v2
36+
with:
37+
name: _version.py
38+
path: build/lib/monai/_version.py
39+
- name: Clean up directory
40+
shell: bash
41+
run: |
42+
ls -al
43+
rm -rf {*,.[^.]*}
44+
45+
local_docker:
46+
# builds two versions: local_monai:latest and local_monai:dockerhub
47+
# latest: used for local tests
48+
# dockerhub: release, no flake package
49+
if: github.repository == 'Project-MONAI/MONAI'
50+
needs: versioning
51+
runs-on: [self-hosted, linux, x64, build_only]
52+
steps:
53+
- uses: actions/checkout@v2
54+
with:
55+
ref: master
56+
- name: Download version
57+
uses: actions/download-artifact@v2
58+
with:
59+
name: _version.py
60+
- name: docker_build
61+
shell: bash
62+
run: |
63+
# get tag info for versioning
64+
cat _version.py
65+
mv _version.py monai/
66+
# build and run original docker image for local registry
67+
docker build -t localhost:5000/local_monai:latest -f Dockerfile .
68+
docker push localhost:5000/local_monai:latest
69+
# build once more w/ tag "latest": remove flake package as it is not needed on hub.docker.com
70+
sed -i '/flake/d' requirements-dev.txt
71+
docker build -t projectmonai/monai:latest -f Dockerfile .
72+
# also push as tag "dockerhub" to local registry
73+
docker image tag projectmonai/monai:latest localhost:5000/local_monai:dockerhub
74+
docker push localhost:5000/local_monai:dockerhub
75+
# distribute as always w/ tag "latest" to hub.docker.com
76+
echo "${{ secrets.DOCKER_PW }}" | docker login -u projectmonai --password-stdin
77+
docker push projectmonai/monai:latest
78+
docker logout
79+
80+
docker_test_latest:
81+
if: github.repository == 'Project-MONAI/MONAI'
82+
needs: local_docker
83+
container:
84+
image: localhost:5000/local_monai:latest
85+
runs-on: [self-hosted, linux, x64, common]
86+
steps:
87+
- name: Import
88+
run: |
89+
python -c 'import monai; monai.config.print_config()'
90+
cd /opt/monai
91+
ls -al
92+
ngc --version
93+
python -m tests.min_tests
94+
env:
95+
QUICKTEST: True
96+
97+
docker_test_dockerhub:
98+
if: github.repository == 'Project-MONAI/MONAI'
99+
needs: local_docker
100+
container:
101+
image: localhost:5000/local_monai:dockerhub
102+
runs-on: [self-hosted, linux, x64, common]
103+
steps:
104+
- name: Import
105+
run: |
106+
python -c 'import monai; monai.config.print_config()'
107+
cd /opt/monai
108+
ls -al
109+
ngc --version
110+
python -m tests.min_tests
111+
env:
112+
QUICKTEST: True

.github/workflows/release.yml

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,49 @@ jobs:
8383
password: ${{ secrets.TEST_PYPI }}
8484
repository_url: https://test.pypi.org/legacy/
8585

86-
release_docker:
86+
versioning:
87+
# compute versioning file from python setup.py
88+
# upload as artifact
89+
# (also used in docker.yml)
8790
if: github.repository == 'Project-MONAI/MONAI'
8891
needs: packaging
89-
runs-on: [ self-hosted, linux, x64, build_only ]
92+
container:
93+
image: localhost:5000/local_monai:latest
94+
runs-on: [self-hosted, linux, x64, build_only]
9095
steps:
9196
- uses: actions/checkout@v2
97+
# full history so that we can git describe
9298
with:
9399
ref: master
100+
fetch-depth: 0
101+
- shell: bash
102+
run: |
103+
git describe
104+
python setup.py build
105+
cat build/lib/monai/_version.py
106+
- name: Upload version
107+
uses: actions/upload-artifact@v2
108+
with:
109+
name: _version.py
110+
path: build/lib/monai/_version.py
111+
- name: Clean up directory
112+
shell: bash
113+
run: |
114+
ls -al
115+
rm -rf {*,.[^.]*}
116+
117+
release_tag_docker:
118+
if: github.repository == 'Project-MONAI/MONAI'
119+
needs: versioning
120+
runs-on: [self-hosted, linux, x64, build_only]
121+
steps:
122+
- uses: actions/checkout@v2
123+
with:
124+
ref: master
125+
- name: Download version
126+
uses: actions/download-artifact@v2
127+
with:
128+
name: _version.py
94129
- name: Set tag
95130
id: versioning
96131
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
@@ -99,12 +134,15 @@ jobs:
99134
RELEASE_VERSION: ${{ steps.versioning.outputs.tag }}
100135
run: |
101136
echo "$RELEASE_VERSION"
137+
cat _version.py
102138
- if: startsWith(github.ref, 'refs/tags/')
103139
name: build with the tag
104140
env:
105141
RELEASE_VERSION: ${{ steps.versioning.outputs.tag }}
142+
shell: bash
106143
run: |
107-
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
144+
# get tag info for versioning
145+
mv _version.py monai/
108146
# remove flake package as it is not needed on hub.docker.com
109147
sed -i '/flake/d' requirements-dev.txt
110148
docker build -t projectmonai/monai:"$RELEASE_VERSION" -f Dockerfile .

.github/workflows/setupapp.yml

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -148,46 +148,3 @@ jobs:
148148
python -m tests.min_tests
149149
env:
150150
QUICKTEST: True
151-
152-
local_docker:
153-
if: github.repository == 'Project-MONAI/MONAI'
154-
runs-on: [self-hosted, linux, x64, build_only]
155-
# we only push built container if it is built from master branch
156-
steps:
157-
- uses: actions/checkout@v2
158-
with:
159-
ref: master
160-
- name: docker_build
161-
run: |
162-
# get tag info for versioning
163-
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
164-
# build and run original docker image for local registry
165-
docker build -t localhost:5000/local_monai:latest -f Dockerfile .
166-
docker push localhost:5000/local_monai:latest
167-
# build once more w/ tag "latest": remove flake package as it is not needed on hub.docker.com
168-
sed -i '/flake/d' requirements-dev.txt
169-
docker build -t projectmonai/monai:latest -f Dockerfile .
170-
# also push as tag "dockerhub" to local registry
171-
docker image tag projectmonai/monai:latest localhost:5000/local_monai:dockerhub
172-
docker push localhost:5000/local_monai:dockerhub
173-
# distribute as always w/ tag "latest" to hub.docker.com
174-
echo "${{ secrets.DOCKER_PW }}" | docker login -u projectmonai --password-stdin
175-
docker push projectmonai/monai:latest
176-
docker logout
177-
178-
docker:
179-
if: github.repository == 'Project-MONAI/MONAI'
180-
needs: local_docker
181-
container:
182-
image: localhost:5000/local_monai:latest
183-
runs-on: [self-hosted, linux, x64, common]
184-
steps:
185-
- name: Import
186-
run: |
187-
python -c 'import monai; monai.config.print_config()'
188-
cd /opt/monai
189-
ls -al
190-
ngc --version
191-
python -m tests.min_tests
192-
env:
193-
QUICKTEST: True

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ RUN cp /tmp/requirements.txt /tmp/req.bak \
3030
# please specify exact files and folders to be copied -- else, basically always, the Docker build process cannot cache
3131
# this or anything below it and always will build from at most here; one file change leads to no caching from here on...
3232

33-
COPY LICENSE setup.py setup.cfg versioneer.py runtests.sh .gitignore .gitattributes README.md MANIFEST.in ./
33+
COPY LICENSE CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md README.md versioneer.py setup.py setup.cfg runtests.sh MANIFEST.in ./
3434
COPY tests ./tests
3535
COPY monai ./monai
36-
COPY .git ./.git
3736
RUN BUILD_MONAI=1 FORCE_CUDA=1 python setup.py develop \
3837
&& rm -rf build __pycache__
3938

0 commit comments

Comments
 (0)