Skip to content

Instantly share code, notes, and snippets.

@timothymugayi
Last active March 7, 2020 07:31
Show Gist options
  • Select an option

  • Save timothymugayi/f65ff085dc32c30d89eab3a037000be3 to your computer and use it in GitHub Desktop.

Select an option

Save timothymugayi/f65ff085dc32c30d89eab3a037000be3 to your computer and use it in GitHub Desktop.
# download and use an existing image which already has Conda installed and set up
FROM continuumio/miniconda3:4.7.12
# Dumb init minimal init system intended to be used in Linux containers
RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64
RUN chmod +x /usr/local/bin/dumb-init
# Because miniconda3 image releases may sometimes be behind we need to play catchup manually
RUN conda update conda && conda install "conda=4.8.2"
ENV CONDA_ENV_NAME conda-env
LABEL maintainer="Timothy Mugayi <timothy.mugayi@gmail.com>"
# GAMS license Url
ARG LICENSE_URL
# Private Pypi artifactory Username
ARG ARTIFACTORY_USERNAME
# Private Pypi artifactory secret token
ARG ARTIFACTORY_SECRET_TOKEN
ENV GAMS_LICENSE_URL=$LICENSE_URL
# Configure private Pypi server if you you have additional append with white space after each url
RUN echo "[global]\nextra-index-url= https://$ARTIFACTORY_USERNAME:$ARTIFACTORY_SECRET_TOKEN@artifactory.com/api/pypi/simple" >> /etc/pip.conf
# Lets get the environment up to date
RUN apt-get update && apt-get install -y --no-install-recommends
WORKDIR /usr/src/app
COPY environment.yml .
# Now we want to activate a Conda environment which has the necessary Python version installed and has all the libraries installed required to run our app
RUN conda env create -n $CONDA_ENV_NAME -f environment.yml
RUN echo "source activate $CONDA_ENV_NAME" > /etc/bashrc
ENV PATH=/opt/conda/envs/$CONDA_ENV_NAME/bin:$PATH
# Make sure the environment is activated:
RUN echo "Make sure GAMS is installed:"
RUN python -c "import gams"
# Temporary measure add GAMS to LINUX PATH below, this will break if GAMS version is upgraded, this is an intrim solution
# To be removed once python package is updated with sed logic append new libs to bashrc file global path
ENV GAMS_DIRECTORY=/opt/GAMS/gams30.2_linux_x64_64_sfx
ENV PATH=$GAMS_DIRECTORY:$PATH
# Copy the hellworld file into the docker working directory define by WORKDIR
COPY helloworld.py .
# the -u argument tells python to dumped logs to the stream instead of being buffered which flushes out output this allows us to see the print command output in python code
ENTRYPOINT ["/usr/local/bin/dumb-init", "python3", "-u", "./helloworld.py"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment