#!/bin/bash

declare -A versions=(
  ["dev"]="http://github.com/splitbrain/dokuwiki/tarball/master"
  ["rc"]="https://download.dokuwiki.org/src/dokuwiki/dokuwiki-rc.tgz"
  ["stable"]="https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz"
  ["oldstable"]="https://download.dokuwiki.org/src/dokuwiki/dokuwiki-oldstable.tgz"
)

declare -r name=${1:-docker.seblu.net/docker/dokuwiki}

for version in "${!versions[@]}"; do
  url=${versions[$version]}
  echo "Building $version at $url"
  docker build --build-arg=DOKUWIKI_URL="$url" --tag "$name:$version" $BUILD_EXTRA .
done

# latest is always rc, because dokuwiki upstream consider last install should
# be the rc one. The update_check is always looking for RC too.
# https://forum.dokuwiki.org/d/8939-update-check-should-not-be-used-for-release-candidates
docker tag $name:rc $name:latest

echo =========================================================================
echo ::: IMAGE NOT PUSHED
echo ::: to push image:
for version in "${!versions[@]}"; do
  echo       docker push "$name:$version"
done
echo       docker push "${name%:*}:latest"
echo =========================================================================
