blob: 4c2603fbf80c7145447e79bcd2dc91dbdd8fe387 [file] [log] [blame]
Matt Jeanneret2e3051a2019-05-11 15:01:46 -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
khenaidoocfee5f42018-07-19 22:47:38 -040015# -------------
16# Build stage
17
David K. Bainbridge3768fde2020-07-29 21:15:35 -070018ARG GOLANG_IMAGE=golang:1.13.8-alpine3.11
19ARG DEPLOY_IMAGE=alpine:3.11.3
20# hadolint ignore=DL3006
21FROM $GOLANG_IMAGE AS build-env
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040022
23# Install required packages
David K. Bainbridge3768fde2020-07-29 21:15:35 -070024RUN if command -v apk; then apk add --no-cache build-base=0.5-r1; fi
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040025
girishk5259f8e2019-10-10 18:44:44 +000026# Use Standard go build directory structure
27WORKDIR /go/src
khenaidooffe076b2019-01-15 16:08:08 -050028
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040029# Copy common files.
sbarbari17d7e222019-11-05 10:02:29 -050030COPY db ./db
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040031COPY vendor ./vendor
32
khenaidoocfee5f42018-07-19 22:47:38 -040033# Copy files
Matt Jeanneret85ab5082019-04-01 11:29:20 -040034COPY rw_core ./rw_core
girishk5259f8e2019-10-10 18:44:44 +000035COPY go.mod ./
36COPY go.sum ./
khenaidooffe076b2019-01-15 16:08:08 -050037
Kent Hagermanc64df642020-04-07 10:26:41 -040038ARG EXTRA_GO_BUILD_TAGS=""
39
Matt Jeanneret877b5c22019-07-03 11:09:50 -040040ARG org_label_schema_version=unknown
41ARG org_label_schema_vcs_url=unknown
42ARG org_label_schema_vcs_ref=unknown
43ARG org_label_schema_build_date=unknown
44ARG org_opencord_vcs_commit_date=unknown
45ARG org_opencord_vcs_dirty=unknown
46
Matt Jeanneret85ab5082019-04-01 11:29:20 -040047# Build
girishk5259f8e2019-10-10 18:44:44 +000048WORKDIR /go/src/rw_core
David K. Bainbridge3768fde2020-07-29 21:15:35 -070049# Need to ignore DL4006 as depending on the image being used different
50# shell may be used and there is no known way to parameterize the
51# Dockerfile SHELL command as build args did not seems to work
52# hadolint ignore=DL4006
Kent Hagermanc64df642020-04-07 10:26:41 -040053RUN go build $EXTRA_GO_BUILD_TAGS -mod=vendor -o /go/bin/rw_core \
David K. Bainbridgef430cd52019-05-28 15:00:35 -070054 -ldflags \
Maninderdfadc982020-10-28 14:04:33 +053055 "-X github.com/opencord/voltha-lib-go/v4/pkg/version.version=$org_label_schema_version \
56 -X github.com/opencord/voltha-lib-go/v4/pkg/version.vcsRef=$org_label_schema_vcs_ref \
57 -X github.com/opencord/voltha-lib-go/v4/pkg/version.vcsDirty=$org_opencord_vcs_dirty \
58 -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') \
59 -X github.com/opencord/voltha-lib-go/v4/pkg/version.os=$(go env GOHOSTOS) \
60 -X github.com/opencord/voltha-lib-go/v4/pkg/version.arch=$(go env GOHOSTARCH) \
61 -X github.com/opencord/voltha-lib-go/v4/pkg/version.buildTime=$org_label_schema_build_date"
Matt Jeanneret85ab5082019-04-01 11:29:20 -040062
khenaidoocfee5f42018-07-19 22:47:38 -040063# -------------
64# Image creation stage
65
David K. Bainbridge3768fde2020-07-29 21:15:35 -070066# hadolint ignore=DL3006
67FROM $DEPLOY_IMAGE
khenaidoocfee5f42018-07-19 22:47:38 -040068
69# Set the working directory
70WORKDIR /app
71
72# Copy required files
girishk5259f8e2019-10-10 18:44:44 +000073COPY --from=build-env /go/bin/rw_core /app/
khenaidoocfee5f42018-07-19 22:47:38 -040074
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040075# Label image
76ARG org_label_schema_version=unknown
77ARG org_label_schema_vcs_url=unknown
78ARG org_label_schema_vcs_ref=unknown
79ARG org_label_schema_build_date=unknown
80ARG org_opencord_vcs_commit_date=unknown
Kent Hagermanf4a3aab2019-05-22 14:42:34 -040081ARG org_opencord_vcs_dirty=unknown
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040082
83LABEL org.label-schema.schema-version=1.0 \
84 org.label-schema.name=voltha-rw-core \
85 org.label-schema.version=$org_label_schema_version \
86 org.label-schema.vcs-url=$org_label_schema_vcs_url \
87 org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
88 org.label-schema.build-date=$org_label_schema_build_date \
Kent Hagermanf4a3aab2019-05-22 14:42:34 -040089 org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \
90 org.opencord.vcs-dirty=$org_opencord_vcs_dirty