Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 1 | # Copyright 2018-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | # bbsim dockerfile |
| 16 | |
| 17 | # builder parent |
| 18 | FROM golang:1.12-stretch as builder |
| 19 | |
| 20 | # install prereqs |
| 21 | ENV PROTOC_VERSION 3.6.1 |
| 22 | ENV PROTOC_SHA256SUM 6003de742ea3fcf703cfec1cd4a3380fd143081a2eb0e559065563496af27807 |
| 23 | |
| 24 | RUN apt-get update \ |
| 25 | && apt-get install -y unzip libpcap-dev \ |
| 26 | && curl -L -o /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip \ |
| 27 | && echo "$PROTOC_SHA256SUM /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip" | sha256sum -c - \ |
| 28 | && unzip /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /tmp/protoc3 \ |
| 29 | && mv /tmp/protoc3/bin/* /usr/local/bin/ \ |
| 30 | && mv /tmp/protoc3/include/* /usr/local/include/ \ |
| 31 | && go get -v github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \ |
| 32 | && go get -v github.com/golang/protobuf/protoc-gen-go |
| 33 | |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 34 | WORKDIR /go/src/github.com/opencord/bbsim |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 35 | ENV GO111MODULE=on |
| 36 | ENV GOPROXY=https://proxy.golang.org |
| 37 | |
| 38 | # get dependencies |
| 39 | COPY go.mod go.sum ./ |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 40 | COPY vendor ./vendor |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 41 | |
| 42 | # build the protos |
| 43 | COPY Makefile ./ |
| 44 | COPY api ./api |
| 45 | RUN make protos |
| 46 | |
| 47 | # copy and build |
| 48 | COPY . ./ |
Matteo Scandolo | 5f82fa9 | 2019-09-24 07:25:33 -0700 | [diff] [blame^] | 49 | RUN go mod vendor -v # we can't vendor dependencies unless the code is there |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 50 | ARG GIT_STATUS=Clean |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 51 | RUN GO111MODULE=on go build -mod vendor\ |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 52 | -ldflags "-X main.buildTime=$(date +ā%Y/%m/%d-%H:%M:%Sā) \ |
| 53 | -X main.commitHash=$(git log --pretty=format:%H -n 1) \ |
| 54 | -X main.gitStatus=${GIT_STATUS}\ |
| 55 | -X main.version=$(cat VERSION)" \ |
| 56 | -o ./cmd/bbsim ./internal/bbsim |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 57 | |
| 58 | # runtime parent |
| 59 | FROM golang:1.12-stretch |
| 60 | |
| 61 | # runtime prereqs |
| 62 | # the symlink on libpcap is because both alpine and debian come with 1.8.x, but |
| 63 | # debian symlinks it to 0.8 for historical reasons: |
| 64 | # https://packages.debian.org/stretch/libpcap0.8-dev |
| 65 | RUN apt-get update \ |
| 66 | && apt-get install -y libpcap-dev isc-dhcp-server network-manager\ |
| 67 | && ln -s /usr/lib/libpcap.so.1.8.1 /usr/lib/libpcap.so.0.8 |
| 68 | |
| 69 | COPY ./configs/isc-dhcp-server /etc/default/ |
| 70 | COPY ./configs/dhcpd.conf /etc/dhcp/ |
| 71 | RUN mv /usr/sbin/dhcpd /usr/local/bin/ \ |
| 72 | && mv /sbin/dhclient /usr/local/bin/ \ |
| 73 | && touch /var/lib/dhcp/dhcpd.leases |
| 74 | |
| 75 | WORKDIR /app |
Matteo Scandolo | 47e69bb | 2019-08-28 15:41:12 -0700 | [diff] [blame] | 76 | COPY --from=builder /go/src/github.com/opencord/bbsim/cmd/bbsim /app/bbsim |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 77 | RUN chmod a+x /app/bbsim |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 78 | ENTRYPOINT [ '/app/bbsim' ] |