forked from ShadowNinja/minetest-mapper-cpp
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize Dockerfile and add GH workflow to publish image
- Loading branch information
Showing
2 changed files
with
91 additions
and
5 deletions.
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,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