Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [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 | d80007b | 2021-04-12 12:22:29 +0000 | [diff] [blame] | 18 | FROM --platform=linux/amd64 golang:1.16.3-alpine3.13 AS dev |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 19 | |
Matteo Scandolo | dcd9318 | 2020-04-29 13:21:45 -0700 | [diff] [blame] | 20 | # Install required packages |
David K. Bainbridge | d80007b | 2021-04-12 12:22:29 +0000 | [diff] [blame] | 21 | RUN apk add --no-cache build-base=0.5-r2 |
Matteo Scandolo | dcd9318 | 2020-04-29 13:21:45 -0700 | [diff] [blame] | 22 | |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 23 | # Use Standard go build directory structure |
| 24 | WORKDIR /go/src |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 25 | COPY . . |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 26 | |
Holger Hildebrandt | 6999fe5 | 2021-02-11 11:49:05 +0000 | [diff] [blame] | 27 | ARG EXTRA_GO_BUILD_TAGS="" |
| 28 | |
David K. Bainbridge | 740ca85 | 2021-04-15 00:23:35 +0000 | [diff] [blame] | 29 | ARG CGO_PARAMETER=0 |
| 30 | |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 31 | ARG org_label_schema_version=unknown |
| 32 | ARG org_label_schema_vcs_url=unknown |
| 33 | ARG org_label_schema_vcs_ref=unknown |
| 34 | ARG org_label_schema_build_date=unknown |
| 35 | ARG org_opencord_vcs_commit_date=unknown |
| 36 | ARG org_opencord_vcs_dirty=unknown |
| 37 | |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 38 | # Build |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 39 | SHELL ["/bin/ash", "-o", "pipefail", "-c"] |
David K. Bainbridge | 2d33743 | 2021-04-01 20:27:34 +0000 | [diff] [blame] | 40 | RUN \ |
David K. Bainbridge | 740ca85 | 2021-04-15 00:23:35 +0000 | [diff] [blame] | 41 | CGO_ENABLED=$CGO_PARAMETER go build $EXTRA_GO_BUILD_TAGS -mod=vendor -o /app/openonu \ |
David K. Bainbridge | 2d33743 | 2021-04-01 20:27:34 +0000 | [diff] [blame] | 42 | -ldflags \ |
| 43 | "-X github.com/opencord/voltha-lib-go/v4/pkg/version.version=$org_label_schema_version \ |
| 44 | -X github.com/opencord/voltha-lib-go/v4/pkg/version.vcsRef=$org_label_schema_vcs_ref \ |
| 45 | -X github.com/opencord/voltha-lib-go/v4/pkg/version.vcsDirty=$org_opencord_vcs_dirty \ |
| 46 | -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') \ |
| 47 | -X github.com/opencord/voltha-lib-go/v4/pkg/version.os=$(go env GOHOSTOS) \ |
| 48 | -X github.com/opencord/voltha-lib-go/v4/pkg/version.arch=$(go env GOHOSTARCH) \ |
| 49 | -X github.com/opencord/voltha-lib-go/v4/pkg/version.buildTime=$org_label_schema_build_date" \ |
| 50 | ./cmd/openonu-adapter/ |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 51 | |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 52 | WORKDIR /app |
| 53 | |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 54 | # ------------- |
| 55 | # Image creation stage |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 56 | |
| 57 | FROM --platform=linux/amd64 gcr.io/distroless/static:nonroot AS prod |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 58 | |
| 59 | # Set the working directory |
| 60 | WORKDIR /app |
| 61 | |
| 62 | # Copy required files |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 63 | COPY --from=dev /app/openonu /app/openonu |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 64 | |
| 65 | # Label image |
| 66 | ARG org_label_schema_version=unknown |
| 67 | ARG org_label_schema_vcs_url=unknown |
| 68 | ARG org_label_schema_vcs_ref=unknown |
| 69 | ARG org_label_schema_build_date=unknown |
| 70 | ARG org_opencord_vcs_commit_date=unknown |
| 71 | ARG org_opencord_vcs_dirty=unknown |
| 72 | |
David K. Bainbridge | 2d33743 | 2021-04-01 20:27:34 +0000 | [diff] [blame] | 73 | LABEL \ |
| 74 | org.label-schema.schema-version=1.0 \ |
| 75 | org.label-schema.name=voltha-openonu-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 \ |
| 80 | org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \ |
| 81 | org.opencord.vcs-dirty=$org_opencord_vcs_dirty |
| 82 | |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 83 | USER nonroot:nonroot |