Skip to content

Commit

Permalink
Update 1.1
Browse files Browse the repository at this point in the history
- Automatically detect CPU architecture.
- Added MC_RAM value sanitization.
- Automatically skip Lazymc download if cpu-arch is not supported.
  • Loading branch information
Okazakee authored Jan 31, 2023
1 parent ef73457 commit e4fceb2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 49 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/release-on-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
VERSION=$(sed -n 's/## \([0-9.]*\).*/\1/p' changelog.md | head -n 1)
echo "::set-output name=version::$VERSION"
CHANGELOG=$(awk '/## '$VERSION'/{flag=1;next}/##/{flag=0}flag' changelog.md)
printf "## %s (date)\n\n%s" $VERSION "$CHANGELOG"
echo "::set-output name=changelog::$CHANGELOG"
echo "## ${VERSION} (date)\n\n${CHANGELOG}" > changelog.txt
- name: Create Release
id: create_release
uses: actions/create-release@v1.1.4
Expand All @@ -27,6 +26,6 @@ jobs:
with:
tag_name: ${{ steps.get_changelog.outputs.version }}
release_name: Release ${{ steps.get_changelog.outputs.version }}
body: ${{ steps.get_changelog.outputs.changelog }}
body_file: changelog.txt
draft: false
prerelease: false
prerelease: false
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
FROM eclipse-temurin:19-jre-jammy

# Environment variables
ENV CPU_ARCH="" \
SERVER_PROVIDER="purpur" \
ENV SERVER_PROVIDER="purpur" \
LAZYMC_VERSION="latest" \
MC_VERSION="latest" \
SERVER_BUILD="latest" \
Expand All @@ -24,4 +23,4 @@ EXPOSE 25565/tcp
EXPOSE 25565/udp
EXPOSE 25575/tcp
EXPOSE 25575/udp
VOLUME /mcserver
VOLUME /mcserver
25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

<img alt="logo" width='30%' align="right" src="https://raw.githubusercontent.com/Okazakee/Global-Assets/main/mcserver-lazymc-docker/logo%20project%20mcdocker-min.png" />

## Minecraft Servers w/ `lazymc` using Docker

## Minecraft Servers w/ [Lazymc](https://github.com/timvisee/lazymc) using Docker

This is a Linux Docker image for creating Minecraft servers with `lazymc`.

[lazymc](https://github.com/timvisee/lazymc) is a utility that puts your Minecraft server to rest when idle and wakes it up when players try to connect.
**Lazymc** is a utility that puts your Minecraft server to rest when idle and wakes it up when players try to connect.
This allows the server to not waste resources if nobody is connected.

This image provides a basic Minecraft server using one of the supported providers. All customizations are left to the user.
Expand All @@ -20,7 +22,7 @@ It is assumed that the user has already acquired a working Docker installation.

## Using docker run:
```bash
sudo docker run -p 25565:25565 -e CPU_ARCH="<your_cpu_arch>" okazakee/mcserver-lazymc-docker
sudo docker run -p 25565:25565 -e okazakee/mcserver-lazymc-docker
```
While this command will work just fine in many cases, it is only the bare minimum required to start a functional server and can be vastly improved by specifying more options/envs.

Expand All @@ -34,7 +36,6 @@ services:
- '<your-port>:25565'
container_name: <your-container-name>
environment:
- CPU_ARCH=<your-cpu-architecture>
- SERVER_PROVIDER=<your-server-provider>
- LAZYMC_VERSION=<your-lazymc-version>
- MC_VERSION=<your-mc-version>
Expand Down Expand Up @@ -80,18 +81,12 @@ There is one more command line option, but it is a bit special and deserves its
### Environment Variables
Environment variables are options that are specified in the format `-e <NAME>="<VALUE>"` where `<NAME>` is the name of the environment variable and `<VALUE>` is the value that the environment variable is being set to. Please note that setting an evironment variable with no value leaves the default value, which you can look up below.

Mandatory `ENV` fields will have a `*` after their name.
[comment]: <> (Mandatory `ENV` fields will have a `*` after their name.)

This image has seven environment variables:
- CPU Architecture *
- **Name:** `CPU_ARCH`
- Set this to the cpu architecture you want to use.
- Avaliable architectures are: `x64`, `x64-static`, `aarch64`, `armv7`.
- No default value for this, make sure to include it in the command or docker compose.
- `-e CPU_ARCH="<x64>"`
- Server Provider
- **Name:** `SERVER_PROVIDER`
- Set this to the server provider you want to use.
- Set this to the server [Provider](#supported-server-providers) you want to use.
- Default value: `purpur`.
- `-e SERVER_PROVIDER="<paper>"`
- Lazymc Version
Expand All @@ -103,13 +98,13 @@ This image has seven environment variables:
- Minecraft Version
- **Name:** `MC_VERSION`
- Set this to the Minecraft version that the server should support.
- Note: there must be a PaperMC (or alternatives) release for the specified version of Minecraft.
- Note: there must be a [Provider](#supported-server-providers) release for the specified version of Minecraft.
- Default value: `latest`.
- Changing this on an existing server will change the version *without wiping the server*.
- `-e MC_VERSION="<latest>"`
- Server Build
- **Name:** `SERVER_BUILD`
- Set this to the number of the PaperMC (or alternatives) build that the server should use (**not the Minecraft version**).
- Set this to the number of the [Provider](#supported-server-providers) build that the server should use (**not the Minecraft version**).
- Default value: `latest`.
- Changing this on an existing server will change the version *without wiping the server*.
- `-e SERVER_BUILD="<latest>"`
Expand Down Expand Up @@ -139,7 +134,7 @@ From this point, the server should be configured in the same way as any other Mi
## Technical
This project *does **NOT** redistribute the Minecraft server files*.

**PLEASE NOTE:** This is an unofficial project. I did not create PaperMC or other providers.
**PLEASE NOTE:** This is an unofficial project. I did not create any of the supported [Providers](#supported-server-providers).

## Project Pages
- [GitHub page](https://github.com/okazakee/mcserver-lazymc-docker).
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.1.0 (31/01/2023)

- Automatically detect CPU architecture.
- Added MC_RAM value sanitization.
- Automatically skip Lazymc download if cpu-arch is not supported.

## 1.0.0 (27-01-2023)

- First stable release!
Expand Down
62 changes: 35 additions & 27 deletions mcserver.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
#!/bin/bash

# Check if CPU architecture is set and if it's a correct value
ACCEPTED_VALUES="armv7 aarch64 x64 x64-static"
if [ -z "$CPU_ARCH" ] || ! echo "$ACCEPTED_VALUES" | grep -wq "$CPU_ARCH"
# Ram selection sanitization
if ! echo "$MC_RAM" | grep -Eq '^[0-9]+[MG]$'; then
if ! [ -z "$MC_RAM" ]
then
echo "\033[0;31mError: $MC_RAM is not a valid RAM format. Exiting... \033[0m" | tee server_cfg.txt
exit 1
fi
fi

# Declare supported Lazymc archs
lazymc_supported_archs="aarch64 x86_64 armv7"

# Getting arch from system
CPU_ARCH=$(uname -m)

# Adapt the answer in x86 case to support Lazymc url schema
[ $CPU_ARCH = "x86_64" ] && CPU_ARCH="x64"

# Check if Lazymc is supported for that arch, if not, continue disabling Lazymc
if ! echo "$lazymc_supported_archs" | grep -wq "$CPU_ARCH"
then
echo "\033[0;31mError: Please include a valid CPU architecture. Exiting... \033[0m"
exit 1
echo "\033[0;31mWarning! Your CPU architecture ($CPU_ARCH) is not supported by Lazymc. Disabling it... \033[0m"
LAZYMC_VERSION="disabled"
fi

# Enter server directory
Expand All @@ -19,7 +36,6 @@ echo "Minecraft Version= \033[0;33m$MC_VERSION\033[0m" | tee -a server_cfg.txt
echo "Lazymc version= \033[0;33m$LAZYMC_VERSION\033[0m" | tee -a server_cfg.txt
echo "Server provider= \033[0;33m$SERVER_PROVIDER\033[0m" | tee -a server_cfg.txt
echo "Server build= \033[0;33m$SERVER_BUILD\033[0m" | tee -a server_cfg.txt
echo "CPU architecture= \033[0;33m$CPU_ARCH\033[0m" | tee -a server_cfg.txt
echo "Dedicated RAM= \033[0;33m${MC_RAM:-"Not specified."}\033[0m" | tee -a server_cfg.txt
echo "Java options= \033[0;33m${JAVA_OPTS:-"Not specified."}\033[0m" | tee -a server_cfg.txt
echo ""
Expand All @@ -29,40 +45,32 @@ echo ""
#give user time to read
sleep 1

# Lazymc handler
lazymc_download() {
echo "\033[0;33mDownloading lazymc $LAZYMC_VERSION... \033[0m"
echo ""
wget -qO lazymc ${LAZYMC_URL}
chmod +x lazymc
}

# URL builder
# Lazymc setup handler
if [ "$LAZYMC_VERSION" = "disabled" ]
then
# Skip download
echo "\033[0;33mSkipping lazymc download... \033[0m"
echo ""
elif [ "$LAZYMC_VERSION" = "latest" ]
then
# Build latest ver download url
LAZYMC_VERSION=$(wget -qO - https://api.github.com/repos/timvisee/lazymc/releases/latest | jq -r .tag_name | cut -c 2-)
if [ -z "$LAZYMC_VERSION" ]
else
if [ "$LAZYMC_VERSION" = "latest" ]
then
echo "\033[0;31mError: Could not get latest version of lazymc. Exiting... \033[0m" | tee server_cfg.txt
exit 1
LAZYMC_VERSION=$(wget -qO - https://api.github.com/repos/timvisee/lazymc/releases/latest | jq -r .tag_name | cut -c 2-)
if [ -z "$LAZYMC_VERSION" ]
then
echo "\033[0;31mError: Could not get latest version of lazymc. Exiting... \033[0m" | tee server_cfg.txt
exit 1
fi
fi
else
# Build specified ver download url
LAZYMC_URL="https://github.com/timvisee/lazymc/releases/download/v$LAZYMC_VERSION/lazymc-v$LAZYMC_VERSION-linux-$CPU_ARCH"
status_code=$(curl -s -o /dev/null -w '%{http_code}' ${LAZYMC_URL})
if [ "$status_code" -ne 302 ]
then
echo "\033[0;31mError: Lazymc $LAZYMC_VERSION version does not exist or is not available. Exiting... \033[0m" | tee server_cfg.txt
exit 1
fi
# Download lazymc
lazymc_download
echo "\033[0;33mDownloading lazymc $LAZYMC_VERSION... \033[0m"
echo ""
wget -qO lazymc ${LAZYMC_URL}
chmod +x lazymc
fi

# Declaring supported types
Expand Down

0 comments on commit e4fceb2

Please sign in to comment.