blob: 94c24ba116f5ff0bcc5fc253fd5d84a58f123868 [file] [log] [blame]
Joey Armstrong811e9542022-12-25 21:45:27 -05001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2016-2023 Open Networking Foundation (ONF) and the ONF Contributors
Matt Jeanneret2e3051a2019-05-11 15:01:46 -04004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Joey Armstrong811e9542022-12-25 21:45:27 -050016# -----------------------------------------------------------------------
17
18# ---------------------------------------------------------------------------
19# Alternates to try when APK is having repository problems.
20# http://dl-cnd.alpinelinux.org
21# http://dl-3.alpinelinux.org
22# http://dl-4.alpinelinux.org
23# ---------------------------------------------------------------------------
24#9 0.263 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKIND4EX.tar.gz
25#9 5.269 ERROR: https://dl-cdn.alpinelinux.org/alpine/v3.13/main: temporary error (try again later)
26#9 5.269 WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.13/main: No such file or directory
27#9 5.269 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
28# ---------------------------------------------------------------------------
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040029
khenaidoocfee5f42018-07-19 22:47:38 -040030# -------------
31# Build stage
32
David K. Bainbridgefc8e1812021-04-09 16:09:49 +000033FROM --platform=linux/amd64 golang:1.16.3-alpine3.13 AS dev
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040034
Joey Armstrong811e9542022-12-25 21:45:27 -050035# [TODO] update
36# FROM --platform=linux/amd64 golang:1.19.4-r0-alpine3.17 AS dev
37
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040038# Install required packages
Joey Armstrong811e9542022-12-25 21:45:27 -050039
40RUN apk --update update # refresh the index
41RUN apk --update add --no-cache build-base=0.5-r3
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040042
girishk5259f8e2019-10-10 18:44:44 +000043# Use Standard go build directory structure
44WORKDIR /go/src
khenaidooffe076b2019-01-15 16:08:08 -050045
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040046# Copy common files.
sbarbari17d7e222019-11-05 10:02:29 -050047COPY db ./db
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040048COPY vendor ./vendor
49
Joey Armstrong811e9542022-12-25 21:45:27 -050050# go test -coverprofile fails w/o this.
51COPY tests/results/go-test-coverage.out ./tests/results/go-test-coverage.out
52
khenaidoocfee5f42018-07-19 22:47:38 -040053# Copy files
Matt Jeanneret85ab5082019-04-01 11:29:20 -040054COPY rw_core ./rw_core
girishk5259f8e2019-10-10 18:44:44 +000055COPY go.mod ./
56COPY go.sum ./
khenaidooffe076b2019-01-15 16:08:08 -050057
Kent Hagermanc64df642020-04-07 10:26:41 -040058ARG EXTRA_GO_BUILD_TAGS=""
59
Andrea Campanella8d4f3e32021-04-13 10:02:03 +020060ARG CGO_PARAMETER="CGO_ENABLED=0"
61
Matt Jeanneret877b5c22019-07-03 11:09:50 -040062ARG org_label_schema_version=unknown
63ARG org_label_schema_vcs_url=unknown
64ARG org_label_schema_vcs_ref=unknown
65ARG org_label_schema_build_date=unknown
66ARG org_opencord_vcs_commit_date=unknown
67ARG org_opencord_vcs_dirty=unknown
68
Matt Jeanneret85ab5082019-04-01 11:29:20 -040069# Build
girishk5259f8e2019-10-10 18:44:44 +000070WORKDIR /go/src/rw_core
David K. Bainbridge41835142021-04-01 17:26:12 +000071SHELL ["/bin/ash", "-o", "pipefail", "-c"]
72RUN \
Andrea Campanella8d4f3e32021-04-13 10:02:03 +020073export ${CGO_PARAMETER?} && go build $EXTRA_GO_BUILD_TAGS -mod=vendor -o /app/rw_core \
David K. Bainbridge41835142021-04-01 17:26:12 +000074-ldflags \
khenaidood948f772021-08-11 17:49:24 -040075"-X github.com/opencord/voltha-lib-go/v7/pkg/version.version=$org_label_schema_version \
76-X github.com/opencord/voltha-lib-go/v7/pkg/version.vcsRef=$org_label_schema_vcs_ref \
77-X github.com/opencord/voltha-lib-go/v7/pkg/version.vcsDirty=$org_opencord_vcs_dirty \
78-X github.com/opencord/voltha-lib-go/v7/pkg/version.goVersion=$(go version 2>&1 | sed -E 's/.*go([0-9]+\.[0-9]+\.[0-9]+).*/\1/g') \
79-X github.com/opencord/voltha-lib-go/v7/pkg/version.os=$(go env GOHOSTOS) \
80-X github.com/opencord/voltha-lib-go/v7/pkg/version.arch=$(go env GOHOSTARCH) \
81-X github.com/opencord/voltha-lib-go/v7/pkg/version.buildTime=$org_label_schema_build_date" \
David K. Bainbridge41835142021-04-01 17:26:12 +000082.
83
84WORKDIR /app
Matt Jeanneret85ab5082019-04-01 11:29:20 -040085
khenaidoocfee5f42018-07-19 22:47:38 -040086# -------------
87# Image creation stage
David K. Bainbridge41835142021-04-01 17:26:12 +000088FROM --platform=linux/amd64 gcr.io/distroless/static:nonroot as prod
khenaidoocfee5f42018-07-19 22:47:38 -040089
90# Set the working directory
91WORKDIR /app
92
93# Copy required files
David K. Bainbridge41835142021-04-01 17:26:12 +000094COPY --from=dev /app/rw_core /app/rw_core
khenaidoocfee5f42018-07-19 22:47:38 -040095
Matt Jeanneret2e3051a2019-05-11 15:01:46 -040096# Label image
97ARG org_label_schema_version=unknown
98ARG org_label_schema_vcs_url=unknown
99ARG org_label_schema_vcs_ref=unknown
100ARG org_label_schema_build_date=unknown
101ARG org_opencord_vcs_commit_date=unknown
Kent Hagermanf4a3aab2019-05-22 14:42:34 -0400102ARG org_opencord_vcs_dirty=unknown
Matt Jeanneret2e3051a2019-05-11 15:01:46 -0400103
David K. Bainbridge41835142021-04-01 17:26:12 +0000104LABEL \
105org.label-schema.schema-version=1.0 \
106org.label-schema.name=voltha-rw-core \
107org.label-schema.version=$org_label_schema_version \
108org.label-schema.vcs-url=$org_label_schema_vcs_url \
109org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
110org.label-schema.build-date=$org_label_schema_build_date \
111org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \
112org.opencord.vcs-dirty=$org_opencord_vcs_dirty
113
114USER nonroot:nonroot