Skip to content

Commit bc6625a

Browse files
Sawyer KnoblichSawyer Knoblich
authored andcommitted
Add Dockerfile and Fly.io deployment instructions
1 parent aec13bb commit bc6625a

5 files changed

Lines changed: 117 additions & 0 deletions

File tree

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore any build artifacts that could interfere with the dotnet build happening
2+
# during Docker image creation.
3+
**/bin/
4+
**/obj/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Test Docker Build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build-docker-image:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
18+
- name: Build image
19+
run: docker build .

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
2+
WORKDIR /source
3+
4+
# Copy all .csproj files and use `dotnet restore` to install dependencies.
5+
# Doing this first will allow the dependencies to stay cached if the csproj
6+
# files didn't change, even if other code did.
7+
COPY *.sln .
8+
COPY **/*.csproj ./
9+
RUN dotnet sln list \
10+
| tail -n +3 \
11+
| xargs -I {} sh -c \
12+
'target="{}"; dir="${target%/*}"; file="${target##*/}"; mkdir -p -- "$dir"; mv -- "$file" "$target"'
13+
RUN dotnet restore
14+
15+
# Copy the code over and build the application.
16+
COPY . .
17+
RUN dotnet publish Server -c Release -o /app --no-restore
18+
19+
# Build runtime image.
20+
FROM mcr.microsoft.com/dotnet/runtime:6.0
21+
WORKDIR /app
22+
COPY --from=build-env /app .
23+
ENTRYPOINT ["dotnet", "Server.dll"]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ chmod +x filepath to the server executable
3030
systemctl enable --now smo.service
3131
```
3232

33+
## Running with Docker
34+
35+
A Dockerfile is included if you want to run the server without installing `dotnet`, or if you are using a hosting
36+
environment with Docker support. See [deploy_to_fly_io.md](https://github.com/Sanae6/SmoOnlineServer/blob/master/docs/deploy_to_fly_io.md)
37+
for an easy way to run a server using the [Fly.io](https://www.fly.io) free tier.
38+
3339
## Commands
3440

3541
Run `help` to get what commands are available in the server console.

docs/deploy_to_fly_io.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Deploy to Fly.io
2+
3+
## What is Fly.io?
4+
5+
[Fly.io](https://www.fly.io) is a platform for running applications in the cloud. Their tooling builds
6+
an image from a Dockerfile and runs it in a datacenter without you having to manage the server yourself.
7+
They have a free tier that provides more than enough power to run the SMO Online server code.
8+
9+
Note: Fly *does* require a credit card on signup, but this is only to prevent bots from abusing their free tier. The setup listed in this guide is completely covered by their free tier, so you should not incur any charges.
10+
11+
## Deployment Instructions
12+
13+
1. First, follow Fly's [Installing flyctl](https://fly.io/docs/getting-started/installing-flyctl/) and
14+
[Log in](https://fly.io/docs/getting-started/log-in-to-fly/) instructions to get your computer set up
15+
to interact with Fly.
16+
* `flyctl` is Fly's tool for creating and deploying applications.
17+
2. Clone this repo using `git clone https://github.com/Sanae6/SmoOnlineServer.git` in your terminal.
18+
3. Run `cd SmoOnlineServer` to enter the repo directory.
19+
4. Run `flyctl launch`.
20+
* This is the command for creating a new application on Fly. It will ask for a name to use (must be globally unique) and a region
21+
to deploy to, you should pick a region close to you if it did not pick one automatically.
22+
* This command generates a `fly.toml` file in the repo, which is the configuration that Fly looks at when
23+
deciding how to run your application.
24+
5. By default this `fly.toml` file assumes that you are deploying a standard HTTP application, but this server operates over raw TCP. You will need to edit this file to look like the following:
25+
* ```toml
26+
app = "<your-app-name>"
27+
kill_signal = "SIGINT"
28+
kill_timeout = 5
29+
processes = []
30+
31+
[env]
32+
33+
[experimental]
34+
allowed_public_ports = []
35+
auto_rollback = true
36+
37+
[[services]]
38+
http_checks = []
39+
internal_port = 1027
40+
processes = ["app"]
41+
protocol = "tcp"
42+
script_checks = []
43+
44+
[services.concurrency]
45+
hard_limit = 25
46+
soft_limit = 20
47+
type = "connections"
48+
49+
[[services.ports]]
50+
port = 1027
51+
```
52+
* This configuration tells Fly that you are running the app over plain TCP, not HTTP, and to expose
53+
port 1027 instead of ports 80 and 443 like the default configuration will.
54+
6. Run `flyctl deploy`.
55+
* This will build the server code into a Docker image and push it to Fly, where it will then run in
56+
their datacenter in the region that you chose. This step might take a few minutes to complete.
57+
7. Now that your app is running, you can log in to Fly in your browser. Under your [Apps](https://fly.io/dashboard/personal)
58+
page you should see the application, and clicking on it will bring you to the Overview page.
59+
* The most important thing here is the "IP addresses" box near the middle of the page. When you start the
60+
modded game, this IP will be the one you want to enter (use the one with "v4" next to it).
61+
* Another useful page is the Monitoring page on the left, which will show you useful logs about when users
62+
connect, when moons are picked up, etc.
63+
64+
And that's it! If you've made it this far, you should have the server up and running for free. By default Fly allocates
65+
one CPU core and 256MB of RAM for their free tier, which should be plenty.

0 commit comments

Comments
 (0)