This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
201 lines (165 loc) · 7.57 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# Copyright © 2017 Syndesis Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
BIN := pure-bot
# This repo's root import path (under GOPATH).
PKG := github.com/syndesisio/pure-bot
# Where to push the docker image.
REGISTRY ?= syndesis
# Which architecture to build - see $(ALL_ARCH) for options.
ARCH ?= amd64
# This version-strategy uses git tags to set the version string
BUILD_DATE := $(shell date -u)
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty --always)
OPENSHIFT_IMAGE_STREAM ?= pure-bot:deploy
OPENSHIFT_CLIENT_IMAGE ?= openshift/origin:v3.7.0-rc.0
#
# This version-strategy uses a manual value to set the version string
#VERSION := 1.2.3
###
### These variables should not need tweaking.
###
ALL_ARCH := amd64 arm arm64
# Set default base image dynamically for each arch
ifeq ($(ARCH),amd64)
BASEIMAGE?=alpine:3.6
endif
ifeq ($(ARCH),arm)
BASEIMAGE?=armhf/alpine:3.6
endif
ifeq ($(ARCH),arm64)
BASEIMAGE?=owlab/alpine-arm64:3.6
endif
IMAGE := $(REGISTRY)/$(BIN)
GOVERSION ?= 1.9.2
BUILD_IMAGE ?= golang:$(GOVERSION)-alpine
GOLANG_IMAGE ?= golang:$(GOVERSION)
# If you want to build all binaries, see the 'all-build' rule.
# If you want to build all images, see the 'all-image' rule.
# If you want to build AND push all images, see the 'all-push' rule.
all: build
build-%:
@$(MAKE) --no-print-directory ARCH=$* build
image-%:
@$(MAKE) --no-print-directory ARCH=$* image
push-%:
@$(MAKE) --no-print-directory ARCH=$* push
all-build: $(addprefix build-, $(ALL_ARCH))
all-image: $(addprefix image-, $(ALL_ARCH))
all-push: $(addprefix push-, $(ALL_ARCH))
build: bin/$(ARCH)/$(BIN)
bin/$(ARCH)/$(BIN): vendor build-dirs
@echo "building: $@"
@docker run \
-ti \
-u $$(id -u):$$(id -g) \
-v "$$(pwd)/.go:/go:Z" \
-v "$$(pwd):/go/src/$(PKG):Z" \
-v "$$(pwd)/bin/$(ARCH):/go/bin:Z" \
-v "$$(pwd)/bin/$(ARCH):/go/bin/linux_$(ARCH):Z" \
-v "$$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static:Z" \
-w /go/src/$(PKG) \
$(BUILD_IMAGE) \
/bin/sh -c " \
ARCH=$(ARCH) \
VERSION=$(VERSION) \
BUILD_DATE=\"$(BUILD_DATE)\" \
PKG=$(PKG) \
./build/build.sh \
"
# Example: make shell CMD="-c 'date > datefile'"
shell: build-dirs
@echo "launching a shell in the containerized build environment"
@docker run \
-ti \
--rm \
-u $$(id -u):$$(id -g) \
-v "$$(pwd)/.go:/go":Z \
-v "$$(pwd):/go/src/$(PKG)":Z \
-v "$$(pwd)/bin/$(ARCH):/go/bin":Z \
-v "$$(pwd)/bin/$(ARCH):/go/bin/$$(go env GOOS)_$(ARCH)":Z \
-v "$$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static":Z \
-w /go/src/$(PKG) \
$(BUILD_IMAGE) \
/bin/sh $(CMD)
vendor: build-dirs .vendor Gopkg.lock Gopkg.toml
.vendor:
@echo "updating vendored deps"
@docker run \
-ti \
-v "$$(pwd):/go/src/$(PKG):Z" \
-v "$$(pwd)/bin/$(ARCH):/go/bin:Z" \
-w /go/src/$(PKG) \
$(GOLANG_IMAGE) \
/bin/sh -c " \
./build/update_vendor.sh \
"
@touch .vendor
DOTFILE_IMAGE = $(subst :,_,$(subst /,_,$(IMAGE))-$(VERSION))
image: .image-$(DOTFILE_IMAGE) image-name
.image-$(DOTFILE_IMAGE): bin/$(ARCH)/$(BIN) Dockerfile.in
@sed \
-e 's|ARG_BIN|$(BIN)|g' \
-e 's|ARG_ARCH|$(ARCH)|g' \
-e 's|ARG_FROM|$(BASEIMAGE)|g' \
Dockerfile.in > .dockerfile-$(ARCH)
@docker build -t $(IMAGE):$(VERSION) -f .dockerfile-$(ARCH) .
@docker images -q $(IMAGE):$(VERSION) > $@
image-test: image
@echo "Build date: $(BUILD_DATE)"
@docker tag $(IMAGE):$(VERSION) $(IMAGE):testing
@docker push $(IMAGE):testing
image-name:
@echo "image: $(IMAGE):$(VERSION)"
push: .push-$(DOTFILE_IMAGE) push-name
.push-$(DOTFILE_IMAGE): .image-$(DOTFILE_IMAGE)
ifeq ($(findstring gcr.io,$(REGISTRY)),gcr.io)
@gcloud docker -- push $(IMAGE):$(VERSION)
else
@docker push $(IMAGE):$(VERSION)
endif
@docker images -q $(IMAGE):$(VERSION) > $@
push-name:
@echo "pushed: $(IMAGE):$(VERSION)"
circleci-deploy: push
@docker run --entrypoint=/bin/sh $(OPENSHIFT_CLIENT_IMAGE) -c " \
openshift cli login $$OPENSHIFT_SERVER --token=$$OPENSHIFT_TOKEN && \
openshift cli project $$OPENSHIFT_PROJECT && \
openshift cli tag --source=docker $(IMAGE):$(VERSION) $(OPENSHIFT_IMAGE_STREAM) && \
openshift cli import-image $(OPENSHIFT_IMAGE_STREAM) \
"
version:
@echo $(VERSION)
test: build-dirs
@docker run \
-ti \
-u $$(id -u):$$(id -g) \
-v "$$(pwd)/.go:/go:Z" \
-v "$$(pwd):/go/src/$(PKG):Z" \
-v "$$(pwd)/bin/$(ARCH):/go/bin:Z" \
-v "$$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static:Z" \
-w /go/src/$(PKG) \
$(BUILD_IMAGE) \
/bin/sh -c " \
./build/test.sh \
"
build-dirs:
@mkdir -p bin/$(ARCH)
@mkdir -p .go/src/$(PKG) .go/pkg .go/bin .go/std/$(ARCH)
clean: image-clean bin-clean vendor-clean
image-clean:
rm -rf .image-* .dockerfile-* .push-*
bin-clean:
rm -rf .go bin
vendor-clean:
rm -f .vendor