Skip to content

Commit

Permalink
update dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
dcmcand committed Oct 16, 2023
1 parent 28bd425 commit 36e0a3e
Showing 1 changed file with 42 additions and 26 deletions.
68 changes: 42 additions & 26 deletions conda-store-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
FROM --platform=linux/amd64 condaforge/mambaforge:23.3.1-1 as base
# Stage 1: Build the application
FROM --platform=linux/amd64 condaforge/mambaforge:23.3.1-1 as builder

LABEL org.opencontainers.image.authors="conda-store development team"

ENV PATH=/opt/conda/condabin:/opt/conda/envs/conda-store-server/bin:/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
ENV TZ=America/New_York

RUN --mount=type=cache,target=/var/lib/apt --mount=type=cache,target=/var/cache/apt apt-get update && \
# https://docs.anaconda.org/anaconda/install/linux/#installing-on-linux
apt-get install -yq --no-install-recommends \
# Update and install build dependencies
RUN --mount=type=cache,target=/var/lib/apt --mount=type=cache,target=/var/cache/apt apt update && \
apt install -y --no-install-recommends \
libgl1-mesa-glx \
libegl1-mesa \
libxrandr2 \
Expand All @@ -30,42 +26,62 @@ RUN printf 'channels: []\n' > /opt/conda/.condarc && \
mkdir /.cache && \
chown 1000:1000 /.cache

USER 1000:1000

# Copy environment.yaml and create a conda environment
COPY environment.yaml /opt/conda-store-server/environment.yaml
RUN mamba env create -f /opt/conda-store-server/environment.yaml && conda clean --force-pkgs-dirs

# Copy the application code
COPY ./ /opt/conda-store-server/

USER 0:0
RUN chown -R 1000:1000 /opt/conda-store-server/

FROM builder as dev-builder
# Install the application
RUN --mount=type=cache,target=/root/.cache/pip ls -la /opt/conda-store-server && \
cd /opt/conda-store-server && \
/opt/conda/envs/conda-store-server/bin/pip install -e .

FROM builder as prod-builder
ARG RELEASE_VERSION
# Install the application
RUN chown -R 1000:1000 /opt/conda-store-server/ && \
mkdir /opt/conda/pkgs && \
chown -R 1000:1000 /opt/conda/
RUN --mount=type=cache,target=/root/.cache/pip ls -la /opt/conda-store-server && \
cd /opt/conda-store-server && \
/opt/conda/envs/conda-store-server/bin/pip install conda-store-server==${RELEASE_VERSION}

# Prod Image
# Stage 2: Create the prod runtime image
FROM --platform=linux/amd64 condaforge/mambaforge:23.3.1-1 as prod
LABEL org.opencontainers.image.authors="conda-store development team"
ARG RELEASE_VERSION
# Set environment variables
ENV PATH=/opt/conda/condabin:/opt/conda/envs/conda-store-server/bin:/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
ENV TZ=America/New_York
ARG VERSION
# Copy the conda environment from the builder stage
COPY --from=base /opt/conda /opt/conda
RUN --mount=type=cache,target=/var/lib/apt --mount=type=cache,target=/var/cache/apt \
COPY --from=prod-builder /opt/conda /opt/conda

RUN --mount=type=cache,target=/var/lib/apt \
--mount=type=cache,target=/var/cache/apt \
apt install -y --no-install-recommends curl
RUN --mount=type=cache,target=/root/.cache/pip /opt/conda/envs/conda-store-server/bin/pip install conda-store-server==${RELEASE_VERSION} && \
chown -R 1000:1000 /opt/conda


USER 1000:1000
WORKDIR /var/lib/conda-store

# Dev Image
# Stage 3: Create the dev runtime image
FROM --platform=linux/amd64 condaforge/mambaforge:23.3.1-1 as dev
LABEL org.opencontainers.image.authors="conda-store development team"
ARG RELEASE_VERSION

# Set environment variables
ENV PATH=/opt/conda/condabin:/opt/conda/envs/conda-store-server/bin:/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
ENV TZ=America/New_York
# Copy the conda environment from the builder stage
COPY --from=base /opt/conda /opt/conda
RUN --mount=type=cache,target=/var/lib/apt --mount=type=cache,target=/var/cache/apt \
COPY --from=dev-builder /opt/conda /opt/conda

RUN --mount=type=cache,target=/var/lib/apt \
--mount=type=cache,target=/var/cache/apt \
apt install -y --no-install-recommends curl
COPY --from=base /opt/conda-store-server /opt/conda-store-server
RUN --mount=type=cache,target=/root/.cache/pip cd /opt/conda-store-server && \
/opt/conda/envs/conda-store-server/bin/pip install -e . && \
chown -R 1000:1000 /opt/conda

USER 1000:1000
WORKDIR /var/lib/conda-store

0 comments on commit 36e0a3e

Please sign in to comment.