Skip to content

Commit f989d0f

Browse files
committed
👷 Improve Build caching
1 parent 15b3b0a commit f989d0f

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

.github/workflows/build-container.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,7 @@ jobs:
5555
platforms: linux/amd64,linux/arm64
5656
push: ${{ github.event_name != 'pull_request' }}
5757
tags: ${{ steps.image_tag_lower.outputs.IMAGE_TAG }}
58+
cache-from: type=gha
59+
cache-to: type=gha,mode=max
5860
build-args: |
5961
PYTHONVERSION=${{ matrix.python-version }}

Dockerfile

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ARG USERNAME=ContainerUser
44
ARG PYTHONVERSION=3.11
55

66
# ############################################################################################################
7-
FROM debian:bookworm AS python-base
7+
FROM debian:bookworm AS base
88

99
ENV PYTHONFAULTHANDLER=1 \
1010
PYTHONUNBUFFERED=1 \
@@ -19,21 +19,22 @@ RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloa
1919

2020
# Install Base Reqs
2121
COPY scripts/install_base_deps.sh /tmp/
22-
RUN /tmp/install_base_deps.sh
22+
RUN --mount=target=/var/cache/apt,type=cache,sharing=locked \
23+
--mount=target=/var/lib/apt/lists,type=cache,sharing=locked set -x; /tmp/install_base_deps.sh
2324

2425
# Create User and setup environment
2526
RUN useradd --shell /usr/bin/zsh --create-home ${USERNAME} -u 1000 \
2627
&& mkdir -pm 700 /root/.ssh \
2728
&& echo "alias vi=nvim" > /etc/profile.d/vim_nvim.sh \
2829
&& chown -R ${USERNAME}:${USERNAME} /home/${USERNAME} \
29-
&& echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
30+
&& echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers \
31+
&& chown ${USERNAME}:${USERNAME} /var/cache
3032
ENV EDITOR=nvim
3133

32-
33-
3434
# Fix Locale issues
35-
RUN set -x; \
36-
apt-get install locales -y --no-install-recommends \
35+
RUN --mount=target=/var/cache/apt,type=cache,sharing=locked \
36+
--mount=target=/var/lib/apt/lists,type=cache,sharing=locked set -x; \
37+
apt update && apt-get install locales -y --no-install-recommends \
3738
&& echo "LC_ALL=en_US.UTF-8" >> /etc/environment \
3839
&& echo "LANG=en_US.utf-8" >> /etc/environment \
3940
&& echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
@@ -44,23 +45,9 @@ RUN set -x; \
4445
COPY known_hosts /root/.ssh/known_hosts
4546
COPY --chown=${USERNAME}:${USERNAME} known_hosts /home/${USERNAME}/.ssh/known_hosts
4647

47-
# Install uv
48-
ARG PYTHONVERSION
49-
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
50-
ENV UV_CACHE_DIR=/var/cache/uv \
51-
UV_PYTHON_CACHE_DIR=/var/cache/uv/python \
52-
UV_LINK_MODE=copy
53-
RUN --mount=type=cache,target=/var/cache/uv set -x; \
54-
chown ${USERNAME}:${USERNAME} /var/cache && \
55-
mkdir -p $UV_CACHE_DIR && chown ${USERNAME}:${USERNAME} $UV_CACHE_DIR && \
56-
mkdir -p $UV_PYTHON_CACHE_DIR && chown ${USERNAME}:${USERNAME} $UV_PYTHON_CACHE_DIR
57-
58-
RUN apt autoremove --purge -y && apt clean -y
59-
6048
# Non Root User
6149
USER ${USERNAME}
6250
WORKDIR /home/${USERNAME}
63-
RUN --mount=type=cache,target=/var/cache/uv,sharing=locked set -x; uv python install ${PYTHONVERSION} --default && uv python pin --global ${PYTHONVERSION}
6451

6552
# Oh-My-Zsh user config
6653
RUN set -x ; \
@@ -69,3 +56,14 @@ RUN set -x ; \
6956
COPY --chown=${USERNAME}:${USERNAME} .zshrc .zshrc
7057

7158
ENTRYPOINT [ "/usr/bin/zsh" ]
59+
60+
FROM base AS python-devcontainer
61+
62+
# Install uv
63+
ARG PYTHONVERSION
64+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
65+
ENV UV_CACHE_DIR=/var/cache/uv \
66+
UV_PYTHON_CACHE_DIR=/var/cache/uv/python \
67+
UV_LINK_MODE=copy
68+
69+
RUN --mount=type=cache,target=/var/cache/uv,sharing=locked,uid=1000 set -x; uv python install ${PYTHONVERSION} --default && uv python pin --global ${PYTHONVERSION}

0 commit comments

Comments
 (0)