Dockerfile
The Dockerfile defines the environment for the application. Below is a detailed explanation of the Dockerfile used for setting up the development environment.
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION=3.12
FROM python:${PYTHON_VERSION}
WORKDIR /src
COPY . .
ARG VERSION=0.0.0.dev0
RUN --mount=type=cache,target=/cache/pip \
PIP_CACHE_DIR=/cache/pip \
SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} \
pip install .[ssh]
Breakdown of the Dockerfile
ARG PYTHON_VERSION=3.12: Sets a build-time variable for the Python version, which can be overridden.
FROM python:${PYTHON_VERSION}: Specifies the base image using the provided Python version.
WORKDIR /src: Sets the working directory inside the container to
/src
.COPY . .: Copies the content of the current directory into the working directory of the container.
ARG VERSION=0.0.0.dev0: Also sets another build-time variable for the version of the application.
RUN –mount=type=cache,target=/cache/pip: Uses a cache mount for the pip cache directory, improving performance by reusing previously downloaded packages.
PIP_CACHE_DIR=/cache/pip: Sets an environment variable for pip to use the cached directory.
SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION}: Uses the provided version for setuptools, which helps in versioning during development.
pip install .[ssh]: Installs the application along with the SSH extra dependencies.
Makefile
The Makefile orchestrates various tasks in the development environment. Below is a detailed breakdown of its functions.
Available functions in Makefile: test, SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER ?= $(shell git describe --match '[0-9]*' --dirty='.m' --always --tags 2>/dev/null | sed -r 's/-([0-9]+)/.dev\1/' | sed 's/-/+/')
ifeq ($(SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER),)
SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER = "0.0.0.dev0"
endif
.PHONY: shell integration-dind-ssh setup-network ruff unit-test build-dind-ssh docs integration-test integration-dind-ssl build build-dind-certs integration-dind clean all build-docs
Breakdown of the Makefile
Available functions: Lists the functions that can be invoked through the Makefile, like
test
.SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER ?= …: This line determines the version of the application using
git describe
. If there is no version available, it defaults to0.0.0.dev0
.ifeq: Checks if the
SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER
is empty and assigns the default version if true..PHONY: Declares the listed targets as phony, ensuring that they will always run when invoked, regardless of whether a file with the same name exists.
Usage in Development
To utilize the Dockerfile and Makefile effectively in a development environment, follow these key steps:
Build the Docker Image
Trigger the Docker build with the command:
docker build -t your-image-name .
Run the Docker Container
Start a container based on the built image:
docker run -it --rm your-image-name
Test the Application
You can execute the various Makefile functions to manage your development tasks:
make test
Run Shell Access
If you need shell access inside the container, use:
make shell
Clean Up
To remove any unused images or containers, run the clean task:
make clean
This structured approach facilitates a smooth development workflow, leveraging the capabilities of Docker while streamlining the setup and execution processes.
The information provided here is based on the contents of the files “Dockerfile” and “Makefile”.