百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

Gamocosm

> 后端框架
开源

诚实的 Minecraft 服务器托管

195 stars0 点赞4 次浏览
访问官网GitHub

工具介绍

诚实的 Minecraft 服务器托管

Gamocosm [][circleci] [][coveralls] [][gitter]

Gamocosm makes it easy to run cloud Minecraft servers. Digital Ocean is used as the backend/hosting service, due to cost, reliability, and accessibility. Gamocosm works well for friends who play together, but not 24/7. Running a server 14 hours a week (2 hours every day) may cost 40 cents a month, instead of $5.

This README is directed towards developers; if you are a user looking for more information, please check out the [wiki][wiki] or drop by [Gitter chat][gitter].

Minecraft Server Wrapper

The [Minecraft Server Wrapper][mcsw] (for lack of a better name) is a light python webserver. It provides an HTTP API for starting and stopping Minecraft servers, downloading the world, etc. Please check it out and help improve it too!

Gamocosm Minecraft Flavours

The [gamocosm-minecraft-flavours][minecraft-flavours] repository includes the setup scripts used to install different flavours of Minecraft on a new server. Read this [wiki page][wiki-different-versions] for adding support for new flavours, or manually installing something yourself.

Contributing

Pull requests are welcome!

Setting Up Your Development Environment

You should have a Unix/Linux system. The following instructions were made for Fedora 36 Server, but the steps should be similar on other distributions. The instructions assume you are executing commands as an unprivileged user; the sample commands include sudo if and only if root privileges are necessary.

As of 2022 August 28, deployment and CI have been changed to use containers. For development, it is also recommended to use containers, but only for the PostgreSQL database and Redis store (as they are "static services"). Note that it is still recommended to run the development Rails server and Sidekiq workers "on the host". I use [Podman][podman] instead of Docker, but, at least for these development instructions, they should work by simply replacing podman with docker.

The steps marked with "directory sensitive" should be run from inside the root of the Gamocosm repository.

Configuration

  1. Create your environment file: cp template.env gamocosm.env.

  2. Make your environment file readable (and writable) by the file owner (you) only: chown 600 gamocosm.env.

  3. Update the config in gamocosm.env. See "Environment File" below for documentation.

  4. Load environment variables: source load_env.sh.

    You will need to do this in every new shell you run ruby/rails in.

Container Setup

  1. Install Podman: sudo dnf install podman.

  2. Ensure that your environment variables have been loaded as above.

  3. Create the database container:

    podman create --name gamocosm-database --env "POSTGRES_USER=$DATABASE_USER" --env "POSTGRES_PASSWORD=$DATABASE_PASSWORD" --publish 127.0.0.1:5432:5432 docker.io/postgres:14.5

    You may wish to add the following flag: --volume gamocosm-database-volume:/var/lib/postgresql/data; this will prevent Podman from using a randomly-generated name, which can make debugging or moving things around later easier. See the Docker Hub page for Postgres (scroll down to PGDATA) for more information about persistent data with this Postgres image.

  4. Create the Redis container:

    podman create --name gamocosm-redis --publish 127.0.0.1:6379:6379 docker.io/redis:7.0.4

    You may wish to add the following flag: --volume gamocosm-redis-volume:/data, as above. See the Docker Hub page for Redis (scroll down to "start with persistent storage") for more information about persistent data with this Redis image.

  5. Start the containers: podman start gamocosm-database gamocosm-redis.

As is, you'll have to start these containers manually each time you reboot your computer. You can automate starting Podman containers as "quadlets" using systemd. Example gamocosm-database.container and gamocosm-redis.container files are provided in Gamocosm's sysadmin folder. Unless you changed the default DATABASE_USER from template.env, you shouldn't need to edit these files. If you do need to edit them, systemd supports drop-in configuration (search for "drop-in").

# Store `DATABASE_PASSWORD` as a Podman secret.
# Make sure you loaded your environment variables as above!
printf "$DATABASE_SECRET" | podman secret create gamocosm-database-password -

# Copy the `.container` files to where systemd expects them.
cp sysadmin/gamocosm-database.container sysadmin/gamocosm-redis.container ~/.config/containers/systemd/

# Tell systemd to detect new files/changes.
systemctl --user daemon-reload

# Start the containers.
systemctl --user start gamocosm-database gamocosm-redis

Ruby Setup

I recommend using [rbenv][rbenv] to manage Ruby installations.

  1. Install dependencies to build Ruby - this depends on your system. For a Fedora 36 Server image, the following was sufficient for me: sudo dnf install openssl-devel perl zlib-devel.
  2. Install [rbenv][rbenv] and [ruby-build][ruby-build]. Read their docs for up to date instructions. But, as of 2022 August 28:
    • Run git clone https://github.com/rbenv/rbenv.git ~/.rbenv.

    • Add $HOME/.rbenv/bin to your $PATH, usually done in ~/.bashrc.

      On recent versions of Fedora, ~/.bashrc sources any files in the directory ~/.bashrc.d (if it exists), which is more modular than editing .bashrc directly. It would look something like the following in your ~/.bashrc.

      # User specific aliases and functions
      if [ -d ~/.bashrc.d ]; then
          for rc in ~/.bashrc.d/*; do
              if [ -f "$rc" ]; then
                  . "$rc"
              fi
          done
      fi
      
      unset rc

      Assuming you have/use this setup, to proceed with the rbenv installation:

      • Create the directory (without failing if it already exists): mkdir -p ~/.bashrc.d.
      • Create a configuration/initialization file: echo 'PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc.d/rbenv.
    • Additionally, ensure that rbenv gets autoloaded into any new shells: echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc.d/rbenv (assuming you're following the modular convention).

    • Restart (close and reopen) your shell for the changes to take effect.

    • Create the plugins directory for rbenv: mkdir ~/.rbenv/plugins.

    • Get ruby-build: git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build.

    • Check that ruby-build has been installed correctly: rbenv install --list (lists stable ruby versions).

  3. (directory sensitive) Install Ruby 3.1.2: rbenv install (it reads .ruby-version).
  4. (directory sensitive) Check that ruby -v gives you version 3.1.2.
  5. Install dependencies to build gems: sudo dnf install libpq-devel.
  6. (directory sensitive) Install gem dependencies: bundle install.

Gamocosm Setup

All the commands in this section are "directory sensitive" (should be run in the project root).

  1. Generate SSH keys; Gamocosm expects a passphraseless id_gamocosm private key in the project root.

    Typically, a passphrase is used to encrypt private keys on the local filesystem, and you would be interactively prompted to provide the passphrase when using the key. However, since Gamocosm uses this SSH key "automatically", it can't prompt for a passphrase. Gamocosm used to take a passphrase as a configuration option; however, this doesn't actually provide any additional security - the passphrase would be stored (in plain text) on the same filesystem with the same permissions as the private key itself. So, now, Gamocosm just expects a passphraseless private key.

    Gamocosm uses SSH to connect to and set up the servers it creates. Gamocosm officially only supports ed25519 keys; somewhere down the stack, rsa keys are not supported (ed25519 keys are considered more secure). To generate a new passphraseless key, run: ssh-keygen -t ed25519 -f id_gamocosm -N ''.

    You can use this key directly with ssh -i id_gamocosm (e.g. if you need to connect to a server directly). The files id_gamocosm and id_gamocosm.pub are ignored in Gamocosm's .gitignore, so you don't have to worry about accidentally committing them.

  2. Setup the database: bundle exec rails db:setup.

  3. Start the server: bundle exec rails s (defaults to localhost in development; use --binding 0.0.0.0 to listen on all interfaces).

  4. Start the Sidekiq worker: bundle exec sidekiq.

  5. (Optional) Open the console: bundle exec rails c.

Note: most bundle exec ... commands will work without bundle exec (e.g. just rails c or sidekiq) - as long as you don't have other projects using rbenv, and the same version of Ruby (3.1.2), and the same gem(s), but different versions of those gems.

Environment File

  • DATABASE_HOST: May be an absolute path (for a Unix domain socket), or an IP/hostname (for a TCP connection) ([PostgreSQL docs][postgresql-docs-host]). When using containers as described above, the default value of localhost in template.env corresponds to the 127.0.0.1 passed to --publish in podman create.
  • DATABASE_PORT: Required even for Unix domain sockets. The default should work provided you didn't change the PostgreSQL settings.
  • DATABASE_USER: Hmmmm.
  • DATABASE_PASSWORD: Hmmmm.
  • DIGITAL_OCEAN_API_KEY: Your Digital Ocean API token. This key is added to the dummy user in development (see [db/seeds.rb][db-seeds]) - it's probably convenient for it to have write access. For the test environment, it can be anything (but still needs to be set) - Gamocosm tests "mock" HTTP requests so it won't actually contact Digital Ocean. For production, this key can be read only - it is (just) used to list regions and droplet sizes.
  • REDIS_HOST: When using containers as described above, the default value of localhost in template.env corresponds to the 127.0.0.1 passed to --publish in podman create.
  • REDIS_PORT: You can leave this as the default.
  • MAIL_SERVER_*: See [action mailer configuration][rails-action-mailer] in the Rails guide.
  • SECRET_KEY_BASE: Only production.
  • SIDEKIQ_USERNAME: Only production - HTTP basic auth for Sidekiq web interface.
  • SIDEKIQ_PASSWORD: See previous.
  • DEVELOPER_EMAILS: Comma separated list of emails to send exceptions to.
  • BADNESS_SECRET: Secret to test /badness endpoint.

Testing

  • bundle exec rails test runs the test suite. [The CI runs the tests just like this][circleci-config]. For more options, see [Rails documentation for the test runner][rails-test-runner].
    • Run a specific file: bundle exec rails test path/to/file.rb
    • Run a specific test (by line number): bundle exec rails test path/to/file.rb:123
    • Run a specific test (by name): bundle exec rails test path/to/file.rb --name my_test
  • In the test environment, Gamocosm doesn't actually make external HTTP requests; it mocks the requests and responses using [WebMock][webmock]. So, you don't need a Digital Ocean account or valid API key to run the tests.
  • Unfortunately, not all the tests are idempotent; one failing test may leave data in the database that causes subsequent tests to fail. You can pass --fail-fast to the test runner to stop at the first failing test.
  • RAILS_ENV=test bundle exec rails to run the server or console (respectively) to inspect the test environment.
    • Note: in the test environment, unlike development, the server does not automatically reload source files when you change them.

Simulating a User Server with Containers

In the test environment, Gamocosm doesn't make external HTTP requests; it mocks the API responses from Digital Ocean. Without a server to connect to, Gamocos

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubydigital-oceanminecraftminecraft-serveropen-source

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架