From 1b24767a26a25cd8f669d7b15bb1f1733bfa72fe Mon Sep 17 00:00:00 2001 From: Stephen Tallowitz Date: Sat, 4 May 2019 19:18:46 +0200 Subject: [PATCH 1/6] Add Makefile --- Makefile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..66bff23 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +# Makefile for petzi/docker-pre-commit +# Make targets to help in the development of this docker image + +.DEFAULT_GOAL := help +DOCKER=docker +DOCKER_TAG=petzi/pre-commit + +# The help command is inspired by this post: +# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html +.PHONY: help +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: build +build: ## Build the image on development + $(DOCKER) build -t $(DOCKER_TAG) . From fa042db51aceb23bc34abbeac110962abc9abd46 Mon Sep 17 00:00:00 2001 From: Stephen Tallowitz Date: Sat, 4 May 2019 19:31:12 +0200 Subject: [PATCH 2/6] Add alpine-based image --- Dockerfile.alpine | 1 + Dockerfile.alpine.3.9 | 8 ++++++++ Makefile | 6 +++++- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 120000 Dockerfile.alpine create mode 100644 Dockerfile.alpine.3.9 diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 120000 index 0000000..856402f --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1 @@ +Dockerfile.alpine.3.9 \ No newline at end of file diff --git a/Dockerfile.alpine.3.9 b/Dockerfile.alpine.3.9 new file mode 100644 index 0000000..8813429 --- /dev/null +++ b/Dockerfile.alpine.3.9 @@ -0,0 +1,8 @@ +FROM alpine:3.9 +RUN apk add --no-cache \ + git \ + python3 +COPY requirements.txt . +RUN pip3 install --no-cache-dir -r requirements.txt +RUN pre-commit sample-config > /.pre-commit-config.yaml +ENTRYPOINT ["pre-commit", "run", "--config", "/.pre-commit-config.yaml"] diff --git a/Makefile b/Makefile index 66bff23..23091c7 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,8 @@ .DEFAULT_GOAL := help DOCKER=docker DOCKER_TAG=petzi/pre-commit +DOCKER_TAG_ALPINE=$(DOCKER_TAG):alpine +DOCKER_TAG_UBUNTU=$(DOCKER_TAG):ubuntu # The help command is inspired by this post: # https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html @@ -12,5 +14,7 @@ help: @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' .PHONY: build -build: ## Build the image on development +build: ## Build the images on development $(DOCKER) build -t $(DOCKER_TAG) . + $(DOCKER) build -f Dockerfile.alpine -t $(DOCKER_TAG_ALPINE) . + $(DOCKER) build -f Dockerfile.ubuntu -t $(DOCKER_TAG_UBUNTU) . From 8574c255080388dabb020a3fe534e5dbe3edaac7 Mon Sep 17 00:00:00 2001 From: Stephen Tallowitz Date: Sat, 4 May 2019 19:33:56 +0200 Subject: [PATCH 3/6] Improve docker build caching --- Dockerfile.alpine.3.9 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.alpine.3.9 b/Dockerfile.alpine.3.9 index 8813429..d7e0df8 100644 --- a/Dockerfile.alpine.3.9 +++ b/Dockerfile.alpine.3.9 @@ -1,8 +1,8 @@ FROM alpine:3.9 +ENTRYPOINT ["pre-commit", "run", "--config", "/.pre-commit-config.yaml"] RUN apk add --no-cache \ git \ python3 COPY requirements.txt . RUN pip3 install --no-cache-dir -r requirements.txt RUN pre-commit sample-config > /.pre-commit-config.yaml -ENTRYPOINT ["pre-commit", "run", "--config", "/.pre-commit-config.yaml"] From 8bc89d6d47f289b5c700f5e646ed22b4de150da5 Mon Sep 17 00:00:00 2001 From: Stephen Tallowitz Date: Sat, 4 May 2019 19:46:49 +0200 Subject: [PATCH 4/6] Add test running --- Makefile | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Makefile b/Makefile index 23091c7..25aeb2b 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,17 @@ # Make targets to help in the development of this docker image .DEFAULT_GOAL := help + +# Docker configuration DOCKER=docker +# Docker build configuration DOCKER_TAG=petzi/pre-commit DOCKER_TAG_ALPINE=$(DOCKER_TAG):alpine DOCKER_TAG_UBUNTU=$(DOCKER_TAG):ubuntu +# Docker run configuration +DOCKER_VOL=-v "${PWD}:/src" +DOCKER_WD=-w "/src" +DOCKER_RUN=$(DOCKER) run --rm $(DOCKER_VOL) $(DOCKER_WD) # The help command is inspired by this post: # https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html @@ -18,3 +25,9 @@ build: ## Build the images on development $(DOCKER) build -t $(DOCKER_TAG) . $(DOCKER) build -f Dockerfile.alpine -t $(DOCKER_TAG_ALPINE) . $(DOCKER) build -f Dockerfile.ubuntu -t $(DOCKER_TAG_UBUNTU) . + +.PHONY: test-run +test-run: ## Run each image once to test the build result + $(DOCKER_RUN) $(DOCKER_TAG) + $(DOCKER_RUN) $(DOCKER_TAG_ALPINE) + $(DOCKER_RUN) $(DOCKER_TAG_UBUNTU) From 4f8e3e50dd3675e4073c14c90019c80101f401f3 Mon Sep 17 00:00:00 2001 From: Stephen Tallowitz Date: Sat, 4 May 2019 20:20:49 +0200 Subject: [PATCH 5/6] Add docker image size analysis --- Makefile | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 25aeb2b..7e98985 100644 --- a/Makefile +++ b/Makefile @@ -9,11 +9,20 @@ DOCKER=docker DOCKER_TAG=petzi/pre-commit DOCKER_TAG_ALPINE=$(DOCKER_TAG):alpine DOCKER_TAG_UBUNTU=$(DOCKER_TAG):ubuntu -# Docker run configuration + +# Docker run configuration for the main image DOCKER_VOL=-v "${PWD}:/src" DOCKER_WD=-w "/src" DOCKER_RUN=$(DOCKER) run --rm $(DOCKER_VOL) $(DOCKER_WD) +# Configuration for wagoodman/dive +DIVE_IMAGE=wagoodman/dive +DIVE_VERSION=v0.7.2 +DIVE=$(DIVE_IMAGE):$(DIVE_VERSION) +DIVE_VOL=-v "/var/run/docker.sock:/var/run/docker.sock" +DIVE_CI=-e CI=true +DIVE_RUN=$(DOCKER) run --rm $(DIVE_CI) $(DIVE_VOL) $(DIVE) + # The help command is inspired by this post: # https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html .PHONY: help @@ -26,6 +35,11 @@ build: ## Build the images on development $(DOCKER) build -f Dockerfile.alpine -t $(DOCKER_TAG_ALPINE) . $(DOCKER) build -f Dockerfile.ubuntu -t $(DOCKER_TAG_UBUNTU) . +.PHONY: ci-image-size +ci-image-size: ## Run docker image size analysis + $(DIVE_RUN) $(DOCKER_TAG_ALPINE) + $(DIVE_RUN) $(DOCKER_TAG_UBUNTU) + .PHONY: test-run test-run: ## Run each image once to test the build result $(DOCKER_RUN) $(DOCKER_TAG) From e5580ad54b1a62707b758e89ad1764dd575feaa0 Mon Sep 17 00:00:00 2001 From: Stephen Tallowitz Date: Fri, 10 May 2019 23:33:05 +0200 Subject: [PATCH 6/6] Update readme --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f9de64c..572b1ff 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,15 @@ This is a Docker image containing [pre-commit]. ## Goal -This image provides a base to create derived images containing specific pre-commit tools. Currently, it is based on Ubuntu. This should increase the chance that a derived image can simply use the package manager to install a required package. +This image provides a base to create derived images containing specific pre-commit tools. There is one image based on Ubuntu and one image based on Alpine. + +1. Use the `ubuntu` variant for a higher chance of installing software from the package repository of the operating system. +1. Use the `alpine` variant if you want a smaller docker image size. Example derived image Dockerfile: ``` -FROM petzi/pre-commit:1.15.2 +FROM petzi/pre-commit:1.15.2-ubuntu RUN apt-get install -y --no-install-recommends \ yamllint ``` @@ -31,10 +34,14 @@ A git tag will typically look like this. ### Docker image tag -This repository uses docker hub autobuild and derives many image tags from one build. A docker hub build from git tag `1.15.2-6` will thus create the following docker image tags: +This repository uses docker hub autobuild and creates many different docker image tags form the same git tag. A docker hub build from git tag `1.15.2-6` will thus create the following docker image tags: 1. `1.15.2` 1. `1.15.2-6` +1. `1.15.2-alpine` +1. `1.15.2-alpine-6` +1. `1.15.2-alpine.3.9` +1. `1.15.2-alpine.3.9-6` 1. `1.15.2-ubuntu` 1. `1.15.2-ubuntu-6` 1. `1.15.2-ubuntu.18.10`