forked from temporalio/docker-builds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
120 lines (96 loc) · 4.17 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
all: install
##### Variables ######
COLOR := "\e[1;36m%s\e[0m\n"
# Disable cgo by default.
CGO_ENABLED ?= 0
TEMPORAL_ROOT := temporal
TCTL_ROOT := tctl
CLI_ROOT := cli
DOCKERIZE_ROOT := dockerize
IMAGE_TAG ?= sha-$(shell git rev-parse --short HEAD)
TEMPORAL_SHA := $(shell sh -c 'git submodule status -- temporal | cut -c2-40')
TCTL_SHA := $(shell sh -c "git submodule status -- tctl | cut -c2-40")
DOCKER ?= docker buildx
BAKE := IMAGE_TAG=$(IMAGE_TAG) TEMPORAL_SHA=$(TEMPORAL_SHA) TCTL_SHA=$(TCTL_SHA) $(DOCKER) bake
NATIVE_ARCH := $(shell go env GOARCH)
# Default to loading into the local docker context. Provide the value 'registry' if you wish to push the images
BAKE_OUTPUT ?= docker
##### Scripts ######
.PHONY: install
install: install-submodules
clean:
rm -rf ./build
.PHONY: update
update: update-submodules
.PHONY: install-submodules
install-submodules:
@printf $(COLOR) "Installing submodules..."
git submodule update --init
.PHONY: update-submodules
update-submodules:
@printf $(COLOR) "Updatinging temporal and tctl submodules..."
git submodule update --force --remote $(TEMPORAL_ROOT) $(TCTL_ROOT)
##### Docker #####
# If you're new to Make, this is a pattern rule: https://www.gnu.org/software/make/manual/html_node/Pattern-Rules.html#Pattern-Rules
# $* expands to the stem that matches the %, so when the target is amd64-bins $* expands to amd64
%-bins:
@mkdir -p build/$*
@cd $(DOCKERIZE_ROOT) && CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=$* go build -o ../build/$*/dockerize .
@GOOS=linux GOARCH=$* CGO_ENABLED=$(CGO_ENABLED) make -C $(TEMPORAL_ROOT) clean-bins bins
@cp $(TEMPORAL_ROOT)/temporal-server build/$*/
@cp $(TEMPORAL_ROOT)/temporal-cassandra-tool build/$*/
@cp $(TEMPORAL_ROOT)/temporal-sql-tool build/$*/
@cp $(TEMPORAL_ROOT)/tdbg build/$*/
@cd $(CLI_ROOT) && GOOS=linux GOARCH=$* CGO_ENABLED=$(CGO_ENABLED) go build ./cmd/temporal
@cp ./$(CLI_ROOT)/temporal build/$*/
@GOOS=linux GOARCH=$* CGO_ENABLED=$(CGO_ENABLED) make -C $(TCTL_ROOT) build
@cp ./$(TCTL_ROOT)/tctl build/$*/
@cp ./$(TCTL_ROOT)/tctl-authorization-plugin build/$*/
.PHONY: bins
.NOTPARALLEL: bins
bins: install-submodules amd64-bins arm64-bins
.PHONY: simulate-push
simulate-push:
@act push -s GITHUB_TOKEN="$(shell gh auth token)" -j build-push-images -P ubuntu-latest-16-cores=catthehacker/ubuntu:act-latest
COMMIT =?
.PHONY: simulate-dispatch
simulate-dispatch:
@act workflow_dispatch -s GITHUB_TOKEN="$(shell gh auth token)" -j build-image -P ubuntu-latest-16-cores=catthehacker/ubuntu:act-latest --input commit=$(COMMIT)
# We hard-code the native arch here as the docker machine for mac doesn't support cross-platform builds (unless running within act)
# This target also ignores the BAKE_OUTPUT variable to prevent us from uploading a single-architecture image
.PHONY: build-native
build-native: $(NATIVE_ARCH)-bins
$(BAKE) --set "*.platform=linux/$(NATIVE_ARCH)" --load
.PHONY: build
build: bins
$(BAKE) --set="*.output=type=$(BAKE_OUTPUT)"
.PHONY: docker-server
docker-server: $(NATIVE_ARCH)-bins
@printf $(COLOR) "Building docker image temporalio/server:$(IMAGE_TAG)..."
$(BAKE) server --set "*.platform=linux/$(NATIVE_ARCH)"
.PHONY: docker-admin-tools
docker-admin-tools: $(NATIVE_ARCH)-bins
@printf $(COLOR) "Build docker image temporalio/admin-tools:$(IMAGE_TAG)..."
$(BAKE) admin-tools --set "*.platform=linux/$(NATIVE_ARCH)"
.PHONY: docker-auto-setup
docker-auto-setup: $(NATIVE_ARCH)-bins
@printf $(COLOR) "Build docker image temporalio/auto-setup:$(IMAGE_TAG)..."
$(BAKE) auto-setup --set "*.platform=linux/$(NATIVE_ARCH)"
.PHONY: docker-buildx-container
docker-buildx-container:
docker buildx create --name builder-x --driver docker-container --use
.PHONY: docker-server-x
docker-server-x: bins
@printf $(COLOR) "Building cross-platform docker image temporalio/server:$(IMAGE_TAG)..."
$(BAKE) server
.PHONY: docker-admin-tools-x
docker-admin-tools-x: bins
@printf $(COLOR) "Build cross-platform docker image temporalio/admin-tools:$(IMAGE_TAG)..."
$(BAKE) admin-tools
.PHONY: docker-auto-setup-x
docker-auto-setup-x: bins
@printf $(COLOR) "Build cross-platform docker image temporalio/auto-setup:$(DOCKER_IMAGE_TAG)..."
$(BAKE) auto-setup
.PHONY: test
test:
IMAGE_TAG=$(IMAGE_TAG) ./test.sh