From cd76d311da2cb43909368c1ea1c3a8c8234c1f2b Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Thu, 8 Apr 2021 09:38:25 -0400 Subject: [PATCH 1/6] make: Remove run target Its not currently used. Signed-off-by: Manuel Mendez --- Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Makefile b/Makefile index c5e241b1f..9c7be386b 100644 --- a/Makefile +++ b/Makefile @@ -44,9 +44,6 @@ crosscompile: $(crossbinaries) $(binaries) $(crossbinaries): $(FLAGS) go build $(LDFLAGS) -o $@ ./$(@D) -run: cmd/tink-cli/tink-cli-linux-amd64 cmd/tink-server/tink-server-linux-amd64 cmd/tink-worker/tink-worker-linux-amd64 - docker-compose up -d --build db - docker-compose up --build tinkerbell boots test: go clean -testcache go test ./... -v From c8aa9f3a8cf09c8847d6b2b7d9743a41e7dcb3b1 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Thu, 8 Apr 2021 09:39:37 -0400 Subject: [PATCH 2/6] make: add a help target This will hopefully make the "main" targets of the makefile easier to find/use. Signed-off-by: Manuel Mendez --- Makefile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 9c7be386b..55d01ee7a 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ endif LDFLAGS := -ldflags "-X main.version=$(version)" export CGO_ENABLED := 0 -all: $(binaries) +all: $(binaries) ## Build all binaries for host OS and CPU .PHONY: server $(binaries) cli worker test server: $(server) @@ -33,7 +33,7 @@ worker : $(worker) crossbinaries := $(addsuffix -linux-,$(binaries)) crossbinaries := $(crossbinaries:=386) $(crossbinaries:=amd64) $(crossbinaries:=arm64) $(crossbinaries:=armv6) $(crossbinaries:=armv7) -crosscompile: $(crossbinaries) +crosscompile: $(crossbinaries) ## Build all binaries for Linux OS and all supported CPU arches .PHONY: crosscompile $(crossbinaries) %-386: FLAGS=GOOS=linux GOARCH=386 @@ -44,11 +44,11 @@ crosscompile: $(crossbinaries) $(binaries) $(crossbinaries): $(FLAGS) go build $(LDFLAGS) -o $@ ./$(@D) -test: +test: ## Run tests go clean -testcache go test ./... -v -verify: +verify: ## Run lint like checkers goimports -d . golint ./... @@ -63,3 +63,6 @@ grpc/gen_doc: --doc_out=./doc \ --doc_opt=html,index.html \ protos/hardware/*.proto protos/template/*.proto protos/workflow/*.proto + +help: ## Print this help + @grep --no-filename -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sed 's/:.*##/·/' | sort | column -ts '·' -c 120 From 1556482250ea986eb4fe8a0a679f311823c64087 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Thu, 8 Apr 2021 10:06:29 -0400 Subject: [PATCH 3/6] make: split into high level and low level files Makefile now just has the targets that a caller is likely to be interested in, everything else goes into rules.mk. Hopefully this makes this Makefile easier to use/obvious. Signed-off-by: Manuel Mendez --- Makefile | 58 +++----------------------------------------------------- rules.mk | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 55 deletions(-) create mode 100644 rules.mk diff --git a/Makefile b/Makefile index 55d01ee7a..da99028a1 100644 --- a/Makefile +++ b/Makefile @@ -1,48 +1,8 @@ -# Only use the recipes defined in these makefiles -MAKEFLAGS += --no-builtin-rules -.SUFFIXES: -# Delete target files if there's an error -# This avoids a failure to then skip building on next run if the output is created by shell redirection for example -# Not really necessary for now, but just good to have already if it becomes necessary later. -.DELETE_ON_ERROR: -# Treat the whole recipe as a one shell script/invocation instead of one-per-line -.ONESHELL: -# Use bash instead of plain sh -SHELL := bash -.SHELLFLAGS := -o pipefail -euc +all: cli server worker ## Build all binaries for host OS and CPU -server := cmd/tink-server/tink-server -cli := cmd/tink-cli/tink-cli -worker := cmd/tink-worker/tink-worker -binaries := $(server) $(cli) $(worker) +-include rules.mk -version := $(shell git rev-parse --short HEAD) -tag := $(shell git tag --points-at HEAD) -ifneq (,$(tag)) -version := $(tag)-$(version) -endif -LDFLAGS := -ldflags "-X main.version=$(version)" -export CGO_ENABLED := 0 - -all: $(binaries) ## Build all binaries for host OS and CPU - -.PHONY: server $(binaries) cli worker test -server: $(server) -cli: $(cli) -worker : $(worker) - -crossbinaries := $(addsuffix -linux-,$(binaries)) -crossbinaries := $(crossbinaries:=386) $(crossbinaries:=amd64) $(crossbinaries:=arm64) $(crossbinaries:=armv6) $(crossbinaries:=armv7) -crosscompile: $(crossbinaries) ## Build all binaries for Linux OS and all supported CPU arches -.PHONY: crosscompile $(crossbinaries) - -%-386: FLAGS=GOOS=linux GOARCH=386 -%-amd64: FLAGS=GOOS=linux GOARCH=amd64 -%-arm64: FLAGS=GOOS=linux GOARCH=arm64 -%-armv6: FLAGS=GOOS=linux GOARCH=arm GOARM=6 -%-armv7: FLAGS=GOOS=linux GOARCH=arm GOARM=7 -$(binaries) $(crossbinaries): - $(FLAGS) go build $(LDFLAGS) -o $@ ./$(@D) +crosscompile: $(crossbinaries) ## Build all binaries for Linux and all supported CPU arches test: ## Run tests go clean -testcache @@ -52,17 +12,5 @@ verify: ## Run lint like checkers goimports -d . golint ./... -protos/gen_mock: - go generate ./protos/**/* - goimports -w ./protos/**/mock.go - -grpc/gen_doc: - protoc \ - -I./protos \ - -I./protos/third_party \ - --doc_out=./doc \ - --doc_opt=html,index.html \ - protos/hardware/*.proto protos/template/*.proto protos/workflow/*.proto - help: ## Print this help @grep --no-filename -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sed 's/:.*##/·/' | sort | column -ts '·' -c 120 diff --git a/rules.mk b/rules.mk new file mode 100644 index 000000000..d1cffbfb9 --- /dev/null +++ b/rules.mk @@ -0,0 +1,50 @@ +# Only use the recipes defined in these makefiles +MAKEFLAGS += --no-builtin-rules +.SUFFIXES: +# Delete target files if there's an error +# This avoids a failure to then skip building on next run if the output is created by shell redirection for example +# Not really necessary for now, but just good to have already if it becomes necessary later. +.DELETE_ON_ERROR: +# Treat the whole recipe as a one shell script/invocation instead of one-per-line +.ONESHELL: +# Use bash instead of plain sh +SHELL := bash +.SHELLFLAGS := -o pipefail -euc + +binaries := cmd/tink-cli/tink-cli cmd/tink-server/tink-server cmd/tink-worker/tink-worker +version := $(shell git rev-parse --short HEAD) +tag := $(shell git tag --points-at HEAD) +ifneq (,$(tag)) +version := $(tag)-$(version) +endif +LDFLAGS := -ldflags "-X main.version=$(version)" +export CGO_ENABLED := 0 + +cli: cmd/tink-cli/tink-cli +server: cmd/tink-server/tink-server +worker : cmd/tink-worker/tink-worker + +.PHONY: server cli worker test $(binaries) +crossbinaries := $(addsuffix -linux-,$(binaries)) +crossbinaries := $(crossbinaries:=386) $(crossbinaries:=amd64) $(crossbinaries:=arm64) $(crossbinaries:=armv6) $(crossbinaries:=armv7) + +.PHONY: crosscompile $(crossbinaries) +%-386: FLAGS=GOOS=linux GOARCH=386 +%-amd64: FLAGS=GOOS=linux GOARCH=amd64 +%-arm64: FLAGS=GOOS=linux GOARCH=arm64 +%-armv6: FLAGS=GOOS=linux GOARCH=arm GOARM=6 +%-armv7: FLAGS=GOOS=linux GOARCH=arm GOARM=7 +$(binaries) $(crossbinaries): + $(FLAGS) go build $(LDFLAGS) -o $@ ./$(@D) + +protos/gen_mock: + go generate ./protos/**/* + goimports -w ./protos/**/mock.go + +grpc/gen_doc: + protoc \ + -I./protos \ + -I./protos/third_party \ + --doc_out=./doc \ + --doc_opt=html,index.html \ + protos/hardware/*.proto protos/template/*.proto protos/workflow/*.proto From dc315cb207d0d4682a359f29b98a3b6c6176bb14 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Thu, 8 Apr 2021 10:15:34 -0400 Subject: [PATCH 4/6] make: Add targets to build docker images Signed-off-by: Manuel Mendez --- Makefile | 1 + rules.mk | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/Makefile b/Makefile index da99028a1..4680d809d 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ all: cli server worker ## Build all binaries for host OS and CPU -include rules.mk crosscompile: $(crossbinaries) ## Build all binaries for Linux and all supported CPU arches +images: tink-cli-image tink-server-image tink-worker-image ## Build all docker images test: ## Run tests go clean -testcache diff --git a/rules.mk b/rules.mk index d1cffbfb9..1a1e58571 100644 --- a/rules.mk +++ b/rules.mk @@ -37,6 +37,14 @@ crossbinaries := $(crossbinaries:=386) $(crossbinaries:=amd64) $(crossbinaries:= $(binaries) $(crossbinaries): $(FLAGS) go build $(LDFLAGS) -o $@ ./$(@D) +.PHONY: images tink-cli-image tink-server-image tink-worker-image +tink-cli-image: cmd/tink-cli/tink-cli-linux-amd64 + docker build -t tink-cli -f cmd/tink-cli/Dockerfile +tink-server-image: cmd/tink-server/tink-server-linux-amd64 + docker build -t tink-server -f cmd/tink-server/Dockerfile +tink-worker-image: cmd/tink-worker/tink-worker-linux-amd64 + docker build -t tink-worker -f cmd/tink-worker/Dockerfile + protos/gen_mock: go generate ./protos/**/* goimports -w ./protos/**/mock.go From b13212679b8b829e05ee4923a5024212523f89a2 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Thu, 8 Apr 2021 10:21:32 -0400 Subject: [PATCH 5/6] Rework Dockerfiles with context as same dir as Dockerfile This way the Dockerfile is written to take into account only its current dir for context which minimizes things uploaded to docker for the build. Signed-off-by: Manuel Mendez --- .github/workflows/ci.yaml | 3 +-- cmd/tink-cli/Dockerfile | 2 +- cmd/tink-server/Dockerfile | 2 +- cmd/tink-worker/Dockerfile | 2 +- deploy/docker-compose.yml | 12 +++--------- rules.mk | 6 +++--- 6 files changed, 10 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b84b77f0e..293990852 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -140,8 +140,7 @@ jobs: - name: ${{ matrix.repository }} uses: docker/build-push-action@v2 with: - context: . - file: cmd/${{ matrix.binary }}/Dockerfile + context: cmd/${{ matrix.binary }}/ cache-from: type=registry,ref=${{ matrix.repository }}:latest push: ${{ startsWith(github.ref, 'refs/heads/master') }} tags: ${{ steps.docker-image-tag.outputs.tags }} diff --git a/cmd/tink-cli/Dockerfile b/cmd/tink-cli/Dockerfile index 4f5473bf1..990c0e4c1 100644 --- a/cmd/tink-cli/Dockerfile +++ b/cmd/tink-cli/Dockerfile @@ -5,4 +5,4 @@ ARG TARGETARCH ARG TARGETVARIANT RUN apk add --no-cache --update --upgrade ca-certificates -COPY cmd/tink-cli/tink-cli-linux-${TARGETARCH:-amd64}${TARGETVARIANT} /usr/bin/tink +COPY tink-cli-linux-${TARGETARCH:-amd64}${TARGETVARIANT} /usr/bin/tink diff --git a/cmd/tink-server/Dockerfile b/cmd/tink-server/Dockerfile index 7b1288045..d76552196 100644 --- a/cmd/tink-server/Dockerfile +++ b/cmd/tink-server/Dockerfile @@ -8,4 +8,4 @@ ARG TARGETVARIANT RUN apk add --update ca-certificates && \ apk add --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing cfssl -COPY cmd/tink-server/tink-server-linux-${TARGETARCH:-amd64}${TARGETVARIANT} /usr/bin/tink-server +COPY tink-server-linux-${TARGETARCH:-amd64}${TARGETVARIANT} /usr/bin/tink-server diff --git a/cmd/tink-worker/Dockerfile b/cmd/tink-worker/Dockerfile index b31c38673..c20aeb096 100644 --- a/cmd/tink-worker/Dockerfile +++ b/cmd/tink-worker/Dockerfile @@ -5,4 +5,4 @@ ARG TARGETARCH ARG TARGETVARIANT RUN apk add --no-cache --update --upgrade ca-certificates -COPY cmd/tink-worker/tink-worker-linux-${TARGETARCH:-amd64}${TARGETVARIANT} /usr/bin/tink-worker +COPY tink-worker-linux-${TARGETARCH:-amd64}${TARGETVARIANT} /usr/bin/tink-worker diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index 1a9f00b4d..91e4a5a6f 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -1,9 +1,7 @@ version: "2.1" services: tink-server: - build: - context: ../ - dockerfile: cmd/tink-server/Dockerfile + build: ../cmd/tink-server restart: unless-stopped environment: FACILITY: ${FACILITY:-onprem} @@ -34,9 +32,7 @@ services: - 42114:42114/tcp tink-server-migration: - build: - context: ../ - dockerfile: cmd/tink-server/Dockerfile + build: ../cmd/tink-server restart: on-failure environment: ONLY_MIGRATION: "true" @@ -75,9 +71,7 @@ services: retries: 30 tink-cli: - build: - context: ../ - dockerfile: cmd/tink-cli/Dockerfile + build: ../cmd/tink-cli restart: unless-stopped environment: TINKERBELL_GRPC_AUTHORITY: 127.0.0.1:42113 diff --git a/rules.mk b/rules.mk index 1a1e58571..ce771d0b3 100644 --- a/rules.mk +++ b/rules.mk @@ -39,11 +39,11 @@ $(binaries) $(crossbinaries): .PHONY: images tink-cli-image tink-server-image tink-worker-image tink-cli-image: cmd/tink-cli/tink-cli-linux-amd64 - docker build -t tink-cli -f cmd/tink-cli/Dockerfile + docker build -t tink-cli cmd/tink-cli/ tink-server-image: cmd/tink-server/tink-server-linux-amd64 - docker build -t tink-server -f cmd/tink-server/Dockerfile + docker build -t tink-server cmd/tink-server/ tink-worker-image: cmd/tink-worker/tink-worker-linux-amd64 - docker build -t tink-worker -f cmd/tink-worker/Dockerfile + docker build -t tink-worker cmd/tink-worker/ protos/gen_mock: go generate ./protos/**/* From 81f568e7283087a3976e6ae533f184317499d219 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Thu, 8 Apr 2021 10:49:46 -0400 Subject: [PATCH 6/6] Add small bit of info to README for building binaries/images. Signed-off-by: Manuel Mendez --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 5bf9e1dd4..c291ec3cf 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,13 @@ It is comprised of following five major components: The workflow engine is comprised of a server and a CLI, which communicates over gRPC. The CLI is used to create a workflow and its building blocks: templates and targeted hardware. +## Building + +Use `make help` Luke. +The most interesting targets are `make all` (or just `make`) and `make images`. +`make all` builds all the binaries for your host OS and CPU to enable running directly. +`make images` will build all the binaries for Linux/x86_64 and build docker images with them. + ## Workflow A workflow is a framework responsible for handling flexible, bare metal provisioning, that is...