diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..f0273bb --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,35 @@ +name: Publish multi-arch Docker image + +on: + release: + types: [published] + workflow_dispatch: + inputs: + overpass_version: + description: 'Version number to build (e.g. 0.7.62)' + required: true + type: string + +permissions: + contents: read + +jobs: + build: + uses: docker/github-builder/.github/workflows/build.yml@v1 + permissions: + contents: read + id-token: write + with: + output: image + push: true + platforms: linux/amd64,linux/arm64 + build-args: OVERPASS_VERSION=${{ github.event.release.tag_name || inputs.overpass_version }} + cache: true + cache-mode: max + meta-images: ${{ vars.DOCKERHUB_USERNAME }}/overpass-api + meta-tags: type=semver,pattern={{version}} + secrets: + registry-auths: | + - registry: docker.io + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/Dockerfile.template b/Dockerfile similarity index 90% rename from Dockerfile.template rename to Dockerfile index 6f52353..8508e94 100644 --- a/Dockerfile.template +++ b/Dockerfile @@ -26,7 +26,8 @@ RUN apt-get update \ zlib1g \ zlib1g-dev -ADD http://dev.overpass-api.de/releases/osm-3s_v{version}.tar.gz /app/src.tar.gz +ARG OVERPASS_VERSION +ADD http://dev.overpass-api.de/releases/osm-3s_v${OVERPASS_VERSION}.tar.gz /app/src.tar.gz RUN mkdir -p /app/src \ && cd /app/src \ @@ -91,9 +92,9 @@ COPY docker-entrypoint.sh docker-healthcheck.sh /app/ RUN chmod a+rx /app/docker-entrypoint.sh /app/bin/update_overpass.sh /app/bin/rules_loop.sh /app/bin/dispatcher_start.sh \ /app/bin/oauth_cookie_client.py /app/bin/start_fcgiwarp.sh -ENV OVERPASS_RULES_LOAD=${{OVERPASS_RULES_LOAD:-1}} -ENV OVERPASS_USE_AREAS=${{OVERPASS_USE_AREAS:-true}} -ENV OVERPASS_ALLOW_DUPLICATE_QUERIES=${{OVERPASS_ALLOW_DUPLICATE_QUERIES:-no}} +ENV OVERPASS_RULES_LOAD=${OVERPASS_RULES_LOAD:-1} +ENV OVERPASS_USE_AREAS=${OVERPASS_USE_AREAS:-true} +ENV OVERPASS_ALLOW_DUPLICATE_QUERIES=${OVERPASS_ALLOW_DUPLICATE_QUERIES:-no} EXPOSE 80 diff --git a/build.sh b/build.sh index d49135a..7c2573e 100755 --- a/build.sh +++ b/build.sh @@ -2,28 +2,31 @@ set -e +IMAGE=wiktorn/overpass-api +VERSIONS=$(python update.py) + case "$1" in "build") - python update.py - - # docker build - find . -maxdepth 1 -type d -name '0.*' -exec sh -c 'docker build -t wiktorn/overpass-api:$(basename "$1") -f "$1"/Dockerfile .' sh {} \; + for version in $VERSIONS; do + docker build --build-arg "OVERPASS_VERSION=${version}" -t "${IMAGE}:${version}" . + done - # docker tag - while IFS= read -r -d '' file; do - docker tag "wiktorn/overpass-api:$(basename "$file")" wiktorn/overpass-api:latest - done < <(find . -maxdepth 1 -type d -regex '\./[0-9]\.[0-9]\.[0-9]*' -print0 | sort -nz | tail -z -n 1) + latest=$(echo "$VERSIONS" | sort -V | tail -n 1) + docker tag "${IMAGE}:${latest}" "${IMAGE}:latest" ;; + "push") - # docker push - find . -maxdepth 1 -type d -name '0.*' -exec sh -c 'docker push "wiktorn/overpass-api:$(basename "$1")"' sh {} \; - docker push wiktorn/overpass-api:latest + for version in $VERSIONS; do + docker push "${IMAGE}:${version}" + done + docker push "${IMAGE}:latest" ;; + "$1") echo "Invalid argument $1" echo "Valid arguments:" - echo "$0 build - to build docker images" - echo "$0 push - to push built images to docker hub" + echo "$0 build - to build Docker images" + echo "$0 push - to push built images to Docker Hub" exit 1 ;; esac diff --git a/update.py b/update.py index 9ac58cd..de4ce74 100644 --- a/update.py +++ b/update.py @@ -1,10 +1,12 @@ import html.parser -import os -import pathlib -import shutil import urllib.request url = "http://dev.overpass-api.de/releases/" +skip_prefixes = ( + '0.6', 'eta', '0.7.1', '0.7.2', '0.7.3', '0.7.4', '0.7.50', '0.7.52', + '0.7.54.11', # invalid CRC in archive + '0.7.51', # no autoconf +) class VersionFinder(html.parser.HTMLParser): @@ -23,31 +25,19 @@ def handle_starttag(self, tag, attrs): self.versions.append(version) -def main(): +def versions_to_build(): parser = VersionFinder() response = urllib.request.urlopen(url) data = response.read().decode(response.headers.get_content_charset()) parser.feed(data) - with open("Dockerfile.template") as f: - template = f.read() - for ver in parser.versions: - if any((ver.startswith(x) for x in ('0.6', 'eta', '0.7.1', '0.7.2', '0.7.3', '0.7.4', '0.7.50', '0.7.52', - '0.7.54.11', # invalid CRC in archive - '0.7.51', # no autoconf - ))) or \ - ver == '0.7': - # ignore old releases - continue - if os.path.exists(ver): - shutil.rmtree(ver) - os.mkdir(ver) - with open(pathlib.Path(ver) / "Dockerfile", "w+") as f: - f.write(template.format(version=ver)) - #for i in ("etc", "bin"): - # shutil.copytree(i, pathlib.Path(ver) / i) - #shutil.copyfile("docker-entrypoint.sh", pathlib.Path(ver) / "docker-entrypoint.sh") - #shutil.copyfile("requirements.txt", pathlib.Path(ver) / "requirements.txt") + + return [ + version for version in parser.versions + if version != '0.7' + and not any(version.startswith(skip_prefix) for skip_prefix in skip_prefixes) + ] if __name__ == '__main__': - main() + for version_to_build in versions_to_build(): + print(version_to_build)