aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeer <52707839+HimbeerserverDE@users.noreply.github.com>2024-01-24 16:47:41 +0000
committerGitHub <noreply@github.com>2024-01-24 16:47:41 +0000
commit989383aa9fc3f6f4881e367a0417ff9520701ed1 (patch)
tree262bb00d23cd7a63ff041fab5489690e5a592106
parent56329fdd9c6f5b553fbc0d006a33add7248730e6 (diff)
parentfc55df9297f30f5e98d650c75cdd04eb1d0e0636 (diff)
Merge pull request #144 from HimbeerserverDE/docker
Docker support
-rw-r--r--.github/workflows/docker.yml52
-rw-r--r--Dockerfile18
-rw-r--r--README.md6
-rw-r--r--devel.Dockerfile19
-rw-r--r--doc/docker.md137
5 files changed, 232 insertions, 0 deletions
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
new file mode 100644
index 0000000..4b1b75a
--- /dev/null
+++ b/.github/workflows/docker.yml
@@ -0,0 +1,52 @@
+name: Build and publish a Docker image
+
+on:
+ push:
+ branches: [ main ]
+
+env:
+ REGISTRY: ghcr.io
+ IMAGE_NAME: ${{ github.repository }}
+
+jobs:
+ build-and-publish:
+ runs-on: ubuntu-latest
+
+ permissions:
+ contents: read
+ packages: write
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ - name: Log in to the Container registry
+ uses: docker/login-action@v3
+ with:
+ registry: ${{ env.REGISTRY }}
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Extract metadata (tags, labels)
+ id: meta
+ uses: docker/metadata-action@v5
+ with:
+ images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
+
+ - name: Build and push Docker image (amd64)
+ uses: docker/build-push-action@v5
+ with:
+ context: .
+ push: true
+ tags: ${{ steps.meta.outputs.tags }}
+ labels: ${{ steps.meta.outputs.labels }}
+ platforms: linux/amd64
+
+ - name: Build and push Docker image (arm64)
+ uses: docker/build-push-action@v5
+ with:
+ context: .
+ push: true
+ tags: ${{ steps.meta.outputs.tags }}
+ labels: ${{ steps.meta.outputs.labels }}
+ platforms: linux/arm64
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..62ac15e
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,18 @@
+FROM --platform=${BUILDPLATFORM} golang:1.21.4
+
+ARG VERSION
+ARG BUILDPLATFORM
+ARG BUILDARCH
+ARG TARGETARCH
+
+COPY . /go/src/github.com/HimbeerserverDE/mt-multiserver-proxy
+
+RUN mkdir /usr/local/mt-multiserver-proxy
+RUN GOARCH=${TARGETARCH} go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/...@${VERSION:-`(cd /go/src/github.com/HimbeerserverDE/mt-multiserver-proxy && TZ=UTC git --no-pager show --quiet --abbrev=12 --date='format-local:%Y%m%d%H%M%S' --format='v0.0.0-%cd-%h')`}
+RUN if [ "${TARGETARCH}" = "${BUILDARCH}" ]; then mv /go/bin/mt-* /usr/local/mt-multiserver-proxy/; else mv /go/bin/linux_${TARGETARCH}/mt-* /usr/local/mt-multiserver-proxy/; fi
+
+VOLUME ["/usr/local/mt-multiserver-proxy"]
+
+EXPOSE 40000/udp
+
+CMD ["/usr/local/mt-multiserver-proxy/mt-multiserver-proxy"]
diff --git a/README.md b/README.md
index 8321d3f..a7ab12d 100644
--- a/README.md
+++ b/README.md
@@ -143,3 +143,9 @@ The default chat commands can be installed as a [plugin](https://github.com/Himb
This proxy supports loading Go plugins.
Consult [doc/plugins.md](https://github.com/HimbeerserverDE/mt-multiserver-proxy/blob/main/doc/plugins.md)
for details on how to develop or install them.
+
+## Docker
+
+The proxy can be run in Docker.
+See [doc/docker.md](https://github.com/HimbeerserverDE/mt-multiserver-proxy/blob/main/doc/docker.md)
+for details.
diff --git a/devel.Dockerfile b/devel.Dockerfile
new file mode 100644
index 0000000..990ff2a
--- /dev/null
+++ b/devel.Dockerfile
@@ -0,0 +1,19 @@
+FROM --platform=${BUILDPLATFORM} golang:1.21.4
+
+ARG BUILDPLATFORM
+ARG BUILDARCH
+ARG TARGETARCH
+
+COPY . /go/src/github.com/HimbeerserverDE/mt-multiserver-proxy
+
+WORKDIR /go/src/github.com/HimbeerserverDE/mt-multiserver-proxy
+
+RUN mkdir /usr/local/mt-multiserver-proxy
+RUN GOARCH=${TARGETARCH} go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/...
+RUN if [ "${TARGETARCH}" = "${BUILDARCH}" ]; then mv /go/bin/mt-* /usr/local/mt-multiserver-proxy/; else mv /go/bin/linux_${TARGETARCH}/mt-* /usr/local/mt-multiserver-proxy/; fi
+
+VOLUME ["/usr/local/mt-multiserver-proxy"]
+
+EXPOSE 40000/udp
+
+CMD ["/usr/local/mt-multiserver-proxy/mt-multiserver-proxy"]
diff --git a/doc/docker.md b/doc/docker.md
new file mode 100644
index 0000000..9ff9c38
--- /dev/null
+++ b/doc/docker.md
@@ -0,0 +1,137 @@
+# Docker
+
+This repository contains a `Dockerfile` at its root.
+It can be used to build a release or development version into an image.
+
+## Build
+
+You can replace the `-t` option with anything you need.
+For example, you can add a `:devel` suffix for development builds,
+though remember to refer the image using that name in compose files
+or the `docker run` command.
+
+The images are intended to be built by the default buildx builder.
+
+### Regular
+
+To build an image of the current commit, run the following command
+from the repository root:
+
+```
+docker buildx build -t mt-multiserver-proxy --load .
+```
+
+This works well with CI because it doesn't rely on the Go proxy being up-to-date.
+
+It is also possible to build a specific version into an image:
+
+```
+docker buildx build -t mt-multiserver-proxy --load --build-arg version=VERSION .
+```
+
+where `VERSION` is a Go pseudo-version or `latest` for the latest version
+known by the Go proxy.
+
+### Development
+
+To build an image of the checked-out commit, run the following command
+from the repository root:
+
+```
+docker buildx build -t mt-multiserver-proxy --load -f devel.Dockerfile .
+```
+
+### Cross-compilation
+
+You can add the `--platform linux/ARCH` argument to any of the build commands.
+
+Example (ARMv8 64-bit):
+
+```
+docker buildx build --platform linux/arm64 -t mt-multiserver-proxy --load .
+```
+
+## Run
+
+You can change the external port or the container name to suit your needs.
+
+To run the proxy in a container, run the following command:
+
+```
+docker run \
+ -it \
+ -p 40000:40000/udp \
+ --name mt-multiserver-proxy \
+ mt-multiserver-proxy
+```
+
+In most cases you'll want to use a volume for configuration,
+authentication databases, logs, caching and plugins:
+
+```
+docker run \
+ -it \
+ -v mtproxy_data:/usr/local/mt-multiserver-proxy
+ -p 40000:40000/udp \
+ --name mt-multiserver-proxy \
+ mt-multiserver-proxy
+```
+
+which assumes that you've already set up a `mtproxy_data` volume
+using the `docker volume` command.
+
+Or use compose:
+
+```
+services:
+ proxy:
+ container_name: mt-multiserver-proxy
+ image: mt-multiserver-proxy
+ ports:
+ - "40000:40000/udp"
+ restart: unless-stopped
+ volumes:
+ - mtproxy_data:/usr/local/mt-multiserver-proxy
+volumes:
+ mtproxy_data:
+ external: true
+```
+
+which assumes that you've already set up a `mtproxy_data` volume
+using the `docker volume` command.
+
+Then use the volume to configure the proxy, add plugins, etc.
+
+## mt-auth-convert
+
+You can run mt-auth-convert inside the container:
+
+```
+docker run \
+ -it \
+ -p 40000:40000/udp \
+ --name mt-multiserver-proxy \
+ mt-multiserver-proxy \
+ mt-auth-convert PARAMS
+```
+
+If using a volume:
+
+```
+docker run \
+ -it \
+ -v mtproxy_data:/usr/local/mt-multiserver-proxy
+ -p 40000:40000/udp \
+ --name mt-multiserver-proxy \
+ mt-multiserver-proxy \
+ mt-auth-convert PARAMS
+```
+
+Or use compose:
+
+```
+docker compose run proxy /usr/local/mt-multiserver-proxy/mt-auth-convert PARAMS
+```
+
+Consult the [mt-auth-convert documentation](https://github.com/HimbeerserverDE/mt-multiserver-proxy/blob/main/doc/auth_backends.md#mt-auth-convert)
+for what `PARAMS` to use.