-
Notifications
You must be signed in to change notification settings - Fork 37
Add Dockerfile and Fly.io deployment instructions #9
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
Open
sawyerknoblich
wants to merge
1
commit into
Sanae6:master
Choose a base branch
from
sawyerknoblich:dockerize
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Ignore any build artifacts that could interfere with the dotnet build happening | ||
| # during Docker image creation. | ||
| **/bin/ | ||
| **/obj/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| name: Test Docker Build | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| pull_request: | ||
| branches: | ||
| - master | ||
|
|
||
| jobs: | ||
| build-docker-image: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Build image | ||
| run: docker build . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env | ||
| WORKDIR /source | ||
|
|
||
| # Copy all .csproj files and use `dotnet restore` to install dependencies. | ||
| # Doing this first will allow the dependencies to stay cached if the csproj | ||
| # files didn't change, even if other code did. | ||
| COPY *.sln . | ||
| COPY **/*.csproj ./ | ||
| RUN dotnet sln list \ | ||
| | tail -n +3 \ | ||
| | xargs -I {} sh -c \ | ||
| 'target="{}"; dir="${target%/*}"; file="${target##*/}"; mkdir -p -- "$dir"; mv -- "$file" "$target"' | ||
| RUN dotnet restore | ||
|
|
||
| # Copy the code over and build the application. | ||
| COPY . . | ||
| RUN dotnet publish Server -c Release -o /app --no-restore | ||
|
|
||
| # Build runtime image. | ||
| FROM mcr.microsoft.com/dotnet/runtime:6.0 | ||
| WORKDIR /app | ||
| COPY --from=build-env /app . | ||
| ENTRYPOINT ["dotnet", "Server.dll"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Deploy to Fly.io | ||
|
|
||
| ## What is Fly.io? | ||
|
|
||
| [Fly.io](https://www.fly.io) is a platform for running applications in the cloud. Their tooling builds | ||
| an image from a Dockerfile and runs it in a datacenter without you having to manage the server yourself. | ||
| They have a free tier that provides more than enough power to run the SMO Online server code. | ||
|
|
||
| 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. | ||
|
|
||
| ## Deployment Instructions | ||
|
|
||
| 1. First, follow Fly's [Installing flyctl](https://fly.io/docs/getting-started/installing-flyctl/) and | ||
| [Log in](https://fly.io/docs/getting-started/log-in-to-fly/) instructions to get your computer set up | ||
| to interact with Fly. | ||
| * `flyctl` is Fly's tool for creating and deploying applications. | ||
| 2. Clone this repo using `git clone https://github.com/Sanae6/SmoOnlineServer.git` in your terminal. | ||
| 3. Run `cd SmoOnlineServer` to enter the repo directory. | ||
| 4. Run `flyctl launch`. | ||
| * 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 | ||
| to deploy to, you should pick a region close to you if it did not pick one automatically. | ||
| * This command generates a `fly.toml` file in the repo, which is the configuration that Fly looks at when | ||
| deciding how to run your application. | ||
| 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: | ||
| * ```toml | ||
| app = "<your-app-name>" | ||
| kill_signal = "SIGINT" | ||
| kill_timeout = 5 | ||
| processes = [] | ||
|
|
||
| [env] | ||
|
|
||
| [experimental] | ||
| allowed_public_ports = [] | ||
| auto_rollback = true | ||
|
|
||
| [[services]] | ||
| http_checks = [] | ||
| internal_port = 1027 | ||
| processes = ["app"] | ||
| protocol = "tcp" | ||
| script_checks = [] | ||
|
|
||
| [services.concurrency] | ||
| hard_limit = 25 | ||
| soft_limit = 20 | ||
| type = "connections" | ||
|
|
||
| [[services.ports]] | ||
| port = 1027 | ||
| ``` | ||
| * This configuration tells Fly that you are running the app over plain TCP, not HTTP, and to expose | ||
| port 1027 instead of ports 80 and 443 like the default configuration will. | ||
| 6. Run `flyctl deploy`. | ||
| * This will build the server code into a Docker image and push it to Fly, where it will then run in | ||
| their datacenter in the region that you chose. This step might take a few minutes to complete. | ||
| 7. Now that your app is running, you can log in to Fly in your browser. Under your [Apps](https://fly.io/dashboard/personal) | ||
| page you should see the application, and clicking on it will bring you to the Overview page. | ||
| * The most important thing here is the "IP addresses" box near the middle of the page. When you start the | ||
| modded game, this IP will be the one you want to enter (use the one with "v4" next to it). | ||
| * Another useful page is the Monitoring page on the left, which will show you useful logs about when users | ||
| connect, when moons are picked up, etc. | ||
|
|
||
| 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 | ||
| one CPU core and 256MB of RAM for their free tier, which should be plenty. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken from https://stackoverflow.com/a/65390923, this is a hacky thing you need to do to move each of the .csproj files to the proper directory in the docker image. A little annoying but better than hardcoding it because if anything about the project structure is changed (new project added, project renamed, etc) it won't require any changes to the Dockerfile