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

fix: Add support for multi platform image builds in docker #897

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# syntax=docker/dockerfile:1
ARG GOLANG_VER=1.21
FROM golang:${GOLANG_VER}-alpine AS build

# See https://cloud.docker.com/repository/docker/jdkato/vale
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS build

# TODO: DITA / XML:
# openjdk11 \
Expand All @@ -18,9 +21,8 @@ WORKDIR /app
ENV CGO_ENABLED=1

ARG ltag
ARG TARGETOS TARGETARCH

RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags "-s -w -X main.version=$ltag" -o /app/vale ./cmd/vale
RUN go build -ldflags "-s -w -X main.version=$ltag" -o /app/vale ./cmd/vale

FROM alpine

Expand Down
34 changes: 23 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ GOLANG_CROSS_VERSION ?= v0.2.0
SYSROOT_DIR ?= sysroots
SYSROOT_ARCHIVE ?= sysroots.tar.bz2

LAST_TAG=$(shell git describe --abbrev=0 --tags)
CURR_SHA=$(shell git rev-parse --verify HEAD)
LAST_TAG := $(shell git describe --abbrev=0 --tags)
CURR_SHA := $(shell git rev-parse --verify HEAD)

LDFLAGS=-ldflags "-s -w -X main.version=$(LAST_TAG)"
LDFLAGS := -ldflags "-s -w -X main.version=$(LAST_TAG)"

DOCKER_BUILD_TARGETS := linux/arm64,linux/amd64
DOCKER_USER ?= jdkato

.PHONY: data test lint install rules setup bench compare release choco-cross

Expand Down Expand Up @@ -53,15 +56,24 @@ test:
cd testdata && cucumber --format progress && cd -

docker:
docker login -u jdkato -p ${DOCKER_PASS}
@echo ${DOCKER_PASS} | docker login -u ${DOCKER_USER} --password-stdin

# Ignore command failure
-docker buildx create \
--name container-builder \
--driver docker-container \
--use --bootstrap

docker buildx build \
--build-arg ltag=${LAST_TAG} \
--platform=linux/amd64 \
--file Dockerfile \
--tag jdkato/vale:${LAST_TAG} \
--tag jdkato/vale:latest \
--push \
.
--build-arg ltag=${LAST_TAG} \
--platform=${DOCKER_BUILD_TARGETS} \
--file Dockerfile \
--tag ${DOCKER_USER}/vale:${LAST_TAG} \
--tag ${DOCKER_USER}/vale:latest \
--push \
.

docker buildx rm container-builder #Tidy up

choco-cross:
@docker run \
Expand Down