Skip to content

Commit

Permalink
Merge pull request #144 from HimbeerserverDE/docker
Browse files Browse the repository at this point in the history
Docker support
  • Loading branch information
HimbeerserverDE committed Jan 24, 2024
2 parents 56329fd + fc55df9 commit 989383a
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
19 changes: 19 additions & 0 deletions devel.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
137 changes: 137 additions & 0 deletions doc/docker.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 989383a

Please sign in to comment.