From 250819c08d4ab58b3d5c7419c9acd02d06b3b45e Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 23 Nov 2022 12:41:56 +0100 Subject: [PATCH 1/8] 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" From ace27f78682090f0a3017e3583654b187f3705e6 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 23 Nov 2022 13:20:52 +0100 Subject: [PATCH 2/8] Fix default checkout --- scripts/utils/prepare.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/utils/prepare.sh b/scripts/utils/prepare.sh index 16668ca..44ceffa 100755 --- a/scripts/utils/prepare.sh +++ b/scripts/utils/prepare.sh @@ -18,7 +18,10 @@ alias git="git -C .build/repository" if ! [ -d .build/repository ]; then git clone "${GIT_REPOSITORY}" .build/repository else - git checkout - # Checkout previous branch in case GIT_CHECKOUT was different + # Checkout default-branch in case GIT_CHECKOUT was different + defaultBranch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') + git checkout "${defaultBranch}" + git pull # Get changes fi From d32f36dd297d1467182e2d5b73d0d585f99e4053 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 23 Nov 2022 13:37:43 +0100 Subject: [PATCH 3/8] Add latest-tag to image creation --- scripts/utils/build-multiarch.sh | 1 + scripts/utils/build-ownarch.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/scripts/utils/build-multiarch.sh b/scripts/utils/build-multiarch.sh index 62520b5..f1ffb5f 100755 --- a/scripts/utils/build-multiarch.sh +++ b/scripts/utils/build-multiarch.sh @@ -5,6 +5,7 @@ EXTRA_ARGS=${EXTRA_ARGS:-"$@"} docker buildx build \ --platform $PLATFORM \ +--tag $TAG:latest \ --tag "${TAG}:${VERSION}" \ $EXTRA_ARGS \ . diff --git a/scripts/utils/build-ownarch.sh b/scripts/utils/build-ownarch.sh index f45d297..23b0923 100755 --- a/scripts/utils/build-ownarch.sh +++ b/scripts/utils/build-ownarch.sh @@ -3,6 +3,7 @@ TAG=${TAG:-"${TAG_PREFIX}${NAME}"} EXTRA_ARGS=${EXTRA_ARGS:-"$@"} docker build \ +--tag $TAG:latest \ --tag $TAG:$VERSION \ $EXTRA_ARGS \ . From b6c8457bc3b50e74ee48a7516218eca206755df6 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 23 Nov 2022 18:37:17 +0100 Subject: [PATCH 4/8] Move args-declaration to build --- scripts/build.sh | 3 +++ scripts/utils/build-multiarch.sh | 1 - scripts/utils/build-ownarch.sh | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 5eb74c5..78c7fca 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -4,6 +4,9 @@ scriptPath_file=$(dirname "${BASH_SOURCE[0]}") scriptPath_folder=$(realpath "${scriptPath_file}") utils_path="${scriptPath_folder}/utils" +# Get args without path +EXTRA_ARGS="${@:2}" + # Call prepare printf "# PREPARE\n" source ${utils_path}/prepare.sh diff --git a/scripts/utils/build-multiarch.sh b/scripts/utils/build-multiarch.sh index f1ffb5f..37d4c05 100755 --- a/scripts/utils/build-multiarch.sh +++ b/scripts/utils/build-multiarch.sh @@ -1,7 +1,6 @@ #!/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 \ diff --git a/scripts/utils/build-ownarch.sh b/scripts/utils/build-ownarch.sh index 23b0923..6b5b64c 100755 --- a/scripts/utils/build-ownarch.sh +++ b/scripts/utils/build-ownarch.sh @@ -1,6 +1,5 @@ #!/bin/bash TAG=${TAG:-"${TAG_PREFIX}${NAME}"} -EXTRA_ARGS=${EXTRA_ARGS:-"$@"} docker build \ --tag $TAG:latest \ From 85a3dbfb961dbd18e90f90cb0cd7b0242c326119 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 23 Nov 2022 18:38:52 +0100 Subject: [PATCH 5/8] Use Workdir-variable from arg --- scripts/build.sh | 11 +++++++++++ scripts/utils/build-multiarch.sh | 2 +- scripts/utils/build-ownarch.sh | 2 +- scripts/utils/prepare.sh | 20 +++++++++++++------- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 78c7fca..545928c 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -4,9 +4,16 @@ scriptPath_file=$(dirname "${BASH_SOURCE[0]}") scriptPath_folder=$(realpath "${scriptPath_file}") utils_path="${scriptPath_folder}/utils" +WORKDIR=${1:-$PWD} +WORKDIR=$(realpath "$WORKDIR") + +# Store original path +ORIGINALDIR=$PWD + # Get args without path EXTRA_ARGS="${@:2}" + # Call prepare printf "# PREPARE\n" source ${utils_path}/prepare.sh @@ -15,3 +22,7 @@ source ${utils_path}/prepare.sh printf "# BUILD\n" build_type=${BUILD:-"ownarch"} source ${utils_path}/build-${build_type}.sh + + +# Switch back to original path +cd $ORIGINALDIR diff --git a/scripts/utils/build-multiarch.sh b/scripts/utils/build-multiarch.sh index 37d4c05..15444b7 100755 --- a/scripts/utils/build-multiarch.sh +++ b/scripts/utils/build-multiarch.sh @@ -7,4 +7,4 @@ docker buildx build \ --tag $TAG:latest \ --tag "${TAG}:${VERSION}" \ $EXTRA_ARGS \ -. +$WORKDIR diff --git a/scripts/utils/build-ownarch.sh b/scripts/utils/build-ownarch.sh index 6b5b64c..95b25a7 100755 --- a/scripts/utils/build-ownarch.sh +++ b/scripts/utils/build-ownarch.sh @@ -5,4 +5,4 @@ docker build \ --tag $TAG:latest \ --tag $TAG:$VERSION \ $EXTRA_ARGS \ -. +"$WORKDIR" diff --git a/scripts/utils/prepare.sh b/scripts/utils/prepare.sh index 44ceffa..19fad32 100755 --- a/scripts/utils/prepare.sh +++ b/scripts/utils/prepare.sh @@ -2,26 +2,32 @@ # --- VARIABLES --- # Load variables -source $PWD/info.env +source $WORKDIR/info.env # Check if certain vars are overwritten, set them if missing if [ "${NAME}" = "" ]; then - NAME="$(basename $PWD)" + NAME="$(basename $WORKDIR)" fi export NAME printf "Name: ${NAME}\n" +repositoryFolder="$WORKDIR/.build/repository" # --- SOURCES --- -alias git="git -C .build/repository" # Get sources locally -if ! [ -d .build/repository ]; then - git clone "${GIT_REPOSITORY}" .build/repository -else +if ! [ -d "$repositoryFolder" ]; then + git clone "${GIT_REPOSITORY}" . + cloned=True +fi + +# Change into repository +cd "$repositoryFolder" + +if [ "$cloned" != True ]; then # Checkout default-branch in case GIT_CHECKOUT was different defaultBranch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') git checkout "${defaultBranch}" - + git pull # Get changes fi From 019a6d3f639c3b9b1ca147c620e67be5d475810d Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 23 Nov 2022 18:57:24 +0100 Subject: [PATCH 6/8] Move tag to build.sh --- scripts/build.sh | 3 +++ scripts/utils/build-multiarch.sh | 1 - scripts/utils/build-ownarch.sh | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 545928c..10ff367 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -7,12 +7,15 @@ utils_path="${scriptPath_folder}/utils" WORKDIR=${1:-$PWD} WORKDIR=$(realpath "$WORKDIR") +# -- VARIABLES -- # Store original path ORIGINALDIR=$PWD # Get args without path EXTRA_ARGS="${@:2}" +TAG=${TAG:-"${TAG_PREFIX}${NAME}"} + # Call prepare printf "# PREPARE\n" diff --git a/scripts/utils/build-multiarch.sh b/scripts/utils/build-multiarch.sh index 15444b7..56794c4 100755 --- a/scripts/utils/build-multiarch.sh +++ b/scripts/utils/build-multiarch.sh @@ -1,5 +1,4 @@ #!/bin/bash -TAG=${TAG:-"${TAG_PREFIX}${NAME}"} PLATFORM=${PLATFORM:-"linux/amd64,linux/arm64/v8,linux/arm/v7"} docker buildx build \ diff --git a/scripts/utils/build-ownarch.sh b/scripts/utils/build-ownarch.sh index 95b25a7..1f43303 100755 --- a/scripts/utils/build-ownarch.sh +++ b/scripts/utils/build-ownarch.sh @@ -1,5 +1,4 @@ #!/bin/bash -TAG=${TAG:-"${TAG_PREFIX}${NAME}"} docker build \ --tag $TAG:latest \ From dfb6fc687039f6200d59cc6a629bda53d223efea Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 23 Nov 2022 19:01:36 +0100 Subject: [PATCH 7/8] Ignore build-folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..30bcfa4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.build/ From 0354046e3c0aa9a1cfb47162dd2bee4fd968863c Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 23 Nov 2022 19:09:11 +0100 Subject: [PATCH 8/8] Add Instructions on how to use project --- README.md | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d6d6370..b6f1b8f 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,41 @@ Collection of Dockerfiles created to build & pack various tools.
-- [1. Tools](#1-tools) +- [1. How to use](#1-how-to-use) + - [1.1. CLI](#11-cli) +- [2. Tools](#2-tools)
-# 1. Tools +# 1. How to use + +Run the build-script `script/build.sh` with the path to the tool you want to build. + +
+ +The docker-image will be tagged with `default` and the detected version/commit-hash. + +You can add more tags or change the existing tag-naming-scheme using the environment-variable `TAG`. + +
+ +## 1.1. CLI + +`script/build.sh [extra-args for docker build ..]` + +
+ +### 1.1.1. Environment-Variables + +Variable | Description | Default +-|-|- +`TAG` | Tag for Docker-building | `TAGPREFIX` + `NAME` +`TAGPREFIX` | Set a prefix to the default-tag | - +`NAME` | Change the name used in the tag | *FolderName* + +
+ +# 2. Tools Nothing yet