Skip to content

Commit

Permalink
[ADD] golang proto nodejs
Browse files Browse the repository at this point in the history
  • Loading branch information
SnakeHacker committed Mar 20, 2020
1 parent 9e0d7c8 commit e852338
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 27 deletions.
81 changes: 65 additions & 16 deletions bazel.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ FROM ubuntu:18.04
ENV BAZEL_VERSION 2.1.0
ENV GOLANG_VERSION 1.13.8
ENV PYTHON_VERSION 3.7.6
ENV PROTOBUF_VERSION=3.6.1
ENV NODEJS_VERSION 12

# 更换为阿里云境像
RUN sed -i "s/archive.ubuntu.com/mirrors.aliyun.com/g" /etc/apt/sources.list
Expand All @@ -14,28 +16,41 @@ RUN (apt-get update && apt-get install -y --no-install-recommends \
curl \
wget \
git \
gnupg \
libopenblas-dev \
liblapack-dev \
libssl-dev \
libmetis-dev \
pkg-config \
zlib1g-dev \
openssh-client \
openjdk-11-jdk \
g++ unzip zip \
openjdk-11-jre-headless)

# Install nodejs yarn
RUN curl -sL https://deb.nodesource.com/setup_${NODEJS_VERSION}.x | bash -
RUN apt-get install -y nodejs
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install -y yarn

# Install Python
WORKDIR /tmp/
RUN (wget -P /tmp https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz)
RUN tar -zxvf Python-$PYTHON_VERSION.tgz
WORKDIR /tmp/Python-$PYTHON_VERSION
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get dist-upgrade -y
RUN apt-get update -y && apt-get upgrade -y && apt-get dist-upgrade -y

RUN export DEBIAN_FRONTEND=noninteractive && apt-get install -y tzdata
RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN dpkg-reconfigure --frontend noninteractive tzdata

RUN apt-get install -y --no-install-recommends libbz2-dev libncurses5-dev libgdbm-dev libgdbm-compat-dev liblzma-dev libsqlite3-dev libssl-dev openssl tk-dev uuid-dev libreadline-dev
RUN apt-get install -y --no-install-recommends libffi-dev
RUN ./configure --prefix=/usr/local/python3
RUN make
RUN make install
RUN ./configure --prefix=/usr/local/python3 && \
make && \
make install
RUN update-alternatives --install /usr/bin/python python /usr/local/python3/bin/python3 1
RUN update-alternatives --install /usr/bin/pip pip /usr/local/python3/bin/pip3 1
RUN update-alternatives --config python
Expand All @@ -44,17 +59,53 @@ RUN pip install --upgrade pip
RUN (pip install -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com grpcio numpy && \
touch /root/WORKSPACE)

RUN (curl -L https://dl.google.com/go/go$GOLANG_VERSION.linux-amd64.tar.gz | tar zx -C /usr/lib)

# Install Golang
RUN (curl -L https://dl.google.com/go/go$GOLANG_VERSION.linux-amd64.tar.gz | tar zx -C /usr/local)
ENV PATH /usr/local/go/bin:$PATH
RUN mkdir -p /go/src /go/bin && chmod -R 777 /go
ENV GOROOT /usr/local/go
ENV GOPATH /go
ENV PATH /go/bin:$PATH

# Install go packages
RUN go env -w GO111MODULE=on && \
go env -w GOPROXY=https://goproxy.io,direct
COPY go.mod /go.mod
RUN go mod download

# Install proto buffer
# refer to https://github.com/golang/protobuf
RUN wget -P /tmp https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip
RUN unzip /tmp/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip -d protoc3 && \
rm /tmp/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip
RUN mv protoc3/bin/* /usr/local/bin/ && mv protoc3/include/* /usr/local/include/

# Install GoLang proto gen
RUN go get -u -v github.com/golang/protobuf/protoc-gen-go

# Manually clone golang.org/x/XXX packages from their github mirrors.
# F**K GFW!
WORKDIR /go/src/golang.org/x/
RUN git clone --progress https://github.com/golang/debug.git && \
git clone --progress https://github.com/golang/glog.git && \
git clone --progress https://github.com/golang/time.git && \
git clone --progress https://github.com/golang/sync.git && \
git clone --progress https://github.com/golang/crypto && \
git clone --progress https://github.com/golang/tools && \
git clone --progress https://github.com/golang/sys

# Install packr2
RUN go get -u github.com/gobuffalo/packr/v2/packr2

# Install bazel
RUN (wget -P /tmp https://github.com/bazelbuild/bazel/releases/download/$BAZEL_VERSION/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh)
RUN (chmod +x /tmp/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh)
RUN bash /tmp/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh
RUN echo "export PATH=$PATH:/usr/lib/go/bin" >> /root/.bashrc

# clean
RUN rm -rf /tmp/*
RUN rm -rf /var/lib/apt/lists/*
RUN rm -rf /root/.cache/pip
RUN rm -rf /tmp/* && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /root/.cache/pip

WORKDIR /root

Expand All @@ -69,12 +120,10 @@ RUN update-alternatives --config python3
RUN update-alternatives --config pip3

# dirs for bazel build
RUN mkdir -p /root/cache/bazel
RUN mkdir -p /root/output
RUN mkdir -p /root/cache/bazel && \
mkdir -p /root/output

# https://github.com/pypa/pip/issues/4924
RUN mv /usr/bin/lsb_release /usr/bin/lsb_release.bak

RUN export PATH=$PATH:/usr/lib/go/bin

CMD ["bin/bash"]
77 changes: 66 additions & 11 deletions bazel.gpu.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu18.04
ENV BAZEL_VERSION 2.1.0
ENV GOLANG_VERSION 1.13.8
ENV PYTHON_VERSION 3.7.6
ENV PROTOBUF_VERSION=3.6.1
ENV NODEJS_VERSION 12

# 更换为阿里云境像
RUN sed -i "s/archive.ubuntu.com/mirrors.aliyun.com/g" /etc/apt/sources.list
Expand All @@ -14,11 +16,30 @@ RUN (apt-get update && apt-get install -y --no-install-recommends \
curl \
wget \
git \
gnupg \
libopenblas-dev \
liblapack-dev \
libssl-dev \
libmetis-dev \
pkg-config \
zlib1g-dev \
openssh-client \
openjdk-11-jdk \
g++ unzip zip \
openjdk-11-jre-headless)

# Install nodejs yarn
RUN curl -sL https://deb.nodesource.com/setup_${NODEJS_VERSION}.x | bash -
RUN apt-get install -y nodejs
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install -y yarn

RUN apt-get install -y gcc-6 g++-6
RUN rm /usr/bin/gcc /usr/bin/g++
RUN ln -s /usr/bin/gcc-6 /usr/bin/gcc && ln -s /usr/bin/g++-6 /usr/bin/g++

# Install Python
WORKDIR /tmp/
RUN (wget -P /tmp https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz)
RUN tar -zxvf Python-$PYTHON_VERSION.tgz
Expand All @@ -34,8 +55,7 @@ RUN dpkg-reconfigure --frontend noninteractive tzdata
RUN apt-get install -y --no-install-recommends libbz2-dev libncurses5-dev libgdbm-dev libgdbm-compat-dev liblzma-dev libsqlite3-dev libssl-dev openssl tk-dev uuid-dev libreadline-dev
RUN apt-get install -y --no-install-recommends libffi-dev
RUN ./configure --prefix=/usr/local/python3
RUN make
RUN make install
RUN make && make install
RUN update-alternatives --install /usr/bin/python python /usr/local/python3/bin/python3 1
RUN update-alternatives --install /usr/bin/pip pip /usr/local/python3/bin/pip3 1
RUN update-alternatives --config python
Expand All @@ -44,17 +64,54 @@ RUN pip install --upgrade pip
RUN (pip install -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com grpcio numpy && \
touch /root/WORKSPACE)

RUN (curl -L https://dl.google.com/go/go$GOLANG_VERSION.linux-amd64.tar.gz | tar zx -C /usr/lib)

# Install Golang
RUN (curl -L https://dl.google.com/go/go$GOLANG_VERSION.linux-amd64.tar.gz | tar zx -C /usr/local)
ENV PATH /usr/local/go/bin:$PATH
RUN mkdir -p /go/src /go/bin && chmod -R 777 /go
ENV GOROOT /usr/local/go
ENV GOPATH /go
ENV PATH /go/bin:$PATH

# Install go packages
RUN go env -w GO111MODULE=on && \
go env -w GOPROXY=https://goproxy.io,direct
COPY go.mod /go.mod
RUN go mod download

# Install proto buffer
# refer to https://github.com/golang/protobuf
RUN wget -P /tmp https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip
RUN unzip /tmp/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip -d protoc3 && \
rm /tmp/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip
RUN mv protoc3/bin/* /usr/local/bin/ && mv protoc3/include/* /usr/local/include/

# Install GoLang proto gen
RUN go get -u -v github.com/golang/protobuf/protoc-gen-go

# Manually clone golang.org/x/XXX packages from their github mirrors.
# F**K GFW!
WORKDIR /go/src/golang.org/x/
RUN git clone --progress https://github.com/golang/debug.git && \
git clone --progress https://github.com/golang/glog.git && \
git clone --progress https://github.com/golang/time.git && \
git clone --progress https://github.com/golang/sync.git && \
git clone --progress https://github.com/golang/crypto && \
git clone --progress https://github.com/golang/tools && \
git clone --progress https://github.com/golang/sys

# Install packr2
RUN go get -u github.com/gobuffalo/packr/v2/packr2

# Install bazel
RUN (wget -P /tmp https://github.com/bazelbuild/bazel/releases/download/$BAZEL_VERSION/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh)
RUN (chmod +x /tmp/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh)
RUN bash /tmp/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh
RUN echo "export PATH=$PATH:/usr/lib/go/bin" >> /root/.bashrc

# clean
RUN rm -rf /tmp/*
RUN rm -rf /var/lib/apt/lists/*
RUN rm -rf /root/.cache/pip
RUN rm -rf /tmp/* && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /root/.cache/pip

WORKDIR /root

Expand All @@ -69,12 +126,10 @@ RUN update-alternatives --config python3
RUN update-alternatives --config pip3

# dirs for bazel build
RUN mkdir -p /root/cache/bazel
RUN mkdir -p /root/output
RUN mkdir -p /root/cache/bazel && \
mkdir -p /root/output

# https://github.com/pypa/pip/issues/4924
RUN mv /usr/bin/lsb_release /usr/bin/lsb_release.bak

RUN export PATH=$PATH:/usr/lib/go/bin

CMD ["bin/bash"]

0 comments on commit e852338

Please sign in to comment.