forked from ShadowNinja/minetest-mapper-cpp
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Dockerfile and workflow to publish image #102
Merged
sfan5
merged 3 commits into
minetest:master
from
C-C-Minetest-Server:fork-20240610-docker
Aug 11, 2024
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <account>/<repo> | ||
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/[email protected] | ||
|
||
# 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/[email protected] | ||
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/[email protected] | ||
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/[email protected] | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
ARG DOCKER_IMAGE=alpine:3.19 | ||
FROM $DOCKER_IMAGE AS builder | ||
|
||
RUN apk add --no-cache build-base cmake \ | ||
gd-dev sqlite-dev postgresql-dev hiredis-dev leveldb-dev \ | ||
ninja | ||
|
||
COPY . /usr/src/minetestmapper | ||
WORKDIR /usr/src/minetestmapper | ||
|
||
RUN cmake -B build -G Ninja && \ | ||
cmake --build build --parallel $(nproc) && \ | ||
cmake --install build | ||
|
||
RUN ls /usr/local/share/minetest | ||
Emojigit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 | ||
COPY COPYING /usr/local/share/minetest/minetestmapper.COPYING | ||
|
||
ENTRYPOINT ["/usr/local/bin/minetestmapper"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3.20 these days
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3.19 is used by the Minetest Engine, so I though it would be nice to keep them the same. It would not harm if you decide to upgrade anyways.