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

Build arm64 main image #1487

Merged
merged 26 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0ee1bf9
Build arm64 version of Kroki main image
felixvanoost Mar 22, 2023
91bbe9a
Map target architecture for Rust
felixvanoost Mar 25, 2023
595d89b
Update Rust arm64 mapping
felixvanoost Mar 25, 2023
384a213
Attempt to build only arm64 image for debugging
felixvanoost Mar 25, 2023
66900cf
Attempt to use Cargo sparse registry
felixvanoost Mar 26, 2023
2b41133
Don't specify architecture for SVGBob
felixvanoost Mar 26, 2023
a161e3a
Restrict number of sockets for npm
felixvanoost Mar 26, 2023
458baa3
Build images for native architecture by default
felixvanoost Apr 1, 2023
a649590
Attempt to build multi-arch containers in nightly CI workflow
felixvanoost Apr 1, 2023
2ed0c35
Fix path issue
felixvanoost Apr 1, 2023
0b115ea
Specify images to run smoke tests on
felixvanoost Apr 1, 2023
1f58029
Test multi-arch builds for debugging
felixvanoost Apr 1, 2023
b3fd2ce
Restrict npm to 2 concurrent sockets
felixvanoost Apr 1, 2023
4d04c00
Set Vega tests timeout to 15s
felixvanoost Apr 2, 2023
3563f14
Prune images in between builds
felixvanoost Apr 5, 2023
3be18f4
Merge branch 'yuzutech:main' into build-arm64-main-image
felixvanoost Apr 6, 2023
f2ea43e
Restrict buildx parallelism to 2
felixvanoost Apr 6, 2023
ec8ffba
Don't prune images after building
felixvanoost Apr 6, 2023
8de9820
Free up runner disk space before workflows
felixvanoost Apr 6, 2023
7f4ad6f
Clean up redundant function calls
felixvanoost Apr 6, 2023
6a2f010
FINALLY
felixvanoost Apr 7, 2023
bc3328a
Cross-compile when possible
felixvanoost Apr 12, 2023
7fa3903
Add condition to skip actions when build_multiarch is not enabled
ggrossetie Apr 16, 2023
dcacbd4
Add a default value to setup buildx
ggrossetie Apr 16, 2023
0e74dd8
Global input with a default value
ggrossetie Apr 16, 2023
8784264
Simplify syntax
ggrossetie Apr 16, 2023
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
27 changes: 27 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,28 @@ on:
- 'docs/**'
branches:
- '*'
workflow_call:
inputs:
build_multiarch:
default: 'false'
required: true
type: boolean

jobs:
test-containers:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3

- name: Free up disk space
if: ${{ inputs.build_multiarch }}
uses: jlumbroso/free-disk-space@main
with:
android: true
dotnet: true
haskell: true
large-packages: true
swap-storage: true

- name: Set up JDK 11
uses: actions/setup-java@v3
Expand All @@ -31,11 +47,21 @@ jobs:
run: make buildServer

- name: Set up QEMU
if: ${{ inputs.build_multiarch }}
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
if: ${{ !inputs.build_multiarch }}
uses: docker/setup-buildx-action@v2

- name: Set up Docker Buildx
if: ${{ inputs.build_multiarch }}
uses: docker/setup-buildx-action@v2
with:
config-inline: |
[worker.oci]
max-parallelism = 2

- name: Cache Docker layers
uses: actions/cache@v3
with:
Expand All @@ -47,6 +73,7 @@ jobs:
- name: Build container images
run: make buildDockerImages
env:
BUILD_MULTIARCH: ${{ inputs.build_multiarch }}
CACHE_FROM: 'type=local,src=/tmp/.buildx-cache'
CACHE_TO: 'type=local,dest=/tmp/.buildx-cache-new'

Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: CI (nightly)

on:
schedule:
- cron: '0 2 * * *'

jobs:
test-containers-multiarch:
uses: ./.github/workflows/main.yaml
with:
build_multiarch: true
12 changes: 5 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MULTI_ARCH_AVAILABLE := $(shell docker buildx inspect | grep amd64 | grep arm64 > /dev/null 2>&1; echo $$?)

TESTS_DIR=ci/tests
COMPOSE_TIMEOUT=20
SERVICES_TIMEOUT=15
Expand All @@ -19,20 +17,20 @@ endif
mvn versions:set -DnewVersion=$(RELEASE_VERSION)

buildDockerImages:
ifeq ($(MULTI_ARCH_AVAILABLE), 0)
docker buildx bake --set "*.cache-from=$(CACHE_FROM)" --set "*.cache-to=$(CACHE_TO)" --set "kroki-*.platform=linux/arm64,linux/amd64"
ifdef BUILD_MULTIARCH
docker buildx bake kroki companion-images --set "*.cache-from=$(CACHE_FROM)" --set "*.cache-to=$(CACHE_TO)" --set "*.platform=linux/arm64,linux/amd64"
else
docker buildx bake --set "*.cache-from=$(CACHE_FROM)" --set "*.cache-to=$(CACHE_TO)"
docker buildx bake kroki companion-images --set "*.cache-from=$(CACHE_FROM)" --set "*.cache-to=$(CACHE_TO)"
endif

publishDockerImages:
ifndef RELEASE_VERSION
$(error RELEASE_VERSION is undefined)
endif
docker buildx bake -f docker-bake.hcl -f docker-bake-release.hcl --push --set "kroki-*.platform=linux/arm64,linux/amd64"
docker buildx bake -f docker-bake.hcl -f docker-bake-release.hcl kroki companion-images --push --set "*.platform=linux/arm64,linux/amd64"

smokeTests:
TAG=smoketests docker buildx bake --load --set "*.cache-from=$(CACHE_FROM)" --set "*.cache-to=$(CACHE_TO)"
TAG=smoketests docker buildx bake kroki companion-images --load --set "*.cache-from=$(CACHE_FROM)" --set "*.cache-to=$(CACHE_TO)"
@docker-compose --file "$(TESTS_DIR)/docker-compose.yaml" up --build --detach \
&& echo \
&& docker-compose --file "$(TESTS_DIR)/docker-compose.yaml" ps \
Expand Down
4 changes: 2 additions & 2 deletions bpmn/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Package the Node.js project into a single binary
FROM --platform=${TARGETPLATFORM:-linux/amd64} node:16.18.1-alpine3.16 as builder
FROM --platform=$BUILDPLATFORM node:16.18.1-alpine3.16 as builder

# Workaround: https://github.com/nodejs/docker-node/issues/813#issuecomment-407339011
# Error: could not get uid/gid
Expand All @@ -22,7 +22,7 @@ RUN npm run lint
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM}-$([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH") . -o app.bin

# Create the image
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.16.3
FROM alpine:3.16.3

RUN addgroup -g 1000 kroki && adduser -D -G kroki -u 1000 kroki

Expand Down
4 changes: 2 additions & 2 deletions diagrams.net/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Package the Node.js project into a single binary
FROM --platform=${TARGETPLATFORM:-linux/amd64} node:16.18.1-alpine3.16 as builder
FROM --platform=$BUILDPLATFORM node:16.18.1-alpine3.16 as builder

# Workaround: https://github.com/nodejs/docker-node/issues/813#issuecomment-407339011
# Error: could not get uid/gid
Expand All @@ -22,7 +22,7 @@ RUN npm run lint
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM}-$([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH") . -o app.bin

# Create the image
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.16.3
FROM alpine:3.16.3

RUN addgroup -g 1000 kroki && adduser -D -G kroki -u 1000 kroki

Expand Down
4 changes: 2 additions & 2 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ variable "TAG" {
default = "latest"
}

group "default" {
targets = ["kroki", "kroki-blockdiag", "kroki-mermaid", "kroki-bpmn", "kroki-excalidraw", "kroki-diagramsnet", "kroki-wireviz"]
group "companion-images" {
targets = ["kroki-blockdiag", "kroki-mermaid", "kroki-bpmn", "kroki-excalidraw", "kroki-diagramsnet", "kroki-wireviz"]
}

target "kroki" {
Expand Down
4 changes: 2 additions & 2 deletions excalidraw/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Package the Node.js project into a single binary
FROM --platform=${TARGETPLATFORM:-linux/amd64} node:16.18.1-alpine3.16 as builder
FROM --platform=$BUILDPLATFORM node:16.18.1-alpine3.16 as builder

# Workaround: https://github.com/nodejs/docker-node/issues/813#issuecomment-407339011
# Error: could not get uid/gid
Expand All @@ -24,7 +24,7 @@ RUN npm run prestart
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM}-$([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH") . -o app.bin

# Create the image
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.16.3
FROM alpine:3.16.3

RUN addgroup -g 1000 kroki && adduser -D -G kroki -u 1000 kroki

Expand Down
2 changes: 1 addition & 1 deletion mermaid/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=${TARGETPLATFORM:-linux/amd64} node:16.18-alpine3.16
FROM node:16.18-alpine3.16

RUN addgroup -g 1001 kroki && adduser -D -G kroki -u 1001 kroki

Expand Down
5 changes: 5 additions & 0 deletions server/ops/docker/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"

[target.x86_64-unknown-linux-gnu]
linker = "x86_64-linux-gnu-gcc"
107 changes: 66 additions & 41 deletions server/ops/docker/jdk11-jammy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1.4

## TikZ
FROM ubuntu:jammy AS kroki-builder-dvisvgm
FROM --platform=$BUILDPLATFORM ubuntu:jammy AS kroki-builder-dvisvgm

RUN apt-get update && apt-get install --no-install-recommends --yes \
build-essential \
Expand All @@ -17,40 +17,50 @@ RUN apt-get update && apt-get install --no-install-recommends --yes \

ARG DVISVGM_VERSION=3.0.4

RUN \
curl -LO https://github.com/mgieseki/dvisvgm/releases/download/$DVISVGM_VERSION/dvisvgm-$DVISVGM_VERSION.tar.gz \
&& tar xf dvisvgm-$DVISVGM_VERSION.tar.gz \
&& cd dvisvgm-$DVISVGM_VERSION \
&& ./configure --enable-bundled-libs \
&& make \
&& make install
ARG BUILDARCH
ARG TARGETARCH
RUN curl -LO https://github.com/mgieseki/dvisvgm/releases/download/$DVISVGM_VERSION/dvisvgm-$DVISVGM_VERSION.tar.gz && \
tar xf dvisvgm-$DVISVGM_VERSION.tar.gz && \
cd dvisvgm-$DVISVGM_VERSION && \
case $BUILDARCH in \
"amd64") MAKE_BUILD_ARCH=x86_64 ;; \
"arm64") MAKE_BUILD_ARCH=aarch64 ;; \
*) MAKE_BUILD_ARCH=$TARGETARCH ;; \
esac && \
case $TARGETARCH in \
"amd64") MAKE_TARGET_ARCH=x86_64 ;; \
"arm64") MAKE_TARGET_ARCH=aarch64 ;; \
*) MAKE_TARGET_ARCH=$TARGETARCH ;; \
esac && \
./configure --enable-bundled-libs --build $MAKE_BUILD_ARCH-linux-gnu --host $MAKE_TARGET_ARCH-linux-gnu && \
make && \
make install

## D2
FROM golang:1.19.3-bullseye AS kroki-builder-d2
COPY ops/docker/go.mod .

RUN D2_VERSION=`cat go.mod | grep "oss.terrastruct.com/d2" | cut -d' ' -f3` \
&& rm go.mod \
&& go install "oss.terrastruct.com/d2@${D2_VERSION}"
RUN D2_VERSION=`cat go.mod | grep "oss.terrastruct.com/d2" | cut -d' ' -f3` && \
rm go.mod && \
go install "oss.terrastruct.com/d2@${D2_VERSION}"

## Nomnoml
FROM node:16.18.1-bullseye-slim AS kroki-builder-nomnoml
FROM --platform=$BUILDPLATFORM node:16.18.1-bullseye-slim AS kroki-builder-nomnoml

RUN npm install -g [email protected] [email protected]

ENV NODE node16
ENV PLATFORM linux
RUN /usr/local/bin/pkg-fetch -n ${NODE} -p ${PLATFORM}
RUN /usr/local/bin/pkg-fetch -n ${NODE} -p ${PLATFORM} -a $([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH")

COPY --from=nomnoml index.js package.json package-lock.json /app/
WORKDIR /app

RUN npm i
RUN npm run lint
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM} . -o app.bin
RUN npm install && npm run lint
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM}-$([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH") . -o app.bin

## Vega
FROM node:16.18.1-bullseye-slim AS kroki-builder-vega
FROM --platform=$BUILDPLATFORM node:16.18.1-bullseye-slim AS kroki-builder-vega

# System dependencies for "canvas" Node package
# https://github.com/Automattic/node-canvas#compiling
Expand All @@ -67,65 +77,62 @@ RUN npm install -g [email protected] [email protected]

ENV NODE node16
ENV PLATFORM linux
RUN /usr/local/bin/pkg-fetch -n ${NODE} -p ${PLATFORM}
RUN /usr/local/bin/pkg-fetch -n ${NODE} -p ${PLATFORM} -a $([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH")

COPY --from=vega src /app/src
COPY --from=vega tests /app/tests
COPY --from=vega package.json package-lock.json /app/
WORKDIR /app

RUN npm i
RUN npm run lint && npm t
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM} . -o app.bin
RUN npm install 2 && npm run lint && npm t
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM}-$([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH") . -o app.bin

## DBML
FROM node:16.18.1-bullseye-slim AS kroki-builder-dbml
FROM --platform=$BUILDPLATFORM node:16.18.1-bullseye-slim AS kroki-builder-dbml

RUN npm config set unsafe-perm true

RUN npm install -g [email protected] [email protected]

ENV NODE node16
ENV PLATFORM linux
RUN /usr/local/bin/pkg-fetch -n ${NODE} -p ${PLATFORM}
RUN /usr/local/bin/pkg-fetch -n ${NODE} -p ${PLATFORM} -a $([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH")

COPY --from=dbml index.js package.json package-lock.json /app/
WORKDIR /app

RUN npm i
RUN npm run lint
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM} . -o app.bin
RUN npm install && npm run lint
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM}-$([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH") . -o app.bin

## Wavedrom
FROM node:16.18.1-bullseye-slim AS kroki-builder-wavedrom
FROM --platform=$BUILDPLATFORM node:16.18.1-bullseye-slim AS kroki-builder-wavedrom

RUN npm install -g [email protected] [email protected]

ENV NODE node16
ENV PLATFORM linux
RUN /usr/local/bin/pkg-fetch -n ${NODE} -p ${PLATFORM}
RUN /usr/local/bin/pkg-fetch -n ${NODE} -p ${PLATFORM} -a $([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH")

COPY --from=wavedrom index.js package.json package-lock.json /app/
WORKDIR /app

RUN npm i
RUN npm run lint
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM} . -o app.bin
RUN npm install && npm run lint
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM}-$([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH") . -o app.bin

## Bytefield
FROM node:16.18.1-bullseye-slim AS kroki-builder-bytefield
FROM --platform=$BUILDPLATFORM node:16.18.1-bullseye-slim AS kroki-builder-bytefield

RUN npm install -g [email protected] [email protected]

ENV NODE node16
ENV PLATFORM linux
RUN /usr/local/bin/pkg-fetch -n ${NODE} -p ${PLATFORM}
RUN /usr/local/bin/pkg-fetch -n ${NODE} -p ${PLATFORM} -a $([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH")

COPY --from=bytefield index.js package.json package-lock.json /app/
WORKDIR /app

RUN npm i
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM} . -o app.bin
RUN npm install
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM}-$([ "$TARGETARCH" == "amd64" ] && echo "x64" || echo "$TARGETARCH") . -o app.bin

## ERD
# use a pre-built image to reduce build time
Expand Down Expand Up @@ -170,12 +177,29 @@ RUN wget -q "https://pikchr.org/home/raw/${PIKCHR_VERSION}" -O pikchr.c
RUN gcc -O0 -g -static -Wall -Wextra -DPIKCHR_SHELL pikchr.c -o pikchr -lm

## SVGBob
FROM rust:1.65-slim-bullseye AS kroki-builder-static-svgbob
RUN rustup target add x86_64-unknown-linux-musl
COPY ops/docker/Cargo.toml .
FROM --platform=$BUILDPLATFORM rust:1.68-slim-bullseye AS kroki-builder-static-svgbob

# Install cross-compilation tools
RUN apt-get update && apt-get install --no-install-recommends --yes \
gcc-aarch64-linux-gnu \
gcc-x86-64-linux-gnu \
libc6-dev-amd64-cross \
libc6-dev-arm64-cross && \
apt-get clean && apt-get autoremove

RUN SVGBOB_VERSION=`cat Cargo.toml | grep "svgbob_cli =" | sed -r 's/.*"([^"]+)"/\1/'` \
&& cargo install --quiet --target x86_64-unknown-linux-musl --version $SVGBOB_VERSION svgbob_cli
COPY ops/docker/Cargo.toml .
COPY ops/docker/.cargo .cargo

ARG TARGETARCH
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
RUN SVGBOB_VERSION=`cat Cargo.toml | grep "svgbob_cli =" | sed -r 's/.*"([^"]+)"/\1/'` && \
case $TARGETARCH in \
"amd64") RUST_TARGET_ARCH=x86_64 ;; \
"arm64") RUST_TARGET_ARCH=aarch64 ;; \
*) RUST_TARGET_ARCH=$TARGETARCH ;; \
esac && \
rustup target add $RUST_TARGET_ARCH-unknown-linux-gnu && \
cargo install --quiet --target $RUST_TARGET_ARCH-unknown-linux-gnu --version $SVGBOB_VERSION svgbob_cli

## UMlet
# use a pre-built image to reduce build time
Expand Down Expand Up @@ -226,7 +250,8 @@ RUN apt-get update && apt-get install --no-install-recommends --yes \
texlive-latex-extra \
texlive-pictures \
texlive-pstricks \
texlive-science
texlive-science && \
apt-get clean && apt-get autoremove

COPY --chown=kroki:kroki ops/docker/logback.xml /etc/kroki/logback.xml

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public void should_call_vega_with_correct_arguments() throws Throwable {
assertThat(buffer.toString()).isEqualTo("<svg>vega</svg>");
testContext.completeNow();
})));
// wait at most 2000ms
assertThat(testContext.awaitCompletion(2, TimeUnit.SECONDS)).isTrue();
// wait at most 4000ms
assertThat(testContext.awaitCompletion(4, TimeUnit.SECONDS)).isTrue();
if (testContext.failed()) {
throw testContext.causeOfFailure();
}
Expand All @@ -55,8 +55,8 @@ public void should_call_vega_lite_with_correct_arguments() throws Throwable {
assertThat(buffer.toString()).isEqualTo("<svg>vega-lite</svg>");
testContext.completeNow();
})));
// wait at most 2000ms
assertThat(testContext.awaitCompletion(2, TimeUnit.SECONDS)).isTrue();
// wait at most 4000ms
assertThat(testContext.awaitCompletion(4, TimeUnit.SECONDS)).isTrue();
if (testContext.failed()) {
throw testContext.causeOfFailure();
}
Expand Down
Loading