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
|
||||
@@ -1,49 +0,0 @@
|
||||
# This workflow uses actions that are not certified by GitHub.
|
||||
# They are provided by a third-party and are governed by
|
||||
# separate terms of service, privacy policy, and support
|
||||
# documentation.
|
||||
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
|
||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
|
||||
|
||||
name: Deploy to server
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [ "master", "rev/1.21.6" ]
|
||||
jobs:
|
||||
build:
|
||||
if: github.event_name == 'schedule' || startsWith(github.event.head_commit.message, '(update)')
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
|
||||
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
|
||||
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
with:
|
||||
gradle-version: '8.12'
|
||||
- name: Build with Gradle Wrapper
|
||||
run: gradle remapJar
|
||||
- name: Install JQ
|
||||
uses: dcarbone/install-jq-action@v2.1.0
|
||||
- name: Upload Artifact
|
||||
env:
|
||||
API_ENDPOINT: ${{ secrets.API_ENDPOINT }}
|
||||
SERVER_ID: ${{ secrets.SERVER_ID }}
|
||||
TOKEN: ${{ secrets.TOKEN }}
|
||||
UPLOAD_DIR: "../build/libs"
|
||||
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
|
||||
COMMIT_AUTHOR: ${{ github.event.head_commit.author.name }}
|
||||
run: |
|
||||
cd scripts
|
||||
sh ./update.sh
|
||||
Reference in new issue
Block a user