Skip to content

Commit

Permalink
1956 - docker image building pipelines (Project-MONAI#1957)
Browse files Browse the repository at this point in the history
* refactor docker building

Signed-off-by: Wenqi Li <[email protected]>
  • Loading branch information
wyli authored Apr 7, 2021
1 parent 81cfbf0 commit 5c411d1
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 49 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ docs/
.coverage/
coverage.xml
.readthedocs.yml
*.md
*.toml

!README.md
Expand Down
112 changes: 112 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: docker
# versioning: compute a static version file
# local_docker: use the version file to build docker images
# docker_test_latest: test the latest internal docker image (has flake)
# docker_test_dockerhub: test the latest dockerhub release (no flake)
on:
# master only docker deployment and quick tests
push:
branches:
- master
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
versioning:
# compute versioning file from python setup.py
# upload as artifact
# (also used in release.yml)
if: github.repository == 'Project-MONAI/MONAI'
container:
image: localhost:5000/local_monai:latest
runs-on: [self-hosted, linux, x64, build_only]
steps:
- uses: actions/checkout@v2
# full history so that we can git describe
with:
ref: master
fetch-depth: 0
- shell: bash
run: |
git describe
python setup.py build
cat build/lib/monai/_version.py
- name: Upload version
uses: actions/upload-artifact@v2
with:
name: _version.py
path: build/lib/monai/_version.py
- name: Clean up directory
shell: bash
run: |
ls -al
rm -rf {*,.[^.]*}
local_docker:
# builds two versions: local_monai:latest and local_monai:dockerhub
# latest: used for local tests
# dockerhub: release, no flake package
if: github.repository == 'Project-MONAI/MONAI'
needs: versioning
runs-on: [self-hosted, linux, x64, build_only]
steps:
- uses: actions/checkout@v2
with:
ref: master
- name: Download version
uses: actions/download-artifact@v2
with:
name: _version.py
- name: docker_build
shell: bash
run: |
# get tag info for versioning
cat _version.py
mv _version.py monai/
# build and run original docker image for local registry
docker build -t localhost:5000/local_monai:latest -f Dockerfile .
docker push localhost:5000/local_monai:latest
# build once more w/ tag "latest": remove flake package as it is not needed on hub.docker.com
sed -i '/flake/d' requirements-dev.txt
docker build -t projectmonai/monai:latest -f Dockerfile .
# also push as tag "dockerhub" to local registry
docker image tag projectmonai/monai:latest localhost:5000/local_monai:dockerhub
docker push localhost:5000/local_monai:dockerhub
# distribute as always w/ tag "latest" to hub.docker.com
echo "${{ secrets.DOCKER_PW }}" | docker login -u projectmonai --password-stdin
docker push projectmonai/monai:latest
docker logout
docker_test_latest:
if: github.repository == 'Project-MONAI/MONAI'
needs: local_docker
container:
image: localhost:5000/local_monai:latest
runs-on: [self-hosted, linux, x64, common]
steps:
- name: Import
run: |
python -c 'import monai; monai.config.print_config()'
cd /opt/monai
ls -al
ngc --version
python -m tests.min_tests
env:
QUICKTEST: True

docker_test_dockerhub:
if: github.repository == 'Project-MONAI/MONAI'
needs: local_docker
container:
image: localhost:5000/local_monai:dockerhub
runs-on: [self-hosted, linux, x64, common]
steps:
- name: Import
run: |
python -c 'import monai; monai.config.print_config()'
cd /opt/monai
ls -al
ngc --version
python -m tests.min_tests
env:
QUICKTEST: True
44 changes: 41 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,49 @@ jobs:
password: ${{ secrets.TEST_PYPI }}
repository_url: https://test.pypi.org/legacy/

release_docker:
versioning:
# compute versioning file from python setup.py
# upload as artifact
# (also used in docker.yml)
if: github.repository == 'Project-MONAI/MONAI'
needs: packaging
runs-on: [ self-hosted, linux, x64, build_only ]
container:
image: localhost:5000/local_monai:latest
runs-on: [self-hosted, linux, x64, build_only]
steps:
- uses: actions/checkout@v2
# full history so that we can git describe
with:
ref: master
fetch-depth: 0
- shell: bash
run: |
git describe
python setup.py build
cat build/lib/monai/_version.py
- name: Upload version
uses: actions/upload-artifact@v2
with:
name: _version.py
path: build/lib/monai/_version.py
- name: Clean up directory
shell: bash
run: |
ls -al
rm -rf {*,.[^.]*}
release_tag_docker:
if: github.repository == 'Project-MONAI/MONAI'
needs: versioning
runs-on: [self-hosted, linux, x64, build_only]
steps:
- uses: actions/checkout@v2
with:
ref: master
- name: Download version
uses: actions/download-artifact@v2
with:
name: _version.py
- name: Set tag
id: versioning
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
Expand All @@ -99,12 +134,15 @@ jobs:
RELEASE_VERSION: ${{ steps.versioning.outputs.tag }}
run: |
echo "$RELEASE_VERSION"
cat _version.py
- if: startsWith(github.ref, 'refs/tags/')
name: build with the tag
env:
RELEASE_VERSION: ${{ steps.versioning.outputs.tag }}
shell: bash
run: |
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
# get tag info for versioning
mv _version.py monai/
# remove flake package as it is not needed on hub.docker.com
sed -i '/flake/d' requirements-dev.txt
docker build -t projectmonai/monai:"$RELEASE_VERSION" -f Dockerfile .
Expand Down
43 changes: 0 additions & 43 deletions .github/workflows/setupapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,46 +148,3 @@ jobs:
python -m tests.min_tests
env:
QUICKTEST: True

local_docker:
if: github.repository == 'Project-MONAI/MONAI'
runs-on: [self-hosted, linux, x64, build_only]
# we only push built container if it is built from master branch
steps:
- uses: actions/checkout@v2
with:
ref: master
- name: docker_build
run: |
# get tag info for versioning
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
# build and run original docker image for local registry
docker build -t localhost:5000/local_monai:latest -f Dockerfile .
docker push localhost:5000/local_monai:latest
# build once more w/ tag "latest": remove flake package as it is not needed on hub.docker.com
sed -i '/flake/d' requirements-dev.txt
docker build -t projectmonai/monai:latest -f Dockerfile .
# also push as tag "dockerhub" to local registry
docker image tag projectmonai/monai:latest localhost:5000/local_monai:dockerhub
docker push localhost:5000/local_monai:dockerhub
# distribute as always w/ tag "latest" to hub.docker.com
echo "${{ secrets.DOCKER_PW }}" | docker login -u projectmonai --password-stdin
docker push projectmonai/monai:latest
docker logout
docker:
if: github.repository == 'Project-MONAI/MONAI'
needs: local_docker
container:
image: localhost:5000/local_monai:latest
runs-on: [self-hosted, linux, x64, common]
steps:
- name: Import
run: |
python -c 'import monai; monai.config.print_config()'
cd /opt/monai
ls -al
ngc --version
python -m tests.min_tests
env:
QUICKTEST: True
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ RUN cp /tmp/requirements.txt /tmp/req.bak \
# please specify exact files and folders to be copied -- else, basically always, the Docker build process cannot cache
# this or anything below it and always will build from at most here; one file change leads to no caching from here on...

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

Expand Down

0 comments on commit 5c411d1

Please sign in to comment.