nakama icon indicating copy to clipboard operation
nakama copied to clipboard

Nakama ARM build should be published with the same docker version tag

Open smsunarto opened this issue 1 year ago • 5 comments

It seems like the Nakama ARM images (https://hub.docker.com/r/heroiclabs/nakama/tags) is version tagged separately as vX.X.X-arm. This unfortunately makes it difficult to do downstream multi-platform builds as it would require a separate Dockerfile that imports different base image version tags.

The Docker best practice seems to be to publish different platform images under the same version tag and let docker buildx automatically select the correct image based on the platform. By doing it this way, you can do multi-platform builds using a single Dockerfile.

For example:

  • Redis - Notice how a single version tag is used for multiple architectures.

smsunarto avatar May 28 '24 21:05 smsunarto

Official Docker docs.

It seems easy to accomplish if Docker images are built from GitHub.

If that's not the case it's not that hard anyway, just three steps:

  • Choose an strategy to build the ARM64 containers
  • docker buildx build --platform linux/amd64,linux/arm64 -f ./build/Dockerfile $YOUR_DOCKER_BUILD_PARAMS_HERE
  • docker push $IMAGE_NAME

Here's a GitHub Actions workflow that does this.

It requires two secrets (the Docker hub login credentials).

It publishes a single multi-platform (linux/amd64 and linux/arm64) Docker image when a new release is created:

name: docker-image

on:
  release:
    types:
      - created

env:
  IMAGE_NAME: "heroiclabs/nakama"

jobs:
  docker:
    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:
          # registry: "..." # if not using Docker Hub check https://github.com/docker/login-action?tab=readme-ov-file#usage
          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: ${{ env.IMAGE_NAME }}
          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 }}

EDIT (28/07/2024): Updated workflow.

Check changes to Dockerfile and Action results on my fork.

toqueteos avatar Jul 23 '24 22:07 toqueteos

It is very important for MacBooks with Apple chips, changes it as soon as possible please. I feel #1160 likes this, and #1161 is fixing this.

zcyc avatar Jul 28 '24 08:07 zcyc

We're taking a look at this for the next release, until then using the separate tag should work.

zyro avatar Jul 28 '24 09:07 zyro

Made a working example, you can check the diff here.

Simpler approach than https://github.com/heroiclabs/nakama/pull/1161

GitHub Actions workflow logs

The resulting multi-platform image is available in this public Docker Hub repo: https://hub.docker.com/r/toqueteos/nakama/tags

EDIT: Tried the image on Windows (11), Linux (Ubuntu 22.04) and OSX (Sonoma 14.5) hosts. The same approach works with the dsym and pluginbuilder Dockerfiles.

toqueteos avatar Jul 28 '24 21:07 toqueteos

@zyro any status here? happy to help if you guys are having issues

smsunarto avatar Nov 07 '24 22:11 smsunarto

@smsunarto It would be great to have a pull request to review if you have time 🙏

novabyte avatar Nov 09 '24 20:11 novabyte

This issue is now resolved and we're publishing multi-platform builds starting with the Nakama v3.26.0 release. Just wanted to leave a note thanking those who contributed with PRs or suggestions, they've been useful even if they weren't directly merged. Also thanks @toqueteos for the GH Action examples, we've also taken inspiration from them.

sesposito avatar Jan 28 '25 17:01 sesposito