diff --git a/ecs-agent/daemonimages/csidriver/Makefile b/ecs-agent/daemonimages/csidriver/Makefile index 2f315c432be..86ebae6fdf3 100644 --- a/ecs-agent/daemonimages/csidriver/Makefile +++ b/ecs-agent/daemonimages/csidriver/Makefile @@ -1,4 +1,4 @@ -CSI_DRIVER_VERSION?=v1.0.0 +CSI_DRIVER_VERSION="v$(shell cat ./container/VERSION)" GO111MODULE=on GOPATH=$(shell go env GOPATH) BUILD_DATE=$(shell date -u -Iseconds) @@ -9,10 +9,15 @@ ARCH?=amd64 .PHONY: bin/csi-driver bin/csi-driver: CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -ldflags "\ - -X \"github.com/aws/amazon-ecs-agent/ecs-agent/daemon_images/csi-driver/version.version=$(CSI_DRIVER_VERSION)\" \ - -X \"github.com/aws/amazon-ecs-agent/ecs-agent/daemon_images/csi-driver/version.buildDate=$(BUILD_DATE)\"" \ + -X \"github.com/aws/amazon-ecs-agent/ecs-agent/daemonimages/csidriver/version.version=$(CSI_DRIVER_VERSION)\" \ + -X \"github.com/aws/amazon-ecs-agent/ecs-agent/daemonimages/csidriver/version.buildDate=$(BUILD_DATE)\"" \ -o ./bin/csi-driver ./ +.PHONY: build-csi-driver +build-csi-driver: bin/csi-driver + ./build-csi-driver-image + $(MAKE) clean + .PHONY: test test: go test -v -race -tags unit -timeout=60s ./... diff --git a/ecs-agent/daemonimages/csidriver/build-csi-driver-image b/ecs-agent/daemonimages/csidriver/build-csi-driver-image new file mode 100755 index 00000000000..6becf65c000 --- /dev/null +++ b/ecs-agent/daemonimages/csidriver/build-csi-driver-image @@ -0,0 +1,60 @@ +#!/bin/bash +# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). You may +# not use this file except in compliance with the License. A copy of the +# License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "license" file accompanying this file. This file is distributed +# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +# express or implied. See the License for the specific language governing +# permissions and limitations under the License. + +# This script builds a csi driver image. + +set -ex + +ROOT=$(pwd) +cd "${ROOT}" +VERSION="v$(cat ./container/VERSION)" + +architecture="" +case $(uname -m) in + x86_64) + architecture="amd64" + ;; + arm64) + architecture="arm64" + ;; + aarch64) + architecture="arm64" + ;; + *) + echo $"Unknown architecture $0" + exit 1 +esac + +if [ "$architecture" == "amd64" ]; then export GOARCH=amd64; fi +if [ "$architecture" == "arm64" ]; then export GOARCH=arm64; fi + +# build binary +mkdir -p rootfs/bin/ +cp bin/csi-driver rootfs/bin/csi-driver + +# build container +mkdir -p image/rootfs +tar --mtime="@1492525740" --owner=0 --group=0 --numeric-owner -cf image/rootfs/layer.tar -C rootfs . +DIGEST=$(sha256sum image/rootfs/layer.tar | sed -e 's/ .*//') +install -m 0644 ./container/VERSION image/rootfs/VERSION +install -m 0644 ./container/config.json image/config.json +sed -i "s/~~digest~~/${DIGEST}/" image/config.json +sed -i "s/~~architecture~~/${GOARCH}/" image/config.json +sed -i "s/~~timestamp~~/$(date +"%FT%T.%NZ")/g" image/config.json +install -m 0644 ./container/manifest.json image/manifest.json +install -m 0644 ./container/repositories image/repositories +mkdir -p tarfiles/ +tar --mtime="@1492525740" --owner=0 --group=0 --numeric-owner -cf ./tarfiles/csi-driver-${GOARCH}.tar -C image . +rm -rf image/ +rm -rf rootfs/ diff --git a/ecs-agent/daemonimages/csidriver/container/VERSION b/ecs-agent/daemonimages/csidriver/container/VERSION new file mode 100644 index 00000000000..3eefcb9dd5b --- /dev/null +++ b/ecs-agent/daemonimages/csidriver/container/VERSION @@ -0,0 +1 @@ +1.0.0 diff --git a/ecs-agent/daemonimages/csidriver/container/config.json b/ecs-agent/daemonimages/csidriver/container/config.json new file mode 100644 index 00000000000..ed739f46e0b --- /dev/null +++ b/ecs-agent/daemonimages/csidriver/container/config.json @@ -0,0 +1 @@ +{"architecture":"~~architecture~~","author":"Amazon Web Services, Inc.","config":{"Entrypoint":["/bin/csi-driver"],"ArgsEscaped":true,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":null},"created":"~~timestamp~~","history":[{"created":"~~timestamp~~","author":"Amazon Web Services, Inc.","created_by":"°o°","empty_layer":true}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:~~digest~~"]}} diff --git a/ecs-agent/daemonimages/csidriver/container/manifest.json b/ecs-agent/daemonimages/csidriver/container/manifest.json new file mode 100644 index 00000000000..88754ec821f --- /dev/null +++ b/ecs-agent/daemonimages/csidriver/container/manifest.json @@ -0,0 +1 @@ +[{"Config":"config.json","RepoTags":["amazon/amazon-ebs-csi-driver:latest"],"Layers":["rootfs/layer.tar"]}] diff --git a/ecs-agent/daemonimages/csidriver/container/repositories b/ecs-agent/daemonimages/csidriver/container/repositories new file mode 100644 index 00000000000..d9cb11b72e3 --- /dev/null +++ b/ecs-agent/daemonimages/csidriver/container/repositories @@ -0,0 +1 @@ +{"amazon/amazon-ebs-csi-driver":{"amazon-ecs":"rootfs"}} \ No newline at end of file diff --git a/ecs-agent/daemonimages/csidriver/tarfiles/csi-driver-amd64.tar b/ecs-agent/daemonimages/csidriver/tarfiles/csi-driver-amd64.tar new file mode 100644 index 00000000000..e539c8e94fb Binary files /dev/null and b/ecs-agent/daemonimages/csidriver/tarfiles/csi-driver-amd64.tar differ