1
- # Builds a development environment for gitpod by building numpy with
2
- # ccache enabled. When gitpod is prebuilding or starting up it clones
3
- # a branch into `/workspace/numpy`. The gitpod clone will build numpy
4
- # faster because it is using compliers with ccache enabled.
5
- FROM gitpod/workspace-base as clone
6
-
7
- COPY --chown=gitpod . /tmp/numpy_repo
8
-
9
- # We use a multistage build to create a shallow clone of the repo to avoid
10
- # having the complete git history in the build stage and reducing the image
11
- # size. During the build stage, the shallow clone is used to install the
12
- # dependencies and build numpy to populate the cache used by ccache. Building
13
- # numpy with setup.py uses versioneer.py which requires a git history.
14
- RUN git clone --depth 1 file:////tmp/numpy_repo /tmp/numpy
15
-
16
- FROM gitpod/workspace-base as build
17
-
18
- # gitpod/workspace-base needs at least one file here
19
- RUN touch /home/gitpod/.bashrc.d/empty
1
+ #
2
+ # Dockerfile for NumPy development
3
+ #
4
+ # Usage:
5
+ # -------
6
+ #
7
+ # To make a local build of the container, from the 'Docker-dev' directory:
8
+ # docker build --rm -f "Dockerfile" -t <build-tag> "."
9
+ #
10
+ # To use the container use the following command. It assumes that you are in
11
+ # the root folder of the NumPy git repository, making it available as
12
+ # /home/numpy in the container. Whatever changes you make to that directory
13
+ # are visible in the host and container.
14
+ # The docker image is retrieved from the NumPy dockerhub repository
15
+ #
16
+ # docker run --rm -it -v $(pwd):/home/numpy numpy/numpy-dev:<image-tag>
17
+ #
18
+ # By default the container will activate the conda environment numpy-dev
19
+ # which contains all the dependencies needed for NumPy development
20
+ #
21
+ # To build NumPy run: python setup.py build_ext --inplace
22
+ #
23
+ # To run the tests use: python runtests.py
24
+ #
25
+ # This image is based on: Ubuntu 20.04 (focal)
26
+ # https://hub.docker.com/_/ubuntu/?tab=tags&name=focal
27
+ # OS/ARCH: linux/amd64
28
+ FROM gitpod/workspace-base:latest
20
29
21
30
ARG MAMBAFORGE_VERSION="4.10.0-0"
22
31
ARG CONDA_ENV=numpy-dev
23
32
24
- ENV CONDA_DIR=/home/gitpod/mambaforge3
25
- ENV PATH=$CONDA_DIR/bin:$PATH
26
33
34
+ # ---- Configure environment ----
35
+ ENV CONDA_DIR=/home/gitpod/mambaforge3 \
36
+ SHELL=/bin/bash
37
+ ENV PATH=${CONDA_DIR}/bin:$PATH \
38
+ WORKSPACE=/workspace/numpy
39
+
40
+
41
+ # -----------------------------------------------------------------------------
42
+ # ---- Creating as root - note: make sure to change to gitpod in the end ----
27
43
USER root
28
- RUN install-packages texlive-latex-extra dvisvgm
29
- USER gitpod
44
+
45
+ # hadolint ignore=DL3008
46
+ RUN apt-get update && \
47
+ apt-get install -yq --no-install-recommends \
48
+ ca-certificates \
49
+ dirmngr \
50
+ dvisvgm \
51
+ gnupg \
52
+ gpg-agent \
53
+ texlive-latex-extra \
54
+ vim && \
55
+ # this needs to be done after installing dirmngr
56
+ apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0 && \
57
+ apt-add-repository https://cli.github.com/packages && \
58
+ apt-get install -yq --no-install-recommends \
59
+ gh && \
60
+ locale-gen en_US.UTF-8 && \
61
+ apt-get clean && \
62
+ rm -rf /var/cache/apt/* &&\
63
+ rm -rf /var/lib/apt/lists/* &&\
64
+ rm -rf /tmp/*
30
65
31
66
# Allows this Dockerfile to activate conda environments
32
67
SHELL ["/bin/bash" , "--login" , "-o" , "pipefail" , "-c" ]
33
68
34
- # Install mambaforge3
69
+ # -----------------------------------------------------------------------------
70
+ # ---- Installing mamba ----
35
71
RUN wget -q -O mambaforge3.sh \
36
- https://github.com/conda-forge/miniforge/releases/download/$MAMBAFORGE_VERSION/Mambaforge-$MAMBAFORGE_VERSION-Linux-x86_64.sh && \
37
- bash mambaforge3.sh -p $CONDA_DIR -b && \
72
+ " https://github.com/conda-forge/miniforge/releases/download/$MAMBAFORGE_VERSION/Mambaforge-$MAMBAFORGE_VERSION-Linux-x86_64.sh" && \
73
+ bash mambaforge3.sh -p ${ CONDA_DIR} -b && \
38
74
rm mambaforge3.sh
39
75
40
- # makes conda activate command for this Dockerfile
41
- RUN echo ". $CONDA_DIR/etc/profile.d/conda.sh" >> ~/.profile
42
- # enables conda for interactive sessions
43
- RUN conda init bash
76
+ # -----------------------------------------------------------------------------
77
+ # ---- Copy needed files ----
78
+ # basic workspace configurations
79
+ COPY ./tools/gitpod/workspace_config /usr/local/bin/workspace_config
44
80
45
- # Install numpy dev dependencies
46
- COPY --from=clone --chown=gitpod /tmp/numpy /workspace/numpy
47
- RUN mamba env create -f /workspace/numpy/environment.yml -n $CONDA_ENV && \
48
- conda activate $CONDA_ENV && \
49
- mamba install ccache -y && \
50
- conda clean --all -f -y
81
+ RUN chmod a+rx /usr/local/bin/workspace_config && \
82
+ workspace_config
51
83
52
- # Set up ccache for compilers for this Dockerfile and interactino sessions
53
- # Using `conda env config vars set` does not work with Docker
54
- # REF: https://github.com/conda-forge/compilers-feedstock/issues/31
55
- RUN echo "conda activate $CONDA_ENV" >> ~/.startuprc && \
56
- echo "export CC=\" ccache \$ CC\" " >> ~/.startuprc && \
57
- echo "export CXX=\" ccache \$ CXX\" " >> ~/.startuprc && \
58
- echo "export F77=\" ccache \$ F77\" " >> ~/.startuprc && \
59
- echo "export F90=\" ccache \$ F90\" " >> ~/.startuprc && \
60
- echo "export GFORTRAN=\" ccache \$ GFORTRAN\" " >> ~/.startuprc && \
61
- echo "export FC=\" ccache \$ FC\" " >> ~/.startuprc && \
62
- echo "source ~/.startuprc" >> ~/.profile && \
63
- echo "source ~/.startuprc" >> ~/.bashrc
84
+ # Copy conda environment file into the container - this needs to exists inside
85
+ # the container to create a conda environment from it
86
+ COPY environment.yml /tmp/environment.yml
64
87
65
- # Build numpy to populate the cache used by ccache
66
- RUN python /workspace/numpy/setup.py build_ext -i && \
67
- ccache -s
68
-
69
- # .gitpod.yml is configured to install numpy from /workspace/numpy
70
- RUN echo "export PYTHONPATH=/workspace/numpy" >> ~/.bashrc
88
+ # -----------------------------------------------------------------------------
89
+ # ---- Create conda environment ----
90
+ # Install NumPy dependencies
91
+ RUN mamba env create -f /tmp/environment.yml && \
92
+ conda activate ${CONDA_ENV} && \
93
+ mamba install ccache -y && \
94
+ # needed for docs rendering later on
95
+ python -m pip install --no-cache-dir sphinx-autobuild && \
96
+ conda clean --all -f -y && \
97
+ rm -rf /tmp/*
71
98
72
- # gitpod will load the repository into /workspace/numpy. We remove the
73
- # directoy from the image to prevent conflicts
74
- RUN sudo rm -rf /workspace/numpy
99
+ # -----------------------------------------------------------------------------
100
+ # Always make sure we are not root
101
+ USER gitpod
0 commit comments