From 0c2f5bc63be82135991ca63959a9d4460abed911 Mon Sep 17 00:00:00 2001
From: Jonathan Gonzalez V <jonathan.abdiel@gmail.com>
Date: Fri, 15 Jul 2022 16:40:02 -0400
Subject: [PATCH] feat: add multiarch support

Modify .goreleaser.yml file to build two images one for amd64 and
another for arm64 and then create the proper manifest to publish
with the proper images.

Closes #215

Signed-off-by: Jonathan Gonzalez V <jonathan.abdiel@gmail.com>
---
 .github/workflows/tag.yml |  7 +++++++
 .goreleaser.yml           | 35 ++++++++++++++++++++++++++++++++---
 2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml
index 9f7c09a3..0f56a8fd 100644
--- a/.github/workflows/tag.yml
+++ b/.github/workflows/tag.yml
@@ -18,6 +18,13 @@ jobs:
         with:
           go-version: 1.17
 
+      - name: Set up QEMU
+        uses: docker/setup-qemu-action@v2
+
+      - name: Set up Docker Buildx
+        id: buildx
+        uses: docker/setup-buildx-action@v2
+
       - name: Login docker.io
         run: docker login -u celfring -p ${{ secrets.DOCKER_TOKEN }}
 
diff --git a/.goreleaser.yml b/.goreleaser.yml
index 45227c1d..2f9a08b9 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -50,10 +50,39 @@ changelog:
 
 dockers:
   - dockerfile: build/Dockerfile
+    use: buildx
+    goos: linux
+    goarch: amd64
+    build_flag_templates:
+      - "--platform=linux/amd64"
     image_templates:
-      - "getwoke/woke:latest"
-      - "getwoke/woke:{{ .Major }}.{{ .Minor }}"
-      - "getwoke/woke:{{ .RawVersion }}"
+      - "getwoke/woke:latest-amd64"
+      - "getwoke/woke:{{ .Major }}.{{ .Minor }}-amd64"
+      - "getwoke/woke:{{ .RawVersion }}-amd64"
+  - dockerfile: build/Dockerfile
+    use: buildx
+    goos: linux
+    goarch: arm64
+    build_flag_templates:
+      - "--platform=linux/arm64"
+    image_templates:
+      - "getwoke/woke:latest-arm64"
+      - "getwoke/woke:{{ .Major }}.{{ .Minor }}-arm64"
+      - "getwoke/woke:{{ .RawVersion }}-arm64"
+
+docker_manifests:
+  - name_template: getwoke/woke:latest
+    image_templates:
+      - "getwoke/woke:latest-amd64"
+      - "getwoke/woke:latest-arm64"
+  - name_template: getwoke/woke:{{ .Major }}.{{ .Minor }}
+    image_templates:
+      - "getwoke/woke:{{ .Major }}.{{ .Minor }}-amd64"
+      - "getwoke/woke:{{ .Major }}.{{ .Minor }}-arm64"
+  - name_template: getwoke/woke:{{ .RawVersion }}
+    image_templates:
+      - "getwoke/woke:{{ .RawVersion }}-amd64"
+      - "getwoke/woke:{{ .RawVersion }}-arm64"
 
 brews:
   - tap: