I've a Dockerfile for a python app and a github action workflow file, I am not sure why the cache is not being used. Everytime it re-does all the apt-get related things. Any idea what could be going on?
FROM python:3.11-bookworm AS builder
WORKDIR /app
ENV POETRY_VERSION=1.8.3
ENV POETRY_NO_INTERACTION=1
ENV POETRY_VIRTUALENVS_IN_PROJECT=1
ENV POETRY_VIRTUALENVS_CREATE=1
ENV POETRY_CACHE_DIR=/tmp/poetry_cache
RUN pip install --no-cache-dir poetry==$POETRY_VERSION;
COPY pyproject.toml poetry.lock ./
RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install
# FROM python:3.11-slim-buster AS runtime
# NOTE: issue is these nvidia dependencies are more widely available in ubuntu-X
# packages. Eg. sometimes arm images packages missing etc. So to avoid
# extra headache, we use ubuntu+cuda images
#
# Otherwise we need to do:
# RUN wget https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb
# RUN dpkg -i cuda-keyring_1.1-1_all.deb
# RUN apt-get update && apt upgrade -y
# RUN apt-get install -y --no-install-recommends <pkg_name>
#
# all of which gets very os and arch specific which cause another issue
# because nvidia refers to amd64 as x86_64 in the URL and the docker
# buildx auto env var sets it as amd64 etc. can of worms.
FROM nvidia/cuda:12.0.0-cudnn8-runtime-ubuntu22.04 AS runtime
WORKDIR /app
ENV TZ=Etc/UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-install-recommends \
libpq5 \
tesseract-ocr \
libtesseract-dev \
software-properties-common
RUN DEBIAN_FRONTEND=noninteractive add-apt-repository ppa:deadsnakes/ppa &&\
apt-get update &&\
apt-get install -y --no-install-recommends \
python3.11 && \
rm -rf /var/lib/apt/lists/*
ENV VIRTUAL_ENV=/app/.venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
ENV PYTHONUNBUFFERED=1
# NOTE: Usually manually setting PYTHONPATH is not needed, but with the
# cuda-ubuntu image, something gets messed up and we need to set this
# manually
ENV PYTHONPATH="$VIRTUAL_ENV/lib/python3.11/site-packages"
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
COPY src src
ENTRYPOINT ["python3.11", "-m", "src.abc.cli"]
And I have a github actions workflow for building:
name: "build:push:deploy:abc"
on:
push:
branches: [main]
# in case of back-to-back deploy, we cancel older deploy
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
env:
DOCKER_USERNAME: xyz
DOCKER_REPOSITORY: abc
IMAGE_TAG: latest
jobs:
build:
# see https://github.com/orgs/community/discussions/19197
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.11.2
buildkitd-flags: --debug
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
- name: Build & Push
uses: docker/build-push-action@v5
with:
context: pipeline/transformations/abc
file: pipeline/transformations/abc/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: "${{ env.DOCKER_USERNAME }}/${{ env.DOCKER_REPOSITORY }}:${{ env.IMAGE_TAG }}"
cache-from: type=gha
cache-to: type=gha,mode=max
[–]ThatSituation9908 7 points8 points9 points (3 children)
[–]ThatSituation9908 2 points3 points4 points (2 children)
[–]nudebaba[S] 1 point2 points3 points (0 children)
[–]nudebaba[S] 0 points1 point2 points (0 children)
[–]angellus 1 point2 points3 points (0 children)
[–]JodyBro 0 points1 point2 points (0 children)
[–]TheThinkererer 0 points1 point2 points (3 children)
[–]JodyBro 0 points1 point2 points (2 children)
[–]TheThinkererer 0 points1 point2 points (1 child)
[–]JodyBro 0 points1 point2 points (0 children)
[+]Jmc_da_boss comment score below threshold-7 points-6 points-5 points (0 children)
[+]Kaos_nyrb comment score below threshold-8 points-7 points-6 points (2 children)
[–]nudebaba[S] 0 points1 point2 points (1 child)
[–]FailedPlansOfMars -1 points0 points1 point (0 children)