blob: d7cc1dc00808ced1acf7c9ac6257335a4c5bd772 [file] [log] [blame]
Matt Jeanneret8b823f62019-05-11 11:01:28 -04001# Copyright 2016 the original author or authors.
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
Phaneendra Manda4c62c802019-03-06 21:37:49 +053015# -------------
16# Build stage
17
Matt Jeanneret8b823f62019-05-11 11:01:28 -040018FROM golang:1.12-alpine3.9 AS build-env
Phaneendra Manda4c62c802019-03-06 21:37:49 +053019
20# Install required packages
21RUN apk add --no-cache wget git make build-base protobuf protobuf-dev
22
Phaneendra Manda4c62c802019-03-06 21:37:49 +053023# Prepare directory structure
Matt Jeanneret8b823f62019-05-11 11:01:28 -040024RUN ["mkdir", "-p", "/build"]
Phaneendra Manda4c62c802019-03-06 21:37:49 +053025RUN ["mkdir", "-p", "$GOPATH/src", "$GOPATH/pkg", "$GOPATH/bin"]
26RUN ["mkdir", "-p", "$GOPATH/src/github.com/opencord"]
William Kurkianea869482019-04-09 15:16:11 -040027RUN ["mkdir", "-p", "$GOPATH/src/github.com/opencord/voltha-openolt-adapter"]
Phaneendra Manda4c62c802019-03-06 21:37:49 +053028
William Kurkianea869482019-04-09 15:16:11 -040029WORKDIR $GOPATH/src/github.com/opencord/voltha-openolt-adapter
Phaneendra Manda4c62c802019-03-06 21:37:49 +053030
William Kurkianea869482019-04-09 15:16:11 -040031COPY adaptercore ./adaptercore
32COPY config ./config
33COPY vendor ./vendor
34COPY *.go ./
Phaneendra Manda4c62c802019-03-06 21:37:49 +053035
Matt Jeanneretf880eb62019-07-16 20:08:03 -040036ARG org_label_schema_version=unknown
37ARG org_label_schema_vcs_url=unknown
38ARG org_label_schema_vcs_ref=unknown
39ARG org_label_schema_build_date=unknown
40ARG org_opencord_vcs_commit_date=unknown
41ARG org_opencord_vcs_dirty=unknown
42
Phaneendra Manda4c62c802019-03-06 21:37:49 +053043# Build openolt
Matt Jeanneretf880eb62019-07-16 20:08:03 -040044SHELL ["/bin/ash", "-o", "pipefail", "-c"]
45RUN go build -o /build/openolt \
46 -ldflags \
47 "-X github.com/opencord/voltha-openolt-adapter/vendor/github.com/opencord/voltha-go/common/version.version=$org_label_schema_version \
48 -X github.com/opencord/voltha-openolt-adapter/vendor/github.com/opencord/voltha-go/common/version.vcsRef=$org_label_schema_vcs_ref \
49 -X github.com/opencord/voltha-openolt-adapter/vendor/github.com/opencord/voltha-go/common/version.vcsDirty=$org_opencord_vcs_dirty \
50 -X github.com/opencord/voltha-openolt-adapter/vendor/github.com/opencord/voltha-go/common/version.goVersion=$(go version 2>&1 | sed -E 's/.*go([0-9]+\.[0-9]+\.[0-9]+).*/\1/g') \
51 -X github.com/opencord/voltha-openolt-adapter/vendor/github.com/opencord/voltha-go/common/version.os=$(go env GOHOSTOS) \
52 -X github.com/opencord/voltha-openolt-adapter/vendor/github.com/opencord/voltha-go/common/version.arch=$(go env GOHOSTARCH) \
53 -X github.com/opencord/voltha-openolt-adapter/vendor/github.com/opencord/voltha-go/common/version.buildTime=$org_label_schema_build_date"
Phaneendra Manda4c62c802019-03-06 21:37:49 +053054
55# -------------
56# Image creation stage
57
Matt Jeanneret8b823f62019-05-11 11:01:28 -040058FROM alpine:3.9.4
Phaneendra Manda4c62c802019-03-06 21:37:49 +053059
60# Set the working directory
61WORKDIR /app
62
63# Copy required files
Matt Jeanneret8b823f62019-05-11 11:01:28 -040064COPY --from=build-env /build/openolt /app/
Phaneendra Manda4c62c802019-03-06 21:37:49 +053065
Matt Jeanneret8b823f62019-05-11 11:01:28 -040066# Label image
67ARG org_label_schema_version=unknown
68ARG org_label_schema_vcs_url=unknown
69ARG org_label_schema_vcs_ref=unknown
70ARG org_label_schema_build_date=unknown
71ARG org_opencord_vcs_commit_date=unknown
Matt Jeanneretf880eb62019-07-16 20:08:03 -040072ARG org_opencord_vcs_dirty=unknown
Matt Jeanneret8b823f62019-05-11 11:01:28 -040073
74LABEL org.label-schema.schema-version=1.0 \
75 org.label-schema.name=voltha-openolt-adapter-go \
76 org.label-schema.version=$org_label_schema_version \
77 org.label-schema.vcs-url=$org_label_schema_vcs_url \
78 org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
79 org.label-schema.build-date=$org_label_schema_build_date \
Matt Jeanneretf880eb62019-07-16 20:08:03 -040080 org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \
81 org.opencord.vcs-dirty=$org_opencord_vcs_dirty