Adding support for multi-architecture images and binaries (#184)

* Allow Dockerfile --build-args to override GOOS and GOARCH defaults

Allow Dockerfile --build-args to override GOOS and GOARCH defaults

Support building multi architecture binaries

remove default OS and ARCH to avoid tag confusion when compiling image through Makefile

Tag image with corrosponding OS and ARCH build variables

updating Makefile

Signed-off-by: Michael Fornaro <20387402+xUnholy@users.noreply.github.com>

* remove duplicate import on windows_service.go

Signed-off-by: Michael Fornaro <20387402+xUnholy@users.noreply.github.com>
This commit is contained in:
Michael Fornaro 2020-05-29 11:06:27 +10:00 committed by GitHub
parent 046be63253
commit be0514c5c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 15 deletions

View File

@ -1,8 +1,11 @@
# use a builder image for building cloudflare # use a builder image for building cloudflare
ARG TARGET_GOOS
ARG TARGET_GOARCH
FROM golang:1.13.3 as builder FROM golang:1.13.3 as builder
ENV GO111MODULE=on ENV GO111MODULE=on \
ENV CGO_ENABLED=0 CGO_ENABLED=0 \
ENV GOOS=linux TARGET_GOOS=${TARGET_GOOS} \
TARGET_GOARCH=${TARGET_GOARCH}
WORKDIR /go/src/github.com/cloudflare/cloudflared/ WORKDIR /go/src/github.com/cloudflare/cloudflared/
@ -12,8 +15,6 @@ COPY . .
# compile cloudflared # compile cloudflared
RUN make cloudflared RUN make cloudflared
# ---
# use a distroless base image with glibc # use a distroless base image with glibc
FROM gcr.io/distroless/base-debian10:nonroot FROM gcr.io/distroless/base-debian10:nonroot

View File

@ -7,17 +7,35 @@ PACKAGE_DIR := $(CURDIR)/packaging
INSTALL_BINDIR := usr/local/bin INSTALL_BINDIR := usr/local/bin
EQUINOX_FLAGS = --version="$(VERSION)" \ EQUINOX_FLAGS = --version="$(VERSION)" \
--platforms="$(EQUINOX_BUILD_PLATFORMS)" \ --platforms="$(EQUINOX_BUILD_PLATFORMS)" \
--app="$(EQUINOX_APP_ID)" \ --app="$(EQUINOX_APP_ID)" \
--token="$(EQUINOX_TOKEN)" \ --token="$(EQUINOX_TOKEN)" \
--channel="$(EQUINOX_CHANNEL)" --channel="$(EQUINOX_CHANNEL)"
ifeq ($(EQUINOX_IS_DRAFT), true) ifeq ($(EQUINOX_IS_DRAFT), true)
EQUINOX_FLAGS := --draft $(EQUINOX_FLAGS) EQUINOX_FLAGS := --draft $(EQUINOX_FLAGS)
endif endif
ifeq ($(GOARCH),) LOCAL_ARCH ?= $(shell uname -m)
GOARCH := amd64 ifeq ($(LOCAL_ARCH),x86_64)
TARGET_ARCH ?= amd64
else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 5),armv8)
TARGET_ARCH ?= arm64
else ifeq ($(LOCAL_ARCH),aarch64)
TARGET_ARCH ?= arm64
else ifeq ($(shell echo $(LOCAL_ARCH) | head -c 4),armv)
TARGET_ARCH ?= arm
else
$(error This system's architecture $(LOCAL_ARCH) isn't supported)
endif
LOCAL_OS ?= $(shell go env GOOS)
ifeq ($(LOCAL_OS),linux)
TARGET_OS ?= linux
else ifeq ($(LOCAL_OS),darwin)
TARGET_OS ?= darwin
else
$(error This system's OS $(LOCAL_OS) isn't supported)
endif endif
.PHONY: all .PHONY: all
@ -29,11 +47,11 @@ clean:
.PHONY: cloudflared .PHONY: cloudflared
cloudflared: tunnel-deps cloudflared: tunnel-deps
go build -v -mod=vendor $(VERSION_FLAGS) $(IMPORT_PATH)/cmd/cloudflared GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) go build -v -mod=vendor $(VERSION_FLAGS) $(IMPORT_PATH)/cmd/cloudflared
.PHONY: container .PHONY: container
container: container:
docker build -t cloudflare/cloudflared:"$(VERSION)" . docker build --build-arg=TARGET_ARCH=$(TARGET_ARCH) --build-arg=TARGET_OS=$(TARGET_OS) -t cloudflare/cloudflared-$(TARGET_OS)-$(TARGET_ARCH):"$(VERSION)" .
.PHONY: test .PHONY: test
test: vet test: vet
@ -48,7 +66,7 @@ cloudflared-deb: cloudflared
mkdir -p $(PACKAGE_DIR) mkdir -p $(PACKAGE_DIR)
cp cloudflared $(PACKAGE_DIR)/cloudflared cp cloudflared $(PACKAGE_DIR)/cloudflared
fakeroot fpm -C $(PACKAGE_DIR) -s dir -t deb --deb-compression bzip2 \ fakeroot fpm -C $(PACKAGE_DIR) -s dir -t deb --deb-compression bzip2 \
-a $(GOARCH) -v $(VERSION) -n cloudflared cloudflared=/usr/local/bin/ -a $(TARGET_ARCH) -v $(VERSION) -n cloudflared cloudflared=/usr/local/bin/
.PHONY: cloudflared-darwin-amd64.tgz .PHONY: cloudflared-darwin-amd64.tgz
cloudflared-darwin-amd64.tgz: cloudflared cloudflared-darwin-amd64.tgz: cloudflared

View File

@ -16,7 +16,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
cli "gopkg.in/urfave/cli.v2" cli "gopkg.in/urfave/cli.v2"
"github.com/pkg/errors"
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
"golang.org/x/sys/windows/svc" "golang.org/x/sys/windows/svc"
"golang.org/x/sys/windows/svc/eventlog" "golang.org/x/sys/windows/svc/eventlog"