-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
executable file
·132 lines (98 loc) · 4.01 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/make -f
# vim: noexpandtab ts=4
BUILD = build
CACHE = .cache
SRC = src
DOCKER = docker
TESTS = tests
TEST_ONLY =
ROOT = $(BUILD)/$(ARCH)
ARCH ?= amd64
TAG ?= master
REPO_OWNER ?= Adirelle
REPO_SLUG ?= Adirelle/s6rc-overlay
DISTRIBS ?= $(patsubst $(DOCKER)/Dockerfile.%,%,$(wildcard $(DOCKER)/Dockerfile.*))
SKAWARE_VERSION = 1.19.1
SKAWARE_SOURCE = https://github.com/just-containers/skaware/releases/download/v$(SKAWARE_VERSION)
SKAWARE_ARCHIVES = $(patsubst %,$(CACHE)/%-linux-$(ARCH)-bin.tar.gz,execline-$(execline) s6-$(s6) s6-portable-utils-$(s6-portable-utils) s6-rc-$(s6-rc))
SKAWARE_MANIFEST = $(CACHE)/manifest-portable.txt
-include $(SKAWARE_MANIFEST)
SUEXEC_VERSION = 0.0.2
SUEXEC_MANIFEST_SOURCE = https://github.com/Adirelle/su-exec-musl/releases/download/v$(SUEXEC_VERSION)/manifest.txt
SUEXEC_MANIFEST = $(CACHE)/manifest.txt
-include $(SUEXEC_MANIFEST)
SUEXEC_SOURCE = https://github.com/Adirelle/su-exec-musl/releases/download/v$(SUEXEC_VERSION)/su-exec-$(su-exec)-x86_64-linux
SUEXEC_BIN = $(CACHE)/su-exec-$(su-exec)-x86_64-linux
CURL = curl --silent --show-error --location --remote-time
ifdef $(GITHUB_OAUTH_TOKEN)
CURL += -u$(REPO_OWNER):$(GITHUB_OAUTH_TOKEN)
endif
SRC_FILES = $(shell find $(SRC) -type f -printf "%P\n")
ARCHIVE = $(BUILD)/s6rc-overlay-$(TAG)-$(ARCH).tar.bz2
CHECKSUM = $(ARCHIVE).sha512
MANIFEST = $(BUILD)/manifest.txt
ARTIFACTS = $(ARCHIVE) $(CHECKSUM) $(MANIFEST)
IMAGE_SLUG = $(shell echo $(REPO_SLUG) | tr '[:upper:]' '[:lower:]')
IMAGE_TAGS = $(DISTRIBS)
IMAGES = $(addprefix $(BUILD)/image-,$(IMAGE_TAGS))
TEST_LABEL = test_image_for=s6rc-overlay
TEST_RESULTS = $(addprefix $(BUILD)/test-result-,$(IMAGE_TAGS))
PUSHES = $(addprefix $(BUILD)/pushed-,$(IMAGE_TAGS))
.PHONY: all clean clean-root distclean images test push
all: artifacts
$(SKAWARE_MANIFEST): | $(CACHE)
$(CURL) -o $@ $(SKAWARE_SOURCE)/$(@F)
$(SUEXEC_MANIFEST): | $(CACHE)
$(CURL) -o $@ $(SUEXEC_MANIFEST_SOURCE)
distclean: clean
rm -rf $(CACHE)
-docker images -q "adirelle/s6rc-overlay:*" | xargs -r docker rmi -f
clean:
-chmod -R u+rwx $(ROOT)
rm -rf $(BUILD) $(TESTS)/archive.tar.bz2 $(addprefix $(TESTS)/Dockerfile.,$(IMAGE_TAGS))
-docker ps -q -f label=$(TEST_LABEL) | xargs -r docker rm -fv
-docker images -q -f label=$(TEST_LABEL) | xargs -r docker rmi -f
artifacts: $(ARTIFACTS)
$(ARCHIVE): $(SUEXEC_BIN) $(addprefix $(SRC)/,$(SRC_FILES)) $(SKAWARE_ARCHIVES) | $(BUILD)
@tools/printbanner "Building artifact $@"
tools/mkartifact $@ $(ROOT) $(SRC) $(SUEXEC_BIN) $(SKAWARE_ARCHIVES)
$(SUEXEC_BIN): | $(CACHE)
$(CURL) -o $@ $(SUEXEC_SOURCE)
$(CHECKSUM): $(ARCHIVE)
cd $(<D) && sha512sum $(<F) >$(@F)
$(MANIFEST): $(SKAWARE_MANIFEST) $(SUEXEC_MANIFEST) $(ARCHIVE) | $(BUILD)
echo s6rc-overlay=$(TAG) >$@
cat $(SKAWARE_MANIFEST) >>$@
cat $(SUEXEC_MANIFEST) >>$@
$(CACHE) $(BUILD):
mkdir -p $@
$(SKAWARE_ARCHIVES): $(CACHE)/%: | $(CACHE)
$(CURL) -o $@ $(SKAWARE_SOURCE)/$*
images: $(IMAGES)
$(IMAGES): $(BUILD)/image-%: $(DOCKER)/Dockerfile.% $(DOCKER)/archive.tar.bz2
@tools/printbanner "Building image based on $*"
docker build --pull -t $(IMAGE_SLUG):$* -f $< $(<D)
touch $@
$(DOCKER)/archive.tar.bz2: $(ARCHIVE)
cp -a $< $@
test: $(TEST_RESULTS)
$(TEST_RESULTS): $(BUILD)/test-result-%: $(BUILD)/image-% $(shell find $(TESTS) -type f)
@tools/printbanner "Running tests for $*"
tests/run-all $(IMAGE_SLUG):$* $(TEST_LABEL) $(TEST_ONLY)
touch $@
$(PUSHES): $(BUILD)/pushed-%: $(BUILD)/image-% | $(HOME)/.docker/config.json
@tools/printbanner "Pushing $* and $(TAG)-$*"
docker push $(IMAGE_SLUG):$*
docker tag $(IMAGE_SLUG):$* $(IMAGE_SLUG):$(TAG)-$*
docker push $(IMAGE_SLUG):$(TAG)-$*
ifneq (,$(findstring alpine,$(DISTRIBS)))
PUSHES += $(BUILD)/pushed-latest
$(BUILD)/pushed-latest: $(BUILD)/pushed-alpine | $(HOME)/.docker/config.json
@tools/printbanner "Pushing latest"
docker tag $(IMAGE_SLUG):alpine $(IMAGE_SLUG):latest
docker push $(IMAGE_SLUG):latest
endif
push: $(PUSHES)
$(HOME)/.docker/config.json:
mkdir -p $(@D)
@echo '{"auths":{"https://index.docker.io/v1/":{"auth":"'$(DOCKER_AUTH_TOKEN)'"}}}' >$@