Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Improve Docker support #36

Merged
merged 3 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/node_modules
/dist
/vendor/*.nw
.env

/.git
/.github
/.vscode
/docs
/scripts
/.dockerignore
/.gitignore
/compose.yaml
/Dockerfile
/README.md
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules
/dist
/vendor/*.nw
.env
22 changes: 17 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
FROM node:20
RUN rm -rf /app
WORKDIR /app
RUN git clone --branch main --single-branch https://github.com/screepers/steamless-client.git /app
RUN npm install
CMD ["npm", "start", "--", "--package", "/screeps.nw", "--host", "0.0.0.0"]

WORKDIR /srv/screeps

COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm \
npm clean-install --ignore-scripts

COPY . .

ENV PATH="${PATH}:/srv/screeps/node_modules/bin"
RUN npm run --ignore-scripts build

ENTRYPOINT ["npm", "--ignore-scripts"]
# NOTE: This command will not work out of the box.
# screeps.nw is not included in the image, as it is copyrighted.
# See README.md and compose.yaml for more information.
CMD ["start", "--", "--package", "/screeps.nw", "--host", "0.0.0.0"]
69 changes: 53 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ The Screepers Steamless Client is a web proxy for the [Screeps World](https://st

## Requirements

- Node.js v20+
- Screeps World (installed using Steam)
- Node.js v20+ or Docker Compose v3+
- Screeps World purchased and installed via Steam

Steam and the game do not necessarily need to be installed on the same system on which you will deploy the proxy.
**However**, the game should be legally purchased by you and installed on a system you own.
Not only does this support the developers, but it allows you to keep your proxy up-to-date,
as the client receives regular updates automatically via Steam. Copying the client binary
from another system will require you to repeat that process each time the client is updated.

## Installation

Expand All @@ -28,31 +34,62 @@ npm install -g screepers-steamless-client
screepers-steamless-client
```

### Run with Docker Compose
### Install or Run with Docker Compose

Use Docker Compose to run the client.
- Download the [`compose.yaml`](compose.yaml) file and place it in an empty folder.
- Alternatively, you can add the `client` entry from [`compose.yaml`](compose.yaml) to an existing Docker Compose configuration (e.g., combine it with a Screeps server launcher). If you do this, make sure to use the `--internal_backend` argument in the command to reference the Screeps server container address, like this:

1. Clone this repository

2. Locate the Screeps `package.nw` file from the Steam installation of Screeps. If you are unsure of where to find it, you can right click the game from your Steam library and select the "Browse local files" option.

3. Create a `.env` file in the repo root directory and set `SCREEPS_NW_PATH` to the path of `package.nw`:

1. If you have Screeps installed on your local machine via Steam, you can reference it directly. For example, on macOS:
```bash
SCREEPS_NW_PATH="~/Library/Application Support/Steam/steamapps/common/Screeps/package.nw"
```

2. If Steam and/or Screeps is not installed locally, you can copy `package.nw` from a remote system and place it in the `vendor` subdirectory:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old instructions promotes purchasing Screeps by only recommending it be installed through Steam. There's also logic to detect the local Steam installation path for easy setup when this proxy runs on the same system where Screeps is installed.

Suggesting the transfer of game files across different systems might inadvertently encourage sharing copies with others, which could negatively impact the developers' revenue.

I propose revising the README to avoid mentioning the movement of game files to different systems, ensuring we support the developers by promoting legitimate purchases and installations.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The goal of this change is not to promote piracy, but rather to facilitate the use of the purchased game on other systems a legal purchaser owns which do not have Steam installed. I'll make some tweaks to the language to reflect this.

Copy link
Author

@DocDvorak DocDvorak Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@admon84 I've added language to the "Requirements" section to explicitly encourage purchasing the game via Steam. The new section also points out the benefits of deploying the proxy on a system on which the game is installed via Steam.

The Steam store link for the game is still retained at the top of the README.

The package.nw search logic has not been modified, and the changes to the README still retain the macOS example of the hard-coded path to the client binary from a local Steam installation.

```sh
SCREEPS_NW_PATH="./vendor/package.nw"
```

4. If you want to allow remote connections, add the following line to `.env`:
```sh
SCREEPS_PROXY_HOST="0.0.0.0"
```

5. Run `docker compose up`

Alternatively, you can run the container without cloning the repo by using the NPX run approach from a container. This makes it easier to integrate with existing Docker Compose configurations (ex: alongside a Screeps server launcher).

If your deployment includes a Screeps server, make sure to use the `--internal_backend` argument in the command to reference the Screeps server container address.

Example:
```yaml
services:
client:
image: "node:20"
volumes:
- ${SCREEPS_NW_PATH:?"SCREEPS_NW_PATH not set"}:/screeps.nw
# Defines a volume for the NPM cache to speed up startup
# when the container is recreated
- client-npm-cache:/root/.npm
command: >
npx screepers-steamless-client
--package /screeps.nw
--host 0.0.0.0
--internal_backend http://screeps:21025
```

Set up the `SCREEPS_NW_PATH` environment variable.
- Create a `.env` file with the following content in the same folder as the compose.yaml. Replace the path with the actual path to your Screeps `package.nw` file:

```bash
SCREEPS_NW_PATH="~/Library/Application Support/Steam/steamapps/common/Screeps/package.nw"
```
ports:
- "${SCREEPS_PROXY_HOST:-127.0.0.1}:8080:8080/tcp"
depends_on:
- screeps
restart: unless-stopped
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's interest, I can add an NPX cache volume to the Docker Compose + NPX example config to speed up initialization when the container is recreated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the NPM cache volume


Run the Docker container:
# Additional services defined here...

```bash
docker compose up
volumes:
client-npm-cache:
```

## Usage
Expand Down
15 changes: 9 additions & 6 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
name: "screeps-client"

services:
client:
image: node:20
command: >
npx screepers-steamless-client
--package /screeps.nw
--host 0.0.0.0
build: .
volumes:
- ${SCREEPS_NW_PATH:?"SCREEPS_NW_PATH not set"}:/screeps.nw
command:
- "start"
- "--"
- "--package=/screeps.nw"
- "--host=0.0.0.0"
ports:
- 8080:8080
- "${SCREEPS_PROXY_HOST:-127.0.0.1}:8080:8080/tcp"
restart: unless-stopped
Loading