Skip to content

Commit

Permalink
chore: review
Browse files Browse the repository at this point in the history
Signed-off-by: Niccolò Fei <[email protected]>
  • Loading branch information
NiccoloFei committed Jan 25, 2024
1 parent bcc77ca commit 740b039
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 213 deletions.
244 changes: 127 additions & 117 deletions .github/generate-strategy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,132 +39,142 @@ join() {
echo "${out#$sep}"
}

entries=()

# UBI
cd "$BASE_DIRECTORY"/UBI/
for version in "${ubi_versions[@]}"; do

# Read versions from the definition file
versionFile="${version}/.versions.json"
fullVersion=$(jq -r '.POSTGRES_VERSION' "${versionFile}")
releaseVersion=$(jq -r '.IMAGE_RELEASE_VERSION' "${versionFile}")
ubi8Version=$(jq -r '.UBI8_VERSION' "${versionFile}")
ubi9Version=$(jq -r '.UBI9_VERSION' "${versionFile}")

# Initial aliases are "major version", "optional alias", "full version with release"
# i.e. "13", "latest", "13.2-1"
# A "-beta" suffix will be appended to the beta images.
if [ "${version}" -gt '16' ]; then
fullVersion=$(jq -r '.POSTGRES_VERSION | split("_") | .[0]' "${versionFile}")
versionAliases=(
"${version}-beta"
${aliases[$version]:+"${aliases[$version]}"}
"${fullVersion}-${releaseVersion}"
)
versionAliasesMultiLang=(
"${version}-beta-multilang"
${aliases[$version]:+"${aliases[$version]}-multilang"}
"${fullVersion}-${releaseVersion}-multilang"
)
versionAliasesMultiArch=(
"${version}-beta-multiarch"
${aliases[$version]:+"${aliases[$version]}-multiarch"}
"${fullVersion}-${releaseVersion}-multiarch"
)
else
versionAliases=(
"${version}"
${aliases[$version]:+"${aliases[$version]}"}
"${fullVersion}-${releaseVersion}"
)
versionAliasesMultiLang=(
"${version}-multilang"
${aliases[$version]:+"${aliases[$version]}-multilang"}
"${fullVersion}-${releaseVersion}-multilang"
)
versionAliasesMultiArch=(
"${version}-multiarch"
${aliases[$version]:+"${aliases[$version]}-multiarch"}
"${fullVersion}-${releaseVersion}-multiarch"
generator() {
local ubiRelease="$1"; shift

cd "$BASE_DIRECTORY"/UBI/
for version in "${ubi_versions[@]}"; do

versionFile="${version}/.versions-ubi${ubiRelease}.json"
ubiVersion=$(jq -r '.UBI_VERSION' "${versionFile}")
fullVersion=$(jq -r '.POSTGRES_VERSION' "${versionFile}")
releaseVersion=$(jq -r '.IMAGE_RELEASE_VERSION' "${versionFile}")

# Initial aliases are "major version", "optional alias", "full version with release"
# i.e. "13", "latest", "13.2-1"
# A "-beta" suffix will be appended to the beta images.
if [ "${version}" -gt '16' ]; then
fullVersion=$(jq -r '.POSTGRES_VERSION | split("_") | .[0]' "${versionFile}")
versionAliases=(
"${version}-beta"
${aliases[$version]:+"${aliases[$version]}"}
"${fullVersion}-${releaseVersion}"
)
versionAliasesMultiLang=(
"${version}-beta-multilang"
${aliases[$version]:+"${aliases[$version]}-multilang"}
"${fullVersion}-${releaseVersion}-multilang"
)
versionAliasesMultiArch=(
"${version}-beta-multiarch"
${aliases[$version]:+"${aliases[$version]}-multiarch"}
"${fullVersion}-${releaseVersion}-multiarch"
)
else
versionAliases=(
"${version}"
${aliases[$version]:+"${aliases[$version]}"}
"${fullVersion}-${releaseVersion}"
)
versionAliasesMultiLang=(
"${version}-multilang"
${aliases[$version]:+"${aliases[$version]}-multilang"}
"${fullVersion}-${releaseVersion}-multilang"
)
versionAliasesMultiArch=(
"${version}-multiarch"
${aliases[$version]:+"${aliases[$version]}-multiarch"}
"${fullVersion}-${releaseVersion}-multiarch"
)
fi

# Add all the version prefixes between full version and major version
# i.e "13.2"
while [ "$fullVersion" != "$version" ] && [ "${fullVersion%[.-]*}" != "$fullVersion" ]; do
versionAliases+=("$fullVersion")
versionAliasesMultiLang+=("$fullVersion-multilang")
versionAliasesMultiArch+=("$fullVersion-multiarch")
fullVersion="${fullVersion%[.-]*}"
done

platforms="linux/amd64, linux/arm64"
platformsMultiArch="${platforms}, linux/ppc64le,linux/s390x"

# Build the json entry
entries+=(
"{\"name\": \"${fullVersion} UBI${ubiRelease}\", \"ubi_version\": \"$ubiVersion\", \"platforms\": \"$platforms\", \"dir\": \"UBI/$version\", \"file\": \"UBI/$version/Dockerfile.ubi${ubiRelease}\", \"version\": \"$version\", \"tags\": [\"$(join "\", \"" "${versionAliases[@]}")\"]}"
"{\"name\": \"${fullVersion} UBI${ubiRelease} MultiLang\", \"ubi_version\": \"$ubiVersion\", \"platforms\": \"$platforms\", \"dir\": \"UBI/$version\", \"file\": \"UBI/$version/Dockerfile.multilang.ubi${ubiRelease}\", \"version\": \"$version\", \"tags\": [\"$(join "\", \"" "${versionAliasesMultiLang[@]}")\"]}"
"{\"name\": \"${fullVersion} UBI${ubiRelease} MultiArch\", \"ubi_version\": \"$ubiVersion\", \"platforms\": \"$platformsMultiArch\", \"dir\": \"UBI/$version\", \"file\": \"UBI/$version/Dockerfile.multiarch.ubi${ubiRelease}\", \"version\": \"$version\", \"tags\": [\"$(join "\", \"" "${versionAliasesMultiArch[@]}")\"]}"
)
fi
# Add all the version prefixes between full version and major version
# i.e "13.2"
while [ "$fullVersion" != "$version" ] && [ "${fullVersion%[.-]*}" != "$fullVersion" ]; do
versionAliases+=("$fullVersion")
versionAliasesMultiLang+=("$fullVersion-multilang")
versionAliasesMultiArch+=("$fullVersion-multiarch")
fullVersion="${fullVersion%[.-]*}"
done
}

platforms="linux/amd64, linux/arm64"
platformsMultiArch="${platforms}, linux/ppc64le,linux/s390x"

# Build the json entry
for ubiVersion in "$ubi8Version" "$ubi9Version"; do
majorVersion="${ubiVersion%%.*}"
generator_postgis() {
local ubiRelease="$1"; shift

cd "$BASE_DIRECTORY"/UBI/
for version in "${ubi_versions[@]}"; do

# Read versions from the definition file
versionFile="${version}/.versions-postgis.json"
fullVersion=$(jq -r '.POSTGRES_VERSION' "${versionFile}")
postgisVersion=$(jq -r '.POSTGIS_VERSION' "${versionFile}" | cut -f1,2 -d.)
releaseVersion=$(jq -r '.IMAGE_RELEASE_VERSION' "${versionFile}")

# Initial aliases are "major version", "optional alias", "full version with release"
# i.e. "13", "latest", "13.2-1"
# A "-beta" suffix will be appended to the beta images.
if [ "${version}" -gt '16' ]; then
fullVersion=$(jq -r '.POSTGRES_VERSION | split("_") | .[0]' "${versionFile}")
versionAliases=(
"${version}-beta-postgis"
${aliases[$version]:+"${aliases[$version]}-postgis"}
"${fullVersion}-${postgisVersion}-postgis-${releaseVersion}"
)
versionAliasesMultiLang=(
"${version}-beta-postgis-multilang"
${aliases[$version]:+"${aliases[$version]}-postgis-multilang"}
"${fullVersion}-${postgisVersion}-postgis-${releaseVersion}-multilang"
)
else
versionAliases=(
"${version}-postgis"
${aliases[$version]:+"${aliases[$version]}-postgis"}
"${fullVersion}-${postgisVersion}-postgis-${releaseVersion}"
)
versionAliasesMultiLang=(
"${version}-postgis-multilang"
${aliases[$version]:+"${aliases[$version]}-postgis-multilang"}
"${fullVersion}-${postgisVersion}-postgis-${releaseVersion}-multilang"
)
fi

# Add all the version prefixes between full version and major version
# i.e "13.2"
while [ "$fullVersion" != "$version" ] && [ "${fullVersion%[.-]*}" != "$fullVersion" ]; do
versionAliases+=("$fullVersion-${postgisVersion}-postgis")
versionAliasesMultiLang+=("$fullVersion-${postgisVersion}-postgis-multilang")
fullVersion="${fullVersion%[.-]*}"
done

platforms="linux/amd64,linux/arm64"

# Build the json entry
entries+=(
"{\"name\": \"${fullVersion} UBI${majorVersion}\", \"ubi_version\": \"$ubiVersion\", \"platforms\": \"$platforms\", \"dir\": \"UBI/$version\", \"file\": \"UBI/$version/Dockerfile.ubi$majorVersion\", \"version\": \"$version\", \"tags\": [\"$(join "\", \"" "${versionAliases[@]}")\"]}"
"{\"name\": \"${fullVersion} UBI${majorVersion} MultiLang\", \"ubi_version\": \"$ubiVersion\", \"platforms\": \"$platforms\", \"dir\": \"UBI/$version\", \"file\": \"UBI/$version/Dockerfile.multilang.ubi$majorVersion\", \"version\": \"$version\", \"tags\": [\"$(join "\", \"" "${versionAliasesMultiLang[@]}")\"]}"
"{\"name\": \"${fullVersion} UBI${majorVersion} MultiArch\", \"ubi_version\": \"$ubiVersion\", \"platforms\": \"$platformsMultiArch\", \"dir\": \"UBI/$version\", \"file\": \"UBI/$version/Dockerfile.multiarch.ubi$majorVersion\", \"version\": \"$version\", \"tags\": [\"$(join "\", \"" "${versionAliasesMultiArch[@]}")\"]}"
"{\"name\": \"PostGIS ${fullVersion}-${postgisVersion} UBI${ubiRelease}\", \"platforms\": \"$platforms\", \"dir\": \"UBI/$version\", \"file\": \"UBI/$version/Dockerfile.postgis\",\"version\": \"$version\", \"tags\": [\"$(join "\", \"" "${versionAliases[@]}")\"]}"
"{\"name\": \"PostGIS ${fullVersion}-${postgisVersion} UBI${ubiRelease} MultiLang\", \"platforms\": \"$platforms\", \"dir\": \"UBI/$version\", \"file\": \"UBI/$version/Dockerfile.postgis-multilang\",\"version\": \"$version\", \"tags\": [\"$(join "\", \"" "${versionAliasesMultiLang[@]}")\"]}"
)
done
done
}

# UBI PostGIS
for version in "${ubi_versions[@]}"; do

# Read versions from the definition file
versionFile="${version}/.versions-postgis.json"
fullVersion=$(jq -r '.POSTGRES_VERSION' "${versionFile}")
postgisVersion=$(jq -r '.POSTGIS_VERSION' "${versionFile}" | cut -f1,2 -d.)
releaseVersion=$(jq -r '.IMAGE_RELEASE_VERSION' "${versionFile}")

# Initial aliases are "major version", "optional alias", "full version with release"
# i.e. "13", "latest", "13.2-1"
# A "-beta" suffix will be appended to the beta images.
if [ "${version}" -gt '16' ]; then
fullVersion=$(jq -r '.POSTGRES_VERSION | split("_") | .[0]' "${versionFile}")
versionAliases=(
"${version}-beta-postgis"
${aliases[$version]:+"${aliases[$version]}-postgis"}
"${fullVersion}-${postgisVersion}-postgis-${releaseVersion}"
)
versionAliasesMultiLang=(
"${version}-beta-postgis-multilang"
${aliases[$version]:+"${aliases[$version]}-postgis-multilang"}
"${fullVersion}-${postgisVersion}-postgis-${releaseVersion}-multilang"
)
else
versionAliases=(
"${version}-postgis"
${aliases[$version]:+"${aliases[$version]}-postgis"}
"${fullVersion}-${postgisVersion}-postgis-${releaseVersion}"
)
versionAliasesMultiLang=(
"${version}-postgis-multilang"
${aliases[$version]:+"${aliases[$version]}-postgis-multilang"}
"${fullVersion}-${postgisVersion}-postgis-${releaseVersion}-multilang"
)
fi

# Add all the version prefixes between full version and major version
# i.e "13.2"
while [ "$fullVersion" != "$version" ] && [ "${fullVersion%[.-]*}" != "$fullVersion" ]; do
versionAliases+=("$fullVersion-${postgisVersion}-postgis")
versionAliasesMultiLang+=("$fullVersion-${postgisVersion}-postgis-multilang")
fullVersion="${fullVersion%[.-]*}"
done
entries=()

platforms="linux/amd64,linux/arm64"
# UBI
generator "8"
generator "9"

# Build the json entry
entries+=(
"{\"name\": \"UBI PostGIS ${fullVersion}-${postgisVersion}\", \"platforms\": \"$platforms\", \"dir\": \"UBI/$version\", \"file\": \"UBI/$version/Dockerfile.postgis\",\"version\": \"$version\", \"tags\": [\"$(join "\", \"" "${versionAliases[@]}")\"]}"
"{\"name\": \"UBI PostGIS ${fullVersion}-${postgisVersion} MultiLang\", \"platforms\": \"$platforms\", \"dir\": \"UBI/$version\", \"file\": \"UBI/$version/Dockerfile.postgis-multilang\",\"version\": \"$version\", \"tags\": [\"$(join "\", \"" "${versionAliasesMultiLang[@]}")\"]}"
)
done
# UBI PostGIS
generator "8"

# Build the strategy as a JSON object
strategy="{\"fail-fast\": false, \"matrix\": {\"include\": [$(join ', ' "${entries[@]}")]}}"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ jobs:
tags: ${{ env.TAGS }}
labels: ${{ github.ref != 'refs/heads/main' && 'quay.expires-after=7d' || '' }}
build-args: |
UBI_VERSION=${{ matrix.ubi_version }}
SUBSCRIPTION_NAME=docker-postgresql-cicd-${{ github.run_number }}
# Send a notification on release failure
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Maintenance scripts to generate Immutable Application Containers
for all available PostgreSQL versions (12 to 16) based on
Red Hat Universal Base Images (UBI) 8:
Red Hat Universal Base Images (UBI) 8 and 9:

- Standard minimal image - amd64/arm64
- multilang version (all Locales installed) - amd64/arm64
Expand Down
Loading

0 comments on commit 740b039

Please sign in to comment.