Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Uniformize Dockerfiles #4275

Merged
8 changes: 5 additions & 3 deletions packages/postgres-database/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1
FROM python:3.6-slim as base

LABEL maintainer=sanderegg
Expand All @@ -16,16 +17,17 @@ FROM base as build

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
git \
build-essential \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*


# NOTE: python virtualenv is used here such that installed packages may be moved to production image easily by copying the venv
RUN python -m venv "${VIRTUAL_ENV}"

RUN pip --no-cache-dir install --upgrade \
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install --upgrade \
pip~=23.1 \
wheel \
setuptools
Expand Down
3 changes: 2 additions & 1 deletion packages/postgres-database/docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ SIMCORE_NETWORK ?= $(SWARM_STACK_NAME)_default
.PHONY: build
build: ## build postgres migration image
# use GIT_REPOSITORY='$(GIT_REPOSITORY)' GIT_BRANCH='$(GIT_BRANCH)'
@docker build --file Dockerfile \
@docker buildx build --file Dockerfile \
--load \
--tag $(MIGRATER_TAG_NAME) \
--build-arg GIT_REPOSITORY=$(GIT_REPOSITORY) \
--build-arg GIT_BRANCH=$(GIT_BRANCH) \
Expand Down
7 changes: 5 additions & 2 deletions packages/postgres-database/scripts/erd/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION="3.10.10"
FROM python:${PYTHON_VERSION}-slim-buster as base

Expand All @@ -14,14 +15,16 @@ RUN apt-get update \
&& apt-get clean


RUN pip --no-cache-dir install --upgrade \
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install --upgrade \
pip~=23.1 \
wheel \
setuptools


# devenv
RUN pip install --no-cache-dir \
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install \
pyparsing \
pydot \
sqlalchemy_schemadisplay
3 changes: 2 additions & 1 deletion packages/postgres-database/scripts/erd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ IMAGE_NAME:=local/postgres-database-scripts-erd:${PYTHON_VERSION}
# SEE https://medium.com/faun/set-current-host-user-for-docker-container-4e521cef9ffc
.PHONY: build
build build-nc: ## builds tooling image ${IMAGE_NAME}
docker build $(if $(findstring -nc,$@),--no-cache,) \
docker buildx build $(if $(findstring -nc,$@),--no-cache,) \
--load \
--build-arg PYTHON_VERSION="${PYTHON_VERSION}" \
--tag ${IMAGE_NAME} .

Expand Down
13 changes: 8 additions & 5 deletions packages/service-integration/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION="3.10.10"
FROM python:${PYTHON_VERSION}-slim-buster as base

Expand Down Expand Up @@ -51,7 +52,8 @@ RUN apt-get update \
# packages may be moved to production image easily by copying the venv
RUN python -m venv "${VIRTUAL_ENV}"

RUN pip install --no-cache-dir --upgrade \
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install --upgrade \
pip~=23.1 \
wheel \
setuptools
Expand All @@ -63,10 +65,11 @@ COPY --chown=scu:scu packages/service-integration packages/service-integration


# WARNING: keep synced with `make install-prod` (did not use it directly because if would require copying scripts/common.Makefile and other parts of the repo)
RUN cd packages/service-integration \
&& pip install --no-cache-dir -r requirements/_base.txt \
&& pip install --no-cache-dir ../models-library/ \
&& pip install --no-cache-dir .
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
cd packages/service-integration \
&& pip install -r requirements/_base.txt \
&& pip install ../models-library/ \
&& pip install .


# -------------------------- Build stage -------------------
Expand Down
7 changes: 5 additions & 2 deletions requirements/tools/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1
# NOTE: This is a first step towards a devcontainer
# to perform operations like pip-compile or auto-formatting
# that preserves identical environment across developer machines
Expand All @@ -21,14 +22,16 @@ RUN apt-get update \


# SEE bug with pip==22.1 https://github.com/jazzband/pip-tools/issues/1617
RUN pip --no-cache-dir install --upgrade \
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install --upgrade \
pip~=23.1 \
wheel \
setuptools


# devenv
RUN pip install \
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install \
pip-tools \
pipreqs \
pipdeptree && \
Expand Down
3 changes: 2 additions & 1 deletion requirements/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ IMAGE_NAME:=local/python-devkit:${PYTHON_VERSION}
# SEE https://medium.com/faun/set-current-host-user-for-docker-container-4e521cef9ffc
.PHONY: build
build build-nc: ## builds tooling image ${IMAGE_NAME}
docker build $(if $(findstring -nc,$@),--no-cache,) \
docker buildx build $(if $(findstring -nc,$@),--no-cache,) \
--load \
--build-arg PYTHON_VERSION="${PYTHON_VERSION}" \
--tag ${IMAGE_NAME} .

Expand Down
2 changes: 1 addition & 1 deletion scripts/act.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ DOCKER_IMAGE_NAME=dind-act-runner
ACT_RUNNER=ubuntu-20.04=catthehacker/ubuntu:act-20.04
ACT_VERSION_TAG=v0.2.20 # from https://github.com/nektos/act/releases

docker build -t $DOCKER_IMAGE_NAME - <<EOF
docker buildx build --load -t $DOCKER_IMAGE_NAME - <<EOF
FROM docker:dind

RUN apk add curl bash
Expand Down
3 changes: 2 additions & 1 deletion scripts/erd.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ echo ${IMAGE_DIR}

build() {
echo Building image "${IMAGE_NAME}" at "${IMAGE_DIR}"
docker build \
docker buildx build \
--load \
--quiet \
--tag "$IMAGE_NAME" \
"$IMAGE_DIR"
Expand Down
7 changes: 5 additions & 2 deletions scripts/erd/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1
#
# ERD: Entity Relationship Diagrams
#
Expand All @@ -22,10 +23,12 @@ RUN apt-get update \
&& apt-get clean


RUN pip --no-cache-dir install --upgrade \
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install --upgrade \
pip~=23.1 \
wheel \
setuptools

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install -r requirements.txt
2 changes: 1 addition & 1 deletion scripts/json-schema-dereference.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ image_name="$(basename $0):latest"

# derefernce json-schemas for easy comparison
# SEE https://github.com/davidkelley/json-dereference-cli
docker build --tag "$image_name" - <<EOF
docker buildx build --load --tag "$image_name" - <<EOF
FROM node:12.18.2
RUN npm install -g [email protected]
ENTRYPOINT ["json-dereference"]
Expand Down
2 changes: 1 addition & 1 deletion scripts/json-schema-diff.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ IFS=$'\n\t'

image_name="$(basename $0):latest"

docker build --tag "$image_name" - <<EOF
docker buildx build --load --tag "$image_name" - <<EOF
FROM node:12.18.2
RUN npm install -g [email protected]
ENTRYPOINT ["json-schema-diff"]
Expand Down
2 changes: 1 addition & 1 deletion scripts/json-schema-faker.bash
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ RUN npm install \
ENTRYPOINT ["node", "/app/generate.js"]
EOF

docker build --tag "$image_name" $tmp_dir
docker buildx build --load --tag "$image_name" $tmp_dir

schema="$(basename $1)"
output="$(basename $2)"
Expand Down
2 changes: 1 addition & 1 deletion scripts/json-schema-to-openapi-schema/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ all: build

build:
# builds tool's image
@docker build --tag ${PROJECT_NAME} .
@docker buildx build --load --tag ${PROJECT_NAME} .

clean:
# remove created images
Expand Down
10 changes: 7 additions & 3 deletions scripts/maintenance/migrate_project/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1
FROM python:3.10.10-buster

RUN curl https://rclone.org/install.sh | bash && \
Expand All @@ -6,12 +7,15 @@ RUN curl https://rclone.org/install.sh | bash && \
WORKDIR /scripts

COPY packages/postgres-database postgres-database
RUN cd postgres-database && pip install .
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
cd postgres-database && pip install .

COPY packages/settings-library settings-library
RUN cd settings-library && pip install .
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
cd settings-library && pip install .

COPY scripts/maintenance/migrate_project/requirements.txt /scripts/requirements.txt
RUN pip install -r /scripts/requirements.txt
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install -r /scripts/requirements.txt

COPY scripts/maintenance/migrate_project/src/*.py /scripts/
2 changes: 1 addition & 1 deletion scripts/maintenance/migrate_project/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ endif

.PHONY: build
build: ## Builds docker container for the migration. Run this first.
docker build --tag ${IMAGE_NAME} --file $(PWD)/Dockerfile $(REPO_DIR)
docker buildx build --load --tag ${IMAGE_NAME} --file $(PWD)/Dockerfile $(REPO_DIR)

.PHONY: debug-shell
debug-shell: ## Runs a bash inside the container that performs the migrate. For manual interventions and debuging.
Expand Down
3 changes: 2 additions & 1 deletion scripts/mypy.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ MYPY_CONFIG=$(realpath "${2:-${DEFAULT_MYPY_CONFIG}}")
build() {
echo Building image "$IMAGE_NAME"
#
docker build \
docker buildx build \
--load \
--quiet \
--tag "$IMAGE_NAME" \
"$SCRIPT_DIR/mypy"
Expand Down
8 changes: 5 additions & 3 deletions scripts/mypy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION="3.10.10"
FROM python:${PYTHON_VERSION}-slim-buster as base


COPY requirements.txt /requirements.txt

RUN pip --no-cache-dir install --upgrade pip \
&& pip --no-cache-dir install -r requirements.txt \
&& pip --no-cache-dir freeze
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install --upgrade pip \
&& pip install -r requirements.txt \
&& pip freeze

ENTRYPOINT ["mypy", "--config-file", "/config/mypy.ini", "--warn-unused-configs"]
17 changes: 10 additions & 7 deletions scripts/openapi/oas_resolver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1
# Usage:
# docker build . -t oas_resolver
# docker run -v /path/to/api:/input -v /path/to/compiled/file:/output oas_resolver /input/path/to/openapi.yaml /output/output_file.yaml
Expand All @@ -11,13 +12,15 @@ VOLUME [ "/output" ]
WORKDIR /src

# update pip
RUN pip install --no-cache-dir --upgrade \
pip~=23.1 \
wheel \
setuptools
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install --upgrade \
pip~=23.1 \
wheel \
setuptools

RUN pip install prance && \
pip install click &&\
pip install openapi_spec_validator
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install prance && \
pip install click &&\
pip install openapi_spec_validator

ENTRYPOINT [ "prance", "compile" , "--backend=openapi-spec-validator"]
7 changes: 5 additions & 2 deletions scripts/pydeps-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1
# NOTE: This is a first step towards a devcontainer
# to perform operations like pip-compile or auto-formatting
# that preserves identical environment across developer machines
Expand Down Expand Up @@ -26,12 +27,14 @@ ARG HOME_DIR
RUN mkdir -p ${HOME_DIR}
COPY .pydeps ${HOME_DIR}/.pydeps

RUN pip --no-cache-dir install --upgrade \
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install --upgrade \
pip~=23.1 \
wheel \
setuptools


# devenv
RUN pip install \
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
pip install \
pydeps
3 changes: 2 additions & 1 deletion scripts/pydeps.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ WORKDIR="$(pwd)"

Build()
{
docker build \
docker buildx build \
--load \
--build-arg PYTHON_VERSION="${PYTHON_VERSION}" \
--build-arg HOME_DIR="/home/$USER" \
--tag "$IMAGE_NAME" \
Expand Down
1 change: 1 addition & 0 deletions scripts/pyupgrade.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ WORKDIR="$(pwd)"

Build() {
docker buildx build \
--load \
--build-arg HOME_DIR="/home/$USER" \
--tag "$IMAGE_NAME" \
- <<EOF
Expand Down
Loading