Skip to content

Commit

Permalink
Merge #408 - Refactor update.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Jun 30, 2023
2 parents 2d43a62 + a5b4208 commit 8674356
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Support adding custom configurations in `/etc/phpmyadmin/conf.d` (#401)
- Fix for debian 12 issue (#416) that caused libraries for extensions to be uninstalled
- Add extension `bcmath` for 2nd factor authentication (#415)
- Refactor `update.sh` (#408)

## [5.2.1] - 2023-02-08

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile-alpine.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.2-%%VARIANT%%
FROM php:%%PHP_VERSION%%-%%VARIANT%%

# docker-entrypoint.sh dependencies
RUN apk add --no-cache \
Expand Down Expand Up @@ -95,7 +95,7 @@ RUN set -ex; \
chown www-data:www-data $SESSION_SAVE_PATH; \
\
export GNUPGHOME="$(mktemp -d)"; \
export GPGKEY="3D06A59ECE730EB71B511C17CE752F178259BD92"; \
export GPGKEY="%%GPG_KEY%%"; \
curl -fsSL -o phpMyAdmin.tar.xz $URL; \
curl -fsSL -o phpMyAdmin.tar.xz.asc $URL.asc; \
echo "$SHA256 *phpMyAdmin.tar.xz" | sha256sum -c -; \
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile-debian.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.2-%%VARIANT%%
FROM php:%%PHP_VERSION%%-%%VARIANT%%

# Install dependencies
RUN set -ex; \
Expand Down Expand Up @@ -106,7 +106,7 @@ RUN set -ex; \
chown www-data:www-data $SESSION_SAVE_PATH; \
\
export GNUPGHOME="$(mktemp -d)"; \
export GPGKEY="3D06A59ECE730EB71B511C17CE752F178259BD92"; \
export GPGKEY="%%GPG_KEY%%"; \
curl -fsSL -o phpMyAdmin.tar.xz $URL; \
curl -fsSL -o phpMyAdmin.tar.xz.asc $URL.asc; \
echo "$SHA256 *phpMyAdmin.tar.xz" | sha256sum -c -; \
Expand Down
1 change: 1 addition & 0 deletions apache/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# DO NOT EDIT: created by update.sh from Dockerfile-debian.template
FROM php:8.2-apache

# Install dependencies
Expand Down
1 change: 1 addition & 0 deletions fpm-alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# DO NOT EDIT: created by update.sh from Dockerfile-alpine.template
FROM php:8.2-fpm-alpine

# docker-entrypoint.sh dependencies
Expand Down
1 change: 1 addition & 0 deletions fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# DO NOT EDIT: created by update.sh from Dockerfile-debian.template
FROM php:8.2-fpm

# Install dependencies
Expand Down
102 changes: 80 additions & 22 deletions update.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
#!/bin/bash
set -e
set -eu -o pipefail

# Check for dependencies
command -v curl >/dev/null 2>&1 || { echo >&2 "'curl' is required but not found. Aborting."; exit 1; }
command -v jq >/dev/null 2>&1 || { echo >&2 "'jq' is required but not found. Aborting."; exit 1; }
if [ -z "${BASH_VERSINFO}" ] || [ -z "${BASH_VERSINFO[0]}" ] || [ ${BASH_VERSINFO[0]} -lt 4 ]; then
echo "BASH version 4.0 or greater is required. Aborting."
exit 1
fi

declare -A cmd=(
[apache]='apache2-foreground'
[fpm]='php-fpm'
[fpm-alpine]='php-fpm'
variants=(
apache
fpm
fpm-alpine
)

declare -A base=(
Expand All @@ -21,21 +13,87 @@ declare -A base=(
[fpm-alpine]='alpine'
)

latest="$(curl -fsSL 'https://www.phpmyadmin.net/home_page/version.json' | jq -r '.version')"
sha256="$(curl -fsSL "https://files.phpmyadmin.net/phpMyAdmin/$latest/phpMyAdmin-$latest-all-languages.tar.xz.sha256" | cut -f1 -d ' ' | tr -cd 'a-f0-9' | cut -c 1-64)"
declare -A php_version=(
[default]='8.2'
)

for variant in apache fpm fpm-alpine; do
template="Dockerfile-${base[$variant]}.template"
cp $template "$variant/Dockerfile"
cp config.inc.php "$variant/config.inc.php"
cp docker-entrypoint.sh "$variant/docker-entrypoint.sh"
declare -A cmd=(
[apache]='apache2-foreground'
[fpm]='php-fpm'
[fpm-alpine]='php-fpm'
)

gpg_key='3D06A59ECE730EB71B511C17CE752F178259BD92'

function download_url() {
echo "https://files.phpmyadmin.net/phpMyAdmin/$1/phpMyAdmin-$1-all-languages.tar.xz"
}

function create_variant() {
local variant="$1"
local version="$2"
local sha256="$3"

local branch="$(sed -ne 's/^\([0-9]*\.[0-9]*\)\..*$/\1/p' <<< "$version")"
local url="$(download_url "$version")"
local ascUrl="$(download_url "$version").asc"
local phpVersion="${php_version[$version]-${php_version[default]}}"

echo "updating $version [$branch] $variant"

# Create the variant directory with a Dockerfile
mkdir -p "$variant"

local template="Dockerfile-${base[$variant]}.template"
echo "# DO NOT EDIT: created by update.sh from $template" > "$variant/Dockerfile"
cat "$template" >> "$variant/Dockerfile"

# Replace Dockerfile variables
sed -ri -e '
s/%%VERSION%%/'"$latest"'/;
s/%%SHA256%%/'"$sha256"'/;
s/%%VARIANT%%/'"$variant"'/;
s/%%VERSION%%/'"$version"'/;
s/%%SHA256%%/'"$sha256"'/;
s/%%DOWNLOAD_URL%%/'"$(sed -e 's/[\/&]/\\&/g' <<< "$url")"'/;
s/%%DOWNLOAD_URL_ASC%%/'"$(sed -e 's/[\/&]/\\&/g' <<< "$ascUrl")"'/;
s/%%PHP_VERSION%%/'"$phpVersion"'/g;
s/%%GPG_KEY%%/'"$gpg_key"'/g;
s/%%CMD%%/'"${cmd[$variant]}"'/;
' "$variant/Dockerfile"

# Copy docker-entrypoint.sh
cp docker-entrypoint.sh "$variant/docker-entrypoint.sh"
if [ "$variant" != "apache" ]; then
sed -i "/^# start: Apache specific settings$/,/^# end: Apache specific settings$/d" "$variant/docker-entrypoint.sh"
fi

# Copy config.inc.php
cp config.inc.php "$variant/config.inc.php"

# Add variant to versions.json
versionVariantsJson="$(jq -e \
--arg branch "$branch" --arg variant "$variant" --arg base "${base[$variant]}" --arg phpVersion "$phpVersion" \
'.[$branch].variants[$variant] = {"variant": $variant, "base": $base, "phpVersion": $phpVersion}' versions.json)"
versionJson="$(jq -e \
--arg branch "$branch" --arg version "$version" --arg sha256 "$sha256" --arg url "$url" --arg ascUrl "$ascUrl" --argjson variants "$versionVariantsJson" \
'.[$branch] = {"branch": $branch, "version": $version, "sha256": $sha256, "url": $url, "ascUrl": $ascUrl, "variants": $variants[$branch].variants}' versions.json)"
printf '%s\n' "$versionJson" > versions.json
}

# Check script dependencies
command -v curl >/dev/null 2>&1 || { echo >&2 "'curl' is required but not found. Aborting."; exit 1; }
command -v jq >/dev/null 2>&1 || { echo >&2 "'jq' is required but not found. Aborting."; exit 1; }
[ -n "${BASH_VERSINFO}" ] && [ -n "${BASH_VERSINFO[0]}" ] && [ ${BASH_VERSINFO[0]} -ge 4 ] \
|| { echo >&2 "Bash 4.0 or greater is required. Aborting."; exit 1; }

# Create variants
printf '%s\n' "{}" > versions.json

latest="$(curl -fsSL "https://www.phpmyadmin.net/home_page/version.json" | jq -r '.version')"
sha256="$(curl -fsSL "$(download_url "$latest").sha256" | cut -f1 -d ' ' | tr -cd 'a-f0-9' | cut -c 1-64)"

for variant in "${variants[@]}"; do
create_variant "$variant" "$latest" "$sha256"
done

# Cleanup the file as for now it's not wanted in the repository
rm versions.json

0 comments on commit 8674356

Please sign in to comment.