From 7d125f74e1727429a401be84d19e5f7ea0854bb1 Mon Sep 17 00:00:00 2001 From: Georgios Ntoutsos Date: Mon, 15 Jan 2024 11:07:47 +0200 Subject: [PATCH] Update github actions for multiarch images Signed-off-by: Georgios Ntoutsos --- .github/workflows/docker-image-push.yml | 40 ++++++++++++++-------- .github/workflows/docker-image-release.yml | 12 ++++--- README.md | 6 ++++ 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/.github/workflows/docker-image-push.yml b/.github/workflows/docker-image-push.yml index b76732d..d05573f 100644 --- a/.github/workflows/docker-image-push.yml +++ b/.github/workflows/docker-image-push.yml @@ -6,8 +6,6 @@ on: env: IMAGE_NAME: gntouts/eltrak - USER: gntouts - TAG: roll jobs: @@ -16,16 +14,28 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: docker login - env: - DOCKER_USER: ${{secrets.HUB_NAME }} - DOCKER_PASSWORD: ${{secrets.HUB_PWD }} - run: | - docker login -u $DOCKER_USER -p $DOCKER_PASSWORD - echo ${{ env.IMAGE_NAME }} - echo ${{ env.USER }} - - name: Build the Docker image - run: docker build . --file Dockerfile --tag ${{ env.IMAGE_NAME }}:${{ env.TAG }} - - name: Docker Push - run: docker push ${{ env.IMAGE_NAME }}:${{ env.TAG }} + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.HUB_NAME }} + password: ${{ secrets.HUB_PWD }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: gntouts/eltrak:roll + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/docker-image-release.yml b/.github/workflows/docker-image-release.yml index 1e492ff..06bf96a 100644 --- a/.github/workflows/docker-image-release.yml +++ b/.github/workflows/docker-image-release.yml @@ -16,10 +16,13 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 - + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Log in to Docker Hub - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v3 with: username: ${{ secrets.HUB_NAME }} password: ${{ secrets.HUB_PWD }} @@ -31,9 +34,10 @@ jobs: images: ${{ env.IMAGE_NAME }} - name: Build and push Docker image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + uses: docker/build-push-action@v5 with: context: . push: true + platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/README.md b/README.md index 92f91f7..3f8ec82 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,12 @@ In order to run the server locally (or anywhere else) run the following commands `docker build -t eltrak .` +Alternatively, if you want to build a multi-platform image: + + ```bash + docker buildx build --platform linux/arm64,linux/amd64 --push -t gntouts/eltrak:latest . + ``` + 3. Start the container `docker run -dp 8888:80 eltrak`