generated from jupyter-naas/data-product-framework
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from jupyter-naas/package-abi-into-container
Package abi into container
- Loading branch information
Showing
4 changed files
with
93 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.abi-conda | ||
.logs | ||
Dockerfile* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Use the official Python 3.12 slim image based on Debian Bookworm as the base image | ||
FROM python:3.12-slim-bookworm | ||
|
||
# Set environment variables for build and target platforms | ||
ENV BUILDPLATFORM=Linux | ||
ENV TARGETPLATFORM=x86_64 | ||
|
||
# Update the package list, install wget and make, download and install Miniconda, and clean up | ||
RUN apt update \ | ||
&& apt install --yes wget make \ | ||
&& cd /tmp \ | ||
&& wget https://repo.anaconda.com/miniconda/Miniconda3-latest-$BUILDPLATFORM-$TARGETPLATFORM.sh \ | ||
&& bash Miniconda3-latest-$BUILDPLATFORM-$TARGETPLATFORM.sh -b -u -p /opt/conda \ | ||
&& /opt/conda/bin/conda init bash \ | ||
&& apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
||
# Update PATH to include Miniconda binaries | ||
ENV PATH="/opt/conda/bin:${PATH}" | ||
|
||
# Create a new user 'abi' with a home directory and bash shell | ||
RUN useradd -m abi -s /bin/bash \ | ||
&& mkdir /app && chown abi /app | ||
|
||
# Set the working directory to /app | ||
WORKDIR /app | ||
|
||
# Add conda.yml and Makefile to /app with ownership set to 'abi' | ||
ADD --chown=abi:abi conda.yml Makefile /app/ | ||
|
||
# Switch to user 'abi' | ||
USER abi | ||
|
||
# Initialize conda for bash shell | ||
RUN conda init bash | ||
|
||
# Add conda environment activation command to .bashrc for user 'abi' | ||
RUN echo "conda activate /app/.abi-conda" >> /home/abi/.bashrc | ||
|
||
# Switch back to root user | ||
USER root | ||
|
||
# Run a complex command to install conda packages and clean up to reduce image size | ||
RUN su - abi -c "export PATH=\"/opt/conda/bin:${PATH}\" && cd /app && make conda-install-kernel && conda clean --all -y" && \ | ||
conda clean --all -y && \ | ||
find /opt/conda/ -type f -name '*.a' -delete && \ | ||
find /opt/conda/ -type f -name '*.pyc' -delete && \ | ||
find /opt/conda/ -type f -name '*.pyo' -delete && \ | ||
find /opt/conda/ -type f -name '*.js.map' -delete && \ | ||
rm -rf /opt/conda/pkgs && \ | ||
rm -rf /opt/conda/conda-meta | ||
|
||
# Add conda environment activation command to .bashrc for root user | ||
RUN echo "conda activate /app/.abi-conda" >> /root/.bashrc | ||
|
||
# Add all remaining files to /app with ownership set to 'abi' | ||
ADD --chown=abi:abi . . | ||
|
||
# Switch back to user 'abi' | ||
USER abi | ||
|
||
# Set the entrypoint to the docker-entrypoint.sh script | ||
ENTRYPOINT ["/app/docker-entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Enable conda in this script. | ||
source /opt/conda/etc/profile.d/conda.sh | ||
|
||
# Activate the conda environment. | ||
conda activate /app/.abi-conda | ||
|
||
# Executing user command. | ||
exec "$@" |