Skip to content

Commit b842176

Browse files
committed
protobuf3: build env for using protobuf3
Don't much like doing it this way, but it's an example Signed-off-by: Vincent Batts <[email protected]>
1 parent 50f8aa9 commit b842176

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

proto/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM fedora:latest
2+
3+
ENV PROTO_VERSION 3.0.0-beta-1
4+
RUN dnf install -y wget tar autoconf automake make gcc gcc-c++ unzip libtool
5+
RUN wget https://github.com/google/protobuf/archive/v${PROTO_VERSION}.tar.gz && \
6+
tar xf v${PROTO_VERSION}.tar.gz
7+
WORKDIR protobuf-${PROTO_VERSION}
8+
RUN ./autogen.sh && ./configure
9+
RUN make -j$(grep ^proc /proc/cpuinfo | wc -l)
10+
RUN make install -j$(grep ^proc /proc/cpuinfo | wc -l)
11+
WORKDIR /
12+
RUN dnf install -y golang git hg bzr
13+
ENV GOPATH /gopath
14+
ENV GOBIN /usr/bin
15+
RUN go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
16+
VOLUME /proto /output
17+
CMD bash /proto/run.sh

proto/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ CPP_SOURCE := $(patsubst %.proto,$(CPP_DIR)/%.pb.cc,$(PROTO_FILES))
1414
CPP_HDR := $(patsubst %.proto,$(CPP_DIR)/%.pb.h,$(PROTO_FILES))
1515
CPP_FILES := $(CPP_SOURCE) $(CPP_HDR)
1616

17+
DOCKER ?= docker
18+
CWD := $(shell pwd)
19+
1720
default: example
1821

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

51+
proto3: Dockerfile run.sh
52+
$(DOCKER) build -t $@ . && $(DOCKER) run -it -v $(CWD):/proto:ro -v $(CWD)/output:/output:rw $@
53+
4854
clean:
49-
rm -rf *~ $(GO_FILES) $(C_FILES) $(PY_FILES) $(CPP_FILES)
55+
rm -rf *~ $(GO_FILES) $(C_FILES) $(PY_FILES) $(CPP_FILES) $(CWD)/output
5056

proto/run.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
username="protobuild"
6+
groupname="${username}"
7+
p_dir="/proto/"
8+
o_dir="/output/"
9+
10+
uid=$(stat -c "%u" "${p_dir}")
11+
gid=$(stat -c "%g" "${p_dir}")
12+
groupadd -g "${gid}" "${groupname}"
13+
adduser -u "${uid}" -g "${gid}" "${username}"
14+
chown -R "${username}:${groupname}" "${o_dir}"
15+
cd "${p_dir}"
16+
su "${username}" -c "make go py cpp DESTDIR='${o_dir}'"
17+

0 commit comments

Comments
 (0)