'Generic Commit'
This commit is contained in:
82
publish.sh
82
publish.sh
@@ -6,69 +6,29 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
|
||||
echo "Publishing simple-object-server to gitea.jde.nz/public/simple-object-server:latest"
|
||||
|
||||
PROJECT="simple-object-server"
|
||||
[[ -n $SOS_WRITE_TOKEN ]] || die "SOS_WRITE_TOKEN not specified"
|
||||
|
||||
# FUNCTIONS
|
||||
function title() {
|
||||
echo "----------------------------------------"
|
||||
# Center the text
|
||||
local text="$1"
|
||||
local line_length=40
|
||||
local text_length=${#text}
|
||||
local padding=$(( (line_length - text_length) / 2 ))
|
||||
printf "%*s%s%*s\n" $padding "" "$text" $padding ""
|
||||
echo "----------------------------------------"
|
||||
}
|
||||
|
||||
|
||||
function die() {
|
||||
title "error: $1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Create buildx builder if it doesn't exist
|
||||
if ! docker buildx ls | grep -q "${PROJECT}-multiarch"; then
|
||||
docker buildx create --name ${PROJECT}-multiarch --use \
|
||||
--driver-opt env.BUILDKIT_MAX_PARALLELISM=4
|
||||
else
|
||||
docker buildx use ${PROJECT}-multiarch
|
||||
fi
|
||||
[[ -n $SOS_WRITE_TOKEN ]] || die "SOS_WRITE_TOKEN not specified"
|
||||
|
||||
function build() {
|
||||
local PLATFORM="$1"
|
||||
|
||||
# convert linux/amd64 to linux-amd64, windows/amd64 to windows-amd64, etc.
|
||||
local OSARCH="${PLATFORM//\//-}"
|
||||
|
||||
title "Building ${PROJECT} for ${PLATFORM}"
|
||||
|
||||
docker buildx build \
|
||||
-t "gitea.jde.nz/public/${PROJECT}-build:latest" \
|
||||
-f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \
|
||||
--build-arg PROJECT="${PROJECT}" \
|
||||
--build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
|
||||
--output "${SCRIPT_DIR}/output/${OSARCH}" \
|
||||
--platform "${PLATFORM}" \
|
||||
--cache-from type=local,src=/tmp/.buildx-cache \
|
||||
--cache-to type=local,dest=/tmp/.buildx-cache,mode=max \
|
||||
"${SCRIPT_DIR}"
|
||||
|
||||
mv "${SCRIPT_DIR}/output/${OSARCH}/${PROJECT}" "${SCRIPT_DIR}/output/${PROJECT}-${OSARCH}"
|
||||
rm -rf "${SCRIPT_DIR}/output/${OSARCH}"
|
||||
}
|
||||
|
||||
CMAKE_BUILD_TYPE="Release"
|
||||
|
||||
rm -rf "${SCRIPT_DIR}/output"
|
||||
rm -rf "${SCRIPT_DIR}/output"
|
||||
mkdir -p "${SCRIPT_DIR}/output"
|
||||
mkdir -p /tmp/.buildx-cache
|
||||
|
||||
build "linux/amd64"
|
||||
build "linux/arm64"
|
||||
export CMAKE_BUILD_TYPE="Release"
|
||||
export PROJECT="simple-object-server"
|
||||
|
||||
[ -f "${SCRIPT_DIR}/output/${PROJECT}-linux-amd64" ] || die "${PROJECT}-linux-amd64 not found"
|
||||
[ -f "${SCRIPT_DIR}/output/${PROJECT}-linux-arm64" ] || die "${PROJECT}-linux-arm64 not found"
|
||||
docker build \
|
||||
-t "${PROJECT}-build" \
|
||||
-f "${SCRIPT_DIR}/Dockerfile.dropshell-build" \
|
||||
--build-arg PROJECT="${PROJECT}" \
|
||||
--build-arg CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
|
||||
--output "${SCRIPT_DIR}/output" \
|
||||
"${SCRIPT_DIR}"
|
||||
|
||||
[ -f ${SCRIPT_DIR}/output/simple-object-server ] || die "Build failed."
|
||||
|
||||
# uplaod to getbin.xyz
|
||||
|
||||
@@ -80,7 +40,19 @@ trap 'rm -rf "${SCRIPT_DIR}/temp"' EXIT
|
||||
curl -L -o "${SOS}" "https://getbin.xyz/sos"
|
||||
chmod +x "${SOS}"
|
||||
|
||||
"${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/output/${PROJECT}-linux-amd64" "${PROJECT}:amd64"
|
||||
"${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/output/${PROJECT}-linux-arm64" "${PROJECT}:arm64"
|
||||
ARCH=$(uname -m)
|
||||
|
||||
# upload arch-specific binary
|
||||
"${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/output/${PROJECT}" "${PROJECT}:latest-${ARCH}"
|
||||
|
||||
# upload generic install script (ok if multiple times as we iterate through arch's)
|
||||
"${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/install.sh" "simple-object-server-install:latest"
|
||||
|
||||
# create and upload the arch-specific docker image
|
||||
IMAGE_NAME="gitea.jde.nz/public/simple-object-server:latest-${ARCH}"
|
||||
docker build \
|
||||
-f "${SCRIPT_DIR}/Dockerfile.sos" \
|
||||
-t "${IMAGE_NAME}" \
|
||||
"${SCRIPT_DIR}"
|
||||
|
||||
docker push "${IMAGE_NAME}"
|
||||
|
Reference in New Issue
Block a user