Skip to content

Commit

Permalink
Add linter workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd committed Nov 19, 2024
1 parent 9f6c220 commit 47d4ff3
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CD

on:
on: # yamllint disable-line rule:truthy
push:
tags:
- 'v*'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on:
on: # yamllint disable-line rule:truthy
push:
branches:
- master
Expand All @@ -16,7 +16,7 @@ env:

jobs:
build:
name: CI
name: Build
runs-on: ubuntu-latest

services:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/docker_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ permissions:
contents: read
packages: write

on:
on: # yamllint disable-line rule:truthy
workflow_call:
inputs:
registry:
Expand Down Expand Up @@ -55,8 +55,8 @@ jobs:
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
platform="${{ matrix.platform }}"
echo "PLATFORM_PAIR=${platform//\//-}" >> "${GITHUB_ENV}"
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -158,5 +158,5 @@ jobs:
- name: Create Manifest List and Push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
docker buildx imagetools create "$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "${DOCKER_METADATA_OUTPUT_JSON}")" \
"$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)"
81 changes: 81 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: CI

on: # yamllint disable-line rule:truthy
pull_request:
types: [opened, synchronize, reopened]

jobs:
hadolint:
name: Hadolint
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Lint
uses: reviewdog/action-hadolint@v1
with:
reporter: github-pr-check
filter_mode: nofilter
reviewdog_flags: '-fail-level=any'

shellcheck:
name: ShellCheck
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Lint
uses: reviewdog/action-shellcheck@v1
with:
reporter: github-pr-check
filter_mode: nofilter
reviewdog_flags: '-fail-level=any'

markdownlint:
name: MarkdownLint
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Lint
uses: reviewdog/action-markdownlint@v0
with:
reporter: github-pr-check
filter_mode: nofilter
reviewdog_flags: '-fail-level=any'

yamllint:
name: YamlLint
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Lint
uses: reviewdog/action-yamllint@v1
with:
reporter: github-pr-check
filter_mode: nofilter
reviewdog_flags: '-fail-level=any'

actionlint:
name: ActionLint
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Lint
uses: reviewdog/action-actionlint@v1
with:
reporter: github-pr-check
filter_mode: nofilter
reviewdog_flags: '-fail-level=any'
7 changes: 7 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# MD013/line-length : Line length : https://github.com/DavidAnson/markdownlint/blob/v0.36.1/doc/md013.md
MD013:
# Number of characters
line_length: 140

# MD028/no-blanks-blockquote : Blank line inside blockquote : https://github.com/DavidAnson/markdownlint/blob/v0.36.1/doc/md028.md
MD028: false
6 changes: 6 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rules:
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.document_start
document-start: disable
line-length:
max: 140
allow-non-breakable-words: true
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Docker Minecraft FTB

A Docker image developed to launch Minecraft [FTB](https://www.feed-the-beast.com/) Modpack servers as safely, quickly and easily as possible.
A Docker image developed to launch Minecraft [FTB](https://www.feed-the-beast.com/) Modpack servers as safely, quickly and easily as
possible.

## Features

Expand Down Expand Up @@ -50,13 +51,16 @@ services:
## Notes
> [!WARNING]
> The server process does not shut down gracefully, if no TTY is present. Please pass the `--tty`/`-t` switch (Docker) or use `tty: true` (Docker Compose).
> The server process does not shut down gracefully, if no TTY is present. Please pass the `--tty`/`-t` switch (Docker) or use `tty: true`
> (Docker Compose).

> [!WARNING]
> It is strongly recommended to set the `stop-timeout` (Docker) / `stop_grace_period` (Docker Compose) to at least `60` seconds to avoid data loss when stopping the container.
> It is strongly recommended to set the `stop-timeout` (Docker) / `stop_grace_period` (Docker Compose) to at least `60` seconds to avoid
> data loss when stopping the container.

> [!NOTE]
> It is recommended to pass the `--interactive`/`-i` switch (Docker) or use `stdin_open: true` (Docker Compose) to be able to use the server console after attaching to the container.
> It is recommended to pass the `--interactive`/`-i` switch (Docker) or use `stdin_open: true` (Docker Compose) to be able to use the
> server console after attaching to the container.

## Environment

Expand All @@ -65,7 +69,9 @@ services:
The FTB modpack ID (*required*).

> [!NOTE]
> The modpack ID and the version ID are displayed on the right-hand side of the modpack info page. For example, the [Direwolf20 1.21 modpack](https://www.feed-the-beast.com/modpacks/126-ftb-presents-direwolf20-121) has the ID `126` and the latest version, as of today, is `12599`.
> The modpack ID and the version ID are displayed on the right-hand side of the modpack info page. For example, the
> [Direwolf20 1.21 modpack](https://www.feed-the-beast.com/modpacks/126-ftb-presents-direwolf20-121) has the ID `126` and the latest
> version, as of today, is `12599`.

### `FTB_MODPACK_VERSION_ID`

Expand All @@ -80,17 +86,20 @@ Default: Latest version of the configured modpack.

Set `1` to automatically agree to the [Mojang EULA](https://account.mojang.com/documents/minecraft_eula).

This option enables unattended installation. Otherwise, an interactive session must be used to accept the EULA after installation, or the `eula.txt` must be edited manually and the container restarted.
This option enables unattended installation. Otherwise, an interactive session must be used to accept the EULA after installation, or the
`eula.txt` must be edited manually and the container restarted.

Default: `0`.

### `USER_JVM_ARGS`

Optional, user-defined JVM arguments.

Use the `-Xms` switch to configure the minimum amount of memory used by the JVM. `-Xms1G` sets the minimum amount of memory to 1 GB. The `M` suffix can be used to specify the amount of memory in megabytes instead of gigabytes.
Use the `-Xms` switch to configure the minimum amount of memory used by the JVM. `-Xms1G` sets the minimum amount of memory to 1 GB.
The `M` suffix can be used to specify the amount of memory in megabytes instead of gigabytes.

Use the `-Xmx` switch to configure the maximum amount of memory used by the JVM. `-Xms4G` sets the maximum amount of memory to 4 GB. The `M` suffix can be used to specify the amount of memory in megabytes instead of gigabytes.
Use the `-Xmx` switch to configure the maximum amount of memory used by the JVM. `-Xms4G` sets the maximum amount of memory to 4 GB.
The `M` suffix can be used to specify the amount of memory in megabytes instead of gigabytes.

To specify multiple arguments, combine them with spaces: `-Xms1G -Xmx4G`.

Expand All @@ -103,7 +112,8 @@ Default: *none*

Set `1` to automatically update the modpack when the container is started.

If `FTB_MODPACK_VERSION_ID` is set, the configured version number is used, otherwise the latest version of the modpack is determined automatically.
If `FTB_MODPACK_VERSION_ID` is set, the configured version number is used, otherwise the latest version of the modpack is determined
automatically.

Default: `0`

Expand All @@ -112,7 +122,8 @@ Default: `0`
Set `1` to force a reinstallation of the modpack when the container is started.

> [!WARNING]
> This option should only be used in special cases, as constantly reinstalling the modpack significantly slows down the start of the container.
> This option should only be used in special cases, as constantly reinstalling the modpack significantly slows down the start of the
> container.

Default: `0`

Expand Down
4 changes: 3 additions & 1 deletion minecraft-ftb/data/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ FROM debian:bookworm-slim
ENV FTB_MODPACK_ID=0
ENV FTB_MODPACK_VERSION_ID=0
ENV ACCEPT_MOJANG_EULA=0
ENV USER_JVM_ARGS=
ENV USER_JVM_ARGS=""
ENV AUTO_UPDATE=0
ENV FORCE_REINSTALL=0

# Set up runtime dependencies

# hadolint ignore=DL3008
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
Expand All @@ -22,6 +23,7 @@ RUN set -eux; \

# Set up container user

# hadolint ignore=DL3008
RUN set -eux; \
groupadd --gid 99 --system minecraft; \
useradd \
Expand Down
23 changes: 13 additions & 10 deletions minecraft-ftb/data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ ansi_g="\e[92m"
ansi_r="\e[31m"

echoerr() {
echo -e "${ansi_r}ERROR:${ansi_rst} $@" 1>&2;
echo -e "${ansi_r}ERROR:${ansi_rst} $*" 1>&2;
}

echoinfo() {
echo -e "${ansi_b}INFO:${ansi_rst} $@"
echo -e "${ansi_b}INFO:${ansi_rst} $*"
}

check_environment() {
Expand Down Expand Up @@ -51,8 +51,8 @@ fetch_modpack_info() {
local response
response=$(curl --fail --connect-timeout 30 --max-time 30 --no-progress-meter "https://api.modpacks.ch/public/modpack/$1") || exit $?

if [ -z "${response}" ] || [ $(echo "${response}" | jq -r '.status') != "success" ]; then
echoerr "Failed to fetch modpack info. Please check if the modpack id [${ansi_green}$1${ansi_rst}] is correct."
if [ -z "${response}" ] || [ "$(echo "${response}" | jq -r '.status')" != "success" ]; then
echoerr "Failed to fetch modpack info. Please check if the modpack id [${ansi_g}$1${ansi_rst}] is correct."
echoerr "$(echo "${response}" | jq -r '.message')"
return 1
fi
Expand All @@ -63,6 +63,7 @@ fetch_modpack_info() {
# $1 = modpack info JSON payload
# rt = latest modpack version id
query_latest_version_id() {
# shellcheck disable=SC2155
local result=$(echo "$1" | jq -r '[.versions | sort_by(.updated) | reverse | .[] | select(.type == "Release" and .private == false) | .id][0]')

if [ -z "${result}" ]; then
Expand All @@ -77,10 +78,11 @@ query_latest_version_id() {
# $2 = modpack version id
# rt = modpack version info JSON payload
query_version_info() {
# shellcheck disable=SC2155
local result=$(echo "$1" | jq -r ".versions[] | select(.id == $2)")

if [ -z "${result}" ]; then
echoerr "Failed to query version info. Please check if the modpack version id [${ansi_green}$2${ansi_rst}] is correct."
echoerr "Failed to query version info. Please check if the modpack version id [${ansi_g}$2${ansi_rst}] is correct."
return 1
fi

Expand Down Expand Up @@ -132,21 +134,21 @@ patch_start_script() {
output+="${line}\n"
done < start.sh

if [ ! success ]; then
if [ ! "${success}" ]; then
echoerr "Failed to patch 'start.sh' script."
echoerr "Please open an issue here: https://github.com/flobernd/docker-minecraft-ftb"
return 1
fi

printf "${output}" > /var/lib/minecraft/start.sh
printf "%s" "${output}" > /var/lib/minecraft/start.sh
}

update_user_jvm_args() {
if [ -z "${USER_JVM_ARGS}" ]; then
exit 0
fi

printf "# Generated by "docker-minecraft-ftb"; DO NOT EDIT.\n\n" > /var/lib/minecraft/user_jvm_args.txt
printf "# Generated by \"docker-minecraft-ftb\"; DO NOT EDIT.\n\n" > /var/lib/minecraft/user_jvm_args.txt
printf "%s" "${USER_JVM_ARGS}" | xargs -n 1 printf "%s\n" >> /var/lib/minecraft/user_jvm_args.txt
}

Expand All @@ -171,7 +173,7 @@ if [ "$1" = "/var/lib/minecraft/start.sh" ]; then
fi

if [ "${local_pack_id}" -ne "${target_pack_id}" ]; then
echoerr "A modpack is already installed, but the modpack id [${ansi_green}${local_pack_id}${ansi_rst}] does not " \
echoerr "A modpack is already installed, but the modpack id [${ansi_g}${local_pack_id}${ansi_rst}] does not " \
"match the configured modpack id [${ansi_green}${target_pack_id}${ansi_rst}]."

Check warning on line 177 in minecraft-ftb/data/docker-entrypoint.sh

View workflow job for this annotation

GitHub Actions / ShellCheck

[shellcheck] reported by reviewdog 🐶 ansi_green is referenced but not assigned. Raw Output: ./minecraft-ftb/data/docker-entrypoint.sh:177:55: warning: ansi_green is referenced but not assigned. (ShellCheck.SC2154)
exit 1
fi
Expand Down Expand Up @@ -208,7 +210,8 @@ if [ "$1" = "/var/lib/minecraft/start.sh" ]; then
if [ "${local_pack_id}" -eq 0 ] || [ "${FORCE_REINSTALL}" == 1 ]; then
echo -e "Installing modpack version '${ansi_b}${target_version_name}${ansi_rst}' [${ansi_g}${target_version_id}${ansi_rst}]"

if [ "${FORCE_REINSTALL}" != 1 ] && [ $(ls -A . | wc -l) -ne 0 ]; then
# shellcheck disable=SC2012
if [ "${FORCE_REINSTALL}" != 1 ] && [ "$(ls -A . | wc -l)" -ne 0 ]; then
echoerr "The destination directory is not empty. Installing the modpack could lead to data loss."
echoerr "To continue, set the 'FORCE_REINSTALL' environment variable to '1' and retry."
exit 1
Expand Down

0 comments on commit 47d4ff3

Please sign in to comment.