Skip to content

Commit

Permalink
Prepare docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
bufdev committed Oct 28, 2019
1 parent fe99691 commit bc81150
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 55 deletions.
35 changes: 10 additions & 25 deletions Dockerfile.buf
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
FROM golang:1.13.3-alpine3.10
ARG DOCKER_WORKSPACE_IMAGE

ENV \
CACHE_BASE=/cache/buf \
GO111MODULE=on \
GOPRIVATE=github.com/bufbuild/buf \
GOPATH=/cache/buf/Linux/x86_64/go \
GOBIN=/cache/buf/Linux/x86_64/bin \
PATH=/cache/buf/Linux/x86_64/bin:${PATH}
FROM $DOCKER_WORKSPACE_IMAGE as builder

WORKDIR /workspace
COPY cmd ./cmd
COPY internal ./internal
RUN go build -o /go/bin/buf ./cmd/buf

FROM alpine:3.10

RUN apk add --update --no-cache \
bash \
build-base \
ca-certificates \
curl \
git \
unzip \
wget && \
ca-certificates && \
rm -rf /var/cache/apk/*

RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.30-r0/glibc-2.30-r0.apk && \
apk add --no-cache glibc-2.30-r0.apk && \
rm -rf /var/cache/apk/*
COPY --from=builder /go/bin/buf /usr/local/bin/buf

COPY go.mod go.sum /workspace/
RUN go mod download
COPY make /workspace/make
Copy Makefile /workspace/
RUN make deps
ENTRYPOINT ["/usr/local/bin/buf"]
35 changes: 35 additions & 0 deletions Dockerfile.workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ARG PROJECT
ARG GO_MODULE

FROM golang:1.13.3-alpine3.10

ENV \
CACHE_BASE=/cache/$PROJECT \
GO111MODULE=on \
GOPRIVATE=$GO_MODULE \
GOPATH=/cache/$PROJECT/Linux/x86_64/go \
GOBIN=/cache/$PROJECT/Linux/x86_64/bin \
PATH=/cache/$PROJECT/Linux/x86_64/bin:${PATH}

WORKDIR /workspace

RUN apk add --update --no-cache \
bash \
build-base \
ca-certificates \
curl \
git \
unzip \
wget && \
rm -rf /var/cache/apk/*

RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.30-r0/glibc-2.30-r0.apk && \
apk add --no-cache glibc-2.30-r0.apk && \
rm -rf /var/cache/apk/*

COPY go.mod go.sum /workspace/
RUN go mod download
COPY make /workspace/make
Copy Makefile /workspace/
RUN make deps
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
PROJECT := buf
GO_MODULE := github.com/bufbuild/buf
DOCKER_IMAGE := bufbuild/buf
DOCKER_FILE := Dockerfile.buf
DOCKER_DIR := /workspace
DOCKER_ORG := bufbuild
DOCKER_PROJECT := buf

GOPKGS ?= ./...

Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ require (
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/multierr v1.2.0 // indirect
go.uber.org/zap v1.11.0
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
golang.org/x/net v0.0.0-20191021144547-ec77196f6094 // indirect
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03 // indirect
golang.org/x/crypto v0.0.0-20191028145041-f83a4685e152 // indirect
golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271 // indirect
golang.org/x/sys v0.0.0-20191028164358-195ce5e7f934 // indirect
google.golang.org/genproto v0.0.0-20191028173616-919d9bdd9fe6 // indirect
gopkg.in/src-d/go-billy.v4 v4.3.2
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v2 v2.2.4 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191028145041-f83a4685e152 h1:ZC1Xn5A1nlpSmQCIva4bZ3ob3lmhYIefc+GU+DLg1Ow=
golang.org/x/crypto v0.0.0-20191028145041-f83a4685e152/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
Expand All @@ -109,8 +109,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191021144547-ec77196f6094 h1:5O4U9trLjNpuhpynaDsqwCk+Tw6seqJz1EbqbnzHrc8=
golang.org/x/net v0.0.0-20191021144547-ec77196f6094/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271 h1:N66aaryRB3Ax92gH0v3hp1QYZ3zWWCCUR/j8Ifh45Ss=
golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -122,8 +122,8 @@ golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qqCB4teTffacDWr7CI+0=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191028164358-195ce5e7f934 h1:u/E0NqCIWRDAo9WCFo6Ko49njPFDLSd3z+X1HgWDMpE=
golang.org/x/sys v0.0.0-20191028164358-195ce5e7f934/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand All @@ -136,8 +136,8 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
google.golang.org/genproto v0.0.0-20170818010345-ee236bd376b0 h1:ZvI3lsq5AIkr7axxmT3tfwFlJVRFLqe6Fp0W03+MJ38=
google.golang.org/genproto v0.0.0-20170818010345-ee236bd376b0/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03 h1:4HYDjxeNXAOTv3o1N2tjo8UUSlhQgAD52FVkwxnWgM8=
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
google.golang.org/genproto v0.0.0-20191028173616-919d9bdd9fe6 h1:UXl+Zk3jqqcbEVV7ace5lrt4YdA4tXiz3f/KbmD29Vo=
google.golang.org/genproto v0.0.0-20191028173616-919d9bdd9fe6/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
google.golang.org/grpc v1.8.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.19.0 h1:cfg4PD8YEdSFnm7qLV4++93WcmhH2nIUhMjhdCvl3j8=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
Expand Down
8 changes: 4 additions & 4 deletions make/buf/all.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ GO_BINS := \
protoc-gen-buf-check-lint
GO_GET_PKGS := github.com/jhump/protoreflect@master

include make/buf/versions.mk
DOCKER_BINS := \
buf

include make/buf/versions.mk
include make/base.mk
include make/dep_errcheck.mk
include make/dep_golint.mk
Expand All @@ -19,8 +21,6 @@ include make/golang.mk
include make/protoc_gen_go.mk
include make/docker.mk

RELEASE_DOCKER_IMAGE := golang:1.13.3-buster

.PHONY: buflint
buflint: bufinstall
buf check lint
Expand All @@ -37,4 +37,4 @@ bufdevinstall:

.PHONY: bufrelease
bufrelease: all
docker run --volume "$(CURDIR):/app" --workdir "/app" $(RELEASE_DOCKER_IMAGE) bash -x scripts/buf/release.bash
DOCKER_IMAGE=golang:1.13.3-buster bash scripts/buf/release.bash
53 changes: 42 additions & 11 deletions make/docker.mk
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
ifndef DOCKER_IMAGE
$(error DOCKER_IMAGE is not set)
ifndef DOCKER_ORG
$(error DOCKER_ORG is not set)
endif
ifndef DOCKER_FILE
$(error DOCKER_FILE is not set)
ifndef DOCKER_PROJECT
$(error DOCKER_PROJECT is not set)
endif
ifndef DOCKER_DIR
$(error DOCKER_DIR is not set)
ifndef PROJECT
$(error PROJECT is not set)
endif
ifndef GO_MODULE
$(error GO_MODULE is not set)
endif

DOCKER_WORKSPACE_IMAGE := $(DOCKER_ORG)/$(DOCKER_PROJECT)-workspace
DOCKER_WORKSPACE_FILE := Dockerfile.workspace
DOCKER_WORKSPACE_DIR := /workspace

DOCKER_BINS ?=

.PHONY: dockerbuildworkspace
dockerbuildworkspace:
docker build \
--build-arg PROJECT=$(PROJECT) \
--build-arg GO_MODULE=$(GO_MODULE) \
-t $(DOCKER_WORKSPACE_IMAGE) \
-f $(DOCKER_WORKSPACE_FILE) \
.

.PHONY: dockermakeworkspace
dockermakeworkspace: dockerbuildworkspace
docker run -v "$(CURDIR):$(DOCKER_WORKSPACE_DIR)" $(DOCKER_WORKSPACE_IMAGE) make -j 8

.PHONY: dockerbuild
dockerbuild:
docker build -t $(DOCKER_IMAGE) -f $(DOCKER_FILE) .
dockerbuild::

define dockerbinfunc
.PHONY: dockerbuild$(1)
dockerbuild$(1): dockerbuildworkspace
docker build \
--build-arg DOCKER_WORKSPACE_IMAGE=$(DOCKER_WORKSPACE_IMAGE) \
-t $(DOCKER_ORG)/$(1) \
-f Dockerfile.$(1) \
.

dockerbuild:: dockerbuild$(1)
endef

.PHONY: dockermake
dockermake: dockerbuild
docker run -v "$(CURDIR):$(DOCKER_DIR)" $(DOCKER_IMAGE) make -j 8
$(foreach dockerbin,$(DOCKER_BINS),$(eval $(call dockerbinfunc,$(dockerbin))))
13 changes: 13 additions & 0 deletions scripts/buf/release.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

set -eo pipefail
set -x

DIR="$(cd "$(dirname "${0}")/../.." && pwd)"
cd "${DIR}"
Expand Down Expand Up @@ -38,6 +39,18 @@ sha256() {
fi
}

if [ -z "${INSIDE_DOCKER}" ]; then
if [ -z "${DOCKER_IMAGE}" ]; then
fail "DOCKER_IMAGE must be set"
fi
docker run --volume \
"${DIR}:/app" \
--workdir "/app" \
-e INSIDE_DOCKER=1 \
"${DOCKER_IMAGE}" \
bash -x scripts/buf/release.bash
fi

BASE_NAME="buf"

RELEASE_DIR=".build/release/${BASE_NAME}"
Expand Down

0 comments on commit bc81150

Please sign in to comment.