2022-04-15 13:44:08 +00:00
---
title: "Traefik Building & Testing Documentation"
description: "Compile and test your own Traefik Proxy! Learn how to build your own Traefik binary from the sources, and read the technical documentation."
---
2019-02-26 13:50:07 +00:00
# Building and Testing
Compile and Test Your Own Traefik!
{: .subtitle }
2022-11-15 18:34:04 +00:00
You want to build your own Traefik binary from the sources?
2019-02-26 13:50:07 +00:00
Let's see how.
## Building
2024-01-09 16:00:07 +00:00
You need:
- [Docker ](https://github.com/docker/docker "Link to website of Docker" )
- `make`
- [Go ](https://go.dev/ "Link to website of Go" )
- [misspell ](https://github.com/golangci/misspell )
- [shellcheck ](https://github.com/koalaman/shellcheck )
- [Tailscale ](https://tailscale.com/ ) if you are using Docker Desktop
2019-02-26 13:50:07 +00:00
!!! tip "Source Directory"
2019-05-10 15:24:06 +00:00
2020-09-16 13:46:04 +00:00
It is recommended that you clone Traefik into the `~/go/src/github.com/traefik/traefik` directory.
2019-02-26 13:50:07 +00:00
This is the official golang workspace hierarchy that will allow dependencies to be properly resolved.
!!! note "Environment"
Set your `GOPATH` and `PATH` variable to be set to `~/go` via:
2019-05-10 15:24:06 +00:00
2019-02-26 13:50:07 +00:00
```bash
export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin
```
2019-05-10 15:24:06 +00:00
2019-02-26 13:50:07 +00:00
For convenience, add `GOPATH` and `PATH` to your `.bashrc` or `.bash_profile`
2019-05-10 15:24:06 +00:00
2019-02-26 13:50:07 +00:00
Verify your environment is setup properly by running `$ go env` .
Depending on your OS and environment, you should see an output similar to:
2019-05-10 15:24:06 +00:00
2019-02-26 13:50:07 +00:00
```bash
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/< yourusername > /go"
GORACE=""
## ... and the list goes on
```
2024-01-09 16:00:07 +00:00
### Build Traefik
2019-02-26 13:50:07 +00:00
Once you've set up your go environment and cloned the source repository, you can build Traefik.
2019-12-17 13:30:06 +00:00
2019-12-12 15:32:06 +00:00
```bash
2024-01-09 16:00:07 +00:00
$ make binary
2024-01-17 10:12:05 +00:00
SHA: 8fddfe118288bb5280eb5e77fa952f52def360b4 cheddar 2024-01-11_03:14:57PM
CGO_ENABLED=0 GOGC=off GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w \
-X github.com/traefik/traefik/v2/pkg/version.Version=8fddfe118288bb5280eb5e77fa952f52def360b4 \
-X github.com/traefik/traefik/v2/pkg/version.Codename=cheddar \
-X github.com/traefik/traefik/v2/pkg/version.BuildDate=2024-01-11_03:14:57PM" \
-installsuffix nocgo -o "./dist/darwin/arm64/traefik" ./cmd/traefik
2019-02-26 13:50:07 +00:00
2024-01-09 16:00:07 +00:00
$ ls dist/
traefik*
2019-02-26 13:50:07 +00:00
```
2024-01-09 16:00:07 +00:00
You will find the Traefik executable (`traefik`) in the `./dist` directory.
2019-02-26 13:50:07 +00:00
## Testing
Run unit tests using the `test-unit` target.
Run integration tests using the `test-integration` target.
Run all tests (unit and integration) using the `test` target.
```bash
$ make test-unit
2024-01-17 10:12:05 +00:00
GOOS=darwin GOARCH=arm64 go test -cover "-coverprofile=cover.out" -v ./pkg/... ./cmd/...
2019-02-26 13:50:07 +00:00
+ go test -cover -coverprofile=cover.out .
2020-09-16 13:46:04 +00:00
ok github.com/traefik/traefik 0.005s coverage: 4.1% of statements
2019-02-26 13:50:07 +00:00
Test success
```
For development purposes, you can specify which tests to run by using (only works the `test-integration` target):
2024-01-09 16:00:07 +00:00
??? note "Configuring Tailscale for Docker Desktop user"
2019-02-26 13:50:07 +00:00
2024-01-09 16:00:07 +00:00
Create `tailscale.secret` file in `integration` directory.
This file need to contains a [Tailscale auth key ](https://tailscale.com/kb/1085/auth-keys )
(an ephemeral, but reusable, one is recommended).
2019-02-26 13:50:07 +00:00
2024-01-09 16:00:07 +00:00
Add this section to your tailscale ACLs to auto-approve the routes for the
containers in the docker subnet:
2019-02-26 13:50:07 +00:00
2024-01-09 16:00:07 +00:00
```json
"autoApprovers": {
// Allow myself to automatically
// advertize routes for docker networks
"routes": {
"172.31.42.0/24": ["your_tailscale_identity"],
},
},
```
```bash
# Run every tests in the MyTest suite
TESTFLAGS="-test.run TestAccessLogSuite" make test-integration
2019-02-26 13:50:07 +00:00
2024-01-09 16:00:07 +00:00
# Run the test "MyTest" in the MyTest suite
TESTFLAGS="-test.run TestAccessLogSuite -testify.m ^TestAccessLog$" make test-integration
2019-02-26 13:50:07 +00:00
```