From 4d9f3921ea0474e47dbb98af0fabe71d10252892 Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Sat, 16 Mar 2024 20:53:06 -0700 Subject: [PATCH 1/9] chore(docker): add build workflow --- .github/workflows/build-container.yml | 51 +++++++++++++++++++++++++++ .gitignore | 1 + Dockerfile | 38 ++++++++++++++++++++ entrypoint.sh | 3 ++ 4 files changed, 93 insertions(+) create mode 100644 .github/workflows/build-container.yml create mode 100644 Dockerfile create mode 100644 entrypoint.sh diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml new file mode 100644 index 00000000000..8bfcf56fdc9 --- /dev/null +++ b/.github/workflows/build-container.yml @@ -0,0 +1,51 @@ +--- +name: Build Docker Container +on: + push: + release: + types: [published] + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout Project + uses: actions/checkout@v4 + + - name: Generate Docker Meta + uses: docker/metadata-action@v5 + id: meta + with: + images: ghcr.io/kashalls/grasscutter + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3.1.0 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3.0.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Push Docker image + uses: docker/build-push-action@v5.2.0 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.gitignore b/.gitignore index 33047ac1d01..0ee3fb69f24 100644 --- a/.gitignore +++ b/.gitignore @@ -64,6 +64,7 @@ tmp/ /*.jar /*.sh +!entrypoint.sh GM Handbook*.txt handbook.html diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..0529784c347 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# Builder +FROM gradle:8.5.0-jdk17-alpine as builder + +WORKDIR /app +COPY ./ /app/ + +RUN gradle jar --no-daemon + +# Fetch Data +FROM bitnami/git:2.43.0-debian-11-r1 as data + +ARG DATA_REPOSITORY=https://gitlab.com/YuukiPS/GC-Resources.git +ARG DATA_BRANCH=4.0 + +WORKDIR /app + +RUN git clone --branch ${DATA_BRANCH} --depth 1 ${DATA_REPOSITORY} + +# Result Container +FROM amazoncorretto:17-alpine + +RUN apt-get update && apt-get install unzip + +WORKDIR /app + +# Copy built assets +COPY --from=builder /app/grasscutter-1.7.4.jar /app/grasscutter.jar +COPY --from=builder /app/keystore.p12 /app/keystore.p12 + +# Copy the resources +COPY --from=data /app/GC-Resources/Resources /app/resources/ + +# Copy startup files +COPY ./entrypoint.sh /app/ + +CMD [ "sh", "/app/entrypoint.sh" ] + +EXPOSE 80 443 8888 22102 diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 00000000000..41bfceffad3 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,3 @@ +#/bin/sh + +java -jar /app/grasscutter.jar From d3dc04dcc80a1a5887e254fd00ca451aba70f8ae Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Sat, 16 Mar 2024 20:56:31 -0700 Subject: [PATCH 2/9] chore(docker): update gradle image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0529784c347..0cb17c66c3e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Builder -FROM gradle:8.5.0-jdk17-alpine as builder +FROM gradle:8.6-jdk17-alpine as builder WORKDIR /app COPY ./ /app/ From 279433103249fcd2d5742268b8f98358a1eec7df Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Sat, 16 Mar 2024 21:00:08 -0700 Subject: [PATCH 3/9] chore(docker): this really shouldnt be running on raspberry pi's right now. --- .github/workflows/build-container.yml | 2 +- Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml index 8bfcf56fdc9..385ea0466d3 100644 --- a/.github/workflows/build-container.yml +++ b/.github/workflows/build-container.yml @@ -46,6 +46,6 @@ jobs: with: context: . push: true - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index 0cb17c66c3e..4c1e580bd69 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Builder -FROM gradle:8.6-jdk17-alpine as builder +FROM gradle:jdk17-alpine as builder WORKDIR /app COPY ./ /app/ From c37c4e2a810945d2b37a58f410804153a927b2ca Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Sat, 16 Mar 2024 21:03:54 -0700 Subject: [PATCH 4/9] chore(docker): not sure why we need unzip here --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4c1e580bd69..45f525f4735 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,8 +19,6 @@ RUN git clone --branch ${DATA_BRANCH} --depth 1 ${DATA_REPOSITORY} # Result Container FROM amazoncorretto:17-alpine -RUN apt-get update && apt-get install unzip - WORKDIR /app # Copy built assets From 9328ce09e5fa8e72d87a3ae3a2fdd27ae06d23ec Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Sat, 16 Mar 2024 21:12:29 -0700 Subject: [PATCH 5/9] chore(docker): attempt to add nodejs to allow the handbook to build --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 45f525f4735..49d07c39fa3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,6 +21,8 @@ FROM amazoncorretto:17-alpine WORKDIR /app +RUN apk add --update nodejs + # Copy built assets COPY --from=builder /app/grasscutter-1.7.4.jar /app/grasscutter.jar COPY --from=builder /app/keystore.p12 /app/keystore.p12 From 04401e431777f08a7bec704e9c819bad1c27edb1 Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Sat, 16 Mar 2024 21:15:09 -0700 Subject: [PATCH 6/9] chore(docker): whoops, needs to be done during build --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 49d07c39fa3..d0b79677433 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ # Builder FROM gradle:jdk17-alpine as builder +RUN apk add --update nodejs + WORKDIR /app COPY ./ /app/ @@ -21,8 +23,6 @@ FROM amazoncorretto:17-alpine WORKDIR /app -RUN apk add --update nodejs - # Copy built assets COPY --from=builder /app/grasscutter-1.7.4.jar /app/grasscutter.jar COPY --from=builder /app/keystore.p12 /app/keystore.p12 From bc1fa400d1eb5a0852f974d2fad2104bed650ab9 Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Sat, 16 Mar 2024 21:28:18 -0700 Subject: [PATCH 7/9] chore(docker): i dont know if this is going to work --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d0b79677433..cbe09df3b0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Builder FROM gradle:jdk17-alpine as builder -RUN apk add --update nodejs +RUN apk add --update nodejs npm WORKDIR /app COPY ./ /app/ From 5091fed47b63a0049808f7a81742b62fb31c64e2 Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Sat, 16 Mar 2024 22:39:22 -0700 Subject: [PATCH 8/9] chore(docker): replace my username with repo org as I am no longer testing this --- .github/workflows/build-container.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml index 385ea0466d3..190ac1d1e74 100644 --- a/.github/workflows/build-container.yml +++ b/.github/workflows/build-container.yml @@ -20,7 +20,7 @@ jobs: uses: docker/metadata-action@v5 id: meta with: - images: ghcr.io/kashalls/grasscutter + images: ghcr.io/${{ github.repository_owner }} tags: | type=ref,event=branch type=semver,pattern={{version}} From 6acdf274a6d31167012bac7f7b0f9fd23dec485d Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Sat, 16 Mar 2024 22:46:48 -0700 Subject: [PATCH 9/9] chore(docker): version will change in the future, so fix it now. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index cbe09df3b0f..6c4dbd67783 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,7 @@ FROM amazoncorretto:17-alpine WORKDIR /app # Copy built assets -COPY --from=builder /app/grasscutter-1.7.4.jar /app/grasscutter.jar +COPY --from=builder /app/grasscutter-*.jar /app/grasscutter.jar COPY --from=builder /app/keystore.p12 /app/keystore.p12 # Copy the resources