Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza 2020-04-22 10:04:11 +02:00
Родитель f393dea175
Коммит 88aef2e4e2
3 изменённых файлов: 80 добавлений и 9 удалений

39
Dockerfile Normal file
Просмотреть файл

@ -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/* .

Просмотреть файл

@ -25,21 +25,53 @@
GIT_COMMIT=$(shell git rev-parse --short HEAD)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
PROTOS=$(shell find . -name \*.proto)
export GO111MODULE=auto
export DOCKER_BUILDKIT=1
all: protos example cli
cli:
cd cmd && go build -v -o ../bin/docker
all: dbins
xall: dxbins
bins: cli example
xbins: xcli xexample
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
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:
.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.
// versions:
// protoc-gen-go v1.21.0
// protoc v3.11.4
// protoc-gen-go v1.21.0-devel
// protoc v3.6.1
// source: backend/v1/backend.proto
package v1