From 47fdd4bd4bb26b1ac10786131466d6a06a9c05bf Mon Sep 17 00:00:00 2001
From: thijsheijden <hi@thijsheijden.nl>
Date: Mon, 4 Oct 2021 17:07:55 +0200
Subject: [PATCH] Added multi architecture support

Dockerfile can now build for ARM64 and AMD64.
---
 Dockerfile | 40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index f1773a5..de2959f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,3 +1,39 @@
+# docker buildx build --platform linux/amd64,linux/arm64 -t datastropheregistry.azurecr.io/query-orchestrator . --push --ssh default
+# STAGE 1
+FROM golang:1.16
+
+ARG TARGETARCH
+ARG TARGETOS
+
+WORKDIR /app
+
+# Use SSH instead of HTTPS
+RUN echo "[url \"git@git.science.uu.nl:\"]\n\tinsteadOf = https://git.science.uu.nl/" >> /root/.gitconfig
+
+# Turn off strict host key checking
+RUN mkdir /root/.ssh && echo "StrictHostKeyChecking no " > /root/.ssh/config
+
+# Copy go files into the image
+COPY go.mod ./
+COPY go.sum ./
+COPY cmd/ ./cmd/
+COPY internal/ ./internal/
+COPY pkg/ ./pkg/
+
+# Gather dependencies
+RUN --mount=type=ssh go mod download
+
+# Compile for the target architecture and operating system
+# Add SSH mount as this operation requires access to private repos
+RUN GOARCH=${TARGETARCH} GOOS=${TARGETOS} CGO_ENABLED=0 go build -o ./main ./cmd/query-orchestrator/
+
+# STAGE 2
 FROM busybox
-ADD ./builds/main /
-CMD /main
\ No newline at end of file
+
+WORKDIR /app
+
+# Copy the built binary into this image
+COPY --from=0 /app/main ./
+
+# Run the binary
+CMD ./main
\ No newline at end of file
-- 
GitLab