2019-10-17 06:00:51 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set +e
|
|
|
|
|
|
|
|
if [ -z $1 ]; then
|
|
|
|
error "Please set the 'version' variable"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
VERSION="$1"
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# the temp folder to store binary file...
|
|
|
|
mkdir -p binary
|
|
|
|
rm -rf binary/harbor-scanner-clair || true
|
|
|
|
|
2020-02-14 11:58:51 +01:00
|
|
|
cd $(dirname $0)
|
2019-10-17 06:00:51 +02:00
|
|
|
cur=$PWD
|
|
|
|
|
2020-02-14 11:58:51 +01:00
|
|
|
# The temporary directory to clone Clair adapter source code
|
|
|
|
TEMP=$(mktemp -d ${TMPDIR-/tmp}/clair-adapter.XXXXXX)
|
2019-10-26 19:25:36 +02:00
|
|
|
git clone https://github.com/goharbor/harbor-scanner-clair.git $TEMP
|
2020-04-15 16:04:22 +02:00
|
|
|
cd $TEMP; git checkout $VERSION; export COMMIT=$(git rev-list -1 HEAD); cd -
|
2019-10-17 06:00:51 +02:00
|
|
|
|
2020-07-16 10:20:54 +02:00
|
|
|
echo "Building Clair adapter binary based on golang:1.14.5..."
|
2019-10-17 06:00:51 +02:00
|
|
|
cp Dockerfile.binary $TEMP
|
2020-04-15 16:04:22 +02:00
|
|
|
docker build --build-arg VERSION=${VERSION} --build-arg COMMIT=${COMMIT} -f $TEMP/Dockerfile.binary -t clair-adapter-golang $TEMP
|
2019-10-17 06:00:51 +02:00
|
|
|
|
2020-02-14 11:58:51 +01:00
|
|
|
echo "Copying Clair adapter binary from the container to the local directory..."
|
2019-10-17 06:00:51 +02:00
|
|
|
ID=$(docker create clair-adapter-golang)
|
|
|
|
docker cp $ID:/go/src/github.com/goharbor/harbor-scanner-clair/harbor-scanner-clair binary
|
|
|
|
|
|
|
|
docker rm -f $ID
|
|
|
|
docker rmi -f clair-adapter-golang
|
|
|
|
|
2020-02-14 11:58:51 +01:00
|
|
|
echo "Building Clair adapter binary finished successfully"
|
2019-10-17 06:00:51 +02:00
|
|
|
cd $cur
|
|
|
|
rm -rf $TEMP
|