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