-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
132 lines (103 loc) · 4 KB
/
Makefile
File metadata and controls
132 lines (103 loc) · 4 KB
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
SHELL := /bin/bash
# Version of gcr.io/planet-4-151612/circleci-base to use
BASE_IMAGE_VERSION ?= latest
export BASE_IMAGE_VERSION
BUILD_NAMESPACE ?= gcr.io
GOOGLE_PROJECT_ID ?= cedar-hawk-222400
BUILD_IMAGE ?= deployer
MAINTAINER_NAME ?= Raymond Walker
MAINTAINER_EMAIL ?= hello@raywalker.it
# ============================================================================
SED_MATCH ?= [^a-zA-Z0-9._-]
ifeq ($(CIRCLECI),true)
# Configure build variables based on CircleCI environment vars
BUILD_NUM = $(CIRCLE_BUILD_NUM)
BRANCH_NAME ?= $(shell sed 's/$(SED_MATCH)/-/g' <<< "$(CIRCLE_BRANCH)")
BUILD_TAG ?= $(shell sed 's/$(SED_MATCH)/-/g' <<< "$(CIRCLE_TAG)")
else
# Not in CircleCI environment, try to set sane defaults
BUILD_NUM = local
BRANCH_NAME ?= $(shell git rev-parse --abbrev-ref HEAD | sed 's/$(SED_MATCH)/-/g')
BUILD_TAG ?= $(shell git tag -l --points-at HEAD | tail -n1 | sed 's/$(SED_MATCH)/-/g')
endif
# If BUILD_TAG is blank there's no tag on this commit
ifeq ($(strip $(BUILD_TAG)),)
# Default to branch name
BUILD_TAG := $(BRANCH_NAME)
else
# Consider this the new :latest image
# FIXME: implement build tests before tagging with :latest
PUSH_LATEST := true
endif
REVISION_TAG = $(shell git rev-parse --short HEAD)
export BUILD_NUM
export BUILD_TAG
# ============================================================================
# Check necessary commands exist
CIRCLECI := $(shell command -v circleci 2> /dev/null)
DOCKER := $(shell command -v docker 2> /dev/null)
COMPOSER := $(shell command -v composer 2> /dev/null)
JQ := $(shell command -v jq 2> /dev/null)
SHELLCHECK := $(shell command -v shellcheck 2> /dev/null)
YAMLLINT := $(shell command -v yamllint 2> /dev/null)
# ============================================================================
ALL: clean build push
init:
@chmod 755 .githooks/*
@find .git/hooks -type l -exec rm {} \;
@find .githooks -type f -exec ln -sf ../../{} .git/hooks/ \;
clean:
rm -f src/Dockerfile
lint: init lint-sh lint-yaml lint-json lint-composer lint-docker lint-ci
lint-sh:
ifndef SHELLCHECK
$(error "shellcheck is not installed: https://github.com/koalaman/shellcheck")
endif
@find . -type f -name '*.sh' | xargs shellcheck
lint-yaml:
ifndef YAMLLINT
$(error "yamllint is not installed: https://github.com/adrienverge/yamllint")
endif
@find . -type f -name '*.yml' | xargs yamllint
lint-json:
ifndef JQ
$(error "jq is not installed: https://stedolan.github.io/jq/download/")
endif
@find . -type f -name '*.json' | xargs jq type | grep -q '"object"'
lint-composer:
ifndef COMPOSER
$(error "composer is not installed: https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos")
endif
@find . -type f -name 'composer*.json' | xargs composer validate >/dev/null
lint-docker: src/Dockerfile
ifndef DOCKER
$(error "docker is not installed: https://docs.docker.com/install/")
endif
@docker run --rm -i hadolint/hadolint < src/Dockerfile >/dev/null
lint-ci:
ifndef CIRCLECI
$(error "circleci is not installed: https://circleci.com/docs/2.0/local-cli/#installation")
endif
@circleci config validate >/dev/null
pull:
docker pull gcr.io/planet-4-151612/circleci-base:$(BASE_IMAGE_VERSION)
src/Dockerfile:
envsubst < src/templates/Dockerfile.in > $@
build:
$(MAKE) -j lint pull
docker build \
--tag=$(BUILD_NAMESPACE)/$(GOOGLE_PROJECT_ID)/$(BUILD_IMAGE):$(BUILD_TAG) \
--tag=$(BUILD_NAMESPACE)/$(GOOGLE_PROJECT_ID)/$(BUILD_IMAGE):build-$(BUILD_NUM) \
--tag=$(BUILD_NAMESPACE)/$(GOOGLE_PROJECT_ID)/$(BUILD_IMAGE):$(REVISION_TAG) \
src
push: push-tag push-latest
push-tag:
docker push $(BUILD_NAMESPACE)/$(GOOGLE_PROJECT_ID)/$(BUILD_IMAGE):$(BUILD_TAG)
docker push $(BUILD_NAMESPACE)/$(GOOGLE_PROJECT_ID)/$(BUILD_IMAGE):build-$(BUILD_NUM)
push-latest:
if [[ "$(PUSH_LATEST)" = "true" ]]; then { \
docker tag $(BUILD_NAMESPACE)/$(GOOGLE_PROJECT_ID)/$(BUILD_IMAGE):$(REVISION_TAG) $(BUILD_NAMESPACE)/$(GOOGLE_PROJECT_ID)/$(BUILD_IMAGE):latest; \
docker push $(BUILD_NAMESPACE)/$(GOOGLE_PROJECT_ID)/$(BUILD_IMAGE):latest; \
} else { \
echo "Not tagged.. skipping latest"; \
} fi