From d453c176a4a29147b05e7e9cf66ee126bfdc93f8 Mon Sep 17 00:00:00 2001 From: rekonnected Date: Sun, 30 Oct 2022 16:43:12 -0400 Subject: [PATCH 01/37] Adapt Dockerfile to be multi-arch (amd64/arm64) Splitting the dependencies into their own sets made it easier to selectively exclude the srcds dependencies when arch is arm64, since they don't work --- Dockerfile | 68 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 52f128e..c40ef6a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM ubuntu:20.04 # Set to false to skip downloading the AMP cache which is used for faster upgrades. ARG CACHE_AMP_UPGRADE=true +ARG TARGETPLATFORM ENV UID=1000 ENV GID=1000 @@ -84,25 +85,24 @@ RUN wget -O /tmp/cacert.pem https://curl.haxx.se/ca/cacert.pem && \ cert-sync /tmp/cacert.pem -# Install AMP dependencies -RUN ls -al /usr/local/bin/ -RUN dpkg --add-architecture i386 && \ - apt-get update && \ - apt-get install -y \ - # -------------------- +# Declare and install AMP dependencies + +ARG AMPDEPS="\ # Dependencies for AMP: tmux \ git \ socat \ unzip \ iputils-ping \ - procps \ - # -------------------- + procps" + +ARG MCDEPS="\ # Dependencies for Minecraft: openjdk-17-jre-headless \ openjdk-11-jre-headless \ - openjdk-8-jre-headless \ - # -------------------- + openjdk-8-jre-headless" + +ARG SRCDSDEPS="\ # Dependencies for srcds (TF2, GMod, ...) lib32gcc1 \ lib32stdc++6 \ @@ -113,12 +113,28 @@ RUN dpkg --add-architecture i386 && \ libncurses5:i386 \ libsdl2-2.0-0 \ libsdl2-2.0-0:i386 \ - libtinfo5:i386 \ - # -------------------- + libtinfo5:i386" + +ARG FACDEPS="\ # Dependencies for Factorio: - xz-utils \ - # -------------------- - && \ + xz-utils" + +RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + dpkg --add-architecture aarch64 && \ + apt-get update && \ + apt-get install -y \ + $AMPDEPS \ + $MCDEPS \ + $FACDEPS; \ + else \ + dpkg --add-architecture i386 && \ + apt-get update && \ + apt-get install -y \ + $AMPDEPS \ + $MCDEPS \ + $SRCDSDEPS \ + $FACDEPS; \ + fi && \ apt-get -y clean && \ apt-get -y autoremove --purge && \ rm -rf \ @@ -127,7 +143,10 @@ RUN dpkg --add-architecture i386 && \ /var/tmp/* # Set Java default -RUN update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java +RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + update-alternatives --set java /usr/lib/jvm/java-17-openjdk-arm64/bin/java; \ + else update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java; \ + fi # Manually install ampinstmgr by extracting it from the deb package. # Docker doesn't have systemctl and other things that AMP's deb postinst expects, @@ -136,10 +155,14 @@ RUN apt-get update && \ apt-get install -y --no-install-recommends \ software-properties-common \ dirmngr \ - apt-transport-https && \ - # Add CubeCoders repository and key - apt-key adv --fetch-keys http://repo.cubecoders.com/archive.key && \ - apt-add-repository "deb http://repo.cubecoders.com/ debian/" && \ + apt-transport-https + +# Add CubeCoders repository and key +RUN apt-key adv --fetch-keys http://repo.cubecoders.com/archive.key && \ + if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + apt-add-repository "deb http://repo.cubecoders.com/aarch64 debian/"; \ + else apt-add-repository "deb http://repo.cubecoders.com/ debian/"; \ + fi && \ apt-get update && \ # Just download (don't actually install) ampinstmgr apt-get install -y --no-install-recommends --download-only ampinstmgr && \ @@ -158,7 +181,10 @@ RUN apt-get update && \ RUN if [ "$CACHE_AMP_UPGRADE" = "true" ]; then \ echo "Pre-caching AMP Upgrade..." && \ wget https://cubecoders.com/AMPVersions.json -O /tmp/AMPVersions.json && \ - wget https://cubecoders.com/Downloads/AMP_Latest.zip -O /opt/AMPCache-$(cat /tmp/AMPVersions.json | jq -r '.AMPCore' | sed -e 's/\.//g').zip; \ + if [ "$TARGETPLATFORM" = "linux/arm64 "]; then \ + wget https://cubecoders.com/Downloads/Release/AMP_Latest_AArch64.zip -O /opt/AMPCache-$(cat /tmp/AMPVersions.json | jq -r '.AMPCore' | sed -e 's/\.//g').zip; \ + else wget https://cubecoders.com/Downloads/AMP_Latest.zip -O /opt/AMPCache-$(cat /tmp/AMPVersions.json | jq -r '.AMPCore' | sed -e 's/\.//g').zip; \ + fi; \ else echo "Skipping AMP Upgrade Pre-cache."; \ fi From e176ab2de900d19e7189239bbb5dd9f0394cd964 Mon Sep 17 00:00:00 2001 From: rekonnected Date: Sun, 30 Oct 2022 16:46:49 -0400 Subject: [PATCH 02/37] Add arm64 to arch matrix in build.yml This should hopefully enable Github Workflows to automatically build it in multiarch --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c5dfe1c..4203cd1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - arch: [amd64] + arch: [amd64,arm64] steps: - name: "Checkout Git Repo" uses: actions/checkout@v2 From 4cc19f9a4585593a60afd3038018703665d86bdb Mon Sep 17 00:00:00 2001 From: Mitch Talmadge <8848080+MitchTalmadge@users.noreply.github.com> Date: Thu, 6 Jul 2023 05:04:37 -0600 Subject: [PATCH 03/37] Don't matrix architectures --- .github/workflows/build.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4203cd1..a28fc79 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,9 +24,6 @@ jobs: build: name: "Build" runs-on: ubuntu-latest - strategy: - matrix: - arch: [amd64,arm64] steps: - name: "Checkout Git Repo" uses: actions/checkout@v2 @@ -42,12 +39,12 @@ jobs: build-args: | "CACHE_AMP_UPGRADE=${{ inputs.for_deploy == true }}" context: . - platforms: linux/${{ matrix.arch }} + platforms: linux/amd64,linux/arm64 tags: amp-dockerized:latest outputs: type=docker,dest=/tmp/docker-image-${{ matrix.arch }}.tar - name: "Upload Docker Image Artifact" if: ${{ inputs.for_deploy == true }} uses: actions/upload-artifact@v2 with: - name: image-${{ matrix.arch }} - path: /tmp/docker-image-${{ matrix.arch }}.tar + name: image + path: /tmp/docker-image.tar From aabcdab7966953e60a4878738034ce5fbc7e1573 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge <8848080+MitchTalmadge@users.noreply.github.com> Date: Thu, 6 Jul 2023 05:05:30 -0600 Subject: [PATCH 04/37] Fix leftover matrix item --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a28fc79..43d6f2a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,7 +41,7 @@ jobs: context: . platforms: linux/amd64,linux/arm64 tags: amp-dockerized:latest - outputs: type=docker,dest=/tmp/docker-image-${{ matrix.arch }}.tar + outputs: type=docker,dest=/tmp/docker-image.tar - name: "Upload Docker Image Artifact" if: ${{ inputs.for_deploy == true }} uses: actions/upload-artifact@v2 From 8be97721e27a04138ee31057e9ef5e96e21d593a Mon Sep 17 00:00:00 2001 From: Mitch Talmadge <8848080+MitchTalmadge@users.noreply.github.com> Date: Thu, 6 Jul 2023 05:07:32 -0600 Subject: [PATCH 05/37] Load only one image --- .github/workflows/deploy-staging.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 6c0a551..5b69f36 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -13,15 +13,13 @@ jobs: name: "Deploy Staging" runs-on: ubuntu-latest steps: - - name: "Download Docker Image Artifacts" + - name: "Download Docker Image Artifact" uses: actions/download-artifact@v2 with: path: /tmp - - name: "Load Docker Images" + - name: "Load Docker Image" run: | - for f in $(find /tmp -type f -iname 'docker-image*.tar' -print); do - docker load --input ${f} - done + docker load --input /tmp/docker-image.tar docker image ls -a - name: "Extract Branch Name" id: extract_branch From d5d9b26ea6419fde0f43bd3a478c1572d4f074b9 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge <8848080+MitchTalmadge@users.noreply.github.com> Date: Thu, 6 Jul 2023 05:10:59 -0600 Subject: [PATCH 06/37] Upgrade buildx step --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 43d6f2a..c3da915 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,7 +34,7 @@ jobs: - name: "Set up Docker Buildx" uses: docker/setup-buildx-action@v1 - name: "Build Docker Image" - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 with: build-args: | "CACHE_AMP_UPGRADE=${{ inputs.for_deploy == true }}" From 2204308374a14960f6c38bec7540e369be908b1b Mon Sep 17 00:00:00 2001 From: Mitch Talmadge <8848080+MitchTalmadge@users.noreply.github.com> Date: Thu, 6 Jul 2023 05:22:29 -0600 Subject: [PATCH 07/37] Use OCI --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c3da915..073c3fb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,7 +41,7 @@ jobs: context: . platforms: linux/amd64,linux/arm64 tags: amp-dockerized:latest - outputs: type=docker,dest=/tmp/docker-image.tar + outputs: type=oci,dest=/tmp/docker-image.tar - name: "Upload Docker Image Artifact" if: ${{ inputs.for_deploy == true }} uses: actions/upload-artifact@v2 From 5f6b1afb1727e2d3ccfc886c3e54a12026cb9539 Mon Sep 17 00:00:00 2001 From: rekonnected <31298266+rekonnected@users.noreply.github.com> Date: Thu, 6 Jul 2023 14:35:33 -0400 Subject: [PATCH 08/37] add name to artifact download this should prevent the extra "image" directory from being created, which is blocking the deploy script from seeing the image with its hardcoded path see https://github.com/actions/download-artifact#download-path-output --- .github/workflows/deploy-staging.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 5b69f36..a050da0 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -16,6 +16,7 @@ jobs: - name: "Download Docker Image Artifact" uses: actions/download-artifact@v2 with: + name: "image" path: /tmp - name: "Load Docker Image" run: | From 0322c196912b914a4f16781927bdf7e518312c3e Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Thu, 6 Jul 2023 18:53:00 -0600 Subject: [PATCH 09/37] Attempt to create manifest --- .github/workflows/build.yml | 13 ++++++++----- .github/workflows/deploy-staging.yml | 26 ++++++++++++++++---------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 073c3fb..4203cd1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,6 +24,9 @@ jobs: build: name: "Build" runs-on: ubuntu-latest + strategy: + matrix: + arch: [amd64,arm64] steps: - name: "Checkout Git Repo" uses: actions/checkout@v2 @@ -34,17 +37,17 @@ jobs: - name: "Set up Docker Buildx" uses: docker/setup-buildx-action@v1 - name: "Build Docker Image" - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v2 with: build-args: | "CACHE_AMP_UPGRADE=${{ inputs.for_deploy == true }}" context: . - platforms: linux/amd64,linux/arm64 + platforms: linux/${{ matrix.arch }} tags: amp-dockerized:latest - outputs: type=oci,dest=/tmp/docker-image.tar + outputs: type=docker,dest=/tmp/docker-image-${{ matrix.arch }}.tar - name: "Upload Docker Image Artifact" if: ${{ inputs.for_deploy == true }} uses: actions/upload-artifact@v2 with: - name: image - path: /tmp/docker-image.tar + name: image-${{ matrix.arch }} + path: /tmp/docker-image-${{ matrix.arch }}.tar diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index a050da0..afee4b8 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -13,24 +13,30 @@ jobs: name: "Deploy Staging" runs-on: ubuntu-latest steps: - - name: "Download Docker Image Artifact" + - name: "Download Docker Image Artifacts" uses: actions/download-artifact@v2 with: - name: "image" path: /tmp - - name: "Load Docker Image" + - name: "Load Docker Images" + id: load_images run: | - docker load --input /tmp/docker-image.tar + TAGS="" + BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/}) + for f in $(find /tmp -type f -iname 'docker-image-*.tar' -print); do + ARCH=$(echo ${f} | sed -E 's/.*docker-image-(.*).tar/\1/') + docker load --input ${f} --platform linux/${ARCH} + TAG="mitchtalmadge/amp-dockerized:${BRANCH_NAME}-${ARCH}" + TAGS="${TAGS} ${TAG}" + docker tag amp-dockerized:latest ${TAG} + done + MANIFEST_NAME="mitchtalmadge/amp-dockerized:${BRANCH_NAME}" + docker manifest create ${MANIFEST_NAME} ${TAGS} + echo MANIFEST_NAME=${MANIFEST_NAME} >> $GITHUB_ENV docker image ls -a - - name: "Extract Branch Name" - id: extract_branch - run: echo "::set-output name=name::$(echo ${GITHUB_REF#refs/heads/})" - - name: "Tag Docker Image" - run: docker tag amp-dockerized:latest mitchtalmadge/amp-dockerized:${{ steps.extract_branch.outputs.name }} - name: "Login to Docker Hub" uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: "Deploy to Docker Hub" - run: docker image push --all-tags mitchtalmadge/amp-dockerized + run: docker manifest push ${{ steps.load_images.outputs.MANIFEST_NAME }} From 9e4cafaea2417c351d5ada3a88364b276e08f173 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Thu, 6 Jul 2023 18:56:28 -0600 Subject: [PATCH 10/37] Add empty dockerfile for quick build testing --- .github/workflows/build.yml | 1 + Dockerfile-test | 1 + 2 files changed, 2 insertions(+) create mode 100644 Dockerfile-test diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4203cd1..844388c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,6 +42,7 @@ jobs: build-args: | "CACHE_AMP_UPGRADE=${{ inputs.for_deploy == true }}" context: . + file: ./Dockerfile-test platforms: linux/${{ matrix.arch }} tags: amp-dockerized:latest outputs: type=docker,dest=/tmp/docker-image-${{ matrix.arch }}.tar diff --git a/Dockerfile-test b/Dockerfile-test new file mode 100644 index 0000000..4b5dbe5 --- /dev/null +++ b/Dockerfile-test @@ -0,0 +1 @@ +FROM ubuntu:20.04 \ No newline at end of file From 7064c5877fa3c97e3f482ad687e219b18d59a3f0 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Thu, 6 Jul 2023 18:57:38 -0600 Subject: [PATCH 11/37] Remove invalid platform tag --- .github/workflows/deploy-staging.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index afee4b8..cdd5464 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -24,7 +24,7 @@ jobs: BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/}) for f in $(find /tmp -type f -iname 'docker-image-*.tar' -print); do ARCH=$(echo ${f} | sed -E 's/.*docker-image-(.*).tar/\1/') - docker load --input ${f} --platform linux/${ARCH} + docker load --input ${f} TAG="mitchtalmadge/amp-dockerized:${BRANCH_NAME}-${ARCH}" TAGS="${TAGS} ${TAG}" docker tag amp-dockerized:latest ${TAG} From e111afd439e859eb3901c8aea78164e2ffeb25b5 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Thu, 6 Jul 2023 19:05:31 -0600 Subject: [PATCH 12/37] Push images before making manifest --- .github/workflows/deploy-staging.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index cdd5464..7a2c6ad 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -29,9 +29,7 @@ jobs: TAGS="${TAGS} ${TAG}" docker tag amp-dockerized:latest ${TAG} done - MANIFEST_NAME="mitchtalmadge/amp-dockerized:${BRANCH_NAME}" - docker manifest create ${MANIFEST_NAME} ${TAGS} - echo MANIFEST_NAME=${MANIFEST_NAME} >> $GITHUB_ENV + echo "TAGS=${TAGS}" >> $GITHUB_ENV docker image ls -a - name: "Login to Docker Hub" uses: docker/login-action@v1 @@ -39,4 +37,9 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: "Deploy to Docker Hub" - run: docker manifest push ${{ steps.load_images.outputs.MANIFEST_NAME }} + run: docker image push --all-tags mitchtalmadge/amp-dockerized + - name: "Deploy Multi-Arch Manifest" + run: | + MANIFEST="mitchtalmadge/amp-dockerized:${BRANCH_NAME}" + docker manifest create ${MANIFEST} ${{ steps.load_images.outputs.TAGS }} + docker manifest push ${MANIFEST} From 3e3dd150ab6cd19649d816b6aac55418ce223e99 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Thu, 6 Jul 2023 19:06:18 -0600 Subject: [PATCH 13/37] Add missing branch name var --- .github/workflows/deploy-staging.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 7a2c6ad..b1c73fb 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -40,6 +40,7 @@ jobs: run: docker image push --all-tags mitchtalmadge/amp-dockerized - name: "Deploy Multi-Arch Manifest" run: | + BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/}) MANIFEST="mitchtalmadge/amp-dockerized:${BRANCH_NAME}" docker manifest create ${MANIFEST} ${{ steps.load_images.outputs.TAGS }} docker manifest push ${MANIFEST} From eae551c1e822657b22d7b632cb2daae3111bc25c Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Thu, 6 Jul 2023 19:07:33 -0600 Subject: [PATCH 14/37] Emit to output --- .github/workflows/deploy-staging.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index b1c73fb..c28459e 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -29,7 +29,7 @@ jobs: TAGS="${TAGS} ${TAG}" docker tag amp-dockerized:latest ${TAG} done - echo "TAGS=${TAGS}" >> $GITHUB_ENV + echo "TAGS=${TAGS}" >> $GITHUB_OUTPUT docker image ls -a - name: "Login to Docker Hub" uses: docker/login-action@v1 From 00014c89c9c96b723f03c2d5214e6978e7a09493 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Thu, 6 Jul 2023 19:09:34 -0600 Subject: [PATCH 15/37] Restore main dockerfile build --- .github/workflows/build.yml | 1 - Dockerfile-test | 1 - 2 files changed, 2 deletions(-) delete mode 100644 Dockerfile-test diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 844388c..4203cd1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,7 +42,6 @@ jobs: build-args: | "CACHE_AMP_UPGRADE=${{ inputs.for_deploy == true }}" context: . - file: ./Dockerfile-test platforms: linux/${{ matrix.arch }} tags: amp-dockerized:latest outputs: type=docker,dest=/tmp/docker-image-${{ matrix.arch }}.tar diff --git a/Dockerfile-test b/Dockerfile-test deleted file mode 100644 index 4b5dbe5..0000000 --- a/Dockerfile-test +++ /dev/null @@ -1 +0,0 @@ -FROM ubuntu:20.04 \ No newline at end of file From dcb6eaa358bcbcdba5bd0503739f5c06a7b826d1 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Thu, 6 Jul 2023 19:16:22 -0600 Subject: [PATCH 16/37] Stop double build --- .github/workflows/auto-deploy-staging.yml | 5 +++++ .github/workflows/build.yml | 8 +------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/auto-deploy-staging.yml b/.github/workflows/auto-deploy-staging.yml index 4d395f2..b02bbd2 100644 --- a/.github/workflows/auto-deploy-staging.yml +++ b/.github/workflows/auto-deploy-staging.yml @@ -4,6 +4,11 @@ on: push: branches: - "staging*" + paths: + - Dockerfile + - .dockerignore + - entrypoint/** + - .github/workflows/**.yml jobs: build: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4203cd1..bc335e2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,18 +7,12 @@ on: required: true type: boolean workflow_dispatch: - push: - paths: - - Dockerfile - - .dockerignore - - entrypoint/** - - .github/workflows/build.yml pull_request: paths: - Dockerfile - .dockerignore - entrypoint/** - - .github/workflows/build.yml + - .github/workflows/**.yml jobs: build: From 8d62094e785c2f165b855ee79c6c9421d8d9b39b Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Sun, 16 Jul 2023 23:05:33 +0000 Subject: [PATCH 17/37] Remove Java notice --- entrypoint/main.sh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/entrypoint/main.sh b/entrypoint/main.sh index e21eced..2f18fcc 100644 --- a/entrypoint/main.sh +++ b/entrypoint/main.sh @@ -8,7 +8,6 @@ echo "Note: This is an UNOFFICIAL IMAGE for CubeCoders AMP. This was created by echo "Please, DO NOT contact CubeCoders (Discord or otherwise) for technical support when using this image." echo "They do not support nor endorse this image and will not help you." echo "Instead, please direct support requests to https://github.com/MitchTalmadge/AMP-dockerized/issues." -echo "We are happy to help you there!" echo "Thank you!!" echo "----------------------" echo "" @@ -109,12 +108,6 @@ shutdown() { } trap "shutdown" SIGTERM -# Java Notice -echo "----------------------" -echo "NOTICE: Java 17 is now the default in this image. Java 16 has been removed in preference of Java 17, which is LTS." -echo "Use the Java Configuration section in the AMP Web UI to select a specific version. Otherwise, Java 17 will be used automatically." -echo "----------------------" - # Sleep echo "Entrypoint Sleeping. Logs can be viewed through AMP web UI or at ampdata/instances/Main/AMP_Logs" tail -f /dev/null & From d34b6edfc7be91f91a131f7a4dd5bba6d0449a35 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 17 Jul 2023 00:52:29 +0000 Subject: [PATCH 18/37] Upgrade to Decadeus build process --- .github/workflows/build.yml | 2 - .github/workflows/check-for-updates.yml | 87 ------------------------- .github/workflows/deploy-prod.yml | 66 ++++++++----------- .github/workflows/deploy-staging.yml | 20 ++++-- Dockerfile | 22 ++----- README.md | 30 +++++---- entrypoint/main.sh | 68 ++++++++----------- 7 files changed, 90 insertions(+), 205 deletions(-) delete mode 100644 .github/workflows/check-for-updates.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bc335e2..6d1af0b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,8 +33,6 @@ jobs: - name: "Build Docker Image" uses: docker/build-push-action@v2 with: - build-args: | - "CACHE_AMP_UPGRADE=${{ inputs.for_deploy == true }}" context: . platforms: linux/${{ matrix.arch }} tags: amp-dockerized:latest diff --git a/.github/workflows/check-for-updates.yml b/.github/workflows/check-for-updates.yml deleted file mode 100644 index f7c36fe..0000000 --- a/.github/workflows/check-for-updates.yml +++ /dev/null @@ -1,87 +0,0 @@ -name: "Check for Updates" - -on: - schedule: - - cron: "*/15 * * * *" # Every 15 mins - workflow_dispatch: - create: - tags: - - "v[0-9]+" - -jobs: - # Find out what version of AMP exists online right now. - get_latest_version: - name: "Get Latest Version" - runs-on: ubuntu-latest - outputs: - amp_core_version: ${{ steps.parse.outputs.amp_core_version }} - amp_instmgr_version: ${{ steps.parse.outputs.amp_instmgr_version }} - steps: - - name: "Download AMP Versions" - run: wget https://cubecoders.com/AMPVersions.json -O /tmp/AMPVersions.json - - name: "Parse Versions" - id: parse - run: | - echo "::set-output name=amp_core_version::$(jq -r '.AMPCore' /tmp/AMPVersions.json | sed -e 's/\.//g')" - echo "::set-output name=amp_instmgr_version::$(jq -r '.InstanceManagerCLI' /tmp/AMPVersions.json | sed -e 's/\.//g')" - - # Find out when the latest version of AMP was modified. - # Sometimes patches are released under the same version, so only this value will change. - get_last_modified: - name: "Get Last Modified" - runs-on: ubuntu-latest - outputs: - amp_last_modified: ${{ steps.parse.outputs.amp_last_modified }} - steps: - - name: "Get Last Modified" - id: parse - # Converts the last-modified header to seconds since epoch. - run: echo "::set-output name=amp_last_modified::$(curl https://cubecoders.com/Downloads/AMP_Latest.zip --head --silent | awk 'match($0, /last-modified:\s+(.+)\s+/, a) {print a[1]}' | date -f - +%s)" - - # Determine if we have a tag for this combination of version and last-modified. - check_for_tag: - name: "Check for Tag" - runs-on: ubuntu-latest - needs: [ get_latest_version, get_last_modified ] - outputs: - tag_exists: ${{ steps.check_for_tag.outputs.tag_exists }} - git_release_version: ${{ steps.get_git_version.outputs.git_latest_release_version }} - amp_core_version: ${{ needs.get_latest_version.outputs.amp_core_version }} - amp_instmgr_version: ${{ needs.get_latest_version.outputs.amp_instmgr_version }} - amp_last_modified: ${{ needs.get_last_modified.outputs.amp_last_modified }} - - steps: - - name: "Checkout" - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: "Determine Latest Release Version" - id: get_git_version - run: echo "::set-output name=git_latest_release_version::$(git tag -l --sort=-creatordate | grep -E '^v?[0-9]+$' -m 1)" - - name: "Compose Expected Tag" - id: compose_tag - run: echo "::set-output name=expected_tag::${{steps.get_git_version.outputs.git_latest_release_version}}-ampcore${{needs.get_latest_version.outputs.amp_core_version}}-ampinstmgr${{needs.get_latest_version.outputs.amp_instmgr_version}}-${{needs.get_last_modified.outputs.amp_last_modified}}" - - name: "Check for Expected Tag" - id: check_for_tag - run: echo "::set-output name=tag_exists::$(git tag | grep -q ${{steps.compose_tag.outputs.expected_tag}} && echo '1' || echo '0')" - - build: - name: "Build" - needs: [ check_for_tag ] - if: ${{ needs.check_for_tag.outputs.tag_exists == '0' && github.ref == 'refs/heads/master' }} - uses: MitchTalmadge/AMP-Dockerized/.github/workflows/build.yml@master - with: - for_deploy: true - - deploy: - name: "Deploy" - needs: [ build, check_for_tag ] - uses: MitchTalmadge/AMP-dockerized/.github/workflows/deploy-prod.yml@master - with: - git_release_version: ${{ needs.check_for_tag.outputs.git_release_version }} - amp_core_version: ${{ needs.check_for_tag.outputs.amp_core_version }} - amp_instmgr_version: ${{ needs.check_for_tag.outputs.amp_instmgr_version }} - amp_last_modified: ${{ needs.check_for_tag.outputs.amp_last_modified }} - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml index 5c3395a..e8fcb3c 100644 --- a/.github/workflows/deploy-prod.yml +++ b/.github/workflows/deploy-prod.yml @@ -1,27 +1,17 @@ name: "Deploy Production" +# Run when a tag is pushed starting with "v" on: - workflow_call: - inputs: - git_release_version: - required: true - type: string - amp_core_version: - required: true - type: string - amp_instmgr_version: - required: true - type: string - amp_last_modified: - required: true - type: string - secrets: - DOCKERHUB_USERNAME: - required: true - DOCKERHUB_TOKEN: - required: true + push: + tags: + - v* jobs: + build: + uses: MitchTalmadge/AMP-dockerized/.github/workflows/build.yml + with: + for_deploy: true + deploy: name: "Deploy" runs-on: ubuntu-latest @@ -30,29 +20,22 @@ jobs: uses: actions/download-artifact@v2 with: path: /tmp - - name: "Load Docker Image" + - name: "Get Tag Name" + id: get_tag_name + run: echo "TAG_NAME=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_ENV + - name: "Load Docker Images" + id: load_images run: | - for f in $(find /tmp -type f -iname 'docker-image*.tar' -print); do + TAGS="" + for f in $(find /tmp -type f -iname 'docker-image-*.tar' -print); do + ARCH=$(echo ${f} | sed -E 's/.*docker-image-(.*).tar/\1/') docker load --input ${f} + TAG="mitchtalmadge/amp-dockerized:${{ steps.get_tag_name.outputs.TAG_NAME }}-${ARCH}" + TAGS="${TAGS} ${TAG}" + docker tag amp-dockerized:latest ${TAG} done + echo "TAGS=${TAGS}" >> $GITHUB_OUTPUT docker image ls -a - - name: "Tag Docker Images" - run: | - docker tag amp-dockerized:latest mitchtalmadge/amp-dockerized:latest - docker tag amp-dockerized:latest mitchtalmadge/amp-dockerized:${{inputs.git_release_version}} - docker tag amp-dockerized:latest mitchtalmadge/amp-dockerized:${{inputs.git_release_version}}-ampcore${{inputs.amp_core_version}}-ampinstmgr${{inputs.amp_instmgr_version}} - docker tag amp-dockerized:latest mitchtalmadge/amp-dockerized:${{inputs.git_release_version}}-ampcore${{inputs.amp_core_version}}-ampinstmgr${{inputs.amp_instmgr_version}}-${{inputs.amp_last_modified}} - - name: "Checkout Git Repo" - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: "Commit Git Tag" - run: | - git config user.name github-actions - git config user.email github-actions@github.com - TAG=${{inputs.git_release_version}}-ampcore${{inputs.amp_core_version}}-ampinstmgr${{inputs.amp_instmgr_version}}-${{inputs.amp_last_modified}} - git tag -a "${TAG}" -m "Auto Release Latest AMP Version" || { echo "Tag already exists"; exit; } - git push --follow-tags - name: "Login to Docker Hub" uses: docker/login-action@v1 with: @@ -60,3 +43,10 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: "Deploy to Docker Hub" run: docker image push --all-tags mitchtalmadge/amp-dockerized + - name: "Deploy Multi-Arch Manifests" + run: | + MANIFESTS="mitchtalmadge/amp-dockerized:latest mitchtalmadge/amp-dockerized:${{ steps.get_tag_name.outputs.TAG_NAME }}" + for m in ${MANIFESTS}; do + docker manifest create ${m} ${{ steps.load_images.outputs.TAGS }} + docker manifest push ${m} + done diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index c28459e..7ba5707 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -1,14 +1,22 @@ name: "Deploy Staging" on: - workflow_call: - secrets: - DOCKERHUB_USERNAME: - required: true - DOCKERHUB_TOKEN: - required: true + push: + branches: + - "staging*" + paths: + - Dockerfile + - .dockerignore + - entrypoint/** + - .github/workflows/**.yml jobs: + build: + if: ${{ startsWith(github.ref, 'refs/heads/staging') }} + uses: MitchTalmadge/AMP-dockerized/.github/workflows/build.yml@staging + with: + for_deploy: true + deploy: name: "Deploy Staging" runs-on: ubuntu-latest diff --git a/Dockerfile b/Dockerfile index c40ef6a..7f8e2c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,6 @@ FROM ubuntu:20.04 -# Set to false to skip downloading the AMP cache which is used for faster upgrades. -ARG CACHE_AMP_UPGRADE=true -ARG TARGETPLATFORM +ARG TARGETPLATFORM # Set by Docker, see https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope ENV UID=1000 ENV GID=1000 @@ -10,10 +8,12 @@ ENV TZ=Etc/UTC ENV PORT=8080 ENV USERNAME=admin ENV PASSWORD=password -ENV LICENCE=notset -ENV MODULE=ADS ENV IPBINDING=0.0.0.0 +ENV AMP_AUTO_UPDATE=true +ENV AMP_LICENCE=notset +ENV AMP_MODULE=ADS +ENV AMP_RELEASE_STREAM=Mainline ENV AMP_SUPPORT_LEVEL=UNSUPPORTED ENV AMP_SUPPORT_TOKEN=AST0/MTAD ENV AMP_SUPPORT_TAGS="nosupport docker community unofficial unraid" @@ -177,18 +177,6 @@ RUN apt-key adv --fetch-keys http://repo.cubecoders.com/archive.key && \ /var/lib/apt/lists/* \ /var/tmp/* -# Get the latest AMP Core to pre-cache upgrades. -RUN if [ "$CACHE_AMP_UPGRADE" = "true" ]; then \ - echo "Pre-caching AMP Upgrade..." && \ - wget https://cubecoders.com/AMPVersions.json -O /tmp/AMPVersions.json && \ - if [ "$TARGETPLATFORM" = "linux/arm64 "]; then \ - wget https://cubecoders.com/Downloads/Release/AMP_Latest_AArch64.zip -O /opt/AMPCache-$(cat /tmp/AMPVersions.json | jq -r '.AMPCore' | sed -e 's/\.//g').zip; \ - else wget https://cubecoders.com/Downloads/AMP_Latest.zip -O /opt/AMPCache-$(cat /tmp/AMPVersions.json | jq -r '.AMPCore' | sed -e 's/\.//g').zip; \ - fi; \ - else echo "Skipping AMP Upgrade Pre-cache."; \ - fi - - # Set up environment COPY entrypoint /opt/entrypoint RUN chmod -R +x /opt/entrypoint diff --git a/README.md b/README.md index f1055dc..271a5c6 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,13 @@ Updates to AMP are automatically bundled into new Docker images. We check for up **Please DO NOT bug CubeCoders for support without first asking here; they do not support nor endorse this image and will tell you that you are on your own.** -If you need help with AMP when using this image, please [create an issue](https://github.com/MitchTalmadge/AMP-dockerized/issues/new) and we will figure it out! +If you need help with AMP when using this image, please [create an issue](https://github.com/MitchTalmadge/AMP-dockerized/issues/new) in this repository. + +If you have coding skills and find this repository useful, please consider helping out by answering questions in the issues or making pull requests to fix bugs. I really can't do this alone. ## Unraid If you are using Unraid, please check out [this support topic](https://forums.unraid.net/topic/98290-support-amp-application-management-panel-corneliousjd-repo/) made by one of our community members, [@CorneliousJD](https://github.com/CorneliousJD)! - # Supported Modules **Tested and Working:** @@ -98,9 +99,9 @@ Just a quick note about ports: some games use TCP, some games use UDP. Make sure ### Licence -| Name | Description | Default Value | -|-----------|----------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------| -| `LICENCE` | The licence key for CubeCoders AMP. You can retrieve or buy this on [their website.](https://manage.cubecoders.com/) | No Default. AMP will not boot without a real licence. | +| Name | Description | Default Value | +|---------------|--------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------| +| `AMP_LICENCE` | The licence key for CubeCoders AMP. You can retrieve or buy this on [their website.](https://manage.cubecoders.com/) | No Default. AMP will not boot without a real licence. | **Important Details:** - _Americans:_ This is spelled licenCe not licenSe. Got me a few times. @@ -109,9 +110,9 @@ Just a quick note about ports: some games use TCP, some games use UDP. Make sure ### Module -| Name | Description | Default Value | -|----------|------------------------------------------------------------------|---------------| -| `MODULE` | Which Module to use for the main instance created by this image. | `ADS` | +| Name | Description | Default Value | +|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|---------------| +| `AMP_MODULE` | Which Module to use for the Main instance created by this image (note: changing this value will have no effect after the Main instance is created). | `ADS` | To run multiple game servers under this image, use the default value of `ADS` (Application Deployment Service) which allows you to create various modules from the web ui. @@ -162,10 +163,10 @@ Example: `TZ=America/Denver` | `USERNAME` | The username of the admin user created on first boot. | `admin` | | `PASSWORD` | The password of the admin user. This value is only used when creating the new user. If you use the default value, please change it after first sign-in. | `password` | -### Nightly Builds -| Name | Description | Default Value | -|-------|----------------------------------------------------------------------|---------------| -| `NIGHTLY` | Set to any value to enable nightly builds. All instances will be migrated to nightly builds on next image start. Unset this variable to go back to MainLine builds (stable releases). | UNSET | +### Release Stream +| Name | Description | Default Value | +|----------------------|----------------------------------------------------------------------------------------------------|---------------| +| `AMP_RELEASE_STREAM` | Valid values are `Mainline` or `Development`. Don't change this unless you know what you're doing. | `Mainline` | ## Volumes @@ -198,8 +199,11 @@ To restart the AMP instances, just restart the Docker container. Or, just put [CloudFlare](https://www.cloudflare.com/) and its free SSL cert in front of your web UI and save yourself hours of pain. # Upgrading AMP +To upgrade, just restart your container! On startup, we check for updates and install them if they are available. -To upgrade, all you have to do is pull our latest Docker image! We automatically check for AMP updates every hour. When a new version is released, we build and publish an image both as a standalone tag and on `:latest`. +| Name | Description | Default Value | +|-------------------|-------------------------------------------------------------------------------------------------|---------------| +| `AMP_AUTO_UPDATE` | Set to `false` if you would not like AMP to automatically update when you reboot the container. | `true` | # Contributing diff --git a/entrypoint/main.sh b/entrypoint/main.sh index 2f18fcc..e54e03e 100644 --- a/entrypoint/main.sh +++ b/entrypoint/main.sh @@ -12,7 +12,11 @@ echo "Thank you!!" echo "----------------------" echo "" -# Run user startup script +# Migrate legacy vars +export AMP_LICENCE=${AMP_LICENCE:-${LICENCE:-"notset"}}} +export AMP_MODULE=${AMP_MODULE:-${MODULE:-"ADS"}} + +# Users may provide their own startup script for installing dependencies, etc. STARTUP_SCRIPT="/home/amp/scripts/startup.sh" if [ -f ${STARTUP_SCRIPT} ]; then echo "Running startup script..." @@ -20,14 +24,7 @@ if [ -f ${STARTUP_SCRIPT} ]; then /bin/bash ${STARTUP_SCRIPT} fi -# Copy the pre-cached AMP Core from the image into the location AMP expects. -# This will allow upgrades to use the cache and not need to do any downloads. -echo "Copying AMP Core..." -mkdir -p /home/amp/.ampdata/instances/ -cp /opt/AMPCache* /home/amp/.ampdata/instances/ - -# Create user and group that will own the config files (if they don't exist already). -echo "Ensuring AMP user exists..." +echo "Creating AMP user..." if [ ! "$(getent group ${GID})" ]; then # Create group addgroup \ @@ -47,57 +44,44 @@ if [ ! "$(getent passwd ${UID})" ]; then fi APP_USER=$(getent passwd ${UID} | awk -F ":" '{ print $1 }') -# Let all volume data be owned by the new user. -echo "Ensuring correct file permissions..." +echo "Checking file permissions..." chown -R ${APP_USER}:${APP_GROUP} /home/amp -# Set Timezone -echo "Setting timezone from TZ env var..." +echo "Configuring timezone..." ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone dpkg-reconfigure --frontend noninteractive tzdata -# Ensure a Licence was set -if [ ${LICENCE} = "notset" ]; then - echo "Error: no Licence specified. You need to have a valid AMP licence from cubecoders.com specified in the LICENCE environment variable" +echo "Checking licence..." +if [ ${AMP_LICENCE} = "notset" ]; then + echo "Error: AMP_LICENCE is not set. You need to have a valid AMP licence from cubecoders.com specified in the AMP_LICENCE environment variable" exit 1 fi -# Create Main Instance if not exists -echo "Making sure Main instance exists..." +echo "Checking Main instance..." if [ ! $(su ${APP_USER} --command "ampinstmgr ShowInstancesList" | grep "Instance Name" | awk '{ print $4 }' | grep "Main") ]; then echo "Creating Main instance... (This can take a while)" - su ${APP_USER} --command "ampinstmgr CreateInstance \"${MODULE}\" Main \"${IPBINDING}\" \"${PORT}\" \"${LICENCE}\" \"${USERNAME}\" \"${PASSWORD}\"" | grep --line-buffered -v -E '\[[-#]+\]' + su ${APP_USER} --command "ampinstmgr CreateInstance \"${AMP_MODULE}\" Main \"${IPBINDING}\" \"${PORT}\" \"${AMP_LICENCE}\" \"${USERNAME}\" \"${PASSWORD}\"" | grep --line-buffered -v -E '\[[-#]+\]' fi -# Set instances to MainLine or Nightly -if [ ! -z "$NIGHTLY" ]; then - # Nightly - echo "Setting all instances to use Nightly updates..." - su ${APP_USER} --command "ampinstmgr ShowInstancesList" | grep "Instance Name" | awk '{ print $4 }' | while read -r INSTANCE_NAME; do - echo "> ${INSTANCE_NAME}:" - su ${APP_USER} --command "ampinstmgr Switch \"${INSTANCE_NAME}\" Nightly" | grep --line-buffered -v -E '\[[-#]+\]' - done +echo "Setting release stream to ${AMP_RELEASE_STREAM}..." +su ${APP_USER} --command "ampinstmgr ShowInstancesList" | grep "Instance Name" | awk '{ print $4 }' | while read -r INSTANCE_NAME; do + echo "> ${INSTANCE_NAME}:" + su ${APP_USER} --command "ampinstmgr ChangeInstanceStream \"${INSTANCE_NAME}\" ${AMP_RELEASE_STREAM} True" | grep --line-buffered -v -E '\[[-#]+\]' +done + +if [ ${AMP_AUTO_UPDATE} = "true" ]; then + echo "Auto-updating instances..." + su ${APP_USER} --command "ampinstmgr UpgradeAll" | grep --line-buffered -v -E '\[[-#]+\]' else - # MainLine - echo "Setting all instances to use MainLine updates..." - su ${APP_USER} --command "ampinstmgr ShowInstancesList" | grep "Instance Name" | awk '{ print $4 }' | while read -r INSTANCE_NAME; do - echo "> ${INSTANCE_NAME}:" - su ${APP_USER} --command "ampinstmgr Switch \"${INSTANCE_NAME}\" MainLine True" | grep --line-buffered -v -E '\[[-#]+\]' - done + echo "Skipping automatic updates." fi -# Upgrade instances -echo "Upgrading Instances..." -su ${APP_USER} --command "ampinstmgr UpgradeAll" | grep --line-buffered -v -E '\[[-#]+\]' - -# Set Main instance to start on boot if not already. -echo "Ensuring Main Instance will Start on Boot..." +echo "Setting Main instance to start on boot..." su ${APP_USER} --command "ampinstmgr ShowInstanceInfo Main | grep \"Start on Boot\" | grep \"No\" && ampinstmgr SetStartBoot Main yes || true" -# Startup echo "Starting AMP..." su ${APP_USER} --command "ampinstmgr StartBoot" -echo "AMP Started." +echo "AMP Started!" # Trap SIGTERM for a graceful shutdown shutdown() { @@ -109,6 +93,6 @@ shutdown() { trap "shutdown" SIGTERM # Sleep -echo "Entrypoint Sleeping. Logs can be viewed through AMP web UI or at ampdata/instances/Main/AMP_Logs" +echo "AMP is now running. Logs can be viewed through AMP web UI or at ampdata/instances/Main/AMP_Logs" tail -f /dev/null & wait $! From 3f1a39149455f324072350231595e377ae272ff5 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 17 Jul 2023 00:54:07 +0000 Subject: [PATCH 19/37] Remove old action --- .github/workflows/auto-deploy-staging.yml | 25 ----------------------- 1 file changed, 25 deletions(-) delete mode 100644 .github/workflows/auto-deploy-staging.yml diff --git a/.github/workflows/auto-deploy-staging.yml b/.github/workflows/auto-deploy-staging.yml deleted file mode 100644 index b02bbd2..0000000 --- a/.github/workflows/auto-deploy-staging.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: "Auto Deploy Staging Branches" - -on: - push: - branches: - - "staging*" - paths: - - Dockerfile - - .dockerignore - - entrypoint/** - - .github/workflows/**.yml - -jobs: - build: - if: ${{ startsWith(github.ref, 'refs/heads/staging') }} - uses: MitchTalmadge/AMP-dockerized/.github/workflows/build.yml@staging - with: - for_deploy: true - - deploy: - needs: [build] - uses: MitchTalmadge/AMP-dockerized/.github/workflows/deploy-staging.yml@staging - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} From 790b0bd79f01302cb9c683d47b2f3498b2674852 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 17 Jul 2023 00:55:34 +0000 Subject: [PATCH 20/37] Prod deploy only on master --- .github/workflows/deploy-prod.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml index e8fcb3c..6069a22 100644 --- a/.github/workflows/deploy-prod.yml +++ b/.github/workflows/deploy-prod.yml @@ -3,6 +3,8 @@ name: "Deploy Production" # Run when a tag is pushed starting with "v" on: push: + branches: + - "master" tags: - v* From dae9cca9ff920fd6c3079a1f07f5a39fbea37eb9 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 17 Jul 2023 00:57:06 +0000 Subject: [PATCH 21/37] Wait for build to complete --- .github/workflows/deploy-prod.yml | 2 +- .github/workflows/deploy-staging.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml index 6069a22..38becdb 100644 --- a/.github/workflows/deploy-prod.yml +++ b/.github/workflows/deploy-prod.yml @@ -1,6 +1,5 @@ name: "Deploy Production" -# Run when a tag is pushed starting with "v" on: push: branches: @@ -17,6 +16,7 @@ jobs: deploy: name: "Deploy" runs-on: ubuntu-latest + needs: build steps: - name: "Download Docker Image Artifacts" uses: actions/download-artifact@v2 diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 7ba5707..01403cf 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -20,6 +20,7 @@ jobs: deploy: name: "Deploy Staging" runs-on: ubuntu-latest + needs: build steps: - name: "Download Docker Image Artifacts" uses: actions/download-artifact@v2 From 3fdd3f22ee51091a5eac2135ef9ec52bd3e67ae4 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 17 Jul 2023 00:58:08 +0000 Subject: [PATCH 22/37] Fix missing version reference --- .github/workflows/deploy-prod.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml index 38becdb..c08bfbb 100644 --- a/.github/workflows/deploy-prod.yml +++ b/.github/workflows/deploy-prod.yml @@ -9,7 +9,7 @@ on: jobs: build: - uses: MitchTalmadge/AMP-dockerized/.github/workflows/build.yml + uses: MitchTalmadge/AMP-dockerized/.github/workflows/build.yml@master with: for_deploy: true From 6ab0fc063abf16b642938bffae6b660ab28b9b21 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 17 Jul 2023 04:19:37 +0000 Subject: [PATCH 23/37] Re-organize entrypoint. Improve release stream changeover. --- entrypoint/main.sh | 86 +++++++--------------------- entrypoint/routines.sh | 124 +++++++++++++++++++++++++++++++++++++++++ entrypoint/utils.sh | 13 +++++ 3 files changed, 158 insertions(+), 65 deletions(-) create mode 100644 entrypoint/routines.sh create mode 100644 entrypoint/utils.sh diff --git a/entrypoint/main.sh b/entrypoint/main.sh index e54e03e..8366319 100644 --- a/entrypoint/main.sh +++ b/entrypoint/main.sh @@ -1,5 +1,6 @@ #!/bin/bash -e -set +o xtrace +#set -o xtrace +set -e echo "----------------------" echo "Starting AMP-Dockerized..." @@ -12,85 +13,40 @@ echo "Thank you!!" echo "----------------------" echo "" -# Migrate legacy vars -export AMP_LICENCE=${AMP_LICENCE:-${LICENCE:-"notset"}}} -export AMP_MODULE=${AMP_MODULE:-${MODULE:-"ADS"}} +source /opt/entrypoint/utils.sh +source /opt/entrypoint/routines.sh +trap 'handle_error' ERR -# Users may provide their own startup script for installing dependencies, etc. -STARTUP_SCRIPT="/home/amp/scripts/startup.sh" -if [ -f ${STARTUP_SCRIPT} ]; then - echo "Running startup script..." - chmod +x ${STARTUP_SCRIPT} - /bin/bash ${STARTUP_SCRIPT} +# Migrate legacy vars +export AMP_LICENCE=${LICENCE:-${AMP_LICENCE:-"notset"}} +export AMP_MODULE=${MODULE:-${AMP_MODULE:-"ADS"}} +if [ ! -z "${NIGHTLY}" ]; then + export AMP_RELEASE_STREAM="Development" fi -echo "Creating AMP user..." -if [ ! "$(getent group ${GID})" ]; then - # Create group - addgroup \ - --gid ${GID} \ - amp -fi -APP_GROUP=$(getent group ${GID} | awk -F ":" '{ print $1 }') -if [ ! "$(getent passwd ${UID})" ]; then - # Create user - adduser \ - --uid ${UID} \ - --shell /bin/bash \ - --no-create-home \ - --ingroup ${APP_GROUP} \ - --system \ - amp -fi -APP_USER=$(getent passwd ${UID} | awk -F ":" '{ print $1 }') +run_startup_script -echo "Checking file permissions..." -chown -R ${APP_USER}:${APP_GROUP} /home/amp +create_amp_user -echo "Configuring timezone..." -ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone -dpkg-reconfigure --frontend noninteractive tzdata +check_licence -echo "Checking licence..." -if [ ${AMP_LICENCE} = "notset" ]; then - echo "Error: AMP_LICENCE is not set. You need to have a valid AMP licence from cubecoders.com specified in the AMP_LICENCE environment variable" - exit 1 -fi +configure_timezone -echo "Checking Main instance..." -if [ ! $(su ${APP_USER} --command "ampinstmgr ShowInstancesList" | grep "Instance Name" | awk '{ print $4 }' | grep "Main") ]; then - echo "Creating Main instance... (This can take a while)" - su ${APP_USER} --command "ampinstmgr CreateInstance \"${AMP_MODULE}\" Main \"${IPBINDING}\" \"${PORT}\" \"${AMP_LICENCE}\" \"${USERNAME}\" \"${PASSWORD}\"" | grep --line-buffered -v -E '\[[-#]+\]' -fi +check_file_permissions + +configure_main_instance -echo "Setting release stream to ${AMP_RELEASE_STREAM}..." -su ${APP_USER} --command "ampinstmgr ShowInstancesList" | grep "Instance Name" | awk '{ print $4 }' | while read -r INSTANCE_NAME; do - echo "> ${INSTANCE_NAME}:" - su ${APP_USER} --command "ampinstmgr ChangeInstanceStream \"${INSTANCE_NAME}\" ${AMP_RELEASE_STREAM} True" | grep --line-buffered -v -E '\[[-#]+\]' -done +configure_release_stream if [ ${AMP_AUTO_UPDATE} = "true" ]; then - echo "Auto-updating instances..." - su ${APP_USER} --command "ampinstmgr UpgradeAll" | grep --line-buffered -v -E '\[[-#]+\]' + upgrade_instances else echo "Skipping automatic updates." fi -echo "Setting Main instance to start on boot..." -su ${APP_USER} --command "ampinstmgr ShowInstanceInfo Main | grep \"Start on Boot\" | grep \"No\" && ampinstmgr SetStartBoot Main yes || true" - -echo "Starting AMP..." -su ${APP_USER} --command "ampinstmgr StartBoot" -echo "AMP Started!" - +start_amp # Trap SIGTERM for a graceful shutdown -shutdown() { - echo "Shutting Down AMP..." - su ${APP_USER} --command "ampinstmgr StopAll" - echo "Shutdown Complete." - exit 0 -} -trap "shutdown" SIGTERM +trap "stop_amp" SIGTERM # Sleep echo "AMP is now running. Logs can be viewed through AMP web UI or at ampdata/instances/Main/AMP_Logs" diff --git a/entrypoint/routines.sh b/entrypoint/routines.sh new file mode 100644 index 0000000..b6dbb14 --- /dev/null +++ b/entrypoint/routines.sh @@ -0,0 +1,124 @@ +#!/bin/bash + +check_file_permissions() { + echo "Checking file permissions..." + chown -R ${APP_USER}:${APP_GROUP} /home/amp +} + +check_licence() { + echo "Checking licence..." + if [ ${AMP_LICENCE} = "notset" ]; then + handle_error "AMP_LICENCE is not set. You need to have a valid AMP licence from cubecoders.com specified in the AMP_LICENCE environment variable" + fi + # TODO: Find a way to test the licence validity +} + +configure_main_instance() { + echo "Checking Main instance existence..." + if ! does_main_instance_exist; then + echo "Creating Main instance... (This can take a while)" + run_amp_command "CreateInstance \"${AMP_MODULE}\" Main \"${IPBINDING}\" \"${PORT}\" \"${AMP_LICENCE}\" \"${USERNAME}\" \"${PASSWORD}\"" | consume_progress_bars + if ! does_main_instance_exist; then + handle_error "Failed to create Main instance. Please check your configuration." + fi + fi + + echo "Setting Main instance to start on boot..." + run_amp_command "ShowInstanceInfo Main" | grep "Start on Boot" | grep -q "No" && run_amp_command "SetStartBoot Main yes" || true +} + +configure_release_stream() { + echo "Setting release stream to ${AMP_RELEASE_STREAM}..." + # Example Output from ShowInstancesList: + # [Info] AMP Instance Manager v2.4.5.4 built 26/06/2023 18:20 + # [Info] Stream: Mainline / Release - built by CUBECODERS/buildbot on CCL-DEV + # Instance ID │ 295e9fc7-9987-4e4e-94a6-183cb04de459 + # Module │ ADS + # Instance Name │ Main + # Friendly Name │ Main + # URL │ http://127.0.0.1:8080/ + # Running │ No + # Runs in Container │ No + # Runs as Shared │ No + # Start on Boot │ Yes + # AMP Version │ 2.4.5.4 + # Release Stream │ Mainline + # Data Path │ /home/amp/.ampdata/instances/Main + run_amp_command "ShowInstancesList" | grep "Instance Name" | awk '{ print $4 }' | while read -r INSTANCE_NAME; do + local RELEASE_STREAM=$(run_amp_command "ShowInstanceInfo \"${INSTANCE_NAME}\"" | grep "Release Stream" | awk '{ print $4 }') + if [ "${RELEASE_STREAM}" != "${AMP_RELEASE_STREAM}" ]; then + echo "Changing release stream of ${INSTANCE_NAME} from ${RELEASE_STREAM} to ${AMP_RELEASE_STREAM}..." + run_amp_command "ChangeInstanceStream \"${INSTANCE_NAME}\" ${AMP_RELEASE_STREAM} True" | consume_progress_bars + # Since we changed release streams we have to force an upgrade + run_amp_command "UpgradeInstance \"${INSTANCE_NAME}\"" | consume_progress_bars + fi + done +} + +configure_timezone() { + echo "Configuring timezone..." + ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone + dpkg-reconfigure --frontend noninteractive tzdata +} + +create_amp_user() { + echo "Creating AMP user..." + if [ ! "$(getent group ${GID})" ]; then + # Create group + addgroup \ + --gid ${GID} \ + amp + fi + APP_GROUP=$(getent group ${GID} | awk -F ":" '{ print $1 }') + if [ ! "$(getent passwd ${UID})" ]; then + # Create user + adduser \ + --uid ${UID} \ + --shell /bin/bash \ + --no-create-home \ + --ingroup ${APP_GROUP} \ + --system \ + amp + fi + APP_USER=$(getent passwd ${UID} | awk -F ":" '{ print $1 }') +} + +handle_error() { + # Prints a nice error message and exits. + # Usage: handle_error "Error message" + local error_message="$1" + echo "Sorry! An error occurred during startup and AMP needs to shut down." + if [ ! -z "${error_message}" ]; then + echo "Error message: ${error_message}" + fi + echo "Please direct any questions or concerns to https://github.com/MitchTalmadge/AMP-dockerized/issues" + exit 1 +} + +run_startup_script() { + # Users may provide their own startup script for installing dependencies, etc. + STARTUP_SCRIPT="/home/amp/scripts/startup.sh" + if [ -f ${STARTUP_SCRIPT} ]; then + echo "Running startup script..." + chmod +x ${STARTUP_SCRIPT} + /bin/bash ${STARTUP_SCRIPT} + fi +} + +start_amp() { + echo "Starting AMP..." + run_amp_command "StartBoot" + echo "AMP Started!" +} + +stop_amp() { + echo "Stopping AMP..." + run_amp_command "StopAll" + echo "AMP Stopped." + exit 0 +} + +upgrade_instances() { + echo "Upgrading instances..." + run_amp_command "UpgradeAll" | consume_progress_bars +} \ No newline at end of file diff --git a/entrypoint/utils.sh b/entrypoint/utils.sh new file mode 100644 index 0000000..79b4e77 --- /dev/null +++ b/entrypoint/utils.sh @@ -0,0 +1,13 @@ +#!/bin/bash +consume_progress_bars() { + # See https://github.com/MitchTalmadge/AMP-dockerized/issues/25#issuecomment-670251321 + grep --line-buffered -v -E '\[[-#]+\]' +} + +does_main_instance_exist() { + run_amp_command "ShowInstancesList" | grep "Instance Name" | awk '{ print $4 }' | grep -q "Main" +} + +run_amp_command() { + su ${APP_USER} --command "ampinstmgr $1" +} \ No newline at end of file From 3233bd3ae2e7e3c9228188f97a642ceb4ef809ce Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 17 Jul 2023 04:35:41 +0000 Subject: [PATCH 24/37] Update build action deps --- .github/workflows/build.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6d1af0b..e433494 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,15 +23,15 @@ jobs: arch: [amd64,arm64] steps: - name: "Checkout Git Repo" - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - name: "Set up QEMU" - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v2 - name: "Set up Docker Buildx" - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 - name: "Build Docker Image" - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 with: context: . platforms: linux/${{ matrix.arch }} @@ -39,7 +39,7 @@ jobs: outputs: type=docker,dest=/tmp/docker-image-${{ matrix.arch }}.tar - name: "Upload Docker Image Artifact" if: ${{ inputs.for_deploy == true }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: image-${{ matrix.arch }} path: /tmp/docker-image-${{ matrix.arch }}.tar From 99c248f49e5fd442cce71129a88faffeabf89995 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 17 Jul 2023 04:38:27 +0000 Subject: [PATCH 25/37] Use branch local build action in staging --- .github/workflows/deploy-staging.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 01403cf..4529a61 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -13,7 +13,7 @@ on: jobs: build: if: ${{ startsWith(github.ref, 'refs/heads/staging') }} - uses: MitchTalmadge/AMP-dockerized/.github/workflows/build.yml@staging + uses: MitchTalmadge/AMP-dockerized/.github/workflows/build.yml@${{ github.sha }} with: for_deploy: true From 102a90facb6b138ce1963eb7370228ba48a617d1 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 17 Jul 2023 04:42:21 +0000 Subject: [PATCH 26/37] Local ref build action --- .github/workflows/deploy-prod.yml | 2 +- .github/workflows/deploy-staging.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml index c08bfbb..78fa8f3 100644 --- a/.github/workflows/deploy-prod.yml +++ b/.github/workflows/deploy-prod.yml @@ -9,7 +9,7 @@ on: jobs: build: - uses: MitchTalmadge/AMP-dockerized/.github/workflows/build.yml@master + uses: ./.github/workflows/build.yml with: for_deploy: true diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 4529a61..b2daaa4 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -13,7 +13,7 @@ on: jobs: build: if: ${{ startsWith(github.ref, 'refs/heads/staging') }} - uses: MitchTalmadge/AMP-dockerized/.github/workflows/build.yml@${{ github.sha }} + uses: ./.github/workflows/build.yml with: for_deploy: true From e38b3feaead980358b779e6d69a698b5faa63f11 Mon Sep 17 00:00:00 2001 From: James Manker Date: Wed, 19 Jul 2023 00:12:05 -0500 Subject: [PATCH 27/37] Multiple Updates This provides the following updates: - Switches to Debian 12 slim - Uses Adoptium for Java - Adds Wine & Xvfb - Adds miscellaneous dependencies identified previously for specific games My main goal here was to mirror the CubeCoders Docker images as closely as possible. While it doesn't make much difference in terms of how the image will function, it makes future changes between the two more streamlined. Also adding support for Xvfb/Wine allows for many more games to run. My next step will be adding Box/Box64 support for ARM systems to play I386 through emulation in a future Pull Request. :) --- Dockerfile | 116 +++++++++++++++++++++++------------------ entrypoint/routines.sh | 1 - 2 files changed, 65 insertions(+), 52 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7f8e2c0..7a2c459 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:20.04 +FROM debian:12-slim ARG TARGETPLATFORM # Set by Docker, see https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope @@ -18,6 +18,7 @@ ENV AMP_SUPPORT_LEVEL=UNSUPPORTED ENV AMP_SUPPORT_TOKEN=AST0/MTAD ENV AMP_SUPPORT_TAGS="nosupport docker community unofficial unraid" ENV AMP_SUPPORT_URL="https://github.com/MitchTalmadge/AMP-dockerized/" +ENV LD_LIBRARY_PATH="./:/opt/cubecoders/amp/:/AMP/" ARG DEBIAN_FRONTEND=noninteractive @@ -35,7 +36,6 @@ RUN apt-get update && \ /var/lib/apt/lists/* \ /var/tmp/* - # Configure Locales RUN apt-get update && \ apt-get install -y --no-install-recommends locales && \ @@ -53,58 +53,56 @@ ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 -# Add Mono apt source +# Install Mono RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - apt-transport-https \ + apt-get install -y \ dirmngr \ - software-properties-common \ - gnupg \ - ca-certificates && \ - apt-get -y clean && \ - apt-get -y autoremove --purge && \ - rm -rf \ - /tmp/* \ - /var/lib/apt/lists/* \ - /var/tmp/* -RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF && \ - echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" | tee /etc/apt/sources.list.d/mono-official-stable.list - - -# Install Mono Certificates -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - ca-certificates-mono && \ + ca-certificates \ + gnupg && \ + gpg --homedir /tmp --no-default-keyring --keyring /usr/share/keyrings/mono-official-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF && \ + echo "deb [signed-by=/usr/share/keyrings/mono-official-archive-keyring.gpg] https://download.mono-project.com/repo/debian stable-buster main" | tee /etc/apt/sources.list.d/mono-official-stable.list && \ + apt-get update && \ + apt-get install -y mono-devel && \ apt-get -y clean && \ apt-get -y autoremove --purge && \ rm -rf \ /tmp/* \ /var/lib/apt/lists/* \ /var/tmp/* -RUN wget -O /tmp/cacert.pem https://curl.haxx.se/ca/cacert.pem && \ - cert-sync /tmp/cacert.pem - # Declare and install AMP dependencies ARG AMPDEPS="\ # Dependencies for AMP: + apt-transport-https \ tmux \ git \ + git-lfs \ socat \ unzip \ iputils-ping \ - procps" - -ARG MCDEPS="\ - # Dependencies for Minecraft: - openjdk-17-jre-headless \ - openjdk-11-jre-headless \ - openjdk-8-jre-headless" - + procps \ + numactl \ + gnupg \ + locales \ + software-properties-common \ + libc++-dev \ + coreutils \ + libsqlite3-0 \ + curl \ + gdb \ + xz-utils \ + bzip2 \ + libzstd1 \ + libgdiplus \ + libc6 \ + libatomic1 \ + libpulse-dev \ + liblua5.3-0" + ARG SRCDSDEPS="\ # Dependencies for srcds (TF2, GMod, ...) - lib32gcc1 \ + lib32gcc-s1 \ lib32stdc++6 \ lib32z1 \ libbz2-1.0:i386 \ @@ -115,25 +113,38 @@ ARG SRCDSDEPS="\ libsdl2-2.0-0:i386 \ libtinfo5:i386" +ARG WINEXVFB="\ + # Needed for games that require Wine and Xvfb + xvfb \ + wine \ + wine32 \ + wine64 \ + wine-binfmt \ + python3 \ + winbind \ + libwine \ + libwine:i386 \ + fonts-wine \ + xauth" + ARG FACDEPS="\ # Dependencies for Factorio: xz-utils" -RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ +RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ dpkg --add-architecture aarch64 && \ apt-get update && \ apt-get install -y \ - $AMPDEPS \ - $MCDEPS \ - $FACDEPS; \ + $AMPDEPS \ + $FACDEPS; \ else \ - dpkg --add-architecture i386 && \ + dpkg --add-architecture i386 && \ apt-get update && \ apt-get install -y \ - $AMPDEPS \ - $MCDEPS \ - $SRCDSDEPS \ - $FACDEPS; \ + $AMPDEPS \ + $SRCDSDEPS \ + $WINEXVFB \ + $FACDEPS; \ fi && \ apt-get -y clean && \ apt-get -y autoremove --purge && \ @@ -142,11 +153,13 @@ RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ /var/lib/apt/lists/* \ /var/tmp/* -# Set Java default -RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ - update-alternatives --set java /usr/lib/jvm/java-17-openjdk-arm64/bin/java; \ - else update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java; \ - fi +# Install Adoptium JDK +RUN wget -qO- https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor > /usr/share/keyrings/adoptium.gpg && \ + echo "deb [signed-by=/usr/share/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb bookworm main" > /etc/apt/sources.list.d/adoptium.list && \ + apt-get update && \ + apt-get install -y temurin-8-jdk temurin-11-jdk temurin-17-jdk && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* # Manually install ampinstmgr by extracting it from the deb package. # Docker doesn't have systemctl and other things that AMP's deb postinst expects, @@ -158,10 +171,11 @@ RUN apt-get update && \ apt-transport-https # Add CubeCoders repository and key -RUN apt-key adv --fetch-keys http://repo.cubecoders.com/archive.key && \ +RUN wget -qO - http://repo.cubecoders.com/archive.key | gpg --dearmor > /etc/apt/trusted.gpg.d/cubecoders-archive-keyring.gpg && \ if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ apt-add-repository "deb http://repo.cubecoders.com/aarch64 debian/"; \ - else apt-add-repository "deb http://repo.cubecoders.com/ debian/"; \ + else \ + apt-add-repository "deb http://repo.cubecoders.com/ debian/"; \ fi && \ apt-get update && \ # Just download (don't actually install) ampinstmgr @@ -183,4 +197,4 @@ RUN chmod -R +x /opt/entrypoint VOLUME ["/home/amp/.ampdata"] -ENTRYPOINT ["/opt/entrypoint/main.sh"] +ENTRYPOINT ["/opt/entrypoint/main.sh"] \ No newline at end of file diff --git a/entrypoint/routines.sh b/entrypoint/routines.sh index b6dbb14..9bc3958 100644 --- a/entrypoint/routines.sh +++ b/entrypoint/routines.sh @@ -77,7 +77,6 @@ create_amp_user() { --shell /bin/bash \ --no-create-home \ --ingroup ${APP_GROUP} \ - --system \ amp fi APP_USER=$(getent passwd ${UID} | awk -F ":" '{ print $1 }') From be790bbd180ec7def2333bd73cbe68117cec6d82 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge <8848080+MitchTalmadge@users.noreply.github.com> Date: Sat, 2 Sep 2023 23:26:41 -0600 Subject: [PATCH 28/37] Trigger rebuild --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7a2c459..4f3dd17 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM debian:12-slim - + ARG TARGETPLATFORM # Set by Docker, see https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope ENV UID=1000 @@ -197,4 +197,4 @@ RUN chmod -R +x /opt/entrypoint VOLUME ["/home/amp/.ampdata"] -ENTRYPOINT ["/opt/entrypoint/main.sh"] \ No newline at end of file +ENTRYPOINT ["/opt/entrypoint/main.sh"] From 6f44a6eb5f6c124316c56ec7acf0925b78888968 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 30 Oct 2023 12:07:58 -0600 Subject: [PATCH 29/37] Fix adduser --- entrypoint/routines.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/entrypoint/routines.sh b/entrypoint/routines.sh index 9bc3958..e964f16 100644 --- a/entrypoint/routines.sh +++ b/entrypoint/routines.sh @@ -62,7 +62,7 @@ configure_timezone() { } create_amp_user() { - echo "Creating AMP user..." + echo "Creating AMP group..." if [ ! "$(getent group ${GID})" ]; then # Create group addgroup \ @@ -70,16 +70,22 @@ create_amp_user() { amp fi APP_GROUP=$(getent group ${GID} | awk -F ":" '{ print $1 }') + echo "Group Created: ${APP_GROUP} (${GID})" + + echo "Creating AMP user..." if [ ! "$(getent passwd ${UID})" ]; then # Create user adduser \ - --uid ${UID} \ - --shell /bin/bash \ - --no-create-home \ - --ingroup ${APP_GROUP} \ - amp + --uid ${UID} \ + --shell /bin/bash \ + --no-create-home \ + --disabled-password \ + --gecos "" \ + --ingroup ${APP_GROUP} \ + amp fi APP_USER=$(getent passwd ${UID} | awk -F ":" '{ print $1 }') + echo "User Created: ${APP_USER} (${UID})" } handle_error() { From 781f419966ab04d358671b3c30aa25a0aaa196e1 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 30 Oct 2023 12:08:08 -0600 Subject: [PATCH 30/37] Add documentation for example configs --- example-configs/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 example-configs/README.md diff --git a/example-configs/README.md b/example-configs/README.md new file mode 100644 index 0000000..72aa479 --- /dev/null +++ b/example-configs/README.md @@ -0,0 +1,8 @@ +# Example Configs + +## Which one do I use? +- If you're using Unraid's Docker tool, this directory doesn't apply to you. +- If you think there's a chance that you'll ever want to run more than one game server, start with the `ads` config. This will launch an "ADS" instance which can be used to create other instances. +- If you want to run one specific game only, you can just use one of those configs (e.g. `factorio`) +- If you have an old McMyAdmin license (if you don't know what this is, you don't have one), then you must use the `mcmyadmin` config. +- These are just examples -- you can of course make your own config! You don't even have to use `docker compose` if you don't want to, and know what you're doing. \ No newline at end of file From 5857976d0d529efab3ec31e6af9c041b66557bf3 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 30 Oct 2023 13:22:58 -0600 Subject: [PATCH 31/37] Monitor AMP and run scheduled tasks --- entrypoint/main.sh | 1 + entrypoint/routines.sh | 8 ++++++++ entrypoint/utils.sh | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/entrypoint/main.sh b/entrypoint/main.sh index 8366319..96efe73 100644 --- a/entrypoint/main.sh +++ b/entrypoint/main.sh @@ -50,5 +50,6 @@ trap "stop_amp" SIGTERM # Sleep echo "AMP is now running. Logs can be viewed through AMP web UI or at ampdata/instances/Main/AMP_Logs" +monitor_amp & tail -f /dev/null & wait $! diff --git a/entrypoint/routines.sh b/entrypoint/routines.sh index e964f16..8b1ced8 100644 --- a/entrypoint/routines.sh +++ b/entrypoint/routines.sh @@ -100,6 +100,14 @@ handle_error() { exit 1 } +monitor_amp() { + # Periodically process pending tasks (e.g. upgrade, reboots, ...) + while true; do + run_amp_command_silently "ProcessPendingTasks" + sleep 5 # The UI's restart timeout is 10 seconds, so let's be safe. + done +} + run_startup_script() { # Users may provide their own startup script for installing dependencies, etc. STARTUP_SCRIPT="/home/amp/scripts/startup.sh" diff --git a/entrypoint/utils.sh b/entrypoint/utils.sh index 79b4e77..773429d 100644 --- a/entrypoint/utils.sh +++ b/entrypoint/utils.sh @@ -10,4 +10,8 @@ does_main_instance_exist() { run_amp_command() { su ${APP_USER} --command "ampinstmgr $1" +} + +run_amp_command_silently() { + su ${APP_USER} --command "ampinstmgr --silent $1" } \ No newline at end of file From c6b36f1664f876e14db1329e6e0f5023ce46bf65 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 30 Oct 2023 13:56:40 -0600 Subject: [PATCH 32/37] Fix unreliable shutdown behavior --- entrypoint/main.sh | 3 +-- entrypoint/routines.sh | 10 +++++++++- entrypoint/utils.sh | 10 +++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/entrypoint/main.sh b/entrypoint/main.sh index 96efe73..caa2e6a 100644 --- a/entrypoint/main.sh +++ b/entrypoint/main.sh @@ -16,6 +16,7 @@ echo "" source /opt/entrypoint/utils.sh source /opt/entrypoint/routines.sh trap 'handle_error' ERR +trap_with_arg 'shutdown' INT TERM HUP QUIT KILL # Migrate legacy vars export AMP_LICENCE=${LICENCE:-${AMP_LICENCE:-"notset"}} @@ -45,8 +46,6 @@ else fi start_amp -# Trap SIGTERM for a graceful shutdown -trap "stop_amp" SIGTERM # Sleep echo "AMP is now running. Logs can be viewed through AMP web UI or at ampdata/instances/Main/AMP_Logs" diff --git a/entrypoint/routines.sh b/entrypoint/routines.sh index 8b1ced8..2bb93c8 100644 --- a/entrypoint/routines.sh +++ b/entrypoint/routines.sh @@ -118,9 +118,18 @@ run_startup_script() { fi } +shutdown() { + echo "Shutting down... (Signal ${1})" + if [ -n "${AMP_STARTED}" ] && [ "${AMP_STARTED}" -eq 1 ] && [ "${1}" != "KILL" ]; then + stop_amp + fi + exit 0 +} + start_amp() { echo "Starting AMP..." run_amp_command "StartBoot" + export AMP_STARTED=1 echo "AMP Started!" } @@ -128,7 +137,6 @@ stop_amp() { echo "Stopping AMP..." run_amp_command "StopAll" echo "AMP Stopped." - exit 0 } upgrade_instances() { diff --git a/entrypoint/utils.sh b/entrypoint/utils.sh index 773429d..34bfcd2 100644 --- a/entrypoint/utils.sh +++ b/entrypoint/utils.sh @@ -14,4 +14,12 @@ run_amp_command() { run_amp_command_silently() { su ${APP_USER} --command "ampinstmgr --silent $1" -} \ No newline at end of file +} + +trap_with_arg() { + # Credit https://stackoverflow.com/a/2183063/2364405 + func="$1" ; shift + for sig ; do + trap "$func $sig" "$sig" + done +} From 7faecdb32c70539b9865732496c24e53ab067718 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 30 Oct 2023 13:57:14 -0600 Subject: [PATCH 33/37] Install JDK 8,11,17,21 via AWS Corretto --- Dockerfile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4f3dd17..a34041d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -153,11 +153,15 @@ RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ /var/lib/apt/lists/* \ /var/tmp/* -# Install Adoptium JDK -RUN wget -qO- https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor > /usr/share/keyrings/adoptium.gpg && \ - echo "deb [signed-by=/usr/share/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb bookworm main" > /etc/apt/sources.list.d/adoptium.list && \ +# Install Corretto JDK +RUN wget -O- https://apt.corretto.aws/corretto.key | gpg --dearmor > /etc/apt/trusted.gpg.d/corretto.gpg && \ + add-apt-repository "deb https://apt.corretto.aws stable main" && \ apt-get update && \ - apt-get install -y temurin-8-jdk temurin-11-jdk temurin-17-jdk && \ + apt-get install -y \ + java-1.8.0-amazon-corretto-jdk \ + java-11-amazon-corretto-jdk \ + java-17-amazon-corretto-jdk \ + java-21-amazon-corretto-jdk && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* From c46b8a69702bf72b41a9705caee535f5be0dae5f Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 30 Oct 2023 23:27:59 -0600 Subject: [PATCH 34/37] Sort dependencies --- Dockerfile | 64 +++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/Dockerfile b/Dockerfile index a34041d..b8af7e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,6 +25,7 @@ ARG DEBIAN_FRONTEND=noninteractive # Initialize RUN apt-get update && \ apt-get install -y --no-install-recommends \ + apt-transport-https \ jq \ sed \ tzdata \ @@ -72,36 +73,35 @@ RUN apt-get update && \ # Declare and install AMP dependencies +# AMP core dependencies ARG AMPDEPS="\ - # Dependencies for AMP: - apt-transport-https \ - tmux \ + bzip2 \ + coreutils \ + curl \ + gdb \ git \ git-lfs \ - socat \ - unzip \ - iputils-ping \ - procps \ - numactl \ gnupg \ - locales \ - software-properties-common \ + iputils-ping \ libc++-dev \ - coreutils \ - libsqlite3-0 \ - curl \ - gdb \ - xz-utils \ - bzip2 \ - libzstd1 \ - libgdiplus \ libc6 \ libatomic1 \ + libgdiplus \ + liblua5.3-0 \ libpulse-dev \ - liblua5.3-0" + libsqlite3-0 \ + libzstd1 \ + locales \ + numactl \ + procps \ + software-properties-common \ + socat \ + tmux \ + unzip \ + xz-utils" +# srcds (TF2, GMod, ...) dependencies ARG SRCDSDEPS="\ - # Dependencies for srcds (TF2, GMod, ...) lib32gcc-s1 \ lib32stdc++6 \ lib32z1 \ @@ -113,38 +113,32 @@ ARG SRCDSDEPS="\ libsdl2-2.0-0:i386 \ libtinfo5:i386" +# Needed for games that require Wine and Xvfb ARG WINEXVFB="\ - # Needed for games that require Wine and Xvfb - xvfb \ + fonts-wine \ + libwine \ + libwine:i386 \ + python3 \ wine \ wine32 \ wine64 \ wine-binfmt \ - python3 \ winbind \ - libwine \ - libwine:i386 \ - fonts-wine \ - xauth" - -ARG FACDEPS="\ - # Dependencies for Factorio: - xz-utils" + xauth \ + xvfb" RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ dpkg --add-architecture aarch64 && \ apt-get update && \ apt-get install -y \ - $AMPDEPS \ - $FACDEPS; \ + $AMPDEPS; \ else \ dpkg --add-architecture i386 && \ apt-get update && \ apt-get install -y \ $AMPDEPS \ $SRCDSDEPS \ - $WINEXVFB \ - $FACDEPS; \ + $WINEXVFB; \ fi && \ apt-get -y clean && \ apt-get -y autoremove --purge && \ From 4ba22a0e5a645e4a53906a680523171ec2938448 Mon Sep 17 00:00:00 2001 From: Mitch Talmadge Date: Mon, 30 Oct 2023 23:28:27 -0600 Subject: [PATCH 35/37] Revert back to Adoptium for better AMP support. Fix Adoptium install --- Dockerfile | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index b8af7e2..d48dafb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -147,15 +147,11 @@ RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ /var/lib/apt/lists/* \ /var/tmp/* -# Install Corretto JDK -RUN wget -O- https://apt.corretto.aws/corretto.key | gpg --dearmor > /etc/apt/trusted.gpg.d/corretto.gpg && \ - add-apt-repository "deb https://apt.corretto.aws stable main" && \ +# Install Adoptium JDK +RUN wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | tee /etc/apt/keyrings/adoptium.asc && \ + echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list && \ apt-get update && \ - apt-get install -y \ - java-1.8.0-amazon-corretto-jdk \ - java-11-amazon-corretto-jdk \ - java-17-amazon-corretto-jdk \ - java-21-amazon-corretto-jdk && \ + apt-get install -y temurin-8-jdk temurin-11-jdk temurin-17-jdk temurin-21-jdk && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* From a98d235a8ff879aadf0377ab76de21027eba5d3a Mon Sep 17 00:00:00 2001 From: IceOfWraith <96364530+IceOfWraith@users.noreply.github.com> Date: Wed, 1 Nov 2023 21:59:07 -0500 Subject: [PATCH 36/37] Add python3-venv This adds support for the latest Python3 changes that require virtual environments and in turn, GatekeeperV2 support. --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index d48dafb..3da326c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -119,6 +119,7 @@ ARG WINEXVFB="\ libwine \ libwine:i386 \ python3 \ + python3-venv \ wine \ wine32 \ wine64 \ From 82e5c7f0fc47c5e7ec828d8312f71a67ca3e51e0 Mon Sep 17 00:00:00 2001 From: IceOfWraith <96364530+IceOfWraith@users.noreply.github.com> Date: Wed, 1 Nov 2023 22:02:13 -0500 Subject: [PATCH 37/37] Tentative Space Engineers support --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 3da326c..ed76f57 100644 --- a/Dockerfile +++ b/Dockerfile @@ -120,6 +120,7 @@ ARG WINEXVFB="\ libwine:i386 \ python3 \ python3-venv \ + cabextract \ wine \ wine32 \ wine64 \