add: automatic server deployment
This commit is contained in:
24 files changed
+509
-49
No files matched your search
@@ -0,0 +1,74 @@
|
||||
name: Build & Push Server Image
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
paths:
|
||||
- "server-deploy/**"
|
||||
- ".github/workflows/build-server-image.yml"
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
# Image published as ghcr.io/<owner>/<repo> (metadata-action lowercases it).
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# The Dockerfile reads MC/loader versions from pack.toml itself; here we only
|
||||
# need the MC version to derive the image tag.
|
||||
- name: Extract MC version
|
||||
id: pack
|
||||
run: |
|
||||
mc=$(grep '^minecraft' server-deploy/pack/pack.toml | head -n1 | cut -d'"' -f2)
|
||||
if [ -z "$mc" ]; then echo "::error::could not read minecraft version from pack.toml"; exit 1; fi
|
||||
echo "mc=$mc" >> "$GITHUB_OUTPUT"
|
||||
echo "Minecraft=$mc"
|
||||
|
||||
- name: Log in to GHCR
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Docker metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
type=raw,value=mc-${{ steps.pack.outputs.mc }}
|
||||
type=ref,event=branch
|
||||
type=ref,event=tag
|
||||
type=sha,format=short
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: server-deploy
|
||||
file: server-deploy/Dockerfile
|
||||
# mc-server-runner is downloaded as linux_amd64 in the Dockerfile.
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
Reference in new issue
Block a user