Skip to content

Commit

Permalink
chore: add py312 docker
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-stoian-zama committed Oct 29, 2024
1 parent ca3d122 commit 3a75af8
Show file tree
Hide file tree
Showing 4 changed files with 712 additions and 505 deletions.
25 changes: 17 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
SHELL:=$(shell /usr/bin/env which bash)

DEV_DOCKER_PYTHON?=py38
$(warning now we reached ifeq DEV_DOCKER_PYTHON=$(DEV_DOCKER_PYTHON))
ifeq ($(DEV_DOCKER_PYTHON),py312)
UBUNTU_BASE=24.10
else
UBUNTU_BASE=20.04
endif

DEV_DOCKER_IMG:=concrete-ml-dev
DEV_DOCKERFILE:=docker/Dockerfile.dev
DEV_CONTAINER_VENV_VOLUME:=concrete-ml-venv
DEV_CONTAINER_CACHE_VOLUME:=concrete-ml-cache
DEV_CONTAINER_VENV_VOLUME:=concrete-ml-venv-$(DEV_DOCKER_PYTHON)
DEV_CONTAINER_CACHE_VOLUME:=concrete-ml-cache-$(DEV_DOCKER_PYTHON)
DOCKER_VENV_PATH:="$${HOME}"/dev_venv/
SRC_DIR:=src
TEST?=tests
Expand Down Expand Up @@ -342,12 +350,13 @@ mypy_ci:

.PHONY: docker_build # Build dev docker
docker_build:
BUILD_ARGS=; \
BUILD_ARGS="--build-arg UBUNTU_BASE=$(UBUNTU_BASE) ";\
BUILD_ARGS+="--build-arg OS_DEPS_ARG=linux-install-python "; \
if [[ $$(uname) == "Linux" ]]; then \
BUILD_ARGS="--build-arg BUILD_UID=$$(id -u) --build-arg BUILD_GID=$$(id -g)"; \
BUILD_ARGS+="--build-arg BUILD_UID=$$(id -u) --build-arg BUILD_GID=$$(id -g)"; \
fi; \
DOCKER_BUILDKIT=1 docker build $${BUILD_ARGS:+$$BUILD_ARGS} \
--pull -t $(DEV_DOCKER_IMG) -f $(DEV_DOCKERFILE) .
--pull -t $(DEV_DOCKER_IMG):$(DEV_DOCKER_PYTHON) -f $(DEV_DOCKERFILE) .

.PHONY: docker_rebuild # Rebuild docker
docker_rebuild: docker_clean_volumes
Expand All @@ -356,7 +365,7 @@ docker_rebuild: docker_clean_volumes
BUILD_ARGS="--build-arg BUILD_UID=$$(id -u) --build-arg BUILD_GID=$$(id -g)"; \
fi; \
DOCKER_BUILDKIT=1 docker build $${BUILD_ARGS:+$$BUILD_ARGS} \
--pull --no-cache -t $(DEV_DOCKER_IMG) -f $(DEV_DOCKERFILE) .
--pull --no-cache -t $(DEV_DOCKER_IMG):$(DEV_DOCKER_PYTHON) -f $(DEV_DOCKERFILE) .

.PHONY: docker_start # Launch docker
docker_start:
Expand All @@ -371,7 +380,7 @@ docker_start:
--volume /"$$(pwd)":/src \
--volume $(DEV_CONTAINER_VENV_VOLUME):/home/dev_user/dev_venv \
--volume $(DEV_CONTAINER_CACHE_VOLUME):/home/dev_user/.cache \
$(DEV_DOCKER_IMG) || rm -f "$${EV_FILE}"
$(DEV_DOCKER_IMG):$(DEV_DOCKER_PYTHON) || rm -f "$${EV_FILE}"

.PHONY: docker_build_and_start # Docker build and start
docker_build_and_start: docker_build docker_start
Expand Down Expand Up @@ -642,7 +651,7 @@ docker_publish_measurements: docker_rebuild
docker run --volume /"$$(pwd)":/src \
--volume $(DEV_CONTAINER_VENV_VOLUME):/home/dev_user/dev_venv \
--volume $(DEV_CONTAINER_CACHE_VOLUME):/home/dev_user/.cache \
$(DEV_DOCKER_IMG) \
$(DEV_DOCKER_IMG):$(DEV_DOCKER_PYTHON) \
/bin/bash ./script/progress_tracker_utils/benchmark_and_publish_findings_in_docker.sh \
"$${LAUNCH_COMMAND}"

Expand Down
17 changes: 15 additions & 2 deletions docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM ubuntu:20.04
ARG UBUNTU_BASE=20.04
FROM ubuntu:${UBUNTU_BASE}

ENV TZ=Europe/Paris
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
Expand All @@ -22,12 +23,17 @@ RUN apt-get update && \
apt-get install --no-install-recommends -y sudo vim && \
rm -rf /var/lib/apt/lists/*

# For ubuntu>23 the ubuntu user will exist and use uid/gid=1000
# we need to remove this user if it exists
RUN userdel -f -r ubuntu; exit 0

# From https://dev.to/emmanuelnk/using-sudo-without-password-prompt-as-non-root-docker-user-52bg
# Create dev_user and add it to relevant groups
# Create /src and make the dev user own it
# Ensure sudo group users are not asked for a password when using
# sudo command by ammending sudoers file
RUN groupadd -g "${BUILD_GID}" dev_user && \

RUN groupadd -f -g "${BUILD_GID}" dev_user && \
adduser --disabled-password \
--uid "${BUILD_UID}" --gid "${BUILD_GID}" --shell /bin/bash --gecos "" dev_user && \
usermod -aG sudo dev_user && \
Expand All @@ -38,6 +44,13 @@ RUN groupadd -g "${BUILD_GID}" dev_user && \
# Now switch to the newly created user
USER dev_user

RUN (pipx install poetry && pipx ensurepath) || \
(\
python3 -m pip install --no-cache-dir --upgrade pip && \
python3 -m pip install --no-cache-dir --ignore-installed poetry==1.7.1 && \
echo 'PATH=$PATH:/home/dev_user/.local/bin/' >> ~/.bashrc \
)

RUN echo "source ~/dev_venv/bin/activate" >> ~/.bashrc && \
echo "if [[ \"\$?\" != \"0\" ]]; then" >> ~/.bashrc && \
echo " python3 -m venv ~/dev_venv" >> ~/.bashrc && \
Expand Down
Loading

0 comments on commit 3a75af8

Please sign in to comment.