From 7697b5862ec97317979aad4c62376dbfcdea9641 Mon Sep 17 00:00:00 2001 From: snxraven Date: Fri, 6 Jun 2025 19:03:06 -0400 Subject: [PATCH] first commit --- .github/workflows/publish-image.yaml | 14 ++ Dockerfile | 23 ++++ README.md | 186 +++++++++++++++++++++++++++ run.sh | 64 +++++++++ 4 files changed, 287 insertions(+) create mode 100644 .github/workflows/publish-image.yaml create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 run.sh diff --git a/.github/workflows/publish-image.yaml b/.github/workflows/publish-image.yaml new file mode 100644 index 0000000..ec82934 --- /dev/null +++ b/.github/workflows/publish-image.yaml @@ -0,0 +1,14 @@ +name: Docker image CI for GHCR + +on: push + +jobs: + build_and_publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build and push image + run: | + docker login --username anaxios --password ${{ secrets.GH_TOKEN }} ghcr.io + docker build . --tag ghcr.io/anaxios/holesail-docker:latest + docker push ghcr.io/anaxios/holesail-docker:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bba6496 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM node:lts-slim AS base + +WORKDIR /temp +COPY run.sh . +RUN chmod +x run.sh + +RUN npm install -g holesail@2.1.0 + +ENV MODE server +ENV HOST 0.0.0.0 +ENV PORT 8989 +ENV PUBLIC true +ENV USERNAME admin +ENV PASSWORD admin +ENV ROLE user +ENV CONNECTOR "" +ENV FORCE "" + +#EXPOSE 8989 + +WORKDIR /data + +ENTRYPOINT [ "/temp/run.sh" ] diff --git a/README.md b/README.md new file mode 100644 index 0000000..734406b --- /dev/null +++ b/README.md @@ -0,0 +1,186 @@ +# Holesail-docker + +- [ ] TODO: Make README more clear. + +Holesail-docker is a Docker container that proxies traffic from or to other containers. + +Environment Variables + +The container uses several environment variables to customize its behavior. These variables can be set when running the container using the -e flag. + +## Available Environment Variables + +The following environment variables are available: + +- MODE: The mode in which the container should run. Can be one of client, server, or filemanager. +- PORT: The port number to use for the client or server mode. +- HOST: The hostname or IP address to use for the client or server mode. +- PUBLIC: A boolean value indicating whether the server should use a public connetor string. Only applicable in server mode. +- FORCE: A boolean value indicating whether to force a short connector string of less than 32 chars. Only applicable in server and filemanager modes. +- CONNECTOR: A connector string used to identify the connection. Can be used in client, server, and filemanager modes. +- USERNAME: The username to use for authentication in filemanager mode. +- PASSWORD: The password to use for authentication in filemanager mode. +- ROLE: The role to assign to the user in filemanager mode. Can be either admin or user. + +## Setup + +### Create a Docker Network + +Create a Docker network to connect your containers: + +```bash +docker network create holesail +``` + +### Use the Image + +Use the latest Holesail-docker image: + +```bash +docker run -d --name holesail \ + -e MODE=server \ + -e PORT=25565 \ + -e HOST=minecraft \ + -e CONNECTOR=very-super-secret \ + -e PUBLIC=false \ + --network holesail \ + anaxios/holesail:latest +``` + +## Modes + +Holesail-docker can run in three modes: Server, Client, and Filemanager. + +### Server Mode + +In Server mode, Holesail-docker proxies traffic from one container to another. Example `docker-compose.yml` file: + +```yaml +services: + holesail: + container_name: holesail + restart: unless-stopped + image: anaxios/holesail:latest + environment: + MODE: server + PORT: 25565 + HOST: minecraft + PUBLIC: false + CONNECTOR: very-super-secret + networks: + - holesail + + mc: + image: itzg/minecraft-server + container_name: minecraft + tty: true + stdin_open: true + restart: unless-stopped + ports: + - "25565:25565" + environment: + EULA: "TRUE" + volumes: + - ./data:/data + depends_on: + - holesail + networks: + - holesail + +networks: + holesail: + external: true +``` + +### Client Mode + +In Client mode, Holesail-docker connects to a remote host. Example `docker-compose.yml` file: + +```yaml +services: + holesail: + container_name: holesail + restart: unless-stopped + network_mode: "host" + image: anaxios/holesail:latest + environment: + MODE: client + PORT: 8989 + HOST: 0.0.0.0 + PUBLIC: false + CONNECTOR: very-super-secret +``` + +**Note:** Client mode only works on Linux, and is incompatible with Windows and Mac. + +### Filemanager Mode + +In Filemanager mode, Holesail-docker serves a file manager interface. Example `docker-compose.yml` file: + +```yaml +services: + holesail: + container_name: holesail + restart: unless-stopped + image: anaxios/holesail:latest + environment: + MODE: filemanager + PORT: 8989 + HOST: 0.0.0.0 + PUBLIC: true + ROLE: user + USERNAME: admin + PASSWORD: admin + CONNECTOR: very-super-secret + volumes: + - :/data +``` + +Replace `` with the directory you wish to share. + +## Development + +To develop Holesail-docker, clone this repository, create docker-compose.yml and run: + +```yaml +services: + holesail: + container_name: holesail + restart: unless-stopped + build: . + environment: + MODE: server + PORT: 25565 + HOST: minecraft + PUBLIC: false + CONNECTOR: very-super-secret + networks: + - holesail + + mc: + image: itzg/minecraft-server + container_name: minecraft + tty: true + stdin_open: true + restart: unless-stopped + ports: + - "25565:25565" + environment: + EULA: "TRUE" + volumes: + - ./data:/data + depends_on: + - holesail + networks: + - holesail + +networks: + holesail: + external: true +``` + +```bash +docker compose up --build +``` + +This will start the containers and rebuild the image if necessary. diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..9b1f146 --- /dev/null +++ b/run.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +CYAN="\033[1;96m" +RED="\033[0;91m" +GREEN="\033[0;92m" +RESET='\033[0m' + +print () { + echo -e "$1 $2 $RESET" +} + +info () { + print "$CYAN" "$1" +} + +error() { + print "$RED" "$1" +} + +success() { + print "$GREEN" "$1" +} + +cmd_argument_builder () { + local args=""; + case "$MODE" in + "client") + [[ "$PORT" ]] && args="$args --port $PORT"; + [[ "$HOST" ]] && args="$args --host $HOST"; + [[ "$CONNECTOR" ]] && args="$args $CONNECTOR"; + [[ "$UDP" = "true" ]] && args="$args --udp"; + ;; + "server") + [[ "$PORT" ]] && args="$args --live $PORT"; + [[ "$HOST" ]] && args="$args --host $HOST"; + [[ "$PUBLIC" = "true" ]] && args="$args --public"; + [[ "$FORCE" = "true" ]] && args="$args --force"; + [[ "$CONNECTOR" ]] && args="$args --key $CONNECTOR"; + [[ "$UDP" = "true" ]] && args="$args --udp"; + ;; + "filemanager") + args="--filemanager"; + [[ "$FORCE" = "true" ]] && args="$args --force"; + [[ "$PUBLIC" = "true" ]] && args="$args --public"; + [[ "$HOST" ]] && args="$args --host $HOST"; + [[ "$USERNAME" ]] && args="$args --username $USERNAME"; + [[ "$PASSWORD" ]] && args="$args --password $PASSWORD"; + [[ "$ROLE" = "admin" ]] && args="$args --role admin"; + [[ "$ROLE" = "user" ]] && args="$args --role user"; + [[ "$CONNECTOR" ]] && args="$args --connector $CONNECTOR"; + ;; + esac + + printf "%s" "$args"; +} + +ARGS="$(cmd_argument_builder)" + +if [[ ! $ARGS ]]; then + error "Invalid Mode." + exit 1 +fi + +holesail $ARGS