From ccccdecb6af65c64401fdb5046a8e0937d3fb79e Mon Sep 17 00:00:00 2001 From: "Robin C. Ladiges" Date: Sun, 17 Jul 2022 21:00:31 +0200 Subject: [PATCH] Provide docker image (#6) * add Dockerfile * add docker-compose.yml * Github workflow to build and deploy docker image * workdir /data/ instead of /app/ * use a local directory instead of a named volume This makes the settings.json more accessible from the outside by default, but is less portable. The -v command with $PWD might not work on native Windows shells, but rather wants an absolute Windows path like C:\User\... or /c/User/... And on Linux, because the /data/ directory and the settings.json will be owned by root. Though that can be changed. * more docker-compose command examples * add linux/arm/v7 ; improve build & runtime * fix: just arm not arm32 * test docker build for PRs * back to the microsoft runtime --- .github/workflows/deploy.yml | 74 +++++++++++++++++++++++++++++++++++ .github/workflows/test-pr.yml | 37 ++++++++++++++++++ Dockerfile | 45 +++++++++++++++++++++ README.md | 31 +++++++++++++++ docker-compose.yml | 12 ++++++ 5 files changed, 199 insertions(+) create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/test-pr.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..e542ed9 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,74 @@ +name: Build and deploy + +on: + push: + branches: + - '**' + tags: + - '*.*.*' + - 'v*.*.*' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + IMAGE: ${{ github.repository_owner }}/smo-online-server + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - + name: Environment + run: | + IMAGE=`echo ${{ env.IMAGE }} | tr '[:upper:]' '[:lower:]'` + echo "IMAGE=$IMAGE" >>$GITHUB_ENV + - + name: Checkout + uses: actions/checkout@v3 + - + id: meta + name: Docker meta + uses: docker/metadata-action@v4 + with: + images: | + ghcr.io/${{ env.IMAGE }} + flavor: | + latest=false + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=semver,pattern={{major}}.{{minor}}.{{patch}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=ref,event=branch + labels: | + org.opencontainers.image.licenses=UNLICENSED + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: amd64,arm64,arm + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to GHCR + uses: docker/login-action@v2 + with: + registry : ghcr.io + username : ${{ github.repository_owner }} + password : ${{ secrets.GITHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v3 + with: + pull : true + push : true + context : . + file : ./Dockerfile + tags : ${{ steps.meta.outputs.tags }} + labels : ${{ steps.meta.outputs.labels }} + platforms : linux/amd64,linux/arm/v7,linux/arm64/v8 + cache-from : type=gha,scope=${{ github.workflow }} + cache-to : type=gha,scope=${{ github.workflow }},mode=max diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml new file mode 100644 index 0000000..d858bed --- /dev/null +++ b/.github/workflows/test-pr.yml @@ -0,0 +1,37 @@ +name: Test PR + +on: + pull_request: + branches: + - '**' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + test: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: amd64,arm64,arm + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Build + uses: docker/build-push-action@v3 + with: + pull : true + push : false + context : . + file : ./Dockerfile + platforms : linux/amd64,linux/arm/v7,linux/arm64/v8 + cache-from : type=gha,scope=${{ github.workflow }} + cache-to : type=gha,scope=${{ github.workflow }},mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..23be278 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +################################################################################ +################################################################## build ### + +FROM --platform=linux/amd64 mcr.microsoft.com/dotnet/sdk:6.0 as build + +WORKDIR /app/ + +COPY ./Server/ ./Server/ +COPY ./Shared/ ./Shared/ + +ARG TARGETARCH + +# Download NuGet dependencies +RUN dotnet restore \ + ./Server/Server.csproj \ + -r debian.11-`echo $TARGETARCH | sed 's@^amd@x@'` \ +; + +# Build application binary +RUN dotnet publish \ + ./Server/Server.csproj \ + -r debian.11-`echo $TARGETARCH | sed 's@^amd@x@'` \ + -c Release \ + -o ./out/ \ + --no-restore \ + --self-contained \ + -p:publishSingleFile=true \ +; + +################################################################## build ### +################################################################################ +################################################################ runtime ### + +FROM mcr.microsoft.com/dotnet/runtime:6.0 as runtime + +# Copy application binary from build stage +COPY --from=build /app/out/ /app/ + +ENTRYPOINT [ "/app/Server" ] +EXPOSE 1027/tcp +WORKDIR /data/ +VOLUME /data/ + +################################################################ runtime ### +################################################################################ diff --git a/README.md b/README.md index 97e0006..be2b7dd 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ The official server for the [Super Mario Odyssey: Online](https://github.com/Cra ## Windows Setup + 1. Download latest build from [Releases](https://github.com/Sanae6/SmoOnlineServer/releases) 2. Run `Server.exe` 3. `settings.json` is autogenerated in step 2, modify it however you'd like. @@ -30,6 +31,36 @@ chmod +x filepath to the server executable systemctl enable --now smo.service ``` +## Run docker image + +If you have [docker](https://docs.docker.com/) on your system, you can use the existing docker image. +That way you don't have to build this server yourself or manually handle executables. + +```shell +docker run --rm -it -p 1027:1027 -v "/$PWD/data/://data/" ghcr.io/sanae6/smo-online-server +# on Windows, depending on the shell you're using, $PWD might not work. Use an absolute path instead. +``` + +To always check for and use the latest server version you can add `--pull=always` to the options. + +Alternatively there's a `docker-compose.yml` for [docker-compose](https://docs.docker.com/compose/) to simplify the command line options: +```shell +# update server +docker-compose pull + +# start server +docker-compose up -d + +# open the server cli +docker attach `docker-compose ps -q` --sig-proxy=false + +# watch server logs +docker-compose logs --tail=20 --follow + +# stop server +docker-compose stop +``` + ## Commands Run `help` to get what commands are available in the server console. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e794f60 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3.9" + +services: + server: + image: ghcr.io/sanae6/smo-online-server + #build: . + #user: 1000:1000 + stdin_open: true + ports: + - 1027:1027 + volumes: + - ./data/:/data/