From fff57784e53bbb9ae97a85708910feeb3d658dfb Mon Sep 17 00:00:00 2001 From: Phillip Schichtel Date: Tue, 3 Oct 2023 01:28:21 +0200 Subject: [PATCH] build them images --- .dockerignore | 5 ++ .github/workflows/pushDocker.yml | 8 --- .gitignore | 3 +- Dockerfile | 5 +- Dockerfile.local | 100 ------------------------------- build-images.sh | 26 +++++++- 6 files changed, 31 insertions(+), 116 deletions(-) create mode 100644 .dockerignore delete mode 100644 Dockerfile.local diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cb88716 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.idea/ +.git/ +.gitignore +*-versions.jar +Dockerfile* diff --git a/.github/workflows/pushDocker.yml b/.github/workflows/pushDocker.yml index 07ad428..0aa8d6b 100644 --- a/.github/workflows/pushDocker.yml +++ b/.github/workflows/pushDocker.yml @@ -1,8 +1,5 @@ -# This is a basic workflow to help you get started with Actions - name: Build Image -# Controls when the action will run. on: push: branches: @@ -14,14 +11,9 @@ on: - build-images.sh workflow_dispatch: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" build: - # The type of runner that the job will run on runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job steps: - uses: actions/checkout@v3 - name: Build and push diff --git a/.gitignore b/.gitignore index 591a014..31c26fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ /tmp/ -*.iml \ No newline at end of file +*.iml +*.jar diff --git a/Dockerfile b/Dockerfile index 91c623f..a983977 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,9 +12,6 @@ RUN cd /tmp \ FROM $JAVA_BASE_IMAGE -ARG SPONGE_VERSION="1.16.5-8.2.0" -# "rc" or "release" -ARG SPONGE_TYPE="rc" ENV MINECRAFT_DIR="/minecraft" RUN addgroup -g 1000 "minecraft" && adduser -u 1000 -D -G "minecraft" -h "${MINECRAFT_DIR}" "minecraft" @@ -32,7 +29,7 @@ ENV SPONGE_JAR="${MINECRAFT_DIR}/sponge.jar" \ # gettext: envsubst RUN apk add --update --no-cache curl bash gettext -RUN curl -s -L -o "/sponge.jar" "https://repo.spongepowered.org/service/rest/v1/search/assets/download?sort=version&repository=maven-releases&maven.groupId=org.spongepowered&maven.artifactId=spongevanilla&maven.extension=jar&maven.classifier=universal&maven.baseVersion=${SPONGE_VERSION}" +COPY sponge.jar /sponge.jar COPY --from=mcrcon /mcrcon /opt/mcrcon COPY mcrcon.sh /usr/local/bin/mcrcon diff --git a/Dockerfile.local b/Dockerfile.local deleted file mode 100644 index 44362a5..0000000 --- a/Dockerfile.local +++ /dev/null @@ -1,100 +0,0 @@ -ARG JAVA_VERSION=8 - -FROM adoptopenjdk/openjdk${JAVA_VERSION}:alpine-jre - -ARG SPONGE_VERSION="1.16.5-8.0.0-*" -# "rc" or "release" -ARG SPONGE_TYPE="rc" -ENV MINECRAFT_DIR="/minecraft" - -RUN adduser -D -h "${MINECRAFT_DIR}" "minecraft" - -ENV SPONGE_JAR="${MINECRAFT_DIR}/sponge.jar" \ - MINECRAFT_MODS_DIR="${MINECRAFT_DIR}/mods" \ - MINECRAFT_CONFIG_DIR="${MINECRAFT_DIR}/config" \ - MINECRAFT_WORLD_DIR="${MINECRAFT_DIR}/world" \ - MINECRAFT_LOGS_DIR="${MINECRAFT_DIR}/logs" \ - MINECRAFT_ROOT_STUFF_DIR="${MINECRAFT_DIR}/root" - -# bash: easy scripting -# curl: sponge download and nice to have -# gettext: envsubst -RUN apk add --update --no-cache curl bash gettext - -COPY sponge.jar / - -COPY log4j2.xml / -COPY launcher.conf.template / - -USER "minecraft:minecraft" - -WORKDIR ${MINECRAFT_DIR} -COPY docker-entrypoint.sh / -ENTRYPOINT ["/docker-entrypoint.sh"] - -CMD ["--nogui"] - -EXPOSE 25565/tcp 25575/tcp - -VOLUME ["${MINECRAFT_DIR}"] - -ENV JVM_ARGS="" -ENV LAUNCHER_JVM_ARGS="" - -ENV DB_CONNECTION_STRING="jdbc:postgresql://user:password@localhost:5432/minecraft" \ - DB_ALIAS="database" - -ENV OPS="" - -# The next env variables control the server.properties file. Have a look at the documentation of the file to get the meaning. -ENV ALLOW_FLIGHT=false \ - ALLOW_NETHER=true \ - BROADCAST_CONSOLE_TO_OPS=true \ - BROADCAST_RCON_TO_OPS=true \ - DIFFICULTY=easy \ - ENABLE_COMMAND_BLOCK=false \ - ENABLE_JMX_MONITORING=false \ - ENABLE_QUERY=false \ - ENABLE_RCON=false \ - ENABLE_STATUS=true \ - ENFORCE_WHITELIST=false \ - ENTITY_BROADCAST_RANGE_PERCENTAGE=100 \ - FORCE_GAMEMODE=false \ - FUNCTION_PERMISSION_LEVEL=2 \ - GAMEMODE=survival \ - GENERATE_STRUCTURES=true \ - GENERATOR_SETTINGS="" \ - HARDCORE=false \ - LEVEL_NAME=world \ - LEVEL_SEED="" \ - LEVEL_TYPE=default \ - MAX_BUILD_HEIGHT=256 \ - MAX_PLAYERS=20 \ - MAX_TICK_TIME=60000 \ - MAX_WORLD_SIZE=29999984 \ - MOTD="A Minecraft Server" \ - NETWORK_COMPRESSION_THRESHOLD=256 \ - ONLINE_MODE=true \ - OP_PERMISSION_LEVEL=4 \ - PLAYER_IDLE_TIMEOUT=0 \ - PREVENT_PROXY_CONNECTIONS=false \ - PVP=true \ - QUERY_PORT=25565 \ - RATE_LIMIT=0 \ - RCON_PASSWORD="" \ - RCON_PORT=25575 \ - RESOURCE_PACK_SHA1="" \ - RESOURCE_PACK="" \ - SERVER_IP="" \ - SERVER_PORT=25565 \ - SNOOPER_ENABLED=true \ - SPAWN_ANIMALS=true \ - SPAWN_MONSTERS=true \ - SPAWN_NPCS=true \ - SPAWN_PROTECTION=16 \ - SYNC_CHUNK_WRITES=true \ - TEXT_FILTERING_CONFIG="" \ - USE_NATIVE_TRANSPORT=true \ - VIEW_DISTANCE=10 \ - WHITE_LIST=false - diff --git a/build-images.sh b/build-images.sh index 27b063d..daa5742 100755 --- a/build-images.sh +++ b/build-images.sh @@ -1,17 +1,30 @@ #!/usr/bin/env bash +set -euo pipefail + build_image() { local kind="${1?no kind}" local version="${2?no version}" local asset="${3?no asset}" + local sponge_jar_file="sponge.jar" + local download_url="$(curl -s "https://dl-api.spongepowered.org/v2/groups/org.spongepowered/artifacts/spongevanilla/versions/$asset" | jq -r '.assets | map(select(.classifier == "universal")) | first | .downloadUrl')" + curl -s -L -o "$sponge_jar_file" "$download_url" + local repo_name="ghcr.io/cubeengine/sponge" local cache_repo="${repo_name}/cache" local image_name="${repo_name}:latest" - podman build -t "$image_name" --layers --cache-from="$cache_repo" --cache-to="$cache_repo" --timestamp 0 . + podman build \ + -t "$image_name" \ + --layers \ + --cache-from="$cache_repo" \ + --cache-to="$cache_repo" \ + --timestamp 0 \ + . + rm "$sponge_jar_file" - local tags=("$kind-$version" "$kind-$asset" - for t in "${tags}" + local tags=("$kind-$version" "$kind-$asset") + for t in "${tags[@]}" do local name="$repo_name:$t" podman tag "$image_name" "$name" @@ -22,7 +35,14 @@ build_image() { build_images() { local kind="${1?no kind}" + local file="$kind-versions.json" + readarray -t versions <<< "$(jq -r 'to_entries | map(.key) | .[]' < $file)" + for version in "${versions[@]}" + do + local asset="$(jq -r --arg version "$version" '.[$version]' < $file)" + build_image "$kind" "$version" "$asset" + done } build_images minecraft