Skip to content

Commit

Permalink
Added dockerfile template
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianWilhelm committed Nov 29, 2021
1 parent 517d648 commit 0623730
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/pyscaffoldext/dsproject/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def add_dsproject(struct: Structure, opts: ScaffoldOpts) -> ActionParams:
for folder in ("external", "interim", "preprocessed", "raw")
},
},
"Dockerfile": (template("Dockerfile"), NO_OVERWRITE),
"environment.yml": (template("environment_yml"), NO_OVERWRITE),
"models": {".gitignore": gitignore_all},
"notebooks": {"template.ipynb": (template("template_ipynb"), NO_OVERWRITE)},
Expand Down
44 changes: 44 additions & 0 deletions src/pyscaffoldext/dsproject/templates/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Dockerfile
# * builder steps:
# - create environment and build package
# - save environment for runner
# * runner steps:
# - recreate the same environment and install built package
# - optionally execute provided console_script in ENTRYPOINT
#
# Alternatively, remove builder steps, take `environment.lock.yml` from your repo
# and `pip install ${name}` using an artifact store. Faster and more robust.

FROM condaforge/miniforge3 AS builder
WORKDIR /tmp

COPY . /tmp
RUN conda env create -f environment.yml
# RUN pip install -e . # not needed since it's in environment.yml
SHELL ["conda", "run", "-n", "${name}", "/bin/bash", "-c"]

# build package
RUN tox -e build
RUN conda env export -n ${name} -f environment.lock.yml

FROM condaforge/miniforge3 AS runner
WORKDIR /app

COPY --from=builder /tmp/environment.lock.yml environment.yml
COPY --from=builder /tmp/dist/*.whl /tmp

RUN conda env create -f environment.yml

# Create default pip.conf.
# Replace value of `index-url` with your artifact store if needed.
RUN echo "[global]\n" \
"timeout = 60\n" \
"index-url = https://pypi.org/simple/\n" > /etc/pip.conf

# Make RUN commands use the conda environment
SHELL ["conda", "run", "-n", "${name}", "/bin/bash", "-c"]

RUN pip install /tmp/*.whl

# Code to run when container is started
# ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "${name}", "YOUR_CONSOLE_SCRIPT"]

0 comments on commit 0623730

Please sign in to comment.