forked from gliderlabs/logspout
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
165 lines (138 loc) · 5.22 KB
/
Copy pathMakefile
File metadata and controls
165 lines (138 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
NAME=logspout
VERSION=$(shell cat VERSION)
# max image size of 40MB
MAX_IMAGE_SIZE := 40000000
GOBIN := $(shell go env GOPATH | awk -F ":" '{ print $$1 }')/bin
GOLANGCI_LINT_VERSION := v2.12.2
ifeq ($(shell uname), Darwin)
XARGS_ARG="-L1"
endif
GOPACKAGES ?= $(shell go list ./... | egrep -v 'custom|vendor')
TEST_ARGS ?= -race
ifdef TEST_RUN
TESTRUN := -run ${TEST_RUN}
endif
build-dev:
docker build -f Dockerfile.dev -t $(NAME):dev .
dev: build-dev
@docker run --rm \
-e DEBUG=true \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(PWD):/go/src/github.com/gliderlabs/logspout \
-p 8000:80 \
-e ROUTE_URIS=$(ROUTE) \
$(NAME):dev
build:
mkdir -p build
docker build -t $(NAME):$(VERSION) .
docker save $(NAME):$(VERSION) | gzip -9 > build/$(NAME)_$(VERSION).tgz
build-custom:
docker tag $(NAME):$(VERSION) gliderlabs/$(NAME):master
cd custom && docker build -t $(NAME):custom .
lint-requirements:
ifeq ($(shell which golangci-lint), )
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) $(GOLANGCI_LINT_VERSION)
endif
lint: lint-requirements
$(GOBIN)/golangci-lint run
lint-ci-direct: lint-requirements
$(GOBIN)/golangci-lint --verbose run
lint-ci: build-dev
docker run \
-v $(PWD):/go/src/github.com/gliderlabs/logspout \
$(NAME):dev make -e lint-ci-direct
test: build-dev
docker run \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(PWD):/go/src/github.com/gliderlabs/logspout \
-e TEST_ARGS="" \
-e DEBUG=$(DEBUG) \
$(NAME):dev make -e test-direct
test-direct:
go test -p 1 -v $(TEST_ARGS) $(GOPACKAGES) $(TESTRUN)
# Integration tests: connect to Docker via DOCKER_HOST (or auto-detects Colima
# socket), start real containers, and verify log forwarding end-to-end.
test-integration:
go test -tags integration -p 1 -v -timeout 120s ./integration/...
# Journal integration tests: cross-compile for the Colima VM (linux/arm64),
# copy the binary into the VM, and run it there so it can access journald.
test-integration-journal:
GOARCH=arm64 GOOS=linux \
go test -c -tags 'integration journal' -o /tmp/logspout-inttest ./integration/...
colima ssh -- /tmp/logspout-inttest -test.v -test.timeout 120s
test-image-size:
@if [ $(shell docker inspect -f '{{ .Size }}' $(NAME):$(VERSION)) -gt $(MAX_IMAGE_SIZE) ]; then \
echo ERROR: image size greater than $(MAX_IMAGE_SIZE); \
exit 2; \
fi
test-tls:
docker run -d --name $(NAME)-tls \
-v /var/run/docker.sock:/var/run/docker.sock \
$(NAME):$(VERSION) syslog+tls://logs3.papertrailapp.com:54202
sleep 2
docker logs $(NAME)-tls
docker inspect --format='{{ .State.Running }}' $(NAME)-tls | grep true
docker stop $(NAME)-tls || true
docker rm $(NAME)-tls || true
test-healthcheck:
docker run -d --name $(NAME)-healthcheck \
-p 8000:80 \
-v /var/run/docker.sock:/var/run/docker.sock \
$(NAME):$(VERSION)
sleep 5
docker logs $(NAME)-healthcheck
docker inspect --format='{{ .State.Running }}' $(NAME)-healthcheck | grep true
curl --head --silent localhost:8000/health | grep "200 OK"
docker stop $(NAME)-healthcheck || true
docker rm $(NAME)-healthcheck || true
test-custom:
docker run --name $(NAME)-custom $(NAME):custom || true
docker logs $(NAME)-custom 2>&1 | grep -q logstash
docker rmi gliderlabs/$(NAME):master || true
docker rm $(NAME)-custom || true
test-tls-custom:
docker run -d --name $(NAME)-tls-custom \
-v /var/run/docker.sock:/var/run/docker.sock \
$(NAME):custom syslog+tls://logs3.papertrailapp.com:54202
sleep 2
docker logs $(NAME)-tls-custom
docker inspect --format='{{ .State.Running }}' $(NAME)-tls-custom | grep true
docker stop $(NAME)-tls-custom || true
docker rm $(NAME)-tls-custom || true
.PHONY: release
release:
rm -rf release && mkdir release
go get github.com/progrium/gh-release/...
cp build/* release
gh-release create gliderlabs/$(NAME) $(VERSION) \
$(shell git rev-parse --abbrev-ref HEAD) $(VERSION)
.PHONY: circleci
circleci:
ifneq ($(CIRCLE_BRANCH), release)
echo build-$$CIRCLE_BUILD_NUM > VERSION
endif
.PHONY: clean
clean:
rm -rf build/
docker rm $(shell docker ps -aq) || true
docker rmi $(NAME):dev $(NAME):$(VERSION) || true
docker rmi $(shell docker images -f 'dangling=true' -q) || true
.PHONY: publish-requirements
publish-requirements:
mkdir -vp ~/.docker/cli-plugins/
curl --silent -L --output ~/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/v0.3.1/buildx-v0.3.1.linux-amd64
chmod a+x ~/.docker/cli-plugins/docker-buildx
docker run -it --rm --privileged tonistiigi/binfmt --install all
docker buildx create --use --name mybuilder
.PHONY: publish-test
publish-test:
docker buildx build --load --platform linux/amd64 -t gliderlabs/$(NAME):linux-amd64-${CIRCLE_BRANCH} .
docker buildx build --load --platform linux/arm/v6 -t gliderlabs/$(NAME):linux-arm-v6-${CIRCLE_BRANCH} .
docker buildx build --load --platform linux/arm64 -t gliderlabs/$(NAME):linux-arm64-${CIRCLE_BRANCH} .
docker images
.PHONY: publish-master
publish-master:
docker buildx build --push --platform linux/amd64,linux/arm/v6,linux/arm64 -t gliderlabs/$(NAME):master -t gliderlabs/$(NAME):latest .
.PHONY: publish-release
publish-release:
docker buildx build --push --platform linux/amd64,linux/arm/v6,linux/arm64 -t gliderlabs/$(NAME):$(VERSION) .