blob: ca9f7fb0631d53113d89776dcae903e78f4e7237 [file] [log] [blame]
Holger Hildebrandtda7758b2020-03-16 11:30:03 +00001# 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
15# -------------
16# Build stage
17
18FROM golang:1.13.8-alpine3.11 AS build-env
19
Matteo Scandolodcd93182020-04-29 13:21:45 -070020# Install required packages
21RUN apk add --no-cache build-base=0.5-r1
22
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000023# Prepare directory structure
Matteo Scandolodcd93182020-04-29 13:21:45 -070024WORKDIR /go/src/github.com/opencord/voltha-openonu-adapter-go
Matteo Scandolobedd2502020-03-25 08:44:18 -070025
26# Copy common files.
Holger Hildebrandtfa074992020-03-27 15:42:06 +000027COPY . .
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000028
Holger Hildebrandt6999fe52021-02-11 11:49:05 +000029ARG EXTRA_GO_BUILD_TAGS=""
30
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000031ARG org_label_schema_version=unknown
32ARG org_label_schema_vcs_url=unknown
33ARG org_label_schema_vcs_ref=unknown
34ARG org_label_schema_build_date=unknown
35ARG org_opencord_vcs_commit_date=unknown
36ARG org_opencord_vcs_dirty=unknown
37
Matteo Scandolobedd2502020-03-25 08:44:18 -070038# Build openonu
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000039SHELL ["/bin/ash", "-o", "pipefail", "-c"]
Holger Hildebrandt6999fe52021-02-11 11:49:05 +000040RUN go build $EXTRA_GO_BUILD_TAGS -mod=vendor -o /go/bin/openonu \
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000041 -ldflags \
Holger Hildebrandt6e846d12020-12-11 14:35:55 +000042 "-X github.com/opencord/voltha-lib-go/v4/pkg/version.version=$org_label_schema_version \
43 -X github.com/opencord/voltha-lib-go/v4/pkg/version.vcsRef=$org_label_schema_vcs_ref \
44 -X github.com/opencord/voltha-lib-go/v4/pkg/version.vcsDirty=$org_opencord_vcs_dirty \
45 -X github.com/opencord/voltha-lib-go/v4/pkg/version.goVersion=$(go version 2>&1 | sed -E 's/.*go([0-9]+\.[0-9]+\.[0-9]+).*/\1/g') \
46 -X github.com/opencord/voltha-lib-go/v4/pkg/version.os=$(go env GOHOSTOS) \
47 -X github.com/opencord/voltha-lib-go/v4/pkg/version.arch=$(go env GOHOSTARCH) \
48 -X github.com/opencord/voltha-lib-go/v4/pkg/version.buildTime=$org_label_schema_build_date" \
Matteo Scandolodcd93182020-04-29 13:21:45 -070049 ./cmd/openonu-adapter/
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000050
51# -------------
52# Image creation stage
53
54FROM alpine:3.11.3
55
56# Set the working directory
57WORKDIR /app
58
59# Copy required files
Matteo Scandolobedd2502020-03-25 08:44:18 -070060COPY --from=build-env /go/bin/openonu /app/
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000061
62# Label image
63ARG org_label_schema_version=unknown
64ARG org_label_schema_vcs_url=unknown
65ARG org_label_schema_vcs_ref=unknown
66ARG org_label_schema_build_date=unknown
67ARG org_opencord_vcs_commit_date=unknown
68ARG org_opencord_vcs_dirty=unknown
69
70LABEL org.label-schema.schema-version=1.0 \
71 org.label-schema.name=voltha-openonu-adapter-go \
72 org.label-schema.version=$org_label_schema_version \
73 org.label-schema.vcs-url=$org_label_schema_vcs_url \
74 org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
75 org.label-schema.build-date=$org_label_schema_build_date \
76 org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \
77 org.opencord.vcs-dirty=$org_opencord_vcs_dirty