#!/usr/bin/env sh

set -ex
export "CGO_ENABLED"="1"
export "GIT_COMMIT"="8756bef55608385dc1981423593eece8355b4372"
export "GOEXPERIMENT"="systemcrypto"
export "GOPROXY"="direct"
export "IMAGE_VERSION"="0.5.0"
export "PKG"="sigs.k8s.io/azurelustre-csi-driver"
export "PROJECT_DIR"="azurelustre-csi"

(
cd ${PROJECT_DIR}

### Finish setting build variables
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS="\"-X ${PKG}/pkg/azurelustre.driverVersion=${IMAGE_VERSION} -X ${PKG}/pkg/azurelustre.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/azurelustre.buildDate=${BUILD_DATE} -s -w -extldflags '-static'\""

make azurelustre-dalec

cp pkg/azurelustreplugin/entrypoint.sh /app/entrypoint.sh
cp pkg/azurelustreplugin/useAzureAptMirror.sh /app/useAzureAptMirror.sh
cp pkg/azurelustreplugin/start.sh /app/start.sh
cp pkg/azurelustreplugin/readinessProbe.sh /app/readinessProbe.sh
cp LICENSE /app/LICENSE

# start.sh and readinessProbe.sh ship as git mode 0644 on upstream/development;
# the artifacts.links /usr/bin/* entries preserve source mode, so make them
# executable to satisfy the Check permissions test (0755).
chmod 0755 /app/entrypoint.sh /app/useAzureAptMirror.sh /app/start.sh /app/readinessProbe.sh

)
