Skip to content

Commit

Permalink
Merge pull request #5 from petzich/develop
Browse files Browse the repository at this point in the history
Switch main image to Alpine
  • Loading branch information
devste authored May 10, 2019
2 parents 3e66580 + e5580ad commit 4bf6755
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
1 change: 1 addition & 0 deletions Dockerfile.alpine
8 changes: 8 additions & 0 deletions Dockerfile.alpine.3.9
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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`
Expand Down

0 comments on commit 4bf6755

Please sign in to comment.