From 97faf452c6f72e665b9d863bd2a949bea9461595 Mon Sep 17 00:00:00 2001 From: Fl3xm3ist3r Date: Sat, 7 Dec 2024 12:36:59 +0100 Subject: [PATCH 1/2] auto deploy to docker hub --- .dockerignorefile | 3 ++- .github/workflows/docker-hub.yml | 37 ++++++++++++++++++++++++++++++++ .gitignore | 1 - launch.sh | 7 +++--- 4 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/docker-hub.yml delete mode 100644 .gitignore diff --git a/.dockerignorefile b/.dockerignorefile index 717b807..a951f58 100644 --- a/.dockerignorefile +++ b/.dockerignorefile @@ -1,2 +1,3 @@ README.md -.git \ No newline at end of file +.git +.github \ No newline at end of file diff --git a/.github/workflows/docker-hub.yml b/.github/workflows/docker-hub.yml new file mode 100644 index 0000000..1a8547c --- /dev/null +++ b/.github/workflows/docker-hub.yml @@ -0,0 +1,37 @@ +name: Docker Hub Image Deploy + +on: + push: + branches: ["master"] + +jobs: + docker-image: + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: Extract SERVER_VERSION from launch.sh + id: extract-version + run: | + SERVER_VERSION=$(grep 'SERVER_VERSION=' launch.sh | cut -d '=' -f2) + echo "SERVER_VERSION=$SERVER_VERSION" >> $GITHUB_ENV + + - name: Log in to Docker Hub + uses: docker/login-action@v3.1.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push the Docker image + uses: docker/build-push-action@v5.3.0 + with: + context: . + push: true + tags: | + ${{ secrets.DOCKERHUB_USERNAME }}/allthemods10:latest + ${{ secrets.DOCKERHUB_USERNAME }}/allthemods10:${{ env.SERVER_VERSION }} diff --git a/.gitignore b/.gitignore deleted file mode 100644 index b8c440d..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -description \ No newline at end of file diff --git a/launch.sh b/launch.sh index 29d9662..e179067 100644 --- a/launch.sh +++ b/launch.sh @@ -3,6 +3,7 @@ set -x NEOFORGE_VERSION=21.1.83 +SERVER_VERSION=1.27.0 cd /data if ! [[ "$EULA" = "false" ]]; then @@ -12,10 +13,10 @@ else exit 99 fi -if ! [[ -f 'Server-Files-1.27.0.zip' ]]; then +if ! [[ -f "Server-Files-$SERVER_VERSION.zip" ]]; then rm -fr config defaultconfigs kubejs mods packmenu Simple.zip forge* - curl -Lo 'Server-Files-1.27.0.zip' 'https://edge.forgecdn.net/files/5965/157/Server-Files-1.27.zip' || exit 9 - unzip -u -o 'Server-Files-1.27.0.zip' -d /data + curl -Lo "Server-Files-SERVER_VERSION.zip" 'https://edge.forgecdn.net/files/5965/157/Server-Files-1.27.zip' || exit 9 + unzip -u -o "Server-Files-$SERVER_VERSION.zip" -d /data DIR_TEST=$(find . -type d -maxdepth 1 | tail -1 | sed 's/^.\{2\}//g') if [[ $(find . -type d -maxdepth 1 | wc -l) -gt 1 ]]; then cd "${DIR_TEST}" From 213722368d8c8c6d91585d86a6cb97c9a5fd0bce Mon Sep 17 00:00:00 2001 From: Fl3xm3ist3r Date: Sat, 7 Dec 2024 12:46:56 +0100 Subject: [PATCH 2/2] adjust build tags --- .github/workflows/docker-hub.yml | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker-hub.yml b/.github/workflows/docker-hub.yml index 1a8547c..79a6225 100644 --- a/.github/workflows/docker-hub.yml +++ b/.github/workflows/docker-hub.yml @@ -2,7 +2,7 @@ name: Docker Hub Image Deploy on: push: - branches: ["master"] + branches: ["main", "develop"] jobs: docker-image: @@ -27,11 +27,18 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push the Docker image - uses: docker/build-push-action@v5.3.0 - with: - context: . - push: true - tags: | - ${{ secrets.DOCKERHUB_USERNAME }}/allthemods10:latest - ${{ secrets.DOCKERHUB_USERNAME }}/allthemods10:${{ env.SERVER_VERSION }} +- name: Build and push the Docker image (versioned tag) + uses: docker/build-push-action@v5.3.0 + with: + context: . + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/allthemods10:${{ env.SERVER_VERSION }} + +- name: Build and push the Docker image (latest tag) + if: ${{ github.ref_name == 'main' }} + uses: docker/build-push-action@v5.3.0 + with: + context: . + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/allthemods10:latest +