Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit a80653c

Browse files
authored
Merge pull request #219 from rumpl/chore-build-without-backends
Build example and local backend conditionaly
2 parents 028750e + 39042aa commit a80653c

File tree

10 files changed

+41
-9
lines changed

10 files changed

+41
-9
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@ jobs:
4646
${{ runner.os }}-go-
4747
4848
- name: Test
49+
env:
50+
BUILD_TAGS: example,local
4951
run: make -f builder.Makefile test
5052

5153
- name: Build
54+
env:
55+
BUILD_TAGS: example,local
5256
run: make -f builder.Makefile cli
5357

5458
- name: E2E Test
@@ -77,9 +81,13 @@ jobs:
7781
${{ runner.os }}-go-
7882
7983
- name: Test
84+
env:
85+
BUILD_TAGS: example,local
8086
run: make -f builder.Makefile test
8187

8288
- name: Build
89+
env:
90+
BUILD_TAGS: example,local
8391
run: make -f builder.Makefile cli
8492

8593
- name: E2E Test

.github/workflows/release.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: releaser
33
on:
44
push:
55
tags:
6-
- 'v*'
6+
- "v*"
77
jobs:
88
upload-release:
99
runs-on: ubuntu-latest
@@ -32,4 +32,3 @@ jobs:
3232
artifacts: "bin/*"
3333
prerelease: true
3434
token: ${{ secrets.GITHUB_TOKEN }}
35-

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ FROM base AS make-cli
3232
ENV CGO_ENABLED=0
3333
ARG TARGETOS
3434
ARG TARGETARCH
35+
ARG BUILD_TAGS
3536
RUN --mount=target=. \
3637
--mount=type=cache,target=/root/.cache/go-build \
3738
GOOS=${TARGETOS} \
3839
GOARCH=${TARGETARCH} \
40+
BUILD_TAGS=${BUILD_TAGS} \
3941
make BINARY=/out/docker -f builder.Makefile cli
4042

4143
FROM base AS make-cross
44+
ARG BUILD_TAGS
4245
RUN --mount=target=. \
4346
--mount=type=cache,target=/root/.cache/go-build \
47+
BUILD_TAGS=${BUILD_TAGS} \
4448
make BINARY=/out/docker -f builder.Makefile cross
4549

4650
FROM scratch AS protos
@@ -53,7 +57,9 @@ FROM scratch AS cross
5357
COPY --from=make-cross /out/* .
5458

5559
FROM base as test
60+
ARG BUILD_TAGS
5661
ENV CGO_ENABLED=0
5762
RUN --mount=target=. \
5863
--mount=type=cache,target=/root/.cache/go-build \
64+
BUILD_TAGS=${BUILD_TAGS} \
5965
make -f builder.Makefile test

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ protos: ## Generate go code from .proto files
4242
cli: ## Compile the cli
4343
@docker build . --target cli \
4444
--platform local \
45+
--build-arg BUILD_TAGS=example,local \
4546
--output ./bin
4647

4748
e2e-local: ## Run End to end local tests
@@ -55,10 +56,13 @@ e2e-aci: ## Run End to end ACI tests (requires azure login)
5556

5657
cross: ## Compile the CLI for linux, darwin and windows
5758
@docker build . --target cross \
59+
--build-arg BUILD_TAGS \
5860
--output ./bin \
5961

6062
test: ## Run unit tests
61-
@docker build . --target test
63+
@docker build . \
64+
--build-arg BUILD_TAGS=example,local \
65+
--target test
6266

6367
cache-clear: ## Clear the builder cache
6468
@docker builder prune --force --filter type=exec.cachemount --filter=unused-for=24h
@@ -68,6 +72,7 @@ lint: ## run linter(s)
6872

6973
serve: cli ## start server
7074
@./bin/docker serve --address unix:///tmp/backend.sock
75+
7176
classic-link: ## create docker-classic symlink if does not already exist
7277
ln -s $(CLASSIC_DOCKER) /usr/local/bin/docker-classic
7378

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ The new CLI delegates to the classic docker for default contexts ; delegation is
2525
$ make
2626
```
2727

28-
If you make changes to the `.proto` files, make sure to `make protos` to generate go code.
28+
This will make the cli with all backends enabled. `make cross` on the other hand will cross-compile the cli without the
29+
example and local backend. We use `make cross` to build for our release, hence the exclusion of those backends. You can
30+
still cross-compile with all backends enabled: `BUILD_TAGS=example,local make cross`.
2931

32+
If you make changes to the `.proto` files, make sure to `make protos` to generate go code.
3033

3134
## Tests
3235

builder.Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,26 @@ GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
4040
BINARY?=bin/docker
4141
BINARY_WITH_EXTENSION=$(BINARY)$(EXTENSION)
4242

43+
TAGS:=
44+
ifdef BUILD_TAGS
45+
TAGS=-tags $(BUILD_TAGS)
46+
endif
47+
4348
all: cli
4449

4550
protos:
4651
@protoc -I. --go_out=plugins=grpc,paths=source_relative:. ${PROTOS}
4752

4853
cli:
49-
GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) -o $(BINARY_WITH_EXTENSION) ./cli
54+
GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(BINARY_WITH_EXTENSION) ./cli
5055

5156
cross:
52-
@GOOS=linux GOARCH=amd64 $(GO_BUILD) -o $(BINARY)-linux-amd64 ./cli
53-
@GOOS=darwin GOARCH=amd64 $(GO_BUILD) -o $(BINARY)-darwin-amd64 ./cli
54-
@GOOS=windows GOARCH=amd64 $(GO_BUILD) -o $(BINARY)-windows-amd64.exe ./cli
57+
@GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-amd64 ./cli
58+
@GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-darwin-amd64 ./cli
59+
@GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-windows-amd64.exe ./cli
5560

5661
test:
57-
@go test -cover $(shell go list ./... | grep -vE 'e2e')
62+
@go test $(TAGS) -cover $(shell go list ./... | grep -vE 'e2e')
5863

5964
lint:
6065
golangci-lint run --timeout 10m0s ./...

example/backend.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build example
2+
13
package example
24

35
import (

example/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package example

local/backend.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build local
2+
13
package local
24

35
import (

local/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package local

0 commit comments

Comments
 (0)