From e17fbd8f8aa05d5032bea345212b8dd21101168f Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Sat, 9 Dec 2023 16:26:28 +0100 Subject: add Dockerfile --- Dockerfile | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..72306ed --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM golang:1.21.4 + +RUN mkdir /usr/local/mt-multiserver-proxy +RUN GOBIN=/usr/local/mt-multiserver-proxy go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/...@latest + +VOLUME ["/usr/local/mt-multiserver-proxy"] + +EXPOSE 40000/udp + +CMD ["/usr/local/mt-multiserver-proxy/mt-multiserver-proxy"] -- cgit v1.2.3 From 1f2a014575d5af824846d2241135c9726dbe819f Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Sat, 9 Dec 2023 16:48:01 +0100 Subject: rename Dockerfile => Dockerfile.latest --- Dockerfile | 10 ---------- Dockerfile.latest | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) delete mode 100644 Dockerfile create mode 100644 Dockerfile.latest diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 72306ed..0000000 --- a/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM golang:1.21.4 - -RUN mkdir /usr/local/mt-multiserver-proxy -RUN GOBIN=/usr/local/mt-multiserver-proxy go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/...@latest - -VOLUME ["/usr/local/mt-multiserver-proxy"] - -EXPOSE 40000/udp - -CMD ["/usr/local/mt-multiserver-proxy/mt-multiserver-proxy"] diff --git a/Dockerfile.latest b/Dockerfile.latest new file mode 100644 index 0000000..72306ed --- /dev/null +++ b/Dockerfile.latest @@ -0,0 +1,10 @@ +FROM golang:1.21.4 + +RUN mkdir /usr/local/mt-multiserver-proxy +RUN GOBIN=/usr/local/mt-multiserver-proxy go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/...@latest + +VOLUME ["/usr/local/mt-multiserver-proxy"] + +EXPOSE 40000/udp + +CMD ["/usr/local/mt-multiserver-proxy/mt-multiserver-proxy"] -- cgit v1.2.3 From 734c85ac8aa08a704e1821969660760b5f0c271e Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Sat, 9 Dec 2023 16:50:56 +0100 Subject: add Dockerfile.devel --- Dockerfile.devel | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Dockerfile.devel diff --git a/Dockerfile.devel b/Dockerfile.devel new file mode 100644 index 0000000..12eaf08 --- /dev/null +++ b/Dockerfile.devel @@ -0,0 +1,14 @@ +FROM golang:1.21.4 + +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 GOBIN=/usr/local/mt-multiserver-proxy go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/... + +VOLUME ["/usr/local/mt-multiserver-proxy"] + +EXPOSE 40000/udp + +CMD ["/usr/local/mt-multiserver-proxy/mt-multiserver-proxy"] -- cgit v1.2.3 From ef3f30c467afa6baa854928fbe7ec0c095323384 Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Sat, 9 Dec 2023 17:03:49 +0100 Subject: rename Dockerfile.latest => Dockerfile --- Dockerfile | 10 ++++++++++ Dockerfile.latest | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 Dockerfile delete mode 100644 Dockerfile.latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..72306ed --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM golang:1.21.4 + +RUN mkdir /usr/local/mt-multiserver-proxy +RUN GOBIN=/usr/local/mt-multiserver-proxy go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/...@latest + +VOLUME ["/usr/local/mt-multiserver-proxy"] + +EXPOSE 40000/udp + +CMD ["/usr/local/mt-multiserver-proxy/mt-multiserver-proxy"] diff --git a/Dockerfile.latest b/Dockerfile.latest deleted file mode 100644 index 72306ed..0000000 --- a/Dockerfile.latest +++ /dev/null @@ -1,10 +0,0 @@ -FROM golang:1.21.4 - -RUN mkdir /usr/local/mt-multiserver-proxy -RUN GOBIN=/usr/local/mt-multiserver-proxy go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/...@latest - -VOLUME ["/usr/local/mt-multiserver-proxy"] - -EXPOSE 40000/udp - -CMD ["/usr/local/mt-multiserver-proxy/mt-multiserver-proxy"] -- cgit v1.2.3 From 0891cd9e52c3fce74f6aa3277135130fb14b23bb Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Sat, 9 Dec 2023 17:05:34 +0100 Subject: main Dockerfile: optionally accept a version --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 72306ed..4fc2960 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,9 @@ FROM golang:1.21.4 +ARG version=latest + RUN mkdir /usr/local/mt-multiserver-proxy -RUN GOBIN=/usr/local/mt-multiserver-proxy go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/...@latest +RUN GOBIN=/usr/local/mt-multiserver-proxy go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/...@${version} VOLUME ["/usr/local/mt-multiserver-proxy"] -- cgit v1.2.3 From 7e2d041ccd36b3a72ba46a13de7b37fb98577753 Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Sat, 9 Dec 2023 17:41:28 +0100 Subject: add docker documentation --- README.md | 6 +++ doc/docker.md | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 doc/docker.md diff --git a/README.md b/README.md index 94e08c7..340e0b6 100644 --- a/README.md +++ b/README.md @@ -133,3 +133,9 @@ for details. 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/doc/docker.md b/doc/docker.md new file mode 100644 index 0000000..229e8b4 --- /dev/null +++ b/doc/docker.md @@ -0,0 +1,125 @@ +# Docker + +This repository contains a `Dockerfile` at its root. +It can be used to build the most recent release version +or a 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. + +### Regular + +To build an image of the latest commit, run the following command +from the repository root: + +``` +docker build -t mt-multiserver-proxy . +``` + +This is the version most people will want. + +It is also possible to build a specific version into an image: + +``` +docker build -t mt-multiserver-proxy --build-arg version=VERSION . +``` + +where `VERSION` is a Go pseudo-version. + +### Development + +To build an image of the checked-out commit, run the following command +from the repository root: + +``` +docker build -t mt-multiserver-proxy -f Dockerfile.devel . +``` + +## 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. -- cgit v1.2.3 From 1caf778b4cc9eaf8570f3d1a3366eef42569ca4b Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Thu, 18 Jan 2024 18:30:26 +0100 Subject: rename Dockerfile.devel => devel.Dockerfile --- Dockerfile.devel | 14 -------------- devel.Dockerfile | 14 ++++++++++++++ doc/docker.md | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) delete mode 100644 Dockerfile.devel create mode 100644 devel.Dockerfile diff --git a/Dockerfile.devel b/Dockerfile.devel deleted file mode 100644 index 12eaf08..0000000 --- a/Dockerfile.devel +++ /dev/null @@ -1,14 +0,0 @@ -FROM golang:1.21.4 - -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 GOBIN=/usr/local/mt-multiserver-proxy go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/... - -VOLUME ["/usr/local/mt-multiserver-proxy"] - -EXPOSE 40000/udp - -CMD ["/usr/local/mt-multiserver-proxy/mt-multiserver-proxy"] diff --git a/devel.Dockerfile b/devel.Dockerfile new file mode 100644 index 0000000..12eaf08 --- /dev/null +++ b/devel.Dockerfile @@ -0,0 +1,14 @@ +FROM golang:1.21.4 + +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 GOBIN=/usr/local/mt-multiserver-proxy go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/... + +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 index 229e8b4..7be7ab1 100644 --- a/doc/docker.md +++ b/doc/docker.md @@ -36,7 +36,7 @@ To build an image of the checked-out commit, run the following command from the repository root: ``` -docker build -t mt-multiserver-proxy -f Dockerfile.devel . +docker build -t mt-multiserver-proxy -f devel.Dockerfile . ``` ## Run -- cgit v1.2.3 From e7045f6b32b0d49976472de84b37f31b2f204142 Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Thu, 18 Jan 2024 18:55:50 +0100 Subject: add workflow to build and push docker image --- .github/workflows/docker.yml | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..88a7031 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,42 @@ +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 + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} -- cgit v1.2.3 From d2580f0a3815c5d5ec452fceac3b2cd34c7d57c0 Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Sat, 20 Jan 2024 10:31:58 +0100 Subject: buildx and cross-compilation support --- .github/workflows/docker.yml | 1 + Dockerfile | 8 ++++++-- devel.Dockerfile | 9 +++++++-- doc/docker.md | 18 +++++++++++++++--- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 88a7031..3fa067a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -40,3 +40,4 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 diff --git a/Dockerfile b/Dockerfile index 4fc2960..44edb5f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,13 @@ -FROM golang:1.21.4 +FROM --platform=${BUILDPLATFORM} golang:1.21.4 ARG version=latest +ARG BUILDPLATFORM +ARG BUILDARCH +ARG TARGETARCH RUN mkdir /usr/local/mt-multiserver-proxy -RUN GOBIN=/usr/local/mt-multiserver-proxy go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/...@${version} +RUN GOARCH=${TARGETARCH} go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/...@${version} +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"] diff --git a/devel.Dockerfile b/devel.Dockerfile index 12eaf08..990ff2a 100644 --- a/devel.Dockerfile +++ b/devel.Dockerfile @@ -1,11 +1,16 @@ -FROM golang:1.21.4 +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 GOBIN=/usr/local/mt-multiserver-proxy go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/... +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"] diff --git a/doc/docker.md b/doc/docker.md index 7be7ab1..6af77c5 100644 --- a/doc/docker.md +++ b/doc/docker.md @@ -11,13 +11,15 @@ 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 latest commit, run the following command from the repository root: ``` -docker build -t mt-multiserver-proxy . +docker buildx build -t mt-multiserver-proxy --load . ``` This is the version most people will want. @@ -25,7 +27,7 @@ This is the version most people will want. It is also possible to build a specific version into an image: ``` -docker build -t mt-multiserver-proxy --build-arg version=VERSION . +docker buildx build -t mt-multiserver-proxy --load --build-arg version=VERSION . ``` where `VERSION` is a Go pseudo-version. @@ -36,7 +38,17 @@ To build an image of the checked-out commit, run the following command from the repository root: ``` -docker build -t mt-multiserver-proxy -f devel.Dockerfile . +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 -- cgit v1.2.3 From a7a2bf16e2910854c02b24b2fde4f15a91207c76 Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Sat, 20 Jan 2024 11:10:41 +0100 Subject: ensure CI builds the latest commit The Go proxy is highly unlikely to be up to date already when a commit is pushed. --- Dockerfile | 6 ++++-- doc/docker.md | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 44edb5f..62ac15e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,14 @@ FROM --platform=${BUILDPLATFORM} golang:1.21.4 -ARG version=latest +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} +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"] diff --git a/doc/docker.md b/doc/docker.md index 6af77c5..9ff9c38 100644 --- a/doc/docker.md +++ b/doc/docker.md @@ -1,8 +1,7 @@ # Docker This repository contains a `Dockerfile` at its root. -It can be used to build the most recent release version -or a development version into an image. +It can be used to build a release or development version into an image. ## Build @@ -15,14 +14,14 @@ The images are intended to be built by the default buildx builder. ### Regular -To build an image of the latest commit, run the following command +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 is the version most people will want. +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: @@ -30,7 +29,8 @@ 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. +where `VERSION` is a Go pseudo-version or `latest` for the latest version +known by the Go proxy. ### Development -- cgit v1.2.3 From fc55df9297f30f5e98d650c75cdd04eb1d0e0636 Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Wed, 24 Jan 2024 17:25:14 +0100 Subject: run separate builds for amd64 and arm64 The docker driver doesn't support multi-platform builds. This is a workaround. --- .github/workflows/docker.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 3fa067a..4b1b75a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -33,11 +33,20 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - name: Build and push Docker image + - 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,linux/arm64 + 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 -- cgit v1.2.3