-
Notifications
You must be signed in to change notification settings - Fork 0
/
travis.Makefile
80 lines (63 loc) · 2.61 KB
/
travis.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
REGISTRY_REPO := groundworkdevelopment/$$(basename $$PWD)
DOCKER_REGISTRY := docker.io
COMMIT_HASH := $$(git log -1 --pretty=%h)
# Branch name will be in either TRAVIS_BRANCH or TRAVIS_PULL_REQUEST_BRANCH,
# depending on whether the build is a branch build or pull request build
BRANCH := ${TRAVIS_PULL_REQUEST_BRANCH}
ifeq ($(BRANCH),)
BRANCH := ${TRAVIS_BRANCH}
endif
ifeq ($(BRANCH),)
BRANCH := unknown
endif
# Replace / with - in branch name so it's a valid docker tag
ESCAPED_BRANCH := $(subst /,-,$(BRANCH))
IMG := ${REGISTRY_REPO}:${ESCAPED_BRANCH}
BUILD_ARGS := ${BUILD_ARGS} \
--build-arg COMMIT_HASH \
--build-arg BRANCH \
--build-arg TRAVIS_BUILD_ID \
--build-arg TRAVIS_COMMIT \
--build-arg TRAVIS_COMMIT_MESSAGE \
--build-arg TRAVIS_JOB_ID \
--build-arg TRAVIS_JOB_WEB_URL \
--build-arg TRAVIS_TAG
all: echo login build tag push
echo:
@echo =======================================
@echo REGISTRY_REPO: ${REGISTRY_REPO}
@echo COMMIT_HASH: ${COMMIT_HASH}
@echo IMG: ${IMG}
@echo TRAVIS_TAG: ${TRAVIS_TAG}
@echo BRANCH: ${BRANCH}
@echo ESCAPED_BRANCH: ${ESCAPED_BRANCH}
@echo DOCKER_REGISTRY: ${DOCKER_REGISTRY}
@echo DOCKER_HUB_USERNAME: ${DOCKER_HUB_USERNAME}
@echo BUILD_ARGS: ${BUILD_ARGS}
@echo =======================================
login:
echo "$${DOCKER_HUB_PASSWORD}" | docker login -u "$${DOCKER_HUB_USERNAME}" --password-stdin "$${DOCKER_REGISTRY}"
build:
docker build ${BUILD_ARGS} -t ${IMG} .
tag:
# If the current build is for a git tag, TRAVIS_TAG will be set to the tag's name.
ifeq ($(TRAVIS_TAG),)
@echo "Current build does not correspond to a git tag (TRAVIS_TAG is empty); skipping"
else
@echo "Current build corresponds to git tag $(TRAVIS_TAG); tagging docker image..."
docker tag ${IMG} ${REGISTRY_REPO}:${TRAVIS_TAG}
endif
# If branch is master, tag latest
ifeq ($(BRANCH),master)
docker tag ${IMG} ${REGISTRY_REPO}:latest
endif
push:
./script/docker-push ${REGISTRY_REPO} ${DOCKER_REGISTRY}
trigger-docker-hub-build:
# trigger docker hub build
ifeq ($(DOCKER_HUB_TRIGGER_URL),)
@echo "DOCKER_HUB_TRIGGER_URL is empty; skipping"
else
@echo "DOCKER_HUB_TRIGGER_URL is set to $(DOCKER_HUB_TRIGGER_URL); triggering build..."
curl -i -H "Content-Type: application/json" --data "{"source_type": "Branch", "source_name": "${BRANCH}"}" -X POST "${DOCKER_HUB_TRIGGER_URL}"
endif