Skip to content

Commit 8674356

Browse files
committed
Merge #408 - Refactor update.sh
2 parents 2d43a62 + a5b4208 commit 8674356

File tree

7 files changed

+88
-26
lines changed

7 files changed

+88
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1212
- Support adding custom configurations in `/etc/phpmyadmin/conf.d` (#401)
1313
- Fix for debian 12 issue (#416) that caused libraries for extensions to be uninstalled
1414
- Add extension `bcmath` for 2nd factor authentication (#415)
15+
- Refactor `update.sh` (#408)
1516

1617
## [5.2.1] - 2023-02-08
1718

Dockerfile-alpine.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:8.2-%%VARIANT%%
1+
FROM php:%%PHP_VERSION%%-%%VARIANT%%
22

33
# docker-entrypoint.sh dependencies
44
RUN apk add --no-cache \
@@ -95,7 +95,7 @@ RUN set -ex; \
9595
chown www-data:www-data $SESSION_SAVE_PATH; \
9696
\
9797
export GNUPGHOME="$(mktemp -d)"; \
98-
export GPGKEY="3D06A59ECE730EB71B511C17CE752F178259BD92"; \
98+
export GPGKEY="%%GPG_KEY%%"; \
9999
curl -fsSL -o phpMyAdmin.tar.xz $URL; \
100100
curl -fsSL -o phpMyAdmin.tar.xz.asc $URL.asc; \
101101
echo "$SHA256 *phpMyAdmin.tar.xz" | sha256sum -c -; \

Dockerfile-debian.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:8.2-%%VARIANT%%
1+
FROM php:%%PHP_VERSION%%-%%VARIANT%%
22

33
# Install dependencies
44
RUN set -ex; \
@@ -106,7 +106,7 @@ RUN set -ex; \
106106
chown www-data:www-data $SESSION_SAVE_PATH; \
107107
\
108108
export GNUPGHOME="$(mktemp -d)"; \
109-
export GPGKEY="3D06A59ECE730EB71B511C17CE752F178259BD92"; \
109+
export GPGKEY="%%GPG_KEY%%"; \
110110
curl -fsSL -o phpMyAdmin.tar.xz $URL; \
111111
curl -fsSL -o phpMyAdmin.tar.xz.asc $URL.asc; \
112112
echo "$SHA256 *phpMyAdmin.tar.xz" | sha256sum -c -; \

apache/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# DO NOT EDIT: created by update.sh from Dockerfile-debian.template
12
FROM php:8.2-apache
23

34
# Install dependencies

fpm-alpine/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# DO NOT EDIT: created by update.sh from Dockerfile-alpine.template
12
FROM php:8.2-fpm-alpine
23

34
# docker-entrypoint.sh dependencies

fpm/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# DO NOT EDIT: created by update.sh from Dockerfile-debian.template
12
FROM php:8.2-fpm
23

34
# Install dependencies

update.sh

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
#!/bin/bash
2-
set -e
2+
set -eu -o pipefail
33

4-
# Check for dependencies
5-
command -v curl >/dev/null 2>&1 || { echo >&2 "'curl' is required but not found. Aborting."; exit 1; }
6-
command -v jq >/dev/null 2>&1 || { echo >&2 "'jq' is required but not found. Aborting."; exit 1; }
7-
if [ -z "${BASH_VERSINFO}" ] || [ -z "${BASH_VERSINFO[0]}" ] || [ ${BASH_VERSINFO[0]} -lt 4 ]; then
8-
echo "BASH version 4.0 or greater is required. Aborting."
9-
exit 1
10-
fi
11-
12-
declare -A cmd=(
13-
[apache]='apache2-foreground'
14-
[fpm]='php-fpm'
15-
[fpm-alpine]='php-fpm'
4+
variants=(
5+
apache
6+
fpm
7+
fpm-alpine
168
)
179

1810
declare -A base=(
@@ -21,21 +13,87 @@ declare -A base=(
2113
[fpm-alpine]='alpine'
2214
)
2315

24-
latest="$(curl -fsSL 'https://www.phpmyadmin.net/home_page/version.json' | jq -r '.version')"
25-
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)"
16+
declare -A php_version=(
17+
[default]='8.2'
18+
)
2619

27-
for variant in apache fpm fpm-alpine; do
28-
template="Dockerfile-${base[$variant]}.template"
29-
cp $template "$variant/Dockerfile"
30-
cp config.inc.php "$variant/config.inc.php"
31-
cp docker-entrypoint.sh "$variant/docker-entrypoint.sh"
20+
declare -A cmd=(
21+
[apache]='apache2-foreground'
22+
[fpm]='php-fpm'
23+
[fpm-alpine]='php-fpm'
24+
)
25+
26+
gpg_key='3D06A59ECE730EB71B511C17CE752F178259BD92'
27+
28+
function download_url() {
29+
echo "https://files.phpmyadmin.net/phpMyAdmin/$1/phpMyAdmin-$1-all-languages.tar.xz"
30+
}
31+
32+
function create_variant() {
33+
local variant="$1"
34+
local version="$2"
35+
local sha256="$3"
36+
37+
local branch="$(sed -ne 's/^\([0-9]*\.[0-9]*\)\..*$/\1/p' <<< "$version")"
38+
local url="$(download_url "$version")"
39+
local ascUrl="$(download_url "$version").asc"
40+
local phpVersion="${php_version[$version]-${php_version[default]}}"
41+
42+
echo "updating $version [$branch] $variant"
43+
44+
# Create the variant directory with a Dockerfile
45+
mkdir -p "$variant"
46+
47+
local template="Dockerfile-${base[$variant]}.template"
48+
echo "# DO NOT EDIT: created by update.sh from $template" > "$variant/Dockerfile"
49+
cat "$template" >> "$variant/Dockerfile"
50+
51+
# Replace Dockerfile variables
3252
sed -ri -e '
33-
s/%%VERSION%%/'"$latest"'/;
34-
s/%%SHA256%%/'"$sha256"'/;
3553
s/%%VARIANT%%/'"$variant"'/;
54+
s/%%VERSION%%/'"$version"'/;
55+
s/%%SHA256%%/'"$sha256"'/;
56+
s/%%DOWNLOAD_URL%%/'"$(sed -e 's/[\/&]/\\&/g' <<< "$url")"'/;
57+
s/%%DOWNLOAD_URL_ASC%%/'"$(sed -e 's/[\/&]/\\&/g' <<< "$ascUrl")"'/;
58+
s/%%PHP_VERSION%%/'"$phpVersion"'/g;
59+
s/%%GPG_KEY%%/'"$gpg_key"'/g;
3660
s/%%CMD%%/'"${cmd[$variant]}"'/;
3761
' "$variant/Dockerfile"
62+
63+
# Copy docker-entrypoint.sh
64+
cp docker-entrypoint.sh "$variant/docker-entrypoint.sh"
3865
if [ "$variant" != "apache" ]; then
3966
sed -i "/^# start: Apache specific settings$/,/^# end: Apache specific settings$/d" "$variant/docker-entrypoint.sh"
4067
fi
68+
69+
# Copy config.inc.php
70+
cp config.inc.php "$variant/config.inc.php"
71+
72+
# Add variant to versions.json
73+
versionVariantsJson="$(jq -e \
74+
--arg branch "$branch" --arg variant "$variant" --arg base "${base[$variant]}" --arg phpVersion "$phpVersion" \
75+
'.[$branch].variants[$variant] = {"variant": $variant, "base": $base, "phpVersion": $phpVersion}' versions.json)"
76+
versionJson="$(jq -e \
77+
--arg branch "$branch" --arg version "$version" --arg sha256 "$sha256" --arg url "$url" --arg ascUrl "$ascUrl" --argjson variants "$versionVariantsJson" \
78+
'.[$branch] = {"branch": $branch, "version": $version, "sha256": $sha256, "url": $url, "ascUrl": $ascUrl, "variants": $variants[$branch].variants}' versions.json)"
79+
printf '%s\n' "$versionJson" > versions.json
80+
}
81+
82+
# Check script dependencies
83+
command -v curl >/dev/null 2>&1 || { echo >&2 "'curl' is required but not found. Aborting."; exit 1; }
84+
command -v jq >/dev/null 2>&1 || { echo >&2 "'jq' is required but not found. Aborting."; exit 1; }
85+
[ -n "${BASH_VERSINFO}" ] && [ -n "${BASH_VERSINFO[0]}" ] && [ ${BASH_VERSINFO[0]} -ge 4 ] \
86+
|| { echo >&2 "Bash 4.0 or greater is required. Aborting."; exit 1; }
87+
88+
# Create variants
89+
printf '%s\n' "{}" > versions.json
90+
91+
latest="$(curl -fsSL "https://www.phpmyadmin.net/home_page/version.json" | jq -r '.version')"
92+
sha256="$(curl -fsSL "$(download_url "$latest").sha256" | cut -f1 -d ' ' | tr -cd 'a-f0-9' | cut -c 1-64)"
93+
94+
for variant in "${variants[@]}"; do
95+
create_variant "$variant" "$latest" "$sha256"
4196
done
97+
98+
# Cleanup the file as for now it's not wanted in the repository
99+
rm versions.json

0 commit comments

Comments
 (0)