Skip to content

Commit

Permalink
finishing touches
Browse files Browse the repository at this point in the history
  • Loading branch information
JackBlake-zkq committed Apr 27, 2024
1 parent b4f57e7 commit 8be9d10
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/run.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
on:
workflow_dispatch:
schedule:
- cron: '0 21 * * 6'


jobs:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
**/*.variables
**/server/
**/*.zip
**/*.env
**/*.env*
60 changes: 38 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,58 @@
# Easy MCS

Docs Coming Soon
Docker image that runs your minecraft server so that people can join with **no port forwarding** required, completely **agnostic of what kind of server you are using**. There is also an **optional built-in backup system** (also agnostic of server type).

<!-- Run your Minecraft server IN A Github Workflow such that people can join it. This gives you 50h of free hosting per month, with unlimited customizability and 7GB of RAM. You could even get 14GB of RAM if you can get this working on a Mac or Windows GH Action Runner.
## Quick Start

This repo also has a system for automatic backups to AWS S3, which will probably be free depending on the size of your server folder, but could incur a few cents a month if you have a huge one. If you do a bit of your own customization, you could use your own system.
1. [sign up for ngrok](https://dashboard.ngrok.com/signup) and grab your auth token
2. create a directory including your server directory, renamed to `server`, and a file named `.env` in the format:
```
NGROK_AUTHTOKEN="your ngrok auth token"
START_COMMAND="the command to start your server (from within the server's directory) e.g. java -Xmx4G -Xms2G -jar server.jar nogui"
```
3. Install docker if it's not already installed (see [the docs](https://docs.docker.com/get-docker/)) and run the daemon
4. download [this docker compose file](https://github.com/JackBlake-zkq/easy-mcs/blob/main/docker-compose.yaml)
5. run `docker compose up -d && docker attach mcs`
6. grab the ip address that got printed out and send it to anyone who wants to join!

The workflow starts the server and print the IP address in one of the steps (labelled so that it is obvious).
You can run server commands directly through the standard in. Use `/stop` to close the server.

The workflow can be run manually, or on a schedule (default is to run every Saturday from 8-11pm UTC). You can modify (or remove) the schedule in the workflow.
There are some [limits on ngrok's free tier](https://ngrok.com/docs/guides/limits/)

## Setup
## Backups (Optional)

### Step 1: AWS
This images provides the option to backup to, and load from backups in AWS S3.

First, you'll need to do a few things in AWS:
To setup backups, first do the following in AWS:

1. Create an S3 Bucket. Zip your server folder and upload it into `backup.zip` within the bucket
2. Create an IAM Policy that only allows `GetObject` and `PutObject`, and only on the S3 Bucket for your backups
3. Create IAM User for the policy. Generate credentials for this user.

### Step 2: Ngrok
Add the following to your `.env` file:

Next, [sign up for ngrok](https://dashboard.ngrok.com/signup) and save your auth token for the next step.
```
BACKUP_FREQUENCY="integer of how often to run backups, in milliseconds"
S3_BUCKET_NAME="name of the S3 bucket you created"
S3_REGION="region of your S3 bucket"
AWS_ACCESS_KEY_ID="from generated credentials"
AWS_SECRET_ACCESS_KEY="from generated credentials"
USE_BACKUP="optional, if set (to anything other than empty string), downloads the backup from S3 and uses that instead of a local server directory"
```

### Step 3: GitHub
## Versatility Options

Finally, configure the GitHub repository with your credentials and preferences by creating these Variables and Secrets for Actions in the repo settings:
If you'd like to use this image in a more versatile fashion, e.g. without using an env file, on a different port, different terminal configurations, etc. you can do so with no trouble as long as the following are true:

Secrets:
- `AWS_ACCESS_KEY_ID` - from credentials you generated earlier
- `AWS_SECRET_ACCESS_KEY` - from credentials you generated earlier
- `NGROK_AUTHTOKEN` - the auth token you saved earlier
1. all necessary and desired environment variables are set, e.g. with the `-e` flag with `docker run`
2. either your local server directory is mapped as a volume into `/server` in the container, or the `USE_BACKUP` environment variable is set
3. there is a port mapping to `25565` in the container

Variables:
- `BACKUP_FREQUENCY` - how often to run backups to S3
- `IMAGE_REPO` - path within ghcr.io to store your image at, something like `GH_USERNAME_LOWERCASE/IMAGE_NAME`. I'm doing `jackblake-zkq/mc-server`
- `S3_BUCKET_NAME` - name of S3 bucket you created
- `S3_REGION` - region of your S3 bucket
- `START_COMMAND` - command to start your minecreaft server e.g. `java -Xmx4G -Xms2G -jar server.jar nogui` -->
Recommended:
1. leave the standard in of the container open
2. don't use the `-t` flag or `tty: true` (compose). The image is not built to handle terminal controls.
3. run the image as a daemon, then attach to its standard in, like in the quick start. This will allow you to run commands in the server.

## Experiments

One cool idea is to run this docker image in a GitHub Workflow. I currently have [this workflow](https://github.com/JackBlake-zkq/easy-mcs/blob/main/.github/workflows/run.yaml) set up to do that. This lets you run the server remotely, triggered by certain events, and/or on a schedule, with 50h of free hosting per month with 7GB of RAM. You could even get 14GB of RAM if you can get this working on a Mac or Windows runner. I'm not sure if this ok with the TOS, so I'm not using it.
1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ services:
image: ghcr.io/jackblake-zkq/easy-mcs:latest
build: .
volumes:
- ~/.aws/:/root/.aws:ro
- ./server:/server
env_file:
- .env
Expand Down

0 comments on commit 8be9d10

Please sign in to comment.