Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit e6a655f

Browse files
committed
Add a BUILDING document and self described makefile(s)
- `BUILDING.md` holds instruction to help building `docker-app` from sources (with or without docker) - Adds a `help` target to `Makefile` and `docker.Makefile` 👼 Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 27cfe8b commit e6a655f

3 files changed

Lines changed: 117 additions & 17 deletions

File tree

BUILDING.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Building `docker-app` from source
2+
3+
This guide is useful if you intend to contribute on `docker/app`. Thanks for your
4+
effort. Every contribution is very appreciated.
5+
6+
This doc includes:
7+
* [Build requirements](#build-requirements)
8+
* [Using Go](#build-using-go)
9+
* [Using Docker](#build-using-docker)
10+
* [Testing](#testing-docker-app)
11+
12+
## Build requirements
13+
14+
To build the `docker-app`, at least one of the following build system
15+
dependencies are required:
16+
17+
* Docker (17.12 or above)
18+
* Go (1.10.x or above)
19+
20+
You will also need the following tools:
21+
22+
* GNU Make
23+
* [`dep`](https://github.com/golang/dep)
24+
25+
## Build using Go
26+
27+
First you need to setup your Go development environment. You can follow this
28+
guideline [How to write go code](https://golang.org/doc/code.html) and at the
29+
end you need to have `GOPATH` set in your environment.
30+
31+
At this point you can use `go` to checkout `docker-app` in your `GOPATH`:
32+
33+
```sh
34+
go get github.com/docker/app
35+
```
36+
37+
You are ready to build `docker-app` yourself!
38+
39+
`docker-app` uses `make` to create a repeatable build flow. It means that you
40+
can run:
41+
42+
```sh
43+
make
44+
```
45+
46+
This is going to build all the project binaries in the `./bin/`
47+
directory, run tests (unit and end-to-end).
48+
49+
```sh
50+
make bin/docker-app # builds the docker-app binary
51+
make bin/docker-app-darwin # builds the docker-app binary for darwin
52+
make bin/docker-app-windows.exe # builds the docker-app binary for windows
53+
54+
make lint # run the linter on the sources
55+
make test-unit # run the unit tests
56+
make test-e2e # run the end-to-end tests
57+
```
58+
59+
Vendoring of external imports uses the [`dep`](https://github.com/golang/dep) tool.
60+
Please refer to its documentation if you need to update a dependency.
61+
62+
## Build using Docker
63+
64+
If you don't have Go installed but Docker is present, you can also use
65+
`docker.Makefile` to build `docker-app` and run tests. This
66+
`docker.Makefile` is used by our continuous integration too.
67+
68+
```sh
69+
make -f docker.Makefile # builds cross binaries build and tests
70+
make -f docker.Makefile cross # builds cross binaries (linux, darwin, windows)
71+
72+
make -f docker.Makefile lint # run the linter on the sources
73+
make -f docker.Makefile test-unit # run the unit tests
74+
make -f docker.Makefile test-e2e # run the end-to-end tests
75+
```
76+
77+
## Testing docker-app
78+
79+
During the automated CI, the unit tests and end-to-end tests are run as
80+
part of the PR validation. As a developer you can run these tests
81+
locally by using any of the following `Makefile` targets:
82+
83+
- `make test`: run all non-end-to-end tests
84+
- `make test-e2e`: run all end-to-end tests
85+
86+
To execute a specific test or set of tests you can use the `go test`
87+
capabilities without using the `Makefile` targets. The following
88+
examples show how to specify a test name and also how to use the flag
89+
directly against `go test` to run root-requiring tests.
90+
91+
```sh
92+
# run the test <TEST_NAME>:
93+
go test -v -run "<TEST_NAME>" .
94+
```

Makefile

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ check_go_env:
99
@test $$(go list) = "$(PKG_NAME)" || \
1010
(echo "Invalid Go environment" && false)
1111

12-
cross: bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-windows.exe
12+
cross: bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-windows.exe ## cross-compile binaries (linux, darwin, windows)
1313

1414
e2e-cross: bin/$(BIN_NAME)-e2e-linux bin/$(BIN_NAME)-e2e-darwin bin/$(BIN_NAME)-e2e-windows.exe
1515

@@ -26,17 +26,17 @@ bin/%: cmd/% check_go_env
2626

2727
check: lint test
2828

29-
test: test-unit test-e2e
29+
test: test-unit test-e2e ## run all tests
3030

31-
lint:
31+
lint: ## run linter(s)
3232
@echo "Linting..."
3333
@gometalinter --config=gometalinter.json
3434

35-
test-e2e: bin/$(BIN_NAME)
35+
test-e2e: bin/$(BIN_NAME) ## run end-to-end tests
3636
@echo "Running e2e tests..."
3737
$(GO_TEST) ./e2e/
3838

39-
test-unit:
39+
test-unit: ## run unit tests
4040
@echo "Running unit tests..."
4141
$(GO_TEST) $(shell go list ./... | grep -vE '/e2e')
4242

@@ -53,20 +53,23 @@ coverage-test-e2e: coverage-bin
5353
@$(call mkdir,_build/cov)
5454
DOCKERAPP_BINARY=../e2e/coverage-bin $(GO_TEST) -v ./e2e
5555

56-
coverage: coverage-test-unit coverage-test-e2e
56+
coverage: coverage-test-unit coverage-test-e2e ## run tests with coverage
5757
go install ./vendor/github.com/wadey/gocovmerge/
5858
gocovmerge _build/cov/*.out > _build/cov/all.out
5959
go tool cover -func _build/cov/all.out
6060
go tool cover -html _build/cov/all.out -o _build/cov/coverage.html
6161

62-
clean:
62+
clean: ## clean build artifacts
6363
$(call rm,bin)
6464
$(call rm,_build)
6565
$(call rm,docker-app-*.tar.gz)
6666

67-
vendor:
67+
vendor: ## update vendoring
6868
$(call rm,vendor)
6969
dep ensure -v
7070

71-
.PHONY: cross e2e-cross test check lint test-unit test-e2e coverage coverage-bin coverage-test-unit coverage-test-e2e clean vendor
71+
help: ## this help
72+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
73+
74+
.PHONY: cross e2e-cross test check lint test-unit test-e2e coverage coverage-bin coverage-test-unit coverage-test-e2e clean vendor help
7275
.DEFAULT: all

docker.Makefile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ create_bin:
2323
build_dev_image:
2424
docker build --target=dev -t $(DEV_IMAGE_NAME) .
2525

26-
shell: build_dev_image
26+
shell: build_dev_image ## run a shell in the docker build image
2727
docker run -ti --rm $(DEV_IMAGE_NAME) bash
2828

29-
cross: create_bin
29+
cross: create_bin ## cross-compile binaries (linux, darwin, windows)
3030
docker build --target=$* -t $(CROSS_IMAGE_NAME) .
3131
docker create --name $(CROSS_CTNR_NAME) $(CROSS_IMAGE_NAME) noop
3232
docker cp $(CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-linux
@@ -56,16 +56,16 @@ tars:
5656
tar czf bin/$(BIN_NAME)-windows.tar.gz -C bin $(BIN_NAME)-windows.exe
5757
tar czf bin/$(BIN_NAME)-e2e-windows.tar.gz -C bin $(BIN_NAME)-e2e-windows.exe
5858

59-
test: test-unit test-e2e
59+
test: test-unit test-e2e ## run all tests
6060

61-
test-unit: build_dev_image
61+
test-unit: build_dev_image ## run unit tests
6262
docker run --rm $(DEV_IMAGE_NAME) make test-unit
6363

64-
test-e2e: build_dev_image
64+
test-e2e: build_dev_image ## run end-to-end tests
6565
docker run -v /var/run:/var/run:ro --rm $(DEV_IMAGE_NAME) make bin/$(BIN_NAME) test-e2e
6666

6767
COV_LABEL := com.docker.app.cov-run=$(TAG)
68-
coverage: build_dev_image
68+
coverage: build_dev_image ## run tests with coverage
6969
@$(call mkdir,_build)
7070
docker run -v /var/run:/var/run:ro --name $(COV_CTNR_NAME) -tid $(DEV_IMAGE_NAME) make COMMIT=${COMMIT} TAG=${TAG} coverage
7171
docker logs -f $(COV_CTNR_NAME)
@@ -76,7 +76,7 @@ gradle-test:
7676
tar cf - Dockerfile.gradle bin/docker-app-linux integrations/gradle | docker build -t $(GRADLE_IMAGE_NAME) -f Dockerfile.gradle -
7777
docker run --rm $(GRADLE_IMAGE_NAME) bash -c "./gradlew --stacktrace build && cd example && gradle renderIt"
7878

79-
lint:
79+
lint: ## run linter(s)
8080
$(info Linting...)
8181
docker build -t $(LINT_IMAGE_NAME) -f Dockerfile.lint .
8282
docker run --rm $(LINT_IMAGE_NAME) make lint
@@ -85,4 +85,7 @@ vendor: build_dev_image
8585
$(info Vendoring...)
8686
docker run --rm $(DEV_IMAGE_NAME) sh -c "make vendor && hack/check-git-diff vendor"
8787

88-
.PHONY: lint test-e2e test-unit test cross e2e-cross coverage gradle-test shell build_dev_image tars vendor
88+
help: ## this help
89+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
90+
91+
.PHONY: lint test-e2e test-unit test cross e2e-cross coverage gradle-test shell build_dev_image tars vendor help

0 commit comments

Comments
 (0)