-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (90 loc) · 3.61 KB
/
Makefile
File metadata and controls
116 lines (90 loc) · 3.61 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
.PHONY: dir check_connect_timeout deb-image deb deb-lint deb-ci release-prep deb-test
GO ?= go
GOBUILDFLAGS ?=
LDFLAGS ?=
MODVER ?= 1.20
DOCKERCFGDIR ?=
STOREROOT ?=
COMPOSEROOT ?=
CONNECTTIMEOUT ?=
BASESYSTEMCONFIG ?=
bd = bin
exe = composectl
linter = golangci-lint
DEB_IMAGE ?= ghcr.io/foundriesio/debuild-go-min:trixie
DEB_DOCKERFILE ?= debian/Dockerfile
DEB_OUT_DIR ?= $(bd)/deb
PKG := github.com/foundriesio/composeapp/cmd/composectl/cmd
VERSION ?= $(shell git describe --tags --always --dirty --abbrev=7 --match "v*" 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse --short=7 HEAD 2>/dev/null || echo "none")
DATE ?= $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
LDFLAGS := -X '$(PKG).Version=$(VERSION)' -X '$(PKG).Commit=$(COMMIT)' -X '$(PKG).Date=$(DATE)'
ifdef DOCKERCFGDIR
LDFLAGS += -X 'github.com/foundriesio/composeapp/cmd/composectl/cmd.overrideConfigDir=$(DOCKERCFGDIR)'
endif
ifdef STOREROOT
LDFLAGS += -X 'github.com/foundriesio/composeapp/cmd/composectl/cmd.storeRoot=$(STOREROOT)'
endif
ifdef COMPOSEROOT
LDFLAGS += -X 'github.com/foundriesio/composeapp/cmd/composectl/cmd.composeRoot=$(COMPOSEROOT)'
endif
ifdef CONNECTTIMEOUT
LDFLAGS += -X 'github.com/foundriesio/composeapp/cmd/composectl/cmd.defConnectTimeout=$(CONNECTTIMEOUT)'
endif
ifdef BASESYSTEMCONFIG
LDFLAGS += -X 'github.com/foundriesio/composeapp/cmd/composectl/cmd.baseSystemConfig=$(BASESYSTEMCONFIG)'
endif
ifdef LDFLAGS
GOBUILDFLAGS += -ldflags="$(LDFLAGS)"
endif
all: $(exe)
check_connect_timeout:
@if [ -n "$(strip $(CONNECTTIMEOUT))" ] && ! [ "$(strip $(CONNECTTIMEOUT))" -eq "$(strip $(CONNECTTIMEOUT))" ] 2>/dev/null; then \
echo "ERR: invalid CONNECTTIMEOUT value ($(CONNECTTIMEOUT)); it must be integer."; \
exit 1; \
fi
format:
@$(GO) fmt ./...
test-unit:
@$(GO) test -v ./pkg/compose/... ./internal... ./pkg/docker/...
$(bd):
@mkdir -p $@
$(exe): $(bd) check_connect_timeout
$(GO) build -tags publish $(GOBUILDFLAGS) -o $(bd)/$@ cmd/composectl/main.go
clean:
@rm -r $(bd)
check: format
$(linter) run
tidy-mod:
go mod tidy -go=$(MODVER)
# the followinf targets should be run only in the dev container
preload-images:
test/fixtures/preload-images.sh
test-e2e: $(exe) preload-images
@$(GO) test -v ./...
test-smoke: $(exe) preload-images
@$(GO) test -v -run TestSmoke test/integration/smoke_test.go
deb-image:
@set -e; \
if docker image inspect "$(DEB_IMAGE)" >/dev/null 2>&1; then \
echo "Using local image: $(DEB_IMAGE)"; \
elif docker pull "$(DEB_IMAGE)"; then \
echo "Pulled image: $(DEB_IMAGE)"; \
else \
echo "Image not found locally or in registry, building: $(DEB_IMAGE)"; \
docker build -t "$(DEB_IMAGE)" -f "$(DEB_DOCKERFILE)" .; \
fi
deb: deb-image
@mkdir -p $(DEB_OUT_DIR)
docker run --rm -v "$$(pwd)":/src:ro -v "$$(pwd)/$(DEB_OUT_DIR)":/out:rw $(DEB_IMAGE) /src/debian/build-in-docker.sh
deb-lint:
docker run --rm -u "$$(id -u):$$(id -g)" -v "$$(pwd)/$(DEB_OUT_DIR)":/out:ro $(DEB_IMAGE) bash -lc 'lintian -I /out/*.changes'
deb-test:
docker run --rm -v "$$PWD/bin/deb":/out:ro debian:trixie \
bash -lc 'set -eux && apt-get update && apt-get install -y --no-install-recommends /out/composectl_*.deb && composectl --help >/dev/null'
docker run --rm -v "$$PWD/bin/deb":/out:ro ubuntu:noble \
bash -lc 'set -eux && apt-get update && apt-get install -y --no-install-recommends /out/composectl_*.deb && composectl --help >/dev/null'
deb-ci: deb deb-lint
release-prep: deb-image
@test -n "$(VERSION)" || (echo "Usage: make $@ VERSION=0.1.1" >&2; exit 2)
@docker run --rm -it -u "$$(id -u):$$(id -g)" -v "$$PWD":/src:rw -w /src $(DEB_IMAGE) /src/debian/release-prep-changelog-in-docker.sh $(VERSION)