diff --git a/.architectures-lib b/.architectures-lib new file mode 100644 index 0000000..bc4e689 --- /dev/null +++ b/.architectures-lib @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +_awkArch() { + local version="$1"; shift + local awkExpr="$1"; shift + awk "$@" "/^#|^\$/ { next } $awkExpr" "$version/release-architectures" +} + +hasBashbrewArch() { + local version="$1"; shift + local bashbrewArch="$1"; shift + _awkArch "$version" 'BEGIN { exitCode = 1 } $1 == bashbrewArch { exitCode = 0 } END { exit exitCode }' -v bashbrewArch="$bashbrewArch" +} + +_generateParentRepoToArches() { + local repo="$1"; shift + local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/' + + eval "declare -g -A parentRepoToArches=( $( + find -name 'Dockerfile' -exec awk ' + toupper($1) == "FROM" && $2 !~ /^('"$repo"'|scratch|microsoft\/[^:]+)(:|$)/ { + print "'"$officialImagesUrl"'" $2 + } + ' '{}' + \ + | sort -u \ + | xargs bashbrew cat --format '[{{ .RepoName }}:{{ .TagName }}]="{{ join " " .TagEntry.Architectures }}"' + ) )" +} +_generateParentRepoToArches 'mariadb' + +parentArches() { + local version="$1"; shift # "1.8", etc + + local parent="$(awk 'toupper($1) == "FROM" { print $2 }' "$version/Dockerfile")" + echo "${parentRepoToArches[$parent]:-}" +} +versionArches() { + local version="$1"; shift # "1.8", etc + + local parentArches="$(parentArches "$version")" + + local variantArches=() + for arch in $parentArches; do + if hasBashbrewArch "$version" "$arch"; then + variantArches+=( "$arch" ) + fi + done + echo "${variantArches[*]}" +} diff --git a/10.0/Dockerfile b/10.0/Dockerfile index 1ce0622..3754629 100644 --- a/10.0/Dockerfile +++ b/10.0/Dockerfile @@ -86,15 +86,6 @@ RUN set -ex; \ rm -r "$GNUPGHOME"; \ apt-key list -# add Percona's repo for xtrabackup (which is useful for Galera) -RUN set -e; \ - echo "deb https://repo.percona.com/apt xenial main" > /etc/apt/sources.list.d/percona.list; \ - { \ - echo 'Package: *'; \ - echo 'Pin: release o=Percona Development Team'; \ - echo 'Pin-Priority: 998'; \ - } > /etc/apt/preferences.d/percona - ENV MARIADB_MAJOR 10.0 ENV MARIADB_VERSION 10.0.35+maria-1~xenial @@ -115,11 +106,29 @@ RUN set -ex; \ echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password password 'unused'; \ echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password_again password 'unused'; \ } | debconf-set-selections; \ + XTRABACKUP='percona-xtrabackup'; \ +## from Dockerfile-percona-block ## +# add Percona's repo for xtrabackup (which is useful for Galera) + echo "deb [arch=amd64,i386] https://repo.percona.com/apt xenial main" > /etc/apt/sources.list.d/percona.list; \ + { \ + echo 'Package: *'; \ + echo 'Pin: release o=Percona Development Team'; \ + echo 'Pin-Priority: 998'; \ + } > /etc/apt/preferences.d/percona; \ +# percona-xtrabackup is amd64/i386 only (mariadb-backup is on all arches that mariadb-server is) + dpkgArch="$(dpkg --print-architecture)"; \ + if [[ "$XTRABACKUP" == percona* ]]; then \ + case "${dpkgArch##*-}" in \ + amd64|i396) ;; \ + *) XTRABACKUP= ;; \ + esac; \ + fi; \ +#### apt-get update; \ apt-get install -y \ "mariadb-server=$MARIADB_VERSION" \ # percona-xtrabackup/mariadb-backup is installed at the same time so that `mysql-common` is only installed once from just mariadb repos - percona-xtrabackup \ + $XTRABACKUP \ socat \ ; \ rm -rf /var/lib/apt/lists/*; \ diff --git a/10.0/release-architectures b/10.0/release-architectures new file mode 100644 index 0000000..d499d6f --- /dev/null +++ b/10.0/release-architectures @@ -0,0 +1,5 @@ +# bashbrew-arches +ppc64le +i386 +amd64 +arm64v8 diff --git a/10.1/Dockerfile b/10.1/Dockerfile index 6ad19a5..d1807d0 100644 --- a/10.1/Dockerfile +++ b/10.1/Dockerfile @@ -86,15 +86,6 @@ RUN set -ex; \ rm -r "$GNUPGHOME"; \ apt-key list -# add Percona's repo for xtrabackup (which is useful for Galera) -RUN set -e; \ - echo "deb https://repo.percona.com/apt bionic main" > /etc/apt/sources.list.d/percona.list; \ - { \ - echo 'Package: *'; \ - echo 'Pin: release o=Percona Development Team'; \ - echo 'Pin-Priority: 998'; \ - } > /etc/apt/preferences.d/percona - ENV MARIADB_MAJOR 10.1 ENV MARIADB_VERSION 1:10.1.34+maria-1~bionic @@ -115,11 +106,12 @@ RUN set -ex; \ echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password password 'unused'; \ echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password_again password 'unused'; \ } | debconf-set-selections; \ + XTRABACKUP='mariadb-backup-10.1'; \ apt-get update; \ apt-get install -y \ "mariadb-server=$MARIADB_VERSION" \ # percona-xtrabackup/mariadb-backup is installed at the same time so that `mysql-common` is only installed once from just mariadb repos - mariadb-backup-10.1 \ + $XTRABACKUP \ socat \ ; \ rm -rf /var/lib/apt/lists/*; \ diff --git a/10.1/release-architectures b/10.1/release-architectures new file mode 100644 index 0000000..14be2b5 --- /dev/null +++ b/10.1/release-architectures @@ -0,0 +1,4 @@ +# bashbrew-arches +ppc64le +amd64 +arm64v8 diff --git a/10.2/Dockerfile b/10.2/Dockerfile index 43f5146..453e8f0 100644 --- a/10.2/Dockerfile +++ b/10.2/Dockerfile @@ -86,15 +86,6 @@ RUN set -ex; \ rm -r "$GNUPGHOME"; \ apt-key list -# add Percona's repo for xtrabackup (which is useful for Galera) -RUN set -e; \ - echo "deb https://repo.percona.com/apt bionic main" > /etc/apt/sources.list.d/percona.list; \ - { \ - echo 'Package: *'; \ - echo 'Pin: release o=Percona Development Team'; \ - echo 'Pin-Priority: 998'; \ - } > /etc/apt/preferences.d/percona - ENV MARIADB_MAJOR 10.2 ENV MARIADB_VERSION 1:10.2.16+maria~bionic @@ -115,11 +106,12 @@ RUN set -ex; \ echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password password 'unused'; \ echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password_again password 'unused'; \ } | debconf-set-selections; \ + XTRABACKUP='mariadb-backup-10.2'; \ apt-get update; \ apt-get install -y \ "mariadb-server=$MARIADB_VERSION" \ # percona-xtrabackup/mariadb-backup is installed at the same time so that `mysql-common` is only installed once from just mariadb repos - mariadb-backup-10.2 \ + $XTRABACKUP \ socat \ ; \ rm -rf /var/lib/apt/lists/*; \ diff --git a/10.2/release-architectures b/10.2/release-architectures new file mode 100644 index 0000000..d499d6f --- /dev/null +++ b/10.2/release-architectures @@ -0,0 +1,5 @@ +# bashbrew-arches +ppc64le +i386 +amd64 +arm64v8 diff --git a/10.3/Dockerfile b/10.3/Dockerfile index eb2ae94..2a802f4 100644 --- a/10.3/Dockerfile +++ b/10.3/Dockerfile @@ -86,15 +86,6 @@ RUN set -ex; \ rm -r "$GNUPGHOME"; \ apt-key list -# add Percona's repo for xtrabackup (which is useful for Galera) -RUN set -e; \ - echo "deb https://repo.percona.com/apt bionic main" > /etc/apt/sources.list.d/percona.list; \ - { \ - echo 'Package: *'; \ - echo 'Pin: release o=Percona Development Team'; \ - echo 'Pin-Priority: 998'; \ - } > /etc/apt/preferences.d/percona - ENV MARIADB_MAJOR 10.3 ENV MARIADB_VERSION 1:10.3.8+maria~bionic @@ -115,11 +106,12 @@ RUN set -ex; \ echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password password 'unused'; \ echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password_again password 'unused'; \ } | debconf-set-selections; \ + XTRABACKUP='mariadb-backup'; \ apt-get update; \ apt-get install -y \ "mariadb-server=$MARIADB_VERSION" \ # percona-xtrabackup/mariadb-backup is installed at the same time so that `mysql-common` is only installed once from just mariadb repos - mariadb-backup \ + $XTRABACKUP \ socat \ ; \ rm -rf /var/lib/apt/lists/*; \ diff --git a/10.3/release-architectures b/10.3/release-architectures new file mode 100644 index 0000000..14be2b5 --- /dev/null +++ b/10.3/release-architectures @@ -0,0 +1,4 @@ +# bashbrew-arches +ppc64le +amd64 +arm64v8 diff --git a/5.5/Dockerfile b/5.5/Dockerfile index c3871ea..a41865c 100644 --- a/5.5/Dockerfile +++ b/5.5/Dockerfile @@ -86,15 +86,6 @@ RUN set -ex; \ rm -r "$GNUPGHOME"; \ apt-key list -# add Percona's repo for xtrabackup (which is useful for Galera) -RUN set -e; \ - echo "deb https://repo.percona.com/apt trusty main" > /etc/apt/sources.list.d/percona.list; \ - { \ - echo 'Package: *'; \ - echo 'Pin: release o=Percona Development Team'; \ - echo 'Pin-Priority: 998'; \ - } > /etc/apt/preferences.d/percona - ENV MARIADB_MAJOR 5.5 ENV MARIADB_VERSION 5.5.60+maria-1~trusty @@ -115,11 +106,29 @@ RUN set -ex; \ echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password password 'unused'; \ echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password_again password 'unused'; \ } | debconf-set-selections; \ + XTRABACKUP='percona-xtrabackup'; \ +## from Dockerfile-percona-block ## +# add Percona's repo for xtrabackup (which is useful for Galera) + echo "deb [arch=amd64,i386] https://repo.percona.com/apt trusty main" > /etc/apt/sources.list.d/percona.list; \ + { \ + echo 'Package: *'; \ + echo 'Pin: release o=Percona Development Team'; \ + echo 'Pin-Priority: 998'; \ + } > /etc/apt/preferences.d/percona; \ +# percona-xtrabackup is amd64/i386 only (mariadb-backup is on all arches that mariadb-server is) + dpkgArch="$(dpkg --print-architecture)"; \ + if [[ "$XTRABACKUP" == percona* ]]; then \ + case "${dpkgArch##*-}" in \ + amd64|i396) ;; \ + *) XTRABACKUP= ;; \ + esac; \ + fi; \ +#### apt-get update; \ apt-get install -y \ "mariadb-server=$MARIADB_VERSION" \ # percona-xtrabackup/mariadb-backup is installed at the same time so that `mysql-common` is only installed once from just mariadb repos - percona-xtrabackup \ + $XTRABACKUP \ socat \ ; \ rm -rf /var/lib/apt/lists/*; \ diff --git a/5.5/release-architectures b/5.5/release-architectures new file mode 100644 index 0000000..02b19b3 --- /dev/null +++ b/5.5/release-architectures @@ -0,0 +1,4 @@ +# bashbrew-arches +ppc64le +i386 +amd64 diff --git a/Dockerfile-percona-block b/Dockerfile-percona-block new file mode 100644 index 0000000..7c173c7 --- /dev/null +++ b/Dockerfile-percona-block @@ -0,0 +1,17 @@ +## from Dockerfile-percona-block ## +# add Percona's repo for xtrabackup (which is useful for Galera) + echo "deb [arch=amd64,i386] https://repo.percona.com/apt %%SUITE%% main" > /etc/apt/sources.list.d/percona.list; \ + { \ + echo 'Package: *'; \ + echo 'Pin: release o=Percona Development Team'; \ + echo 'Pin-Priority: 998'; \ + } > /etc/apt/preferences.d/percona; \ +# percona-xtrabackup is amd64/i386 only (mariadb-backup is on all arches that mariadb-server is) + dpkgArch="$(dpkg --print-architecture)"; \ + if [[ "$XTRABACKUP" == percona* ]]; then \ + case "${dpkgArch##*-}" in \ + amd64|i396) ;; \ + *) XTRABACKUP= ;; \ + esac; \ + fi; \ +#### diff --git a/Dockerfile.template b/Dockerfile.template index 79f60ea..c84d8e7 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -86,15 +86,6 @@ RUN set -ex; \ rm -r "$GNUPGHOME"; \ apt-key list -# add Percona's repo for xtrabackup (which is useful for Galera) -RUN set -e; \ - echo "deb https://repo.percona.com/apt %%SUITE%% main" > /etc/apt/sources.list.d/percona.list; \ - { \ - echo 'Package: *'; \ - echo 'Pin: release o=Percona Development Team'; \ - echo 'Pin-Priority: 998'; \ - } > /etc/apt/preferences.d/percona - ENV MARIADB_MAJOR %%MARIADB_MAJOR%% ENV MARIADB_VERSION %%MARIADB_VERSION%% @@ -115,11 +106,12 @@ RUN set -ex; \ echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password password 'unused'; \ echo "mariadb-server-$MARIADB_MAJOR" mysql-server/root_password_again password 'unused'; \ } | debconf-set-selections; \ + XTRABACKUP='%%XTRABACKUP%%'; \ apt-get update; \ apt-get install -y \ "mariadb-server=$MARIADB_VERSION" \ # percona-xtrabackup/mariadb-backup is installed at the same time so that `mysql-common` is only installed once from just mariadb repos - %%XTRABACKUP%% \ + $XTRABACKUP \ socat \ ; \ rm -rf /var/lib/apt/lists/*; \ diff --git a/generate-stackbrew-library.sh b/generate-stackbrew-library.sh index 1f7e656..53488de 100755 --- a/generate-stackbrew-library.sh +++ b/generate-stackbrew-library.sh @@ -9,6 +9,8 @@ declare -A aliases=( self="$(basename "$BASH_SOURCE")" cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" +source '.architectures-lib' + versions=( */ ) versions=( "${versions[@]%/}" ) @@ -74,6 +76,7 @@ for version in "${versions[@]}"; do echo cat <<-EOE Tags: $(join ', ' "${versionAliases[@]}") + Architectures: $(join ', ' $(versionArches $version)) GitCommit: $commit Directory: $version EOE diff --git a/update.sh b/update.sh index f8bdf99..9926fc5 100755 --- a/update.sh +++ b/update.sh @@ -11,6 +11,27 @@ declare -A xtrabackups=( [5.5]='percona-xtrabackup' [10.0]='percona-xtrabackup' ) +declare -A dpkArchToBashbrew=( + [amd64]='amd64' + [armel]='arm32v5' + [armhf]='arm32v7' + [arm64]='arm64v8' + [i386]='i386' + [ppc64el]='ppc64le' + [s390x]='s390x' +) + +getRemoteVersion() { + local version="$1"; shift # 10.3 + local suite="$1"; shift # bionic + local dpkgArch="$1" shift # arm64 + + echo "$( + curl -fsSL "http://ftp.osuosl.org/pub/mariadb/repo/$version/ubuntu/dists/$suite/main/binary-$dpkgArch/Packages" 2>/dev/null \ + | tac|tac \ + | awk -F ': ' '$1 == "Package" { pkg = $2; next } $1 == "Version" && pkg == "mariadb-server" { print $2; exit }' + )" +} cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" @@ -23,31 +44,42 @@ versions=( "${versions[@]%/}" ) travisEnv= for version in "${versions[@]}"; do suite="${suites[$version]:-$defaultSuite}" - fullVersion="$( - curl -fsSL "http://ftp.osuosl.org/pub/mariadb/repo/$version/ubuntu/dists/$suite/main/binary-amd64/Packages" \ - | tac|tac \ - | awk -F ': ' '$1 == "Package" { pkg = $2; next } $1 == "Version" && pkg == "mariadb-server" { print $2; exit }' - )" + fullVersion="$(getRemoteVersion "$version" "$suite" 'amd64')" if [ -z "$fullVersion" ]; then echo >&2 "warning: cannot find $version in $suite" continue fi + echo '# bashbrew-arches' > "$version/release-architectures" + for arch in "${!dpkArchToBashbrew[@]}"; do + if ver="$(getRemoteVersion "$version" "$suite" "$arch")" && [ -n "$ver" ]; then + echo "${dpkArchToBashbrew[$arch]}" >> "$version/release-architectures" + fi + done + + backup="${xtrabackups[$version]:-$defaultXtrabackup}" - # 10.1 and 10.2 have mariadb major version in the package name - if [ "$backup" == 'mariadb-backup' ] && [[ "$version" < 10.3 ]]; then + + cp Dockerfile.template "$version/Dockerfile" + if [ "$backup" == 'percona-xtrabackup' ]; then + gawk -i inplace ' + { print } + /%%XTRABACKUP%%/ && c == 0 { c = 1; system("cat Dockerfile-percona-block") } + ' "$version/Dockerfile" + elif [ "$backup" == 'mariadb-backup' ] && [[ "$version" < 10.3 ]]; then + # 10.1 and 10.2 have mariadb major version in the package name backup="$backup-$version" fi + ( set -x cp docker-entrypoint.sh "$version/" - sed \ + sed -i \ -e 's!%%MARIADB_VERSION%%!'"$fullVersion"'!g' \ -e 's!%%MARIADB_MAJOR%%!'"$version"'!g' \ -e 's!%%SUITE%%!'"$suite"'!g' \ -e 's!%%XTRABACKUP%%!'"$backup"'!g' \ - Dockerfile.template \ - > "$version/Dockerfile" + "$version/Dockerfile" ) travisEnv='\n - VERSION='"$version$travisEnv"