Skip to content

Commit

Permalink
Generate multi-platform Docker images (#1316)
Browse files Browse the repository at this point in the history
Enable cross-compilation in Dockerfiles.
Add build script.
Update instructions around emulation support.
Add GH actions to build and push dsym and pluginbuilder images on releases.
---------
Co-authored-by: Fernando Takagi <[email protected]>
  • Loading branch information
sesposito authored Jan 24, 2025
1 parent 77dd456 commit ba3c0bc
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 284 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/dockerhub-nakama-dsym.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: dockerhub-nakama-dsym

on:
release:
types:
- created

jobs:
nakama_dsym_build_publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Set env vars
run: |
echo "ARG_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "ARG_VERSION=$(echo -n ${{ github.event.release.name }} | cut -c2-)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ github.repository }}-dsym
tags: |
type=semver,pattern={{version}}
- name: Build and push
uses: docker/build-push-action@v6
with:
file: "build/Dockerfile.dsym"
build-args: |
COMMIT=${{ env.ARG_COMMIT }}
VERSION=${{ env.ARG_VERSION }}
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
53 changes: 53 additions & 0 deletions .github/workflows/dockerhub-nakama.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: dockerhub-nakama

on:
release:
types:
- created

jobs:
nakama_build_publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Set env vars
run: |
echo "ARG_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "ARG_VERSION=$(echo -n ${{ github.event.release.name }} | cut -c2-)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ github.repository }}
tags: |
type=semver,pattern={{version}}
- name: Build and push
uses: docker/build-push-action@v6
with:
file: "build/Dockerfile"
build-args: |
COMMIT=${{ env.ARG_COMMIT }}
VERSION=${{ env.ARG_VERSION }}
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
51 changes: 51 additions & 0 deletions .github/workflows/dockerhub-pluginbuilder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: dockerhub-pluginbuilder

on:
release:
types:
- created

jobs:
pluginbuilder_build_publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Set env vars
run: |
echo "ARG_VERSION=$(echo -n ${{ github.event.release.name }} | cut -c2-)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ github.repository }}-pluginbuilder
tags: |
type=semver,pattern={{version}}
- name: Build and push
uses: docker/build-push-action@v6
with:
file: "build/pluginbuilder/Dockerfile"
build-args: |
VERSION=${{ env.ARG_VERSION }}
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
File renamed without changes.
37 changes: 20 additions & 17 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,41 @@
## See the License for the specific language governing permissions and
## limitations under the License.

# docker build "$PWD" --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version=v2.1.1 -t heroiclabs/nakama:2.1.1
# docker build "$PWD" --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version="$(git rev-parse --short HEAD)" -t heroiclabs/nakama-prerelease:"$(git rev-parse --short HEAD)"
# docker build . --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version=v2.1.1 -t heroiclabs/nakama:2.1.1
# docker build . --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version="$(git rev-parse --short HEAD)" -t heroiclabs/nakama-prerelease:"$(git rev-parse --short HEAD)"

FROM golang:1.23.3-bookworm as builder
FROM golang:1.23.5-bookworm AS builder

ARG commit
ARG version
ARG COMMIT
ARG VERSION
ARG TARGETOS
ARG TARGETARCH

ENV GOOS linux
ENV GOARCH amd64
ENV CGO_ENABLED 1
ENV GOOS=$TARGETOS
ENV GOARCH=$TARGETARCH
ENV CGO_ENABLED=1
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y --no-install-recommends ca-certificates gcc libc6-dev git && \
git config --global advice.detachedHead false && \
git clone --quiet --no-checkout https://github.com/heroiclabs/nakama /go/build/nakama
apt-get install -y --no-install-recommends ca-certificates gcc libc6-dev

WORKDIR /go/build/nakama
RUN git checkout --quiet "$commit" && \
go build -o /go/build-out/nakama -trimpath -mod=vendor -gcflags "-trimpath $PWD" -asmflags "-trimpath $PWD" -ldflags "-s -w -X main.version=$version -X main.commitID=$commit"
COPY . .
RUN go build -o /go/build-out/nakama -trimpath -mod=vendor -gcflags "-trimpath $PWD" -asmflags "-trimpath $PWD" -ldflags "-s -w -X main.version=$VERSION -X main.commitID=$COMMIT"

FROM debian:bookworm-slim

MAINTAINER Heroic Labs <[email protected]>
ARG VERSION

ARG version

LABEL version=$version
LABEL maintainer="Heroic Labs"
LABEL contact="[email protected]"
LABEL version=$VERSION
LABEL variant=nakama
LABEL description="Distributed server for social and realtime games and apps."

ENV DEBIAN_FRONTEND=noninteractive

RUN mkdir -p /nakama/data/modules && \
apt-get update && \
apt-get -y upgrade && \
Expand Down
61 changes: 0 additions & 61 deletions build/Dockerfile.arm64

This file was deleted.

38 changes: 19 additions & 19 deletions build/Dockerfile.dsym
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@
## See the License for the specific language governing permissions and
## limitations under the License.

# docker build "$PWD" --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version=v3.19.0 -t heroiclabs/nakama:3.19.0
# docker build "$PWD" --build-arg commit="$(git rev-parse --short HEAD)" --build-arg version="v3.19.0-$(git rev-parse --short HEAD)" -t heroiclabs/nakama-prerelease:"3.19.0-$(git rev-parse --short HEAD)"
FROM golang:1.23.5-bookworm AS builder

FROM golang:1.23.3-bookworm as builder
ARG COMMIT
ARG VERSION
ARG TARGETOS
ARG TARGETARCH

ARG commit
ARG version

ENV GOOS linux
ENV GOARCH amd64
ENV CGO_ENABLED 1
ENV GOOS=$TARGETOS
ENV GOARCH=$TARGETARCH
ENV CGO_ENABLED=1
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y --no-install-recommends ca-certificates gcc libc6-dev git && \
git config --global advice.detachedHead false && \
git clone --quiet --no-checkout https://github.com/heroiclabs/nakama /go/build/nakama
apt-get install -y --no-install-recommends ca-certificates gcc libc6-dev

WORKDIR /go/build/nakama
RUN git checkout --quiet "$commit" && \
go build -o /go/build-out/nakama -trimpath -mod=vendor -gcflags "all=-N -l" -ldflags "-X main.version=$version -X main.commitID=$commit"
COPY . .
RUN go build -o /go/build-out/nakama -trimpath -mod=vendor -gcflags "all=-N -l" -ldflags "-X main.version=$VERSION -X main.commitID=$COMMIT"

FROM debian:bookworm-slim

MAINTAINER Heroic Labs <[email protected]>

ARG version
ARG VERSION

LABEL version=$version
LABEL maintainer="Heroic Labs"
LABEL contact="[email protected]"
LABEL version=$VERSION
LABEL variant=nakama
LABEL description="Distributed server for social and realtime games and apps."
LABEL description="Distributed server for social and realtime games and apps with debug symbols."

ENV DEBIAN_FRONTEND=noninteractive

RUN mkdir -p /nakama/data/modules && \
apt-get update && \
Expand Down
61 changes: 0 additions & 61 deletions build/Dockerfile.dsym.arm64

This file was deleted.

Loading

0 comments on commit ba3c0bc

Please sign in to comment.