From 5c2a80330f653056299ae94ea61f712d19e361da Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Thu, 16 Feb 2023 19:38:02 -0800 Subject: [PATCH 1/3] docker: Install playwright dependencies on arm64 Also changed our code to only install chromium. Closes #835 --- ci/release/docker/Dockerfile | 8 ++++---- lib/png/png.go | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ci/release/docker/Dockerfile b/ci/release/docker/Dockerfile index 50f51c21a..e0f4b60e2 100644 --- a/ci/release/docker/Dockerfile +++ b/ci/release/docker/Dockerfile @@ -7,9 +7,9 @@ RUN apt-get update && apt-get install -y ca-certificates curl dumb-init sudo RUN curl -fsSL https://deb.nodesource.com/setup_19.x | bash -s - && \ apt-get install -y nodejs -# https://github.com/microsoft/playwright/issues/18319 -# Hopefully soon. -RUN if [ "$TARGETARCH" = amd64 ]; then npx playwright install-deps; fi +# @next until 1.31 for arm64 debian support. +# See https://github.com/microsoft/playwright/issues/18319 +RUN npx playwright@next install-deps chromium RUN adduser --gecos '' --disabled-password debian \ && echo "debian ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd @@ -28,7 +28,7 @@ RUN mkdir -p /usr/local/lib/d2 \ && rm -Rf /tmp/d2-*-linux-"$TARGETARCH".tar.gz USER debian:debian -RUN if [ "$TARGETARCH" = amd64 ]; then d2 init-playwright; fi +RUN d2 init-playwright WORKDIR /home/debian/src EXPOSE 8080 diff --git a/lib/png/png.go b/lib/png/png.go index 80d4a51e1..382737cf7 100644 --- a/lib/png/png.go +++ b/lib/png/png.go @@ -56,7 +56,10 @@ func startPlaywright(pw *playwright.Playwright) (Playwright, error) { } func InitPlaywright() (Playwright, error) { - err := playwright.Install(&playwright.RunOptions{Verbose: false}) + err := playwright.Install(&playwright.RunOptions{ + Verbose: false, + Browsers: []string{"chromium"}, + }) if err != nil { return Playwright{}, fmt.Errorf("failed to install Playwright: %w", err) } From 79eac4290559baf35e2db2f60ed5aac7f85bc589 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 27 Feb 2023 11:22:43 -0800 Subject: [PATCH 2/3] docker: Build cross platform release image natively Playwright deps don't install when running under QEMU. --- ci/release/aws/ensure.sh | 23 +++++++++++++++++++---- ci/release/build.sh | 8 ++++---- ci/release/docker/Dockerfile | 3 +-- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ci/release/aws/ensure.sh b/ci/release/aws/ensure.sh index d941273fa..06d782ec5 100755 --- a/ci/release/aws/ensure.sh +++ b/ci/release/aws/ensure.sh @@ -332,10 +332,25 @@ sudo groupadd docker || true sudo usermod -aG docker \$USER printf %s '$CI_DOCKER_TOKEN' | docker login -u terrastruct --password-stdin -# For building images cross platform. -sudo -E apt-get install -y qemu qemu-user-static -if docker buildx ls | grep -q 'default \*'; then - docker buildx create --use + +# For building images cross platform from the arm64 instance. +# We could use QEMU with: +# sudo -E apt-get install -y qemu qemu-user-static +# But we don't as playwright dependencies do not install on QEMU on either arm64 or amd64. +if [ "\$(uname -m)" = aarch64 ]; then + if [ "\$(stat -c '%a' ~/.ssh/id_ed25519 2>/dev/null)" != 600 ]; then + echo '$CI_TSTRUCT_ID_ED25519' >~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + fi + if ! docker context ls | grep -qF ci-d2-linux-amd64; then + docker context create ci-d2-linux-amd64 --docker "host=ssh://$CI_D2_LINUX_AMD64" + fi + if ! docker buildx ls | grep -qF 'd2 *'; then + docker buildx create --use --name d2 default + fi + if ! docker buildx inspect d2 | grep -qF ci-d2-linux-amd64; then + docker buildx create --append --name d2 ci-d2-linux-amd64 + fi fi mkdir -p \$HOME/.local/bin diff --git a/ci/release/build.sh b/ci/release/build.sh index 63122b379..e77cfd138 100755 --- a/ci/release/build.sh +++ b/ci/release/build.sh @@ -263,12 +263,12 @@ build_docker() { return 0 fi - sh_c lockfile_ssh "$CI_D2_LINUX_AMD64" .d2-build-lock - sh_c gitsync "$CI_D2_LINUX_AMD64" src/d2 + sh_c lockfile_ssh "$CI_D2_LINUX_ARM64" .d2-build-lock + sh_c gitsync "$CI_D2_LINUX_ARM64" src/d2 sh_c rsync --archive --human-readable \ "$BUILD_DIR/d2-$VERSION"-linux-*.tar.gz \ - "$CI_D2_LINUX_AMD64:src/d2/$BUILD_DIR/" - sh_c ssh "$CI_D2_LINUX_AMD64" \ + "$CI_D2_LINUX_ARM64:src/d2/$BUILD_DIR/" + sh_c ssh "$CI_D2_LINUX_ARM64" \ "D2_DOCKER_IMAGE=${D2_DOCKER_IMAGE-}" \ "RELEASE=${RELEASE-}" \ ./src/d2/ci/release/docker/build.sh \ diff --git a/ci/release/docker/Dockerfile b/ci/release/docker/Dockerfile index e0f4b60e2..33acac831 100644 --- a/ci/release/docker/Dockerfile +++ b/ci/release/docker/Dockerfile @@ -7,9 +7,8 @@ RUN apt-get update && apt-get install -y ca-certificates curl dumb-init sudo RUN curl -fsSL https://deb.nodesource.com/setup_19.x | bash -s - && \ apt-get install -y nodejs -# @next until 1.31 for arm64 debian support. # See https://github.com/microsoft/playwright/issues/18319 -RUN npx playwright@next install-deps chromium +RUN npx playwright@1.31.1 install-deps chromium RUN adduser --gecos '' --disabled-password debian \ && echo "debian ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd From 25f8361eebcc8c00f8eead84d9840cb9f867f6df Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 27 Feb 2023 11:30:24 -0800 Subject: [PATCH 3/3] changelogs/next.md: Update --- ci/release/changelogs/next.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 3b8b87d42..57e5b1145 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -3,12 +3,14 @@ - PDF exports are now supported. [#120](https://github.com/terrastruct/d2/issues/120) - Diagram background can be styled. [#910](https://github.com/terrastruct/d2/issues/910) - 3D Hexagons are now supported. [#869](https://github.com/terrastruct/d2/issues/869) +- The arm64 docker container now supports rendering diagrams to pngs. [#917](https://github.com/terrastruct/d2/pull/917) #### Improvements 🧹 - `near` key set to sequence diagram children get an appropriate error message. [#899](https://github.com/terrastruct/d2/issues/899) - `class` and `sql_table` shape respect `font-color` styling as header font color. [#899](https://github.com/terrastruct/d2/issues/899) - SVG fits to screen by default in both watch mode and as a standalone SVG (this time with just CSS, no JS). [#725](https://github.com/terrastruct/d2/issues/725) +- Only chromium is installed when rendering png diagrams instead of also installing webkit and firefox. [#835](https://github.com/terrastruct/d2/issues/835) #### Bugfixes ⛑️