I have restructured my Django project on GitHub. Before my Dockerfile worked like that:
# Base image
ARG arch=amd64
FROM --platform=linux/${arch} python:3
# Set work directory
WORKDIR /appname
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Install dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt
# Copy project
COPY . .
# Set default environment variables
ENV DJANGO_SETTINGS_MODULE=appname.settings
ENV DEBUG=False
# Copy entrypoint script
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Command to run on container start
ENTRYPOINT ["/entrypoint.sh"]
where "appname" was the main repository of my Django app where also the Dockerfile laid in. I've restructured the app to make it way cleaner. Now my project looks like this (from root directory/GitHub repo):
.git/
.github/
apps/
appname/
config/
templates/
.gitignore
manage.py
requirements.txt
README.md
The Dockerfile and entrypoint.sh are now in config/docker/..
So I've changed my Dockerfile:
# Base image
ARG arch=amd64
FROM --platform=linux/${arch} python:3
WORKDIR /config
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV DJANGO_SETTINGS_MODULE=appname.settings
ENV DEBUG=False
# Install dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt --no-cache-dir
# Copy things
COPY . .
# Entrypoint script
RUN chmod +x entrypoint.sh
# Command to run on container start
ENTRYPOINT ["entrypoint.sh"]
But I keep getting an error that the requirements.txt
is not found when GitHub Actions is trying to deploy, locally on my machine I can build the Docker image from that Dockerfile.
I've tried a lot of things already but nothing will work.
The error message from GitHub Actions is:
#7 [linux/amd64 2/5] COPY requirements.txt .
#7 ERROR: failed to calculate checksum of ref f0eg9y80n08nz8zngn17kwwx5::m58umy2tp7muiat6aia21a4pf: "/requirements.txt": not found
My deploy step for GitHub Actions that fails looks like this:
- name: Build docker image
uses: docker/build-push-action@v6
with:
no-cache: true
context: ..
file: ./config/docker/dockerfile
push: false
tags: ${{ secrets.DOCKERHUB_USERNAME }}/appname:latest
platforms: linux/amd64,linux/arm64
build-args: arch=amd64
I already tried any variation of paths in the Dockerfile, I already tried some different context options in the deploy.yml
and also tried moving the requirements.txt
into the same directory as the Dockerfile.
I would expect that GitHub Actions would install the requirements as Docker is doing it locally when trying to build the image.
Using the docker build
command in terminal helped me analyzing the problem.
I solved it by modifying my Dockerfile
like that:
# Base image
ARG arch=amd64
FROM --platform=linux/${arch} python:3
WORKDIR /app
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV DJANGO_SETTINGS_MODULE=appname.settings
ENV DEBUG=False
# Install dependencies
COPY ../requirements.txt .
RUN pip install -r requirements.txt --no-cache-dir
# Copy things
COPY .. .
# Entrypoint script
RUN chmod +x config/docker/entrypoint.sh
# Command to run on container start
ENTRYPOINT ["config/docker/entrypoint.sh"]
And changed the context in my deploy.yml
back to just .