From a714cf5e985b92557bf968f86045fa61f290f3eb Mon Sep 17 00:00:00 2001 From: Carlo Mion Date: Thu, 18 Apr 2024 08:58:25 +0200 Subject: [PATCH 1/4] Dockerfile: use private RUN cache to avoid conflicting builds --- 4.4/Dockerfile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/4.4/Dockerfile b/4.4/Dockerfile index 80494fe1..ef4f58ec 100644 --- a/4.4/Dockerfile +++ b/4.4/Dockerfile @@ -8,8 +8,13 @@ ENV LANG=C.UTF-8 WORKDIR /app -RUN \ - --mount=type=cache,target=/var/cache/apt \ +# Inspired by https://github.com/reproducible-containers/buildkit-cache-dance?tab=readme-ov-file#apt-get-github-actions +RUN \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + # Keep downloaded APT packages in the docker build cache + rm -f /etc/apt/apt.conf.d/docker-clean && \ + echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache && \ # Do not start daemons after installation. echo '#!/bin/sh\nexit 101' > /usr/sbin/policy-rc.d \ && chmod +x /usr/sbin/policy-rc.d \ @@ -76,7 +81,7 @@ RUN true \ && echo "listen_addresses='*'" >> /etc/postgresql/14/main/postgresql.conf # Osmium install to run continuous updates. -RUN --mount=type=cache,target=/root/.cache/pip \ +RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked \ pip3 install osmium # Nominatim install. @@ -114,7 +119,6 @@ RUN true \ /tmp/* \ /var/tmp/* \ /app/src/.git \ - /var/lib/apt/lists/* \ # Remove nominatim source and build directories && rm /app/*.tar.bz2 \ && rm -rf /app/build \ From bf7f3a01ee91f45958555a3cb3819e603023f62c Mon Sep 17 00:00:00 2001 From: Carlo Mion Date: Thu, 18 Apr 2024 09:20:28 +0200 Subject: [PATCH 2/4] ci: use docker/metadata-action to set tags and labels --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1c326c6..00e9140e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -263,7 +263,25 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - + + # Compute the Docker tags and labels to apply to the built image + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + # List of Docker images to use as base name for tags + images: | + mediagis/nominatim + + # Disable generation of latest tag + flavor: | + latest=false + prefix=${{ matrix.nominatim.version }} + + # Customize the date format + tags: | + type=schedule,pattern={{date 'YYYY-MM-DDTHH-mm'}},prefix=- + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -274,14 +292,11 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Set container date tag - run: | - echo "DATE_TAG=$(date +%Y-%m-%dT%H-%M)" >> $GITHUB_ENV - - - name: Build and push production docker image to Dockerhub - if: ${{ github.ref == 'refs/heads/master' && github.repository_owner == 'mediagis' }} - run: |- - docker buildx build --platform linux/amd64,linux/arm64 --push \ - -t mediagis/nominatim:${{ matrix.nominatim.version }} \ - -t mediagis/nominatim:${{ matrix.nominatim.version }}-${DATE_TAG} . - working-directory: ${{ matrix.nominatim.version }} \ No newline at end of file + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: ${{ matrix.nominatim.version }} + platforms: linux/amd64,linux/arm64 + push: ${{ github.ref == 'refs/heads/master' && github.repository_owner == 'mediagis' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From 882bfc9ec874a23f679f36be68665645d0dd7080 Mon Sep 17 00:00:00 2001 From: Carlo Mion Date: Thu, 18 Apr 2024 09:43:38 +0200 Subject: [PATCH 3/4] Dockerfile: avoid removing specific packages after compilation, instead use `apt-get --autoremove`. --- 4.4/Dockerfile | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/4.4/Dockerfile b/4.4/Dockerfile index ef4f58ec..23d79a93 100644 --- a/4.4/Dockerfile +++ b/4.4/Dockerfile @@ -29,7 +29,6 @@ RUN \ -o APT::Install-Suggests="false" \ # Build tools from sources. build-essential \ - g++ \ cmake \ libpq-dev \ zlib1g-dev \ @@ -99,18 +98,13 @@ RUN true \ RUN true \ # Remove development and unused packages. - && apt-get -y remove --purge \ - cpp-9 \ - gcc-9* \ - g++ \ + && apt-get -y remove --purge --auto-remove \ + build-essential \ + cmake \ git \ - make \ - cmake* \ llvm-10* \ - libc6-dev \ linux-libc-dev \ libclang-*-dev \ - build-essential \ liblua*-dev \ postgresql-server-dev-14 \ nlohmann-json3-dev \ From 101a702f6126dcdf25d66eac999380dd4239a823 Mon Sep 17 00:00:00 2001 From: Carlo Mion Date: Thu, 18 Apr 2024 10:23:10 +0200 Subject: [PATCH 4/4] Fix generation of custom date tag --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00e9140e..be602e2a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -276,11 +276,11 @@ jobs: # Disable generation of latest tag flavor: | latest=false - prefix=${{ matrix.nominatim.version }} - # Customize the date format + # Add simple tag with nominatim version + tag with custom date format tags: | - type=schedule,pattern={{date 'YYYY-MM-DDTHH-mm'}},prefix=- + type=raw,value=${{ matrix.nominatim.version }} + type=raw,value=${{ matrix.nominatim.version }}-{{date 'YYYY-MM-DDTHH-mm'}} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3