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..d7e0df8 --- /dev/null +++ b/Dockerfile.alpine.3.9 @@ -0,0 +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 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7e98985 --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ +# Makefile for petzi/docker-pre-commit +# 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 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 +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 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: 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) + $(DOCKER_RUN) $(DOCKER_TAG_ALPINE) + $(DOCKER_RUN) $(DOCKER_TAG_UBUNTU) 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`