Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 1 | # 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 | |
David K. Bainbridge | 595b670 | 2021-04-09 16:10:58 +0000 | [diff] [blame] | 18 | FROM --platform=linux/amd64 golang:1.16.3-alpine3.13 AS dev |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 19 | |
David K. Bainbridge | b02c6b9 | 2021-04-14 23:36:08 +0000 | [diff] [blame] | 20 | # Install required packages |
Andrea Campanella | 42dacd6 | 2022-06-22 09:59:41 +0200 | [diff] [blame] | 21 | RUN apk add --no-cache build-base=0.5-r3 |
David K. Bainbridge | b02c6b9 | 2021-04-14 23:36:08 +0000 | [diff] [blame] | 22 | |
David K. Bainbridge | 3d5ac93 | 2021-04-06 18:08:35 +0000 | [diff] [blame] | 23 | WORKDIR /go/src |
| 24 | COPY . . |
| 25 | |
| 26 | ARG EXTRA_GO_BUILD_TAGS="" |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 27 | |
David K. Bainbridge | b02c6b9 | 2021-04-14 23:36:08 +0000 | [diff] [blame] | 28 | ARG CGO_PARAMETER="0" |
| 29 | |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 30 | ARG org_label_schema_version=unknown |
| 31 | ARG org_label_schema_vcs_url=unknown |
| 32 | ARG org_label_schema_vcs_ref=unknown |
| 33 | ARG org_label_schema_build_date=unknown |
| 34 | ARG org_opencord_vcs_commit_date=unknown |
| 35 | ARG org_opencord_vcs_dirty=unknown |
| 36 | |
David K. Bainbridge | 3d5ac93 | 2021-04-06 18:08:35 +0000 | [diff] [blame] | 37 | # Build |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 38 | SHELL ["/bin/ash", "-o", "pipefail", "-c"] |
David K. Bainbridge | 0ee1865 | 2021-04-01 18:29:23 +0000 | [diff] [blame] | 39 | RUN \ |
David K. Bainbridge | b02c6b9 | 2021-04-14 23:36:08 +0000 | [diff] [blame] | 40 | CGO_ENABLED=$CGO_PARAMETER go build $EXTRA_GO_BUILD_TAGS -mod=vendor -o /app/ofagent \ |
David K. Bainbridge | 0ee1865 | 2021-04-01 18:29:23 +0000 | [diff] [blame] | 41 | -ldflags \ |
David K. Bainbridge | e05cf0c | 2021-08-19 03:16:50 +0000 | [diff] [blame] | 42 | "-X github.com/opencord/voltha-lib-go/v7/pkg/version.version=$org_label_schema_version \ |
| 43 | -X github.com/opencord/voltha-lib-go/v7/pkg/version.vcsRef=$org_label_schema_vcs_ref \ |
| 44 | -X github.com/opencord/voltha-lib-go/v7/pkg/version.vcsDirty=$org_opencord_vcs_dirty \ |
| 45 | -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') \ |
| 46 | -X github.com/opencord/voltha-lib-go/v7/pkg/version.os=$(go env GOHOSTOS) \ |
| 47 | -X github.com/opencord/voltha-lib-go/v7/pkg/version.arch=$(go env GOHOSTARCH) \ |
| 48 | -X github.com/opencord/voltha-lib-go/v7/pkg/version.buildTime=$org_label_schema_build_date" \ |
David K. Bainbridge | 0ee1865 | 2021-04-01 18:29:23 +0000 | [diff] [blame] | 49 | ./cmd/ofagent |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 50 | |
David K. Bainbridge | 3d5ac93 | 2021-04-06 18:08:35 +0000 | [diff] [blame] | 51 | WORKDIR /app |
| 52 | |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 53 | # ------------- |
| 54 | # Image creation stage |
David K. Bainbridge | 3d5ac93 | 2021-04-06 18:08:35 +0000 | [diff] [blame] | 55 | FROM --platform=linux/amd64 gcr.io/distroless/static:nonroot AS prod |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 56 | |
| 57 | # Set the working directory |
| 58 | WORKDIR /app |
| 59 | |
| 60 | # Copy required files |
David K. Bainbridge | 3d5ac93 | 2021-04-06 18:08:35 +0000 | [diff] [blame] | 61 | COPY --from=dev /app/ofagent /app/ofagent |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 62 | |
| 63 | # Label image |
| 64 | ARG org_label_schema_version=unknown |
| 65 | ARG org_label_schema_vcs_url=unknown |
| 66 | ARG org_label_schema_vcs_ref=unknown |
| 67 | ARG org_label_schema_build_date=unknown |
| 68 | ARG org_opencord_vcs_commit_date=unknown |
| 69 | ARG org_opencord_vcs_dirty=unknown |
| 70 | |
David K. Bainbridge | 0ee1865 | 2021-04-01 18:29:23 +0000 | [diff] [blame] | 71 | LABEL \ |
| 72 | org.label-schema.schema-version=1.0 \ |
| 73 | org.label-schema.name=voltha-ofagent-go \ |
| 74 | org.label-schema.version=$org_label_schema_version \ |
| 75 | org.label-schema.vcs-url=$org_label_schema_vcs_url \ |
| 76 | org.label-schema.vcs-ref=$org_label_schema_vcs_ref \ |
| 77 | org.label-schema.build-date=$org_label_schema_build_date \ |
| 78 | org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \ |
| 79 | org.opencord.vcs-dirty=$org_opencord_vcs_dirty |
| 80 | |
David K. Bainbridge | 3d5ac93 | 2021-04-06 18:08:35 +0000 | [diff] [blame] | 81 | USER nonroot:nonroot |