Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
isms committed Aug 3, 2021
0 parents commit b45f430
Show file tree
Hide file tree
Showing 18 changed files with 883 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
ignore = E203, E501, W503
max-line-length = 99
47 changes: 47 additions & 0 deletions .github/workflows/build-containers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

name: Build and publish container

on:
push:
branches: [main]
paths: ['runtime/**', '.github/workflows/build-containers.yml']
pull_request:
paths: ['runtime/**', '.github/workflows/build-containers.yml']

jobs:
build:
name: Build, Test, Publish container
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-latest']
proc: ['cpu', 'gpu']
env:
CONTAINER: drivendata/floodwater-competition
SHA_TAG: ${{ matrix.proc }}-${{ github.sha }}
LATEST_TAG: ${{ matrix.proc }}-latest

steps:
- uses: actions/checkout@v2

- name: Build ${{ matrix.proc }} container
run: |
docker build runtime --build-arg CPU_OR_GPU=${{ matrix.proc }} --tag $CONTAINER:$SHA_TAG
docker build runtime --build-arg CPU_OR_GPU=${{ matrix.proc }} --tag $CONTAINER:$LATEST_TAG
- name: Tests container packages
run: |
docker run $CONTAINER:$SHA_TAG /bin/bash -c "conda run --no-capture-output -n condaenv pytest tests/test_packages.py"
- name: Login to DockerHub
if: github.ref == 'refs/heads/main'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Publish container if main branch
if: github.ref == 'refs/heads/main'
run: |
docker push $CONTAINER:$SHA_TAG
docker push $CONTAINER:$LATEST_TAG
33 changes: 33 additions & 0 deletions .github/workflows/test-makefile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

name: Test Makefile

on:
push:
branches: [main]
pull_request:

jobs:
build:
name: Pull images, pack benchmark, test-submission
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-latest']
proc: ['cpu']
env:
CONTAINER: drivendataorg/deid2-competition
SHA_TAG: ${{ matrix.proc }}-${{ github.sha }}
LATEST_TAG: ${{ matrix.proc }}-latest
GITHUB_ACTIONS_NO_TTY: true

steps:
- uses: actions/checkout@v2

- name: Test zipping benchmark
run: |
make pack-benchmark
- name: Pull latest image and run submission in container
run: |
make pull
make test-submission
67 changes: 67 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Basics
*.py[cod]
*.pyc
__pycache__

# OSX
.DS_Store
.AppleDouble
.LSOverride

# Logs
logs
*.log
pip-log.txt
npm-debug.log*

# Unit test / coverage reports
.coverage
.tox
nosetests.xml
htmlcov/
coverage.xml

# Vim
*~
*.swp
*.swo

# SublimeText
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

# workspace files are user-specific
*.sublime-workspace

# Docker
.cache/

# .docker folders
*.docker/

# Ignore notebook temp files
**/.ipynb_checkpoints/

# local env files
.env*
.env.local
.env.*.local

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw*

# package stuff
src.egg-info/
pip-wheel-metadata/
*.egg-info/

# Submissions
submission/
116 changes: 116 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
.PHONY: build debug-container export-requirements pack-benchmark pull resolve-requirements test-container test-submission unpin-requirements

# ================================================================================================
# Settings
# ================================================================================================

ifeq (, $(shell which nvidia-smi))
CPU_OR_GPU ?= cpu
else
CPU_OR_GPU ?= gpu
endif

ifeq (${CPU_OR_GPU}, gpu)
GPU_ARGS = --gpus all
endif

SKIP_GPU ?= false
ifeq (${SKIP_GPU}, true)
GPU_ARGS =
endif

REPO = drivendata/floodwater-competition

TAG = ${CPU_OR_GPU}-latest
LOCAL_TAG = ${CPU_OR_GPU}-local

IMAGE = ${REPO}:${TAG}
LOCAL_IMAGE = ${REPO}:${LOCAL_TAG}

# if not TTY (for example GithubActions CI) no interactive tty commands for docker
ifneq (true, ${GITHUB_ACTIONS_NO_TTY})
TTY_ARGS = -it
endif

# To run a submission, use local version if that exists; otherwise, use official version
# setting SUBMISSION_IMAGE as an environment variable will override the image
SUBMISSION_IMAGE ?= $(shell docker images -q ${LOCAL_IMAGE})
ifeq (,${SUBMISSION_IMAGE})
SUBMISSION_IMAGE := $(shell docker images -q ${IMAGE})
endif

# Give write access to the submission folder to everyone so Docker user can write when mounted
_submission_write_perms:
chmod -R 0777 submission/

# ================================================================================================
# Commands for building the container if you are changing the requirements
# ================================================================================================

## Builds the container locally, tagging it with cpu-local or gpu-local
build:
docker build --build-arg CPU_OR_GPU=${CPU_OR_GPU} -t ${LOCAL_IMAGE} runtime

# ================================================================================================
# Commands for testing that your submission.zip will execute
# ================================================================================================

## Pulls the official container tagged cpu-latest or gpu-latest from Docker hub
pull:
docker pull ${IMAGE}

## Creates a submission/submission.zip file from whatever is in the "benchmark" folder
pack-benchmark:
# Don't overwrite so no work is lost accidentally
ifneq (,$(wildcard ./submission/submission.zip))
$(error You already have a submission/submission.zip file. Rename or remove that file (e.g., rm submission/submission.zip).)
endif
cd benchmark; zip -r ../submission/submission.zip ./*


## Runs container with submission/submission.zip as your submission and data as the data to work with
test-submission: _submission_write_perms

# if submission file does not exist
ifeq (,$(wildcard ./submission/submission.zip))
$(error To test your submission, you must first put a "submission.zip" file in the "submission" folder. \
If you want to use the benchmark, you can run `make pack-benchmark` first)
endif

# if container does not exists, error and tell user to pull or build
ifeq (${SUBMISSION_IMAGE},)
$(error To test your submission, you must first run `make pull` (to get official container) or `make build` \
(to build a local version if you have changes).)
endif
docker run \
${TTY_ARGS} \
${GPU_ARGS} \
--network none \
--mount type=bind,source="$(shell pwd)"/runtime/data,target=/codeexecution/data,readonly \
--mount type=bind,source="$(shell pwd)"/runtime/tests,target=/codeexecution/tests,readonly \
--mount type=bind,source="$(shell pwd)"/runtime/entrypoint.sh,target=/codeexecution/entrypoint.sh \
--mount type=bind,source="$(shell pwd)"/submission,target=/codeexecution/submission \
--shm-size 8g \
${SUBMISSION_IMAGE}


#################################################################################
# Self Documenting Commands #
#################################################################################

.DEFAULT_GOAL := help
.PHONY: help

define PRINT_HELP_PYSCRIPT
import re, sys

pattern = re.compile(r'^## (.*)\n(.+):', re.MULTILINE)
text = "".join(line for line in sys.stdin)
for match in pattern.finditer(text):
help, target = match.groups()
print("%-20s %s" % (target, help))
endef
export PRINT_HELP_PYSCRIPT

help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
Loading

0 comments on commit b45f430

Please sign in to comment.