mirror of https://github.com/docker/compose.git
Merge pull request #13 from ulyssessouza/dockerize-build
Dockerize build
This commit is contained in:
commit
31ad0385b2
|
@ -0,0 +1,39 @@
|
||||||
|
# syntax = docker/dockerfile:experimental
|
||||||
|
ARG GO_VERSION=1.14.2
|
||||||
|
|
||||||
|
FROM golang:${GO_VERSION} AS fs
|
||||||
|
ARG TARGET_OS=unknown
|
||||||
|
ARG TARGET_ARCH=unknown
|
||||||
|
ARG PWD=$GOPATH/src/github.com/docker/api
|
||||||
|
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||||
|
make \
|
||||||
|
git \
|
||||||
|
protobuf-compiler \
|
||||||
|
libprotobuf-dev
|
||||||
|
RUN go get github.com/golang/protobuf/protoc-gen-go
|
||||||
|
WORKDIR ${PWD}
|
||||||
|
ADD go.* ${PWD}
|
||||||
|
RUN go mod download
|
||||||
|
ADD . ${PWD}
|
||||||
|
|
||||||
|
FROM fs AS make-protos
|
||||||
|
RUN make protos
|
||||||
|
|
||||||
|
FROM make-protos AS make-bins
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
GOOS=${TARGET_OS} \
|
||||||
|
GOARCH=${TARGET_ARCH} \
|
||||||
|
make bins
|
||||||
|
|
||||||
|
FROM make-protos AS make-xbins
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
make xbins
|
||||||
|
|
||||||
|
FROM scratch AS protos
|
||||||
|
COPY --from=make-protos /go/src/github.com/docker/api/backend/v1/*.pb.go .
|
||||||
|
|
||||||
|
FROM scratch AS bins
|
||||||
|
COPY --from=make-bins /go/src/github.com/docker/api/bin/* .
|
||||||
|
|
||||||
|
FROM scratch AS xbins
|
||||||
|
COPY --from=make-xbins /go/src/github.com/docker/api/bin/* .
|
46
Makefile
46
Makefile
|
@ -25,21 +25,53 @@
|
||||||
|
|
||||||
GIT_COMMIT=$(shell git rev-parse --short HEAD)
|
GIT_COMMIT=$(shell git rev-parse --short HEAD)
|
||||||
GOOS ?= $(shell go env GOOS)
|
GOOS ?= $(shell go env GOOS)
|
||||||
|
GOARCH ?= $(shell go env GOARCH)
|
||||||
|
|
||||||
PROTOS=$(shell find . -name \*.proto)
|
PROTOS=$(shell find . -name \*.proto)
|
||||||
|
|
||||||
export GO111MODULE=auto
|
export DOCKER_BUILDKIT=1
|
||||||
|
|
||||||
all: protos example cli
|
all: dbins
|
||||||
|
xall: dxbins
|
||||||
cli:
|
bins: cli example
|
||||||
cd cmd && go build -v -o ../bin/docker
|
xbins: xcli xexample
|
||||||
|
|
||||||
protos:
|
protos:
|
||||||
@protoc -I. --go_out=plugins=grpc,paths=source_relative:. ${PROTOS}
|
@protoc -I. --go_out=plugins=grpc,paths=source_relative:. ${PROTOS}
|
||||||
|
|
||||||
example:
|
cli: protos
|
||||||
|
cd cmd && GOOS=${GOOS} GOARCH=${GOARCH} go build -v -o ../bin/docker
|
||||||
|
|
||||||
|
example: protos
|
||||||
cd example/backend && go build -v -o ../../bin/backend-example
|
cd example/backend && go build -v -o ../../bin/backend-example
|
||||||
|
|
||||||
|
xcli: cli
|
||||||
|
cd cmd && GOOS=linux GOARCH=amd64 go build -v -o ../bin/docker-linux-amd64
|
||||||
|
cd cmd && GOOS=darwin GOARCH=amd64 go build -v -o ../bin/docker-darwin-amd64
|
||||||
|
cd cmd && GOOS=windows GOARCH=amd64 go build -v -o ../bin/docker-windows-amd64.exe
|
||||||
|
|
||||||
|
xexample: example
|
||||||
|
cd example/backend && GOOS=linux GOARCH=amd64 go build -v -o ../../bin/backend-example-linux-amd64
|
||||||
|
cd example/backend && GOOS=darwin GOARCH=amd64 go build -v -o ../../bin/backend-example-darwin-amd64
|
||||||
|
cd example/backend && GOOS=windows GOARCH=amd64 go build -v -o ../../bin/backend-example-windows-amd64.exe
|
||||||
|
|
||||||
|
dprotos:
|
||||||
|
docker build . \
|
||||||
|
--output type=local,dest=./backend/v1 \
|
||||||
|
--target protos
|
||||||
|
|
||||||
|
dbins: dprotos
|
||||||
|
docker build . \
|
||||||
|
--output type=local,dest=./bin \
|
||||||
|
--build-arg TARGET_OS=${GOOS} \
|
||||||
|
--build-arg TARGET_ARCH=${GOARCH} \
|
||||||
|
--target bins
|
||||||
|
|
||||||
|
dxbins: dbins
|
||||||
|
docker build . \
|
||||||
|
--output type=local,dest=./bin \
|
||||||
|
--target xbins
|
||||||
|
|
||||||
FORCE:
|
FORCE:
|
||||||
|
|
||||||
.PHONY: protos example cli
|
.PHONY: all xall protos example xexample xcli cli bins dbins dxbins dprotos
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.21.0
|
// protoc-gen-go v1.21.0-devel
|
||||||
// protoc v3.11.4
|
// protoc v3.6.1
|
||||||
// source: backend/v1/backend.proto
|
// source: backend/v1/backend.proto
|
||||||
|
|
||||||
package v1
|
package v1
|
||||||
|
|
Loading…
Reference in New Issue