From b386b498032a71164df2b4279e6547587b68ccd3 Mon Sep 17 00:00:00 2001 From: 1F616EMO Date: Mon, 10 Jun 2024 09:52:22 +0800 Subject: [PATCH 1/3] Add Docker image --- .dockerignore | 16 ++++++++++++++++ Dockerfile | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8f794a5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +.git +.github + +*~ + +minetestmapper +minetestmapper.exe + +CMakeCache.txt +CMakeFiles/ +CPack*.cmake +_CPack_Packages/ +install_manifest.txt +Makefile +cmake_install.cmake +cmake_config.h diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a3d9a14 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +ARG DOCKER_IMAGE=alpine:3.19 +FROM $DOCKER_IMAGE AS dev + +RUN apk add --no-cache build-base cmake \ + gd-dev sqlite-dev postgresql-dev hiredis-dev leveldb-dev \ + ninja ca-certificates + +FROM dev as builder + +COPY . /usr/src/minetestmapper +WORKDIR /usr/src/minetestmapper + +RUN cmake -B build && \ + cmake --build build --parallel $(nproc) && \ + cmake --install build + +RUN ls /usr/local/share/minetest + +FROM $DOCKER_IMAGE AS runtime + +RUN apk add --no-cache libstdc++ libgcc libpq \ + gd sqlite-libs postgresql hiredis leveldb + +COPY --from=builder /usr/local/share/minetest /usr/local/share/minetest +COPY --from=builder /usr/local/bin/minetestmapper /usr/local/bin/minetestmapper + +ENTRYPOINT ["/usr/local/bin/minetestmapper"] From 984996b3a31cb48ae586f30badae8ef041b549f6 Mon Sep 17 00:00:00 2001 From: 1F616EMO Date: Sun, 23 Jun 2024 19:05:26 +0800 Subject: [PATCH 2/3] Optimize Dockerfile and add GH workflow to publish image --- .github/workflows/docker_image.yml | 87 ++++++++++++++++++++++++++++++ Dockerfile | 9 ++-- 2 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/docker_image.yml diff --git a/.github/workflows/docker_image.yml b/.github/workflows/docker_image.yml new file mode 100644 index 0000000..67c6aa2 --- /dev/null +++ b/.github/workflows/docker_image.yml @@ -0,0 +1,87 @@ +--- +name: docker_image + +# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images +# https://docs.docker.com/build/ci/github-actions/multi-platform +# https://github.com/opencontainers/image-spec/blob/main/annotations.md + +on: + push: + branches: [ "master" ] + # Publish semver tags as releases. + tags: [ "*" ] + pull_request: + # Build docker image on pull requests. (but do not publish) + paths: + - '**/**.[ch]' + - '**/**.cpp' + workflow_dispatch: + inputs: + use_cache: + description: "Use build cache" + required: true + type: boolean + default: true + +env: + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + +jobs: + publish: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3.0.0 + + # Login against the Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5.5.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + labels: | + org.opencontainers.image.title=Minetest Mapper + org.opencontainers.image.vendor=Minetest + org.opencontainers.image.licenses=BSD 2-Clause + + # Build and push Docker image + # https://github.com/docker/build-push-action + # No arm support for now. Require cross-compilation support in Dockerfile to not use QEMU. + - name: Build and push Docker image + uses: docker/build-push-action@v5.1.0 + with: + context: . + platforms: linux/amd64 + push: ${{ github.event_name != 'pull_request' }} + load: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + no-cache: ${{ (github.event_name == 'workflow_dispatch' && !inputs.use_cache) || startsWith(github.ref, 'refs/tags/') }} + + - name: Test Docker Image + run: | + docker run --rm $(cut -d, -f1 <<<"$DOCKER_METADATA_OUTPUT_TAGS") minetestserver --version + shell: bash diff --git a/Dockerfile b/Dockerfile index a3d9a14..fcfb582 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,14 @@ ARG DOCKER_IMAGE=alpine:3.19 -FROM $DOCKER_IMAGE AS dev +FROM $DOCKER_IMAGE AS builder RUN apk add --no-cache build-base cmake \ gd-dev sqlite-dev postgresql-dev hiredis-dev leveldb-dev \ - ninja ca-certificates - -FROM dev as builder + ninja COPY . /usr/src/minetestmapper WORKDIR /usr/src/minetestmapper -RUN cmake -B build && \ +RUN cmake -B build -G Ninja && \ cmake --build build --parallel $(nproc) && \ cmake --install build @@ -23,5 +21,6 @@ RUN apk add --no-cache libstdc++ libgcc libpq \ COPY --from=builder /usr/local/share/minetest /usr/local/share/minetest COPY --from=builder /usr/local/bin/minetestmapper /usr/local/bin/minetestmapper +COPY COPYING /usr/local/share/minetest/minetestmapper.COPYING ENTRYPOINT ["/usr/local/bin/minetestmapper"] From 5be39ee66cd904a5980c4fadaad13fb85ab07596 Mon Sep 17 00:00:00 2001 From: 1F616EMO Date: Mon, 24 Jun 2024 19:05:19 +0800 Subject: [PATCH 3/3] Remove testing codes --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index fcfb582..b46109c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,8 +12,6 @@ RUN cmake -B build -G Ninja && \ cmake --build build --parallel $(nproc) && \ cmake --install build -RUN ls /usr/local/share/minetest - FROM $DOCKER_IMAGE AS runtime RUN apk add --no-cache libstdc++ libgcc libpq \