From 250819c08d4ab58b3d5c7419c9acd02d06b3b45e Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 23 Nov 2022 12:41:56 +0100 Subject: [PATCH] Add build-scripts --- scripts/build.sh | 14 ++++++++++ scripts/utils/build-multiarch.sh | 10 +++++++ scripts/utils/build-ownarch.sh | 8 ++++++ scripts/utils/prepare.sh | 46 ++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100755 scripts/build.sh create mode 100755 scripts/utils/build-multiarch.sh create mode 100755 scripts/utils/build-ownarch.sh create mode 100755 scripts/utils/prepare.sh diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..5eb74c5 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +scriptPath_file=$(dirname "${BASH_SOURCE[0]}") +scriptPath_folder=$(realpath "${scriptPath_file}") +utils_path="${scriptPath_folder}/utils" + +# Call prepare +printf "# PREPARE\n" +source ${utils_path}/prepare.sh + +# Call build +printf "# BUILD\n" +build_type=${BUILD:-"ownarch"} +source ${utils_path}/build-${build_type}.sh diff --git a/scripts/utils/build-multiarch.sh b/scripts/utils/build-multiarch.sh new file mode 100755 index 0000000..62520b5 --- /dev/null +++ b/scripts/utils/build-multiarch.sh @@ -0,0 +1,10 @@ +#!/bin/bash +TAG=${TAG:-"${TAG_PREFIX}${NAME}"} +PLATFORM=${PLATFORM:-"linux/amd64,linux/arm64/v8,linux/arm/v7"} +EXTRA_ARGS=${EXTRA_ARGS:-"$@"} + +docker buildx build \ +--platform $PLATFORM \ +--tag "${TAG}:${VERSION}" \ +$EXTRA_ARGS \ +. diff --git a/scripts/utils/build-ownarch.sh b/scripts/utils/build-ownarch.sh new file mode 100755 index 0000000..f45d297 --- /dev/null +++ b/scripts/utils/build-ownarch.sh @@ -0,0 +1,8 @@ +#!/bin/bash +TAG=${TAG:-"${TAG_PREFIX}${NAME}"} +EXTRA_ARGS=${EXTRA_ARGS:-"$@"} + +docker build \ +--tag $TAG:$VERSION \ +$EXTRA_ARGS \ +. diff --git a/scripts/utils/prepare.sh b/scripts/utils/prepare.sh new file mode 100755 index 0000000..16668ca --- /dev/null +++ b/scripts/utils/prepare.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# --- VARIABLES --- +# Load variables +source $PWD/info.env + +# Check if certain vars are overwritten, set them if missing +if [ "${NAME}" = "" ]; then + NAME="$(basename $PWD)" +fi +export NAME +printf "Name: ${NAME}\n" + + +# --- SOURCES --- +alias git="git -C .build/repository" +# Get sources locally +if ! [ -d .build/repository ]; then + git clone "${GIT_REPOSITORY}" .build/repository +else + git checkout - # Checkout previous branch in case GIT_CHECKOUT was different + git pull # Get changes +fi + +# Checkout when set +if [ "$GIT_CHECKOUT" != "" ]; then + # Handle special directives + if [ "$GIT_CHECKOUT" = "latest-tag" ]; then + GIT_CHECKOUT=$(git describe --tags `git rev-list --tags --max-count=1`) # Get latest tag + fi + + git checkout $GIT_CHECKOUT +fi + + +# --- VERSION --- +# Get current version to build +VERSION=$(git describe --tags --long) +if [ $? -ne 0 ]; then + VERSION=$(git rev-parse HEAD) +fi +export VERSION +printf "Version: ${VERSION}\n" + +TAG=${TAG:-"${TAG_PREFIX}${NAME}"} +printf "> ${TAG}\n"