-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scripts for building and running Docker images
- Loading branch information
Showing
5 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/sh | ||
|
||
: "${USER_ID:=$(id -u)}" | ||
: "${GROUP_ID:=$(id -g)}" | ||
|
||
repo=openwrt-build | ||
|
||
selfPath=$(readlink -f "$(command -v "$0")") || exit | ||
selfDir=$(dirname "$selfPath") | ||
dobeRoot=$(dirname "$selfDir") | ||
versionDir=${selfDir}/version | ||
( | ||
cd "$dobeRoot" || exit | ||
version=$( | ||
"${versionDir}/increment" \ | ||
"$versionDir" \ | ||
"${selfPath#"${dobeRoot}/"}" \ | ||
docker/* | ||
) | ||
|
||
docker build \ | ||
-t $repo \ | ||
-t $repo:v"$version" \ | ||
--build-arg "USER_ID=${USER_ID}" \ | ||
--build-arg "GROUP_ID=${GROUP_ID}" \ | ||
docker | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh | ||
|
||
repo=openwrt-build | ||
|
||
versions=$( | ||
docker images --format '{{.Tag}}' $repo \ | ||
| grep -E '^v([0-9]+)$' \ | ||
| sort -nk1.2 \ | ||
| head -n-2 | ||
) | ||
images=$( | ||
for v in $versions; do | ||
printf '%s:%s\n' $repo "$v" | ||
done | ||
) | ||
|
||
[ "$images" ] && docker image rm $images |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/bin/sh | ||
|
||
## Outputs the absolute path when dirname exists, returns with error otherwise. | ||
resolve() { readlink -f "$1"; } ## (relative_path) | ||
## Outputs value of variable referenced by name. | ||
ref() { eval echo "\$${1}"; } ## (name) | ||
## Sets value of variable referenced by name. | ||
refSet() { eval "${1}='$( printf %s "$2" | sed "s/'/'\\\\''/g")'"; } ## (name value) | ||
|
||
selfDir=$(dirname "$(resolve "$(command -v "$0")")") | ||
|
||
: "${DOBE_DIR_ROOT:=$(dirname "$selfDir")/build}" | ||
: "${DOBE_DIR_CACHE:=${DOBE_DIR_ROOT}/cache}" | ||
|
||
: "${DOBE_DIR_SRC:=${DOBE_DIR_ROOT}/src}" | ||
: "${DOBE_DIR_FEEDS:=${DOBE_DIR_ROOT}/feeds}" | ||
: "${DOBE_DIR_OUTPUT:=${DOBE_DIR_ROOT}/output}" | ||
: "${DOBE_DIR_OVERLAY:=${DOBE_DIR_ROOT}/overlay}" | ||
|
||
: "${DOBE_DIR_DL:=${DOBE_DIR_CACHE}/dl}" | ||
: "${DOBE_DIR_BUILD:=${DOBE_DIR_CACHE}/build}" | ||
: "${DOBE_DIR_STAGING:=${DOBE_DIR_CACHE}/staging}" | ||
: "${DOBE_DIR_TMP:=${DOBE_DIR_CACHE}/tmp}" | ||
|
||
for dir in ROOT CACHE SRC FEEDS OUTPUT OVERLAY DL BUILD STAGING TMP; do | ||
path=$(ref "DOBE_DIR_${dir}" ) | ||
if ! resolved=$(resolve "$path"); then | ||
printf 'Could not resolve the %s directory "%s"\n' "$dir" "$path" | ||
exit 1 | ||
fi | ||
[ -d "$resolved" ] || mkdir "$resolved" || exit | ||
refSet "resolved_${dir}" "$resolved" | ||
done | ||
|
||
# shellcheck disable=SC2154 | ||
docker run -it --rm \ | ||
-v "${resolved_SRC}:/src" \ | ||
-v "${resolved_FEEDS}:/src/feeds" \ | ||
-v "${resolved_OUTPUT}:/src/bin" \ | ||
-v "${resolved_OVERLAY}:/src/files" \ | ||
-v "${resolved_DL}:/src/dl" \ | ||
-v "${resolved_BUILD}:/src/build_dir" \ | ||
-v "${resolved_STAGING}:/src/staging_dir" \ | ||
-v "${resolved_TMP}:/src/tmp" \ | ||
-e "TERM=${TERM}" \ | ||
openwrt-build:latest \ | ||
"$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version | ||
version.sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/sh | ||
|
||
dieWithUsage() { | ||
local status=${1:-0} message="$2" | ||
[ "$message" ] && printf %s\\n "$message" >&2 | ||
cat >&2 <<-EOD | ||
Usage: $0 [VERSION_DIR] FILES... | ||
Increment the version number in VERSION_DIR/version when a change in any of the | ||
FILES is detected. | ||
--help display this help and exit | ||
Uses sha1sum to generate checksums of FILES and a checksum of those, and | ||
compares it against the one in VERSION_DIR/version.sum. If they do not match, the | ||
new checksum value is stored, and the version number in VERSION_DIR/version is | ||
incremented by one. | ||
VERSION_DIR defaults to ".", i.e. the current working directory. | ||
EOD | ||
exit "$status" | ||
} | ||
checksum() { | ||
## non-local sumCmd | ||
local sums sum | ||
sums=$($sumCmd "$@") || exit ## Because pipelines suppress exit status. | ||
sum=$( | ||
printf %s "$sums" \ | ||
| sort \ | ||
| $sumCmd - | ||
) | ||
printf %s "${sum% -}" | ||
} | ||
|
||
for arg; do | ||
[ "$arg" = '--help' ] && dieWithUsage | ||
done | ||
|
||
versionDir=. | ||
if [ -d "$1" ]; then | ||
versionDir=$1 | ||
shift | ||
fi | ||
[ $# -eq 0 ] && dieWithUsage 1 'No FILES specified' | ||
|
||
versionFile=$versionDir/version | ||
sumFile=$versionDir/version.sum | ||
sumCmd=sha1sum | ||
|
||
version=$(($(cat "$versionFile" 2>/dev/null || echo 0))) || exit | ||
oldSum=$(cat "$sumFile" 2>/dev/null) | ||
newSum=$(checksum "$@") || exit | ||
|
||
if [ "$oldSum" != "$newSum" ]; then | ||
printf %s\\n "$newSum" >"$sumFile" || exit | ||
echo $((version+=1)) >"$versionFile" || exit | ||
fi | ||
|
||
echo $version |