Skip to content
This repository was archived by the owner on Dec 10, 2018. It is now read-only.

Commit a7f2bc2

Browse files
committed
Impl Docker image with tests
1 parent 2c0cccb commit a7f2bc2

File tree

9 files changed

+247
-0
lines changed

9 files changed

+247
-0
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*

.editorconfig

+16
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,19 @@ indent_style = space
1212
indent_size = 4
1313
trim_trailing_whitespace = false
1414
max_line_length = off
15+
16+
[Dockerfile]
17+
indent_style = space
18+
indent_size = 4
19+
20+
[Makefile]
21+
indent_style = tab
22+
indent_size = 4
23+
24+
[{*.bats,post_push,post_push.tmpl}]
25+
indent_style = space
26+
indent_size = 2
27+
28+
[*.{yml,yaml}]
29+
indent_style = space
30+
indent_size = 2

.travis.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: bash
2+
3+
sudo: false
4+
5+
services:
6+
- docker
7+
8+
before_script:
9+
- make image no-cache=yes VERSION=test
10+
- make deps.bats
11+
12+
script:
13+
- make test VERSION=test
14+
15+
notifications:
16+
email:
17+
on_success: never
18+
on_failure: always

Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# https://hub.docker.com/r/rustlang/rust
2+
FROM rustlang/rust:nightly-slim
3+
4+
MAINTAINER Instrumentisto Team <developer@instrumentisto.com>
5+
6+
7+
# Download and install clippy
8+
RUN cargo install clippy --version 0.0.207 \
9+
\
10+
# Cleanup unnecessary files
11+
&& rm -rf /usr/local/cargo/registry
12+
13+
14+
CMD ["cargo", "clippy"]

Makefile

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# This Makefile automates possible operations of this project.
2+
#
3+
# Images and description on Docker Hub will be automatically rebuilt on
4+
# pushes to `master` branch of this repo and on updates of parent image.
5+
#
6+
# Note! Docker Hub `post_push` hook must be always up-to-date with default
7+
# values of current Makefile. To update it just use:
8+
# make post-push-hook
9+
#
10+
# It's still possible to build, tag and push images manually. Just use:
11+
# make release
12+
13+
14+
IMAGE_NAME := instrumentisto/clippy
15+
VERSION ?= 0.0.207
16+
TAGS ?= 0.0.207,0.0,0,latest
17+
18+
19+
comma := ,
20+
eq = $(if $(or $(1),$(2)),$(and $(findstring $(1),$(2)),\
21+
$(findstring $(2),$(1))),1)
22+
23+
24+
25+
# Build Docker image.
26+
#
27+
# Usage:
28+
# make image [VERSION=<image-version>]
29+
# [no-cache=(no|yes)]
30+
31+
image:
32+
docker build --network=host --force-rm \
33+
$(if $(call eq,$(no-cache),yes),--no-cache --pull,) \
34+
-t $(IMAGE_NAME):$(VERSION) .
35+
36+
37+
38+
# Tag Docker image with given tags.
39+
#
40+
# Usage:
41+
# make tags [VERSION=<image-version>]
42+
# [TAGS=<docker-tag-1>[,<docker-tag-2>...]]
43+
44+
tags:
45+
$(foreach tag,$(subst $(comma), ,$(TAGS)),\
46+
$(call tags.do,$(VERSION),$(tag)))
47+
define tags.do
48+
$(eval from := $(strip $(1)))
49+
$(eval to := $(strip $(2)))
50+
docker tag $(IMAGE_NAME):$(from) $(IMAGE_NAME):$(to)
51+
endef
52+
53+
54+
55+
# Manually push Docker images to Docker Hub.
56+
#
57+
# Usage:
58+
# make push [TAGS=<docker-tag-1>[,<docker-tag-2>...]]
59+
60+
push:
61+
$(foreach tag,$(subst $(comma), ,$(TAGS)),\
62+
$(call push.do,$(tag)))
63+
define push.do
64+
$(eval tag := $(strip $(1)))
65+
docker push $(IMAGE_NAME):$(tag)
66+
endef
67+
68+
69+
70+
# Make manual release of Docker images to Docker Hub.
71+
#
72+
# Usage:
73+
# make release [VERSION=<image-version>] [no-cache=(no|yes)]
74+
# [TAGS=<docker-tag-1>[,<docker-tag-2>...]]
75+
76+
release: | image tags push
77+
78+
79+
80+
# Create `post_push` Docker Hub hook.
81+
#
82+
# When Docker Hub triggers automated build all the tags defined in `post_push`
83+
# hook will be assigned to built image. It allows to link the same image with
84+
# different tags, and not to build identical image for each tag separately.
85+
# See details:
86+
# http://windsock.io/automated-docker-image-builds-with-multiple-tags
87+
#
88+
# Usage:
89+
# make post-push-hook [TAGS=<docker-tag-1>[,<docker-tag-2>...]]
90+
91+
post-push-hook:
92+
@mkdir -p hooks/
93+
docker run --rm -v $(PWD)/post_push.tmpl:/post_push.tmpl:ro \
94+
-e TAGS='$(TAGS)' \
95+
hairyhenderson/gomplate:slim -f /post_push.tmpl \
96+
> hooks/post_push
97+
98+
99+
100+
# Run Bats tests for Docker image.
101+
#
102+
# Documentation of Bats:
103+
# https://github.com/sstephenson/bats
104+
#
105+
# Usage:
106+
# make test [VERSION=<image-version>]
107+
108+
test: deps.bats
109+
IMAGE=$(IMAGE_NAME):$(VERSION) test/bats/bats test/suite.bats
110+
111+
112+
113+
# Resolve project dependencies for running tests.
114+
#
115+
# Usage:
116+
# make deps.bats [BATS_VER=<bats-version>]
117+
118+
BATS_VER ?= 0.4.0
119+
120+
deps.bats:
121+
ifeq ($(wildcard test/bats),)
122+
@mkdir -p test/bats/vendor/
123+
curl -fL -o test/bats/vendor/bats.tar.gz \
124+
https://github.com/sstephenson/bats/archive/v$(BATS_VER).tar.gz
125+
tar -xzf test/bats/vendor/bats.tar.gz -C test/bats/vendor/
126+
@rm -f test/bats/vendor/bats.tar.gz
127+
ln -s $(PWD)/test/bats/vendor/bats-$(BATS_VER)/libexec/* test/bats/
128+
endif
129+
130+
131+
132+
.PHONY: image tags push release post-push-hook test deps.bats

hooks/post_push

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
# AUTOMATICALLY GENERATED
3+
# DO NOT EDIT THIS FILE DIRECTLY, USE /post_push.tmpl
4+
5+
set -e
6+
7+
# Parse image name for repo name
8+
tagStart=$(expr index "$IMAGE_NAME" :)
9+
repoName=${IMAGE_NAME:0:tagStart-1}
10+
11+
# Tag and push image for each additional tag
12+
for tag in {0.0.207,0.0,0,latest}; do
13+
docker tag $IMAGE_NAME ${repoName}:${tag}
14+
docker push ${repoName}:${tag}
15+
done

post_push.tmpl

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
# AUTOMATICALLY GENERATED
3+
# DO NOT EDIT THIS FILE DIRECTLY, USE /post_push.tmpl
4+
5+
set -e
6+
7+
# Parse image name for repo name
8+
tagStart=$(expr index "$IMAGE_NAME" :)
9+
repoName=${IMAGE_NAME:0:tagStart-1}
10+
11+
# Tag and push image for each additional tag
12+
for tag in { {{- .Env.TAGS -}} }; do
13+
docker tag $IMAGE_NAME ${repoName}:${tag}
14+
docker push ${repoName}:${tag}
15+
done

test/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bats/

test/suite.bats

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bats
2+
3+
4+
@test "post_push hook is up-to-date" {
5+
run sh -c "cat Makefile | grep 'TAGS ?= ' | cut -d ' ' -f 3"
6+
[ "$status" -eq 0 ]
7+
[ ! "$output" = '' ]
8+
expected="$output"
9+
10+
run sh -c "cat hooks/post_push | grep 'for tag in' \
11+
| cut -d '{' -f 2 \
12+
| cut -d '}' -f 1"
13+
[ "$status" -eq 0 ]
14+
[ ! "$output" = '' ]
15+
actual="$output"
16+
17+
[ "$actual" = "$expected" ]
18+
}
19+
20+
21+
@test "clippy runs ok" {
22+
run docker run --rm --entrypoint sh $IMAGE -c 'cargo clippy --help'
23+
[ "$status" -eq 0 ]
24+
}
25+
26+
@test "clippy has correct version" {
27+
run sh -c 'cat Makefile | grep "VERSION ?= " | cut -d " " -f 3 | tr -d "\n"'
28+
[ "$status" -eq 0 ]
29+
[ ! "$output" = '' ]
30+
expected="$output"
31+
32+
run docker run --rm --entrypoint sh $IMAGE -c \
33+
"cargo clippy --version | grep -Fx '$expected'"
34+
[ "$status" -eq 0 ]
35+
}

0 commit comments

Comments
 (0)