-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from HimbeerserverDE/docker
Docker support
- Loading branch information
Showing
5 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,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 |
This file contains 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,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"] |
This file contains 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 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 @@ | ||
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"] |
This file contains 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,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. |