Skip to content

Commit

Permalink
Changes in Dockerfile to use Golang based Image
Browse files Browse the repository at this point in the history
  • Loading branch information
tejasshahintel authored and togashidm committed Dec 8, 2021
1 parent 63d2671 commit d3758cb
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 5 deletions.
2 changes: 1 addition & 1 deletion telemetry-aware-scheduling/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ all: format build
build:
CGO_ENABLED=0 GO111MODULE=on go build -ldflags="-s -w" -o ./bin/$(BINARY_NAME) ./cmd
image:
docker build -f deploy/images/Dockerfile bin/ -t tasextender
docker build -f deploy/images/Dockerfile ../ -t tasextender
format:
gofmt -w -s .

Expand Down
20 changes: 16 additions & 4 deletions telemetry-aware-scheduling/deploy/images/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
FROM alpine:3.12.1 as build
FROM golang:1.16-alpine as user_builder
RUN adduser -D -u 10001 tas

FROM golang:1.16-alpine as builder
ARG DIR=telemetry-aware-scheduling
ARG SRC_ROOT=/src_root
COPY . ${SRC_ROOT}

RUN mkdir -p /install_root/etc
COPY --from=user_builder /etc/passwd /install_root/etc/passwd

WORKDIR ${SRC_ROOT}/${DIR}
RUN CGO_ENABLED=0 GO111MODULE=on go build -ldflags="-s -w" -o /install_root/extender ./cmd \
&& install -D ${SRC_ROOT}/${DIR}/LICENSE /install_root/usr/local/share/package-licenses/telemetry-aware-scheduling/LICENSE \
&& scripts/copy-modules-licenses.sh ./cmd /install_root/usr/local/share/

FROM scratch
WORKDIR /
COPY extender .
COPY --from=build /etc/passwd /etc/passwd
COPY --from=builder /install_root /
EXPOSE 9001/tcp
USER tas
ENTRYPOINT ["/extender"]
ENTRYPOINT ["/extender"]
54 changes: 54 additions & 0 deletions telemetry-aware-scheduling/scripts/copy-modules-licenses.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh
#
# Copyright 2019-2021 Intel Corporation.
#
# SPDX-License-Identifier: Apache-2.0
#
# Copy the license obligations of ".Deps" modules for a package to a target directory
set -o errexit
set -o nounset

if [ $# != 2 ] || [ "$1" = "?" ] || [ "$1" = "--help" ]; then
echo "Usage: $0 <package> <target dir>" >&2
exit 1
fi

if [ ! -d "$2" ] || [ ! -w "$2" ]; then
echo "Error: cannot use $2 as the target directory"
exit 1
fi

if [ ! -d "$2"/package-licenses ]; then
mkdir "$2"/package-licenses
fi

export GO111MODULE=on

if [ ! -d vendor ]; then
go mod vendor -v
fi

LICENSE_FILES=$(find vendor |grep -e LICENSE -e NOTICE|cut -d / -f 2-)
PACKAGE_DEPS=$(go list -f '{{ join .Deps "\n" }}' "$1" |grep "\.")

POPD=$(pwd)
cd vendor

for lic in $LICENSE_FILES; do
DIR=$(dirname "$lic")

# Copy the license if its repository path is found in package .Deps
if [ "$(echo "$PACKAGE_DEPS" | grep -c "$DIR")" -gt 0 ]; then
cp --parents "$lic" "$2"/package-licenses

# Copy the source if the license is MPL/GPL/LGPL
if [ "$(grep -c -w -e MPL -e GPL -e LGPL "$lic")" -gt 0 ]; then
if [ ! -d "$2"/package-sources ]; then
mkdir "$2"/package-sources
fi
tar -zvcf "$2"/package-sources/"$(echo "$DIR" | tr / _)".tar.gzip "$DIR"
fi
fi
done

cd "$POPD"

0 comments on commit d3758cb

Please sign in to comment.