From a46ee33b979b24b65fc04877e03033577f674d0a Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Fri, 9 Aug 2019 16:38:50 -0700 Subject: [PATCH] Add multi-arch targets --- Makefile | 53 ++++++++++++++++++++++++++++++++++++++++++++++- client/Dockerfile | 33 ++++++++++++++++++++++++----- server/Dockerfile | 8 ++++++- 3 files changed, 87 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 4ca5a21..c7d45e8 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +DOCKER_TAG := dockamole +MOLE_VERSION := 0.4.0 + .PHONY: default default: server client @@ -45,5 +48,53 @@ keys/etc/ssh/ssh_host_dsa_key: keys keys/etc/ssh/ssh_host_ecdsa_key: keys keys/etc/ssh/ssh_host_ed25519_key: keys keys/etc/ssh/ssh_host_rsa_key: keys - keys/known_hosts: keys + +# Build images + +.PHONY: build +build: build-client build-server + +.PHONY: build-client +build-client: + docker build client -t $(DOCKER_TAG)-client + +.PHONY: build-server +build-server: + docker build server -t $(DOCKER_TAG)-server + +.PHONY: build-arm32v6 +build-arm32v6: build-client-arm32v6 build-server-arm32v6 + +.PHONY: build-client-arm32v6 +build-client-arm32v6: + docker build client --build-arg REPO=arm32v6 --build-arg GOARCH=arm -t $(DOCKER_TAG)-client-arm32v6 + +.PHONY: build-server-arm32v6 +build-server-arm32v6: + docker build server --build-arg REPO=arm32v6 -t $(DOCKER_TAG)-server-arm32v6 + +.PHONY: build-arm32v7 +build-arm32v7: build-client-arm32v7 build-server-arm32v7 + +.PHONY: build-client-arm32v7 +build-client-arm32v7: + docker build client --build-arg REPO=arm32v7 --build-arg GOARCH=arm -t $(DOCKER_TAG)-client-arm32v7 + +.PHONY: build-server-arm32v7 +build-server-arm32v7: + docker build server --build-arg REPO=arm32v7 -t $(DOCKER_TAG)-server-arm32v7 + +.PHONY: build-arm64v8 +build-arm64v8: build-client-arm64v8 build-server-arm64v8 + +.PHONY: build-client-arm64v8 +build-client-arm64v8: + docker build client --build-arg REPO=arm64v8 --build-arg GOARCH=arm64 -t $(DOCKER_TAG)-client-arm64v8 + +.PHONY: build-server-arm64v8 +build-server-arm64v8: + docker build server --build-arg REPO=arm64v8 -t $(DOCKER_TAG)-server-arm64v8 + +.PHONY: build-all +build-all: build build-arm32v6 build-arm64v8 diff --git a/client/Dockerfile b/client/Dockerfile index 9cb9f99..d8feefe 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -1,9 +1,32 @@ -FROM alpine +ARG REPO=library +# Build mole for all arch +FROM golang:1.12-alpine AS builder -# Install latest mole -RUN apk --no-cache add bash curl tar openssh-client && \ - bash -c "bash <(curl -fsSL https://raw.githubusercontent.com/davrodpin/mole/master/tools/install.sh | sed 's/\bsudo\b//g')" && \ - apk del curl tar +ENV MOLE_VERSION=0.4.0 + +RUN apk add --no-cache git curl tar + +RUN mkdir /app +RUN curl -L https://github.com/davrodpin/mole/archive/v${MOLE_VERSION}.tar.gz | tar zx -C /app +WORKDIR /app/mole-${MOLE_VERSION} + +# Download dependencies so they can be cached +RUN go mod download + +# Build static +ARG GOARCH=amd64 +ENV CGO_ENABLED=0 GOOS=linux +RUN go build -a -ldflags '-X main.version=${MOLE_VERSION}-dockamole' -installsuffix nocgo -o /bin/mole github.com/davrodpin/mole/cmd/mole + +# Build client image using target arch +FROM ${REPO}/alpine + +# Make multiarch capable +COPY --from=multiarch/qemu-user-static /usr/bin/qemu-* /usr/bin/ +# Copy mole from builder +COPY --from=builder /bin/mole /usr/bin/mole + +RUN apk --no-cache add bash openssh-client RUN mkdir /mole RUN adduser -S -h /mole mole diff --git a/server/Dockerfile b/server/Dockerfile index 68c8062..2b6fdea 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,4 +1,10 @@ -FROM alpine +ARG REPO=library +FROM multiarch/qemu-user-static AS qemu + +# Build image from alpine +FROM ${REPO}/alpine + +COPY --from=qemu /usr/bin/qemu-* /usr/bin/ # Install SSH and set up basic config RUN apk add openssh-server augeas