mirror of https://github.com/docker/compose.git
Refactor build process to build in containers
This is a re-apply from a previous commit Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com> Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
4be3562450
commit
1a09dc51ea
|
@ -0,0 +1,32 @@
|
|||
# syntax = docker/dockerfile:experimental
|
||||
ARG GO_VERSION=1.14.2
|
||||
|
||||
FROM golang:${GO_VERSION} AS base
|
||||
ARG TARGET_OS=unknown
|
||||
ARG TARGET_ARCH=unknown
|
||||
ARG PWD=/ecs-plugin
|
||||
ENV GO111MODULE=on
|
||||
|
||||
WORKDIR ${PWD}
|
||||
ADD go.* ${PWD}
|
||||
RUN go mod download
|
||||
ADD . ${PWD}
|
||||
|
||||
FROM base AS make-plugin
|
||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
GOOS=${TARGET_OS} \
|
||||
GOARCH=${TARGET_ARCH} \
|
||||
make -f builder.Makefile build
|
||||
|
||||
FROM base AS make-cross
|
||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
make -f builder.Makefile cross
|
||||
|
||||
FROM scratch AS build
|
||||
COPY --from=make-plugin /ecs-plugin/dist/* .
|
||||
|
||||
FROM scratch AS cross
|
||||
COPY --from=make-cross /ecs-plugin/dist/* .
|
||||
|
||||
FROM base as test
|
||||
RUN make -f builder.Makefile test
|
37
ecs/Makefile
37
ecs/Makefile
|
@ -1,11 +1,27 @@
|
|||
clean:
|
||||
rm -rf dist/
|
||||
GOOS ?= $(shell go env GOOS)
|
||||
GOARCH ?= $(shell go env GOARCH)
|
||||
PWD = $(shell pwd)
|
||||
|
||||
build:
|
||||
go build -v -o dist/docker-ecs cmd/main/main.go
|
||||
export DOCKER_BUILDKIT=1
|
||||
|
||||
.DEFAULT_GOAL := build
|
||||
|
||||
build: ## Build for the current
|
||||
@docker build . \
|
||||
--output type=local,dest=./dist \
|
||||
--build-arg TARGET_OS=${GOOS} \
|
||||
--build-arg TARGET_ARCH=${GOARCH} \
|
||||
--target build
|
||||
|
||||
cross: ## Cross build for linux, macos and windows
|
||||
@docker build . \
|
||||
--output type=local,dest=./dist \
|
||||
--target cross
|
||||
|
||||
test: build ## Run tests
|
||||
go test ./... -v
|
||||
@docker build . \
|
||||
--output type=local,dest=./dist \
|
||||
--target test
|
||||
|
||||
e2e: build ## Run tests
|
||||
go test ./... -v -tags=e2e
|
||||
|
@ -15,6 +31,13 @@ dev: build
|
|||
ln -f -s "${PWD}/dist/docker-ecs" "${HOME}/.docker/cli-plugins/docker-ecs"
|
||||
|
||||
lint: ## Verify Go files
|
||||
golangci-lint run --config ./golangci.yaml ./...
|
||||
@docker run --rm -t \
|
||||
-v $(PWD):/app \
|
||||
-w /app \
|
||||
golangci/golangci-lint:v1.27-alpine \
|
||||
golangci-lint run --timeout 10m0s --config ./golangci.yaml ./...
|
||||
|
||||
.PHONY: clean build test dev lint e2e
|
||||
clean:
|
||||
rm -rf dist/
|
||||
|
||||
.PHONY: clean build test dev lint e2e cross
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
GOOS ?= $(shell go env GOOS)
|
||||
GOARCH ?= $(shell go env GOARCH)
|
||||
|
||||
PROTOS=$(shell find . -name \*.proto)
|
||||
|
||||
EXTENSION :=
|
||||
ifeq ($(GOOS),windows)
|
||||
EXTENSION := .exe
|
||||
endif
|
||||
|
||||
STATIC_FLAGS= CGO_ENABLED=0
|
||||
LDFLAGS := "-s -w"
|
||||
GO_BUILD = $(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
|
||||
|
||||
BINARY=dist/docker
|
||||
BINARY_WITH_EXTENSION=$(BINARY)$(EXTENSION)
|
||||
|
||||
export DOCKER_BUILDKIT=1
|
||||
|
||||
all: build
|
||||
|
||||
clean:
|
||||
rm -rf dist/
|
||||
|
||||
build:
|
||||
$(GO_BUILD) -v -o $(BINARY_WITH_EXTENSION) cmd/main/main.go
|
||||
|
||||
cross:
|
||||
@GOOS=linux GOARCH=amd64 $(GO_BUILD) -v -o $(BINARY)-linux-amd64 cmd/main/main.go
|
||||
@GOOS=darwin GOARCH=amd64 $(GO_BUILD) -v -o $(BINARY)-darwin-amd64 cmd/main/main.go
|
||||
@GOOS=windows GOARCH=amd64 $(GO_BUILD) -v -o $(BINARY)-windows-amd64.exe cmd/main/main.go
|
||||
|
||||
test: build ## Run tests
|
||||
@go test ./... -v
|
||||
|
||||
lint: ## Verify Go files
|
||||
golangci-lint run --timeout 10m0s --config ./golangci.yaml ./...
|
||||
|
||||
.PHONY: clean build test dev lint e2e
|
Loading…
Reference in New Issue