Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
smsunarto opened this issue May 28, 2024 · 7 comments
Open

Comments

@smsunarto
Copy link

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.
Copy link

linear bot commented May 28, 2024

@toqueteos
Copy link
Contributor

toqueteos commented Jul 23, 2024

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.

@zcyc
Copy link

zcyc commented Jul 28, 2024

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.

@zyro
Copy link
Member

zyro commented Jul 28, 2024

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

@toqueteos
Copy link
Contributor

toqueteos commented Jul 28, 2024

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

Simpler approach than #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.

@smsunarto
Copy link
Author

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

@novabyte
Copy link
Member

novabyte commented Nov 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants