Skip to content

Commit

Permalink
protobuf3: build env for using protobuf3
Browse files Browse the repository at this point in the history
Don't much like doing it this way, but it's an example

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
  • Loading branch information
vbatts committed Sep 25, 2015
1 parent 50f8aa9 commit b842176
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
17 changes: 17 additions & 0 deletions proto/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM fedora:latest

ENV PROTO_VERSION 3.0.0-beta-1
RUN dnf install -y wget tar autoconf automake make gcc gcc-c++ unzip libtool
RUN wget https://github.com/google/protobuf/archive/v${PROTO_VERSION}.tar.gz && \
tar xf v${PROTO_VERSION}.tar.gz
WORKDIR protobuf-${PROTO_VERSION}
RUN ./autogen.sh && ./configure
RUN make -j$(grep ^proc /proc/cpuinfo | wc -l)
RUN make install -j$(grep ^proc /proc/cpuinfo | wc -l)
WORKDIR /
RUN dnf install -y golang git hg bzr
ENV GOPATH /gopath
ENV GOBIN /usr/bin
RUN go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
VOLUME /proto /output
CMD bash /proto/run.sh
8 changes: 7 additions & 1 deletion proto/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ CPP_SOURCE := $(patsubst %.proto,$(CPP_DIR)/%.pb.cc,$(PROTO_FILES))
CPP_HDR := $(patsubst %.proto,$(CPP_DIR)/%.pb.h,$(PROTO_FILES))
CPP_FILES := $(CPP_SOURCE) $(CPP_HDR)

DOCKER ?= docker
CWD := $(shell pwd)

default: example

all: go py c cpp
Expand Down Expand Up @@ -45,6 +48,9 @@ $(PY_DIR)/%_pb2.py: %.proto
@mkdir -p $(PY_DIR)
protoc --python_out=$(PY_DIR) $^

proto3: Dockerfile run.sh
$(DOCKER) build -t $@ . && $(DOCKER) run -it -v $(CWD):/proto:ro -v $(CWD)/output:/output:rw $@

clean:
rm -rf *~ $(GO_FILES) $(C_FILES) $(PY_FILES) $(CPP_FILES)
rm -rf *~ $(GO_FILES) $(C_FILES) $(PY_FILES) $(CPP_FILES) $(CWD)/output

17 changes: 17 additions & 0 deletions proto/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

username="protobuild"
groupname="${username}"
p_dir="/proto/"
o_dir="/output/"

uid=$(stat -c "%u" "${p_dir}")
gid=$(stat -c "%g" "${p_dir}")
groupadd -g "${gid}" "${groupname}"
adduser -u "${uid}" -g "${gid}" "${username}"
chown -R "${username}:${groupname}" "${o_dir}"
cd "${p_dir}"
su "${username}" -c "make go py cpp DESTDIR='${o_dir}'"

0 comments on commit b842176

Please sign in to comment.