-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMakefile.conf
66 lines (55 loc) · 1.96 KB
/
Makefile.conf
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
# The DockerHub repository name.
# This will also be used as the organisation tag in the image.
ORGANISATION=public.ecr.aws/unocha
# Miscellaneous utilities used by the build scripts.
AWK=/usr/bin/awk
DOCKER=docker
ECHO=echo
GREP=grep -E
MAKE=make
RM=rm
SED=sed
# Initialise empty variables.
UPSTREAM=
VERSION=
EXTRAVERSION=
EXTRAOPTIONS=
# BUILDKIT_COLORS="run=123,20,245:error=yellow:cancel=blue:warning=white"
BUILDKIT_PROGRESS=plain
# Common build targets.
build: clean template
$(DOCKER) build \
--no-cache \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg VCS_URL=`git config --get remote.origin.url | sed 's#[email protected]:#https://github.com/#'` \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VERSION=$(VERSION) \
--build-arg UPSTREAM=$(UPSTREAM) \
--tag $(ORGANISATION)/$(IMAGE):$(VERSION)$(EXTRAVERSION) \
$(EXTRAOPTIONS) \
. 2>&1 | tee buildlog.txt
# auth:
# @echo "Refreshing the AWS ECR authentication token."
# aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/unocha
# Create a Dockerfile from the template.
template:
@$(ECHO) "Generating a Dockerfile to build version $(VERSION)$(EXTRAVERSION) from $(UPSTREAM)"
@$(SED) "s/%%UPSTREAM%%/$(UPSTREAM)/" < Dockerfile.tmpl > Dockerfile
# Tag the image with our organisation, name and version.
tag:
@$(ECHO) "Tagging the built image."
$(eval IMAGE_HASH=$(shell grep -m 1 'writing image' buildlog.txt | $(AWK) '{print $$4}'))
$(DOCKER) tag $(IMAGE_HASH) $(ORGANISATION)/$(IMAGE):$(VERSION)$(EXTRAVERSION)
# Remove the buildlog.
clean:
$(RM) -f Dockerfile buildlog.txt
# Push the tagged image to DockerHub.
push:
$(DOCKER) push $(ORGANISATION)/$(IMAGE):$(VERSION)$(EXTRAVERSION)
# Remove intermediate images.
clean_images:
@echo Clean up intemediate images.
for i in `$(GREP) '^ ---> ([a-z0-9]){12}$$' buildlog.txt | $(AWK) '{print $$2}'`; do \
$(DOCKER) rmi -f $$i; \
done
.PHONY: build tag clean