Skip to content

Commit 6b36159

Browse files
committed
Update Makefile
1 parent e20f525 commit 6b36159

File tree

7 files changed

+96
-78
lines changed

7 files changed

+96
-78
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
# Dependency directories (remove the comment below to include it)
1919
# vendor/
2020

21+
bin/
22+
2123
### Go Patch ###
2224
vendor/
2325
Godeps/

Makefile

Lines changed: 82 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,139 @@
11
SHELL = bash
22
PROJECT_ROOT := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
33

4+
THIS_OS := $(shell uname | cut -d- -f1)
5+
THIS_ARCH := $(shell uname -m)
6+
47
GIT_COMMIT := $(shell git rev-parse HEAD)
58
GIT_DIRTY := $(if $(shell git status --porcelain),+CHANGES)
69

710
GO_LDFLAGS ?= -X=github.com/seashell/drago/version.GitCommit=$(GIT_COMMIT)$(GIT_DIRTY)
811

912
CGO_ENABLED ?= 0
1013

14+
ifeq ($(CI),true)
15+
$(info Running in a CI environment, verbose mode is disabled)
16+
else
17+
VERBOSE="true"
18+
endif
19+
20+
# List of supported OS
21+
SUPPORTED_OSES = Linux
22+
1123
# User defined flags
24+
OS := $(or $(OS),$(O)) ## Define build target OS, e.g linux (coming soon)
25+
ARCH := $(or $(ARCH),$(A)) ## Define build target architecture, e.g amd64 (coming soon)
1226
STATIC := $(or $(STATIC),$(S)) ## If set to 1, build statically linked binary
13-
DOCKER := $(or $(DOCKER),$(D)) ## If set to 1, build using docker container
14-
OS := $(or $(OS),$(O)) # (coming soon) Define build target OS, e.g linux
15-
ARCH := $(or $(ARCH),$(A)) # (coming soon) Define build target architecture, e.g amd64
27+
DOCKER := $(or $(DOCKER),$(D)) ## If set to 1, run build within a Docker container
1628

17-
# Handle static builds
29+
# ---- Handle static builds
1830
ifeq ($(STATIC),1)
19-
GO_LDFLAGS := "${GO_LDFLAGS} -linkmode external -extldflags -static"
31+
GO_LDFLAGS := "${GO_LDFLAGS} -w -extldflags -static"
2032
endif
21-
33+
34+
# ---- In case of a Dockerized build, check if the builder image is available.
2235
ifeq ($(DOCKER),1)
23-
CHECK_DOCKER := $(shell docker images --filter LABEL=com.drago.builder=true -q)
24-
ifeq ($(user),)
25-
# USER retrieved from env, UID from shell.
2636
HOST_USER ?= $(strip $(if $(USER),$(USER),nodummy))
2737
HOST_UID ?= $(strip $(if $(shell id -u),$(shell id -u),4000))
28-
else
29-
# allow override by adding user= and/ or uid= (lowercase!).
30-
# uid= defaults to 0 if user= set (i.e. root).
31-
HOST_USER = $(user)
32-
HOST_UID = $(strip $(if $(uid),$(uid),0))
33-
endif
34-
BUILD_DOCKER := (docker build --label com.drago.builder=true --build-arg HOST_UID=${HOST_UID} --build-arg HOST_USER=${HOST_USER} -t drago_builder . -f ./docker/Dockerfile.builder)
38+
DOCKER_BUILDER_IMAGE_AVAILABLE := $(shell docker images --filter LABEL=com.drago.builder=true -q)
39+
BUILD_DOCKER_BUILDER_IMAGE_CMD := (docker build --label com.drago.builder=true --build-arg HOST_UID=${HOST_UID} --build-arg HOST_USER=${HOST_USER} -t drago_builder . -f ./build/Dockerfile.builder)
3540
endif
3641

37-
# targets
38-
ALL_TARGETS += linux_amd64 \
42+
# =========== Targets ===========
43+
44+
ifeq (Linux,$(THIS_OS))
45+
ALL_TARGETS = linux_amd64
46+
endif
3947

4048
default: help
4149

42-
build/linux_amd64/drago: CMD='CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 \
50+
# ====> Current platform
51+
.PHONY: dev
52+
dev: GOOS=$(shell go env GOOS)
53+
dev: GOARCH=$(shell go env GOARCH)
54+
dev: DEV_TARGET=$(GOOS)_$(GOARCH)
55+
dev: ## Build for the current platform
56+
@rm -rf $(PROJECT_ROOT)/bin
57+
@$(MAKE) --no-print-directory $(DEV_TARGET)
58+
59+
# ====> Container
60+
.PHONY: container
61+
container: ## Build container with the Drago binary inside
62+
@$(MAKE) ui dev STATIC=1
63+
@echo "==> Building container image "drago:latest" ..."
64+
@docker build -t drago:latest . -f ./build/Dockerfile.linux_amd64
65+
66+
# ====> All
67+
.PHONY: all
68+
all: clean ui $(foreach t,$(ALL_TARGETS),$(t)) ## Build all targets supported by this platform
69+
@echo "==> Results:"
70+
@tree --dirsfirst $(PROJECT_ROOT)/bin
71+
72+
# ====> Tidy
73+
.PHONY: tidy
74+
tidy:
75+
@echo "--> Tidying up Drago modules"
76+
@go mod tidy
77+
78+
# ====> Linux AMD 64
79+
.PHONY: linux_amd64
80+
linux_amd64: CMD='CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 \
4381
go build \
4482
-trimpath \
45-
-ldflags $(GO_LDFLAGS) \
46-
-o "$@"'
47-
build/linux_amd64/drago: $(SOURCE_FILES) ## Build drago for linux/amd64
48-
@echo "==> Building $@ with tags $(GO_TAGS)..."
83+
-ldflags ""$(GO_LDFLAGS)"" \
84+
-o "bin/$@/drago"'
85+
linux_amd64: $(SOURCE_FILES) ## Build Drago for linux/amd64
86+
@echo "==> Building $@..."
87+
@echo "==> COMMAND $(CMD)..."
4988
ifeq ($(DOCKER),1)
50-
ifeq ($(CHECK_DOCKER),)
51-
@echo "==> Building docker container builder image..."
52-
@$(call BUILD_DOCKER)
89+
ifeq ($(DOCKER_BUILDER_IMAGE_AVAILABLE),)
90+
@echo "==> Building Docker builder image..."
91+
@$(call BUILD_DOCKER_BUILDER_IMAGE_CMD)
5392
endif
5493
docker run --rm -v ${PROJECT_ROOT}:${PROJECT_ROOT} --workdir=${PROJECT_ROOT} drago_builder \
5594
/bin/sh -c ${CMD}
5695
else
5796
@eval ${CMD}
5897
endif
5998

60-
build/linux_arm64/drago: # (coming soon) Build drago for linux/arm64
99+
# ====> Linux ARM 64
100+
.PHONY: linux/arm64
101+
linux/arm64: ## Build Drago for linux/arm64 (coming soon)
61102
@echo "==> Coming soon..."
62103

63-
build/linux_arm/drago: # (coming soon) Build drago for linux/arm
104+
# ====> Linux ARM
105+
.PHONY: linux/arm
106+
linux/arm: ## Build drago for linux/arm (coming soon)
64107
@echo "==> Coming soon..."
65108

109+
# ====> Web UI
66110
.PHONY: ui
67111
ui: CMD="go generate"
68-
ui: ## Generate UI .go bindings
69-
@echo "==> Generating UI .go bindings..."
112+
ui: ## Build Web UI
113+
@echo "==> Building Web UI..."
70114
ifeq ($(DOCKER),1)
71-
ifeq ($(CHECK_DOCKER),)
72-
@echo "==> Generating docker builder..."
73-
@$(call BUILD_DOCKER)
115+
ifeq ($(DOCKER_BUILDER_IMAGE_AVAILABLE),)
116+
@echo "==> Building Docker builder image..."
117+
@$(call BUILD_DOCKER_BUILDER_IMAGE_CMD)
74118
endif
75119
docker run --rm -v ${PROJECT_ROOT}:${PROJECT_ROOT} --workdir=${PROJECT_ROOT} drago_builder \
76120
/bin/sh -c ${CMD}
77121
else
78122
@eval ${CMD}
79123
endif
80124

81-
.PHONY: dev
82-
dev: GOOS=$(shell go env GOOS)
83-
dev: GOARCH=$(shell go env GOARCH)
84-
dev: DEV_TARGET=build/$(GOOS)_$(GOARCH)/drago
85-
dev: ## Build for the current development platform
86-
@echo "==> Removing old development binary..."
87-
@rm -rf $(PROJECT_ROOT)/build
88-
@$(MAKE) --no-print-directory $(DEV_TARGET)
89-
90-
.PHONY: container
91-
container: ## Build container with drago binary inside
92-
@$(MAKE) ui dev STATIC=1
93-
@echo "==> Building container image "drago:latest" ..."
94-
@docker build -t drago:latest . -f ./docker/Dockerfile.linux_amd64
95-
96-
.PHONY: release
97-
release: clean ui $(foreach t,$(ALL_TARGETS),build/$(t)/drago) ## Build all release packages which can be built on this platform
98-
@echo "==> Results:"
99-
@tree --dirsfirst $(PROJECT_ROOT)/build
100-
101-
102125
.PHONY: clean
103126
clean: ## Remove build artifacts
104127
@echo "==> Cleaning build artifacts..."
105-
@rm -rf "$(PROJECT_ROOT)/build/"
106-
@rm -rf "$(PROJECT_ROOT)/ui/build/"
128+
@rm -rf "$(PROJECT_ROOT)/bin/"
129+
@rm -rf "$(PROJECT_ROOT)/ui/build/*"
107130
@rm -rf "$(PROJECT_ROOT)/ui/node_modules/"
108131

109132
HELP_FORMAT=" \033[36m%-25s\033[0m %s\n"
110133
EG_FORMAT=" \033[36m%s\033[0m %s\n"
134+
111135
.PHONY: help
112-
help: ## Display this usage information
136+
help: ## Display usage information
113137
@echo "Valid targets:"
114138
@grep -E '^[^ ]+:.*?## .*$$' $(MAKEFILE_LIST) | \
115139
sort | \
@@ -126,6 +150,6 @@ help: ## Display this usage information
126150
{printf $(HELP_FORMAT), $$1, $$2}'
127151
@echo ""
128152
@echo "Examples:"
129-
@printf $(EG_FORMAT) "~${PWD}" "$$ make ui dev DOCKER=1"
130153
@printf $(EG_FORMAT) "~${PWD}" "$$ make dev STATIC=1"
154+
@printf $(EG_FORMAT) "~${PWD}" "$$ make ui dev DOCKER=1"
131155
@printf $(EG_FORMAT) "~${PWD}" "$$ make container DOCKER=1"

build/Dockerfile.builder

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
FROM golang:1.13.8-stretch as debian
1+
FROM golang:1.16.2-stretch as drago-builder
2+
3+
ARG HOST_UID=${HOST_UID}
4+
ARG HOST_USER=${HOST_USER}
25

36
RUN curl -sS http://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
47
echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
5-
curl -sL http://deb.nodesource.com/setup_13.x | bash - && \
8+
curl -sL http://deb.nodesource.com/setup_15.x | bash - && \
69
apt-get install -y nodejs && \
710
apt-get update && \
811
apt-get remove cmdtest && \
9-
apt-get install -y yarn
12+
apt-get install -y yarn
1013

1114
RUN apt-get install -y gcc-arm-linux-gnueabihf libc6-dev-armhf-cross \
1215
gcc-aarch64-linux-gnu libc6-dev-arm64-cross
1316

14-
FROM debian
15-
ARG HOST_UID=${HOST_UID}
16-
ARG HOST_USER=${HOST_USER}
17-
1817
RUN if [ "${HOST_USER}" != "root" ]; then \
1918
(adduser -q --gecos "" --home /home/${HOST_USER} --disabled-password -u ${HOST_UID} ${HOST_USER} \
2019
&& chown -R "${HOST_UID}:${HOST_UID}" /home/${HOST_USER}); \
2120
fi
21+
2222
USER ${HOST_USER}

build/Dockerfile.linux_amd64

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
FROM alpine:3.10
1+
FROM alpine:3.13
22

3-
RUN apk add -U wireguard-tools
4-
5-
COPY ./build/linux_amd64/drago ./drago
3+
WORKDIR /home
64

7-
RUN ./drago --version
5+
RUN apk add -U wireguard-tools
86

9-
RUN mkdir -p /opt/drago/client
7+
COPY ./bin/linux_amd64/drago ./drago
108

11-
ENTRYPOINT ./drago agent --config=./config.hcl
9+
ENTRYPOINT [ "./drago" ]

build/drago

-15.6 MB
Binary file not shown.

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ require (
1313
github.com/joho/godotenv v1.3.0
1414
github.com/pkg/errors v0.9.1
1515
github.com/rodaine/table v1.0.1
16-
github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636 // indirect
17-
github.com/shurcooL/go-goon v0.0.0-20210110234559-7585751d9a17 // indirect
1816
github.com/sirupsen/logrus v1.8.1
1917
github.com/vishvananda/netlink v1.1.1-0.20200604160102-dc0e1b988c57
2018
github.com/vmihailenco/msgpack v4.0.4+incompatible

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
172172
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
173173
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
174174
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
175-
github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636 h1:aSISeOcal5irEhJd1M+IrApc0PdcN7e7Aj4yuEnOrfQ=
176-
github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
177-
github.com/shurcooL/go-goon v0.0.0-20210110234559-7585751d9a17 h1:lRAUE0dIvigSSFAmaM2dfg7OH8T+a8zJ5smEh09a/GI=
178-
github.com/shurcooL/go-goon v0.0.0-20210110234559-7585751d9a17/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ=
179175
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
180176
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
181177
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=

0 commit comments

Comments
 (0)