-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from LaurentGoderre/templating
Added templating
- Loading branch information
Showing
13 changed files
with
263 additions
and
118 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,3 @@ | ||
/*/**/Dockerfile linguist-generated | ||
/*/**/docker-entrypoint.sh linguist-generated | ||
/Dockerfile*.template linguist-language=Dockerfile |
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 @@ | ||
.jq-template.awk |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
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
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
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,73 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuo pipefail | ||
|
||
[ -f versions.json ] # run "versions.sh" first | ||
|
||
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" | ||
|
||
jqt='.jq-template.awk' | ||
if [ -n "${BASHBREW_SCRIPTS:-}" ]; then | ||
jqt="$BASHBREW_SCRIPTS/jq-template.awk" | ||
elif [ "$BASH_SOURCE" -nt "$jqt" ]; then | ||
# https://github.com/docker-library/bashbrew/blob/master/scripts/jq-template.awk | ||
wget -qO "$jqt" 'https://github.com/docker-library/bashbrew/raw/9f6a35772ac863a0241f147c820354e4008edf38/scripts/jq-template.awk' | ||
fi | ||
|
||
if [ "$#" -eq 0 ]; then | ||
versions="$(jq -r 'keys | map(@sh) | join(" ")' versions.json)" | ||
eval "set -- $versions" | ||
fi | ||
|
||
generated_warning() { | ||
cat <<-EOH | ||
# | ||
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" | ||
# | ||
# PLEASE DO NOT EDIT IT DIRECTLY. | ||
# | ||
EOH | ||
} | ||
|
||
for version; do | ||
export version | ||
|
||
if [ -d "$version" ]; then | ||
rm -rf "$version" | ||
fi | ||
|
||
if jq -e '.[env.version] | not' versions.json > /dev/null; then | ||
echo "skipping $version ..." | ||
continue | ||
fi | ||
|
||
variants="$(jq -r '.[env.version].variants | map(@sh) | join(" ")' versions.json)" | ||
eval "variants=( $variants )" | ||
|
||
for variant in "${variants[@]}"; do | ||
export variant | ||
|
||
echo "processing $version/$variant ..." | ||
|
||
dir="$version${variant:+/$variant}" | ||
|
||
mkdir -p "$dir" | ||
|
||
cp -f docker-entrypoint.sh "$dir/" | ||
|
||
case "$variant" in | ||
alpine*) | ||
template='Dockerfile-alpine.template' | ||
sed -i -e 's/gosu/su-exec/g' "$dir/docker-entrypoint.sh" | ||
;; | ||
*) | ||
template='Dockerfile-debian.template' | ||
;; | ||
esac | ||
|
||
{ | ||
generated_warning | ||
gawk -f "$jqt" "$template" | ||
} > "$dir/Dockerfile" | ||
done | ||
done |
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
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 |
---|---|---|
@@ -1,71 +1,7 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuo pipefail | ||
|
||
# see https://www.redmine.org/projects/redmine/wiki/redmineinstall | ||
defaultRubyVersion='3.1' | ||
declare -A rubyVersions=( | ||
) | ||
|
||
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" | ||
|
||
versions=( "$@" ) | ||
if [ ${#versions[@]} -eq 0 ]; then | ||
versions=( */ ) | ||
fi | ||
versions=( "${versions[@]%/}" ) | ||
|
||
# https://github.com/docker-library/redmine/issues/256 | ||
downloadsPage="$(curl -fsSL 'https://redmine.org/projects/redmine/wiki/Download')" | ||
|
||
releasesUrl='https://www.redmine.org/releases' | ||
versionsPage="$(curl -fsSL "$releasesUrl")" | ||
|
||
allVersions="$( | ||
sed <<<"$versionsPage"$'\n'"$downloadsPage" \ | ||
-rne 's/.*redmine-([0-9.]+)[.]tar[.]gz.*/\1/p' \ | ||
| sort -ruV | ||
)" | ||
|
||
for version in "${versions[@]}"; do | ||
ourVersions="$(grep -E "^$version[.]" <<<"$allVersions")" | ||
fullVersion= | ||
for tryVersion in $ourVersions; do | ||
url="$releasesUrl/redmine-$tryVersion.tar.gz" | ||
if sha256="$(curl -fsSL "$url.sha256" 2>/dev/null)" && sha256="$(cut -d' ' -f1 <<<"$sha256")" && [ -n "$sha256" ]; then | ||
fullVersion="$tryVersion" | ||
break | ||
fi | ||
if urlLine="$(grep -oEm1 'href="https?://[^"]+/'"redmine-$tryVersion.tar.gz"'".*sha256:.*' <<<"$downloadsPage")" && url="$(cut -d'"' -f2 <<<"$urlLine")" && [ -n "$url" ] && sha256="$(grep -oEm1 'sha256:[[:space:]]*[a-f0-9]{64}' <<<"$urlLine")" && [ -n "$sha256" ] && sha256="${sha256: -64}"; then | ||
fullVersion="$tryVersion" | ||
break | ||
fi | ||
done | ||
if [ -z "$fullVersion" ]; then | ||
echo >&2 "error: failed to find full version for '$version'" | ||
exit 1 | ||
fi | ||
|
||
rubyVersion="${rubyVersions[$version]:-$defaultRubyVersion}" | ||
|
||
text="ruby $rubyVersion" | ||
|
||
echo "$version: $fullVersion ($text)" | ||
|
||
commonSedArgs=( | ||
-r | ||
-e 's/%%REDMINE_VERSION%%/'"$fullVersion"'/' | ||
-e 's/%%RUBY_VERSION%%/'"$rubyVersion"'/' | ||
-e 's!%%REDMINE_DOWNLOAD_URL%%!'"$url"'!' | ||
-e 's/%%REDMINE_DOWNLOAD_SHA256%%/'"$sha256"'/' | ||
-e 's/%%REDMINE%%/redmine:'"$version"'/' | ||
) | ||
|
||
mkdir -p "$version" | ||
cp docker-entrypoint.sh "$version/" | ||
sed "${commonSedArgs[@]}" Dockerfile-debian.template > "$version/Dockerfile" | ||
|
||
mkdir -p "$version/alpine" | ||
cp docker-entrypoint.sh "$version/alpine/" | ||
sed -i -e 's/gosu/su-exec/g' "$version/alpine/docker-entrypoint.sh" | ||
sed "${commonSedArgs[@]}" Dockerfile-alpine.template > "$version/alpine/Dockerfile" | ||
done | ||
./versions.sh "$@" | ||
./apply-templates.sh "$@" |
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,16 @@ | ||
{ | ||
"5.0": { | ||
"alpine": "3.18", | ||
"debian": "bookworm", | ||
"downloadUrl": "https://www.redmine.org/releases/redmine-5.0.6.tar.gz", | ||
"ruby": { | ||
"version": "3.1" | ||
}, | ||
"sha256": "488fe08f37a8eb1011415922a8ea743b7f38d8a7a5f8822950a34a375dcf08ee", | ||
"variants": [ | ||
"bookworm", | ||
"alpine3.18" | ||
], | ||
"version": "5.0.6" | ||
} | ||
} |
Oops, something went wrong.