Skip to content

Commit 27a7563

Browse files
authored
Add simpler and faster debug Makefile target
1 parent 819de02 commit 27a7563

File tree

9 files changed

+48
-34
lines changed

9 files changed

+48
-34
lines changed

.github/workflows/build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
env:
99
GO_VERSION: 1.17
1010
CGO_ENABLED: 0
11-
PRE_TARGET: ""
11+
IN_DOCKER: ""
1212

1313
jobs:
1414

.github/workflows/test-unit.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
env:
99
GO_VERSION: 1.17
10-
PRE_TARGET: ""
10+
IN_DOCKER: ""
1111

1212
jobs:
1313

.github/workflows/validate.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ env:
99
GO_VERSION: 1.17
1010
GOLANGCI_LINT_VERSION: v1.44.0
1111
MISSSPELL_VERSION: v0.3.4
12-
PRE_TARGET: ""
12+
IN_DOCKER: ""
1313

1414
jobs:
1515

.semaphore/semaphore.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ blocks:
4141
commands:
4242
- make pull-images
4343
- touch webui/static/index.html # Avoid generating webui
44-
- PRE_TARGET="" make binary
44+
- IN_DOCKER="" make binary
4545
- make test-integration
4646
- df -h
4747
epilogue:
@@ -65,7 +65,7 @@ blocks:
6565
value: 1.12.1
6666
- name: CODENAME
6767
value: "rocamadour"
68-
- name: PRE_TARGET
68+
- name: IN_DOCKER
6969
value: ""
7070
prologue:
7171
commands:

Makefile

+28-22
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ SHA := $(shell git rev-parse HEAD)
77
VERSION_GIT := $(if $(TAG_NAME),$(TAG_NAME),$(SHA))
88
VERSION := $(if $(VERSION),$(VERSION),$(VERSION_GIT))
99

10-
BIND_DIR := dist
11-
1210
GIT_BRANCH := $(subst heads/,,$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null))
1311
TRAEFIK_DEV_IMAGE := traefik-dev$(if $(GIT_BRANCH),:$(subst /,-,$(GIT_BRANCH)))
1412

@@ -29,22 +27,22 @@ TRAEFIK_ENVS := \
2927
-e CI \
3028
-e CONTAINER=DOCKER # Indicator for integration tests that we are running inside a container.
3129

32-
TRAEFIK_MOUNT := -v "$(CURDIR)/$(BIND_DIR):/go/src/github.com/traefik/traefik/$(BIND_DIR)"
30+
TRAEFIK_MOUNT := -v "$(CURDIR)/dist:/go/src/github.com/traefik/traefik/dist"
3331
DOCKER_RUN_OPTS := $(TRAEFIK_ENVS) $(TRAEFIK_MOUNT) "$(TRAEFIK_DEV_IMAGE)"
3432
DOCKER_NON_INTERACTIVE ?= false
3533
DOCKER_RUN_TRAEFIK := docker run $(INTEGRATION_OPTS) $(if $(DOCKER_NON_INTERACTIVE), , -it) $(DOCKER_RUN_OPTS)
3634
DOCKER_RUN_TRAEFIK_TEST := docker run --add-host=host.docker.internal:127.0.0.1 --rm --name=traefik --network traefik-test-network -v $(PWD):$(PWD) -w $(PWD) $(INTEGRATION_OPTS) $(if $(DOCKER_NON_INTERACTIVE), , -it) $(DOCKER_RUN_OPTS)
3735
DOCKER_RUN_TRAEFIK_NOTTY := docker run $(INTEGRATION_OPTS) $(if $(DOCKER_NON_INTERACTIVE), , -i) $(DOCKER_RUN_OPTS)
3836

39-
PRE_TARGET ?= build-dev-image
37+
IN_DOCKER ?= true
4038

4139
PLATFORM_URL := $(if $(PLATFORM_URL),$(PLATFORM_URL),"https://pilot.traefik.io")
4240

4341
default: binary
4442

4543
## Build Dev Docker image
4644
build-dev-image: dist
47-
docker build $(DOCKER_BUILD_ARGS) -t "$(TRAEFIK_DEV_IMAGE)" -f build.Dockerfile .
45+
$(if $(IN_DOCKER),docker build $(DOCKER_BUILD_ARGS) -t "$(TRAEFIK_DEV_IMAGE)" -f build.Dockerfile .,)
4846

4947
## Build Dev Docker image without cache
5048
build-dev-image-no-cache: dist
@@ -72,9 +70,13 @@ generate-webui:
7270
docker run --rm -v "$$PWD/webui/static":'/src/webui/static' traefik-webui chown -R $(shell id -u):$(shell id -g) ./static; \
7371
fi
7472

75-
## Build the linux binary
76-
binary: generate-webui $(PRE_TARGET)
77-
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK)) ./script/make.sh generate binary
73+
## Build the binary
74+
binary: generate-webui build-dev-image
75+
$(if $(IN_DOCKER),$(DOCKER_RUN_TRAEFIK)) ./script/make.sh generate binary
76+
77+
## Build the linux binary locally
78+
binary-debug: generate-webui
79+
GOOS=linux ./script/make.sh binary
7880

7981
## Build the binary for the standard platforms (linux, darwin, windows)
8082
crossbinary-default: generate-webui build-dev-image
@@ -86,35 +88,35 @@ crossbinary-default-parallel:
8688
$(MAKE) build-dev-image crossbinary-default
8789

8890
## Run the unit and integration tests
89-
test: $(PRE_TARGET)
91+
test: build-dev-image
9092
-docker network create traefik-test-network --driver bridge --subnet 172.31.42.0/24
9193
trap 'docker network rm traefik-test-network' EXIT; \
92-
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK_TEST),) ./script/make.sh generate test-unit binary test-integration
94+
$(if $(IN_DOCKER),$(DOCKER_RUN_TRAEFIK_TEST),) ./script/make.sh generate test-unit binary test-integration
9395

9496
## Run the unit tests
95-
test-unit: $(PRE_TARGET)
97+
test-unit: build-dev-image
9698
-docker network create traefik-test-network --driver bridge --subnet 172.31.42.0/24
9799
trap 'docker network rm traefik-test-network' EXIT; \
98-
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK_TEST)) ./script/make.sh generate test-unit
100+
$(if $(IN_DOCKER),$(DOCKER_RUN_TRAEFIK_TEST)) ./script/make.sh generate test-unit
99101

100102
## Run the integration tests
101-
test-integration: $(PRE_TARGET)
103+
test-integration: build-dev-image
102104
-docker network create traefik-test-network --driver bridge --subnet 172.31.42.0/24
103105
trap 'docker network rm traefik-test-network' EXIT; \
104-
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK_TEST),) ./script/make.sh generate binary test-integration
106+
$(if $(IN_DOCKER),$(DOCKER_RUN_TRAEFIK_TEST),) ./script/make.sh generate binary test-integration
105107

106108
## Pull all images for integration tests
107109
pull-images:
108110
grep --no-filename -E '^\s+image:' ./integration/resources/compose/*.yml | awk '{print $$2}' | sort | uniq | xargs -P 6 -n 1 docker pull
109111

110112
## Validate code and docs
111-
validate-files: $(PRE_TARGET)
112-
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK)) ./script/make.sh generate validate-lint validate-misspell
113+
validate-files: build-dev-image
114+
$(if $(IN_DOCKER),$(DOCKER_RUN_TRAEFIK)) ./script/make.sh generate validate-lint validate-misspell
113115
bash $(CURDIR)/script/validate-shell-script.sh
114116

115117
## Validate code, docs, and vendor
116-
validate: $(PRE_TARGET)
117-
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK)) ./script/make.sh generate validate-lint validate-misspell validate-vendor
118+
validate: build-dev-image
119+
$(if $(IN_DOCKER),$(DOCKER_RUN_TRAEFIK)) ./script/make.sh generate validate-lint validate-misspell validate-vendor
118120
bash $(CURDIR)/script/validate-shell-script.sh
119121

120122
## Clean up static directory and build a Docker Traefik image
@@ -125,6 +127,10 @@ build-image: clean-webui binary
125127
build-image-dirty: binary
126128
docker build -t $(TRAEFIK_IMAGE) .
127129

130+
## Locally build traefik for linux, then shove it an alpine image, with basic tools.
131+
build-image-debug: binary-debug
132+
docker build -t $(TRAEFIK_IMAGE) -f debug.Dockerfile .
133+
128134
## Start a shell inside the build env
129135
shell: build-dev-image
130136
$(DOCKER_RUN_TRAEFIK) /bin/bash
@@ -150,17 +156,17 @@ generate-genconf:
150156
go run ./cmd/internal/gen/
151157

152158
## Create packages for the release
153-
release-packages: generate-webui $(PRE_TARGET)
159+
release-packages: generate-webui build-dev-image
154160
rm -rf dist
155-
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK_NOTTY)) goreleaser release --skip-publish --timeout="90m"
156-
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK_NOTTY)) tar cfz dist/traefik-${VERSION}.src.tar.gz \
161+
$(if $(IN_DOCKER),$(DOCKER_RUN_TRAEFIK_NOTTY)) goreleaser release --skip-publish --timeout="90m"
162+
$(if $(IN_DOCKER),$(DOCKER_RUN_TRAEFIK_NOTTY)) tar cfz dist/traefik-${VERSION}.src.tar.gz \
157163
--exclude-vcs \
158164
--exclude .idea \
159165
--exclude .travis \
160166
--exclude .semaphoreci \
161167
--exclude .github \
162168
--exclude dist .
163-
$(if $(PRE_TARGET),$(DOCKER_RUN_TRAEFIK_NOTTY)) chown -R $(shell id -u):$(shell id -g) dist/
169+
$(if $(IN_DOCKER),$(DOCKER_RUN_TRAEFIK_NOTTY)) chown -R $(shell id -u):$(shell id -g) dist/
164170

165171
## Format the Code
166172
fmt:

build.Dockerfile

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
FROM golang:1.17-alpine
22

3-
RUN apk --update upgrade \
4-
&& apk --no-cache --no-progress add git mercurial bash gcc musl-dev curl tar ca-certificates tzdata \
3+
RUN apk --no-cache --no-progress add git mercurial bash gcc musl-dev curl tar ca-certificates tzdata \
54
&& update-ca-certificates \
65
&& rm -rf /var/cache/apk/*
76

@@ -17,7 +16,7 @@ RUN mkdir -p /usr/local/bin \
1716
RUN curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b $GOPATH/bin v1.44.0
1817

1918
# Download misspell binary to bin folder in $GOPATH
20-
RUN curl -sfL https://raw.githubusercontent.com/client9/misspell/master/install-misspell.sh | bash -s -- -b $GOPATH/bin v0.3.4
19+
RUN curl -sfL https://raw.githubusercontent.com/client9/misspell/master/install-misspell.sh | bash -s -- -b $GOPATH/bin v0.3.4
2120

2221
# Download goreleaser binary to bin folder in $GOPATH
2322
RUN curl -sfL https://gist.githubusercontent.com/traefiker/6d7ac019c11d011e4f131bb2cca8900e/raw/goreleaser.sh | sh

debug.Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM alpine:3.14
2+
# Feel free to add below any helpful dependency for debugging.
3+
# iproute2 is for ss.
4+
RUN apk --no-cache --no-progress add bash curl ca-certificates tzdata lsof iproute2 \
5+
&& update-ca-certificates \
6+
&& rm -rf /var/cache/apk/*
7+
COPY dist/traefik /
8+
EXPOSE 80
9+
VOLUME ["/tmp"]
10+
ENTRYPOINT ["/traefik"]

docs/content/contributing/building-testing.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ $ ls dist/
4545
traefik*
4646
```
4747

48-
The following targets can be executed outside Docker by setting the variable `PRE_TARGET` to an empty string (we don't recommend that):
48+
The following targets can be executed outside Docker by setting the variable `IN_DOCKER` to an empty string (although be aware that some of the tests might fail in that context):
4949

5050
- `test-unit`
5151
- `test-integration`
@@ -55,7 +55,7 @@ The following targets can be executed outside Docker by setting the variable `PR
5555
ex:
5656

5757
```bash
58-
PRE_TARGET= make test-unit
58+
IN_DOCKER= make test-unit
5959
```
6060

6161
### Method 2: Using `go`

exp.Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ RUN npm run build
1414
# BUILD
1515
FROM golang:1.17-alpine as gobuild
1616

17-
RUN apk --update upgrade \
18-
&& apk --no-cache --no-progress add git mercurial bash gcc musl-dev curl tar ca-certificates tzdata \
17+
RUN apk --no-cache --no-progress add git mercurial bash gcc musl-dev curl tar ca-certificates tzdata \
1918
&& update-ca-certificates \
2019
&& rm -rf /var/cache/apk/*
2120

0 commit comments

Comments
 (0)