ci: Build and push official Dockerfile

Closes #76
This commit is contained in:
Anmol Sethi 2022-12-15 22:49:26 -08:00
parent c03ead091d
commit 6fe4af1105
No known key found for this signature in database
GPG key ID: 25BC68888A99A8BA
7 changed files with 81 additions and 29 deletions

18
ci/release/Dockerfile Normal file
View file

@ -0,0 +1,18 @@
# https://hub.docker.com/repository/docker/terrastruct/d2
FROM debian:latest
ARG TARGETARCH
COPY ./d2-*-linux-$TARGETARCH.tar.gz /tmp
RUN mkdir -p /usr/local/lib/d2 \
&& tar -C /usr/local/lib/d2 -xzf /tmp/d2-*-linux-"$TARGETARCH".tar.gz \
&& /usr/local/lib/d2/d2-*/scripts/install.sh \
&& rm -Rf /tmp/d2-*-linux-"$TARGETARCH".tar.gz
WORKDIR /root/src
EXPOSE 8080
ENV PORT 8080
ENV HOST 0.0.0.0
ENV BROWSER false
ENTRYPOINT ["/usr/local/bin/d2"]

View file

@ -20,11 +20,12 @@ Flags:
changed something and need to force rebuild, use this flag. changed something and need to force rebuild, use this flag.
--local --local
By default build.sh uses \$TSTRUCT_MACOS_AMD64_BUILDER, \$TSTRUCT_MACOS_ARM64_BUILDER, By default build.sh uses \$CI_D2_LINUX_AMD64, \$CI_D2_LINUX_ARM64,
\$TSTRUCT_LINUX_AMD64_BUILDER and \$TSTRUCT_LINUX_ARM64_BUILDER to build the release \$CI_D2_MACOS_AMD64 and \$CI_D2_MACOS_ARM64 to build the release
archives. It's required for now due to the following issue: archives. It's required for now due to the following issue:
https://github.com/terrastruct/d2/issues/31 With --local, build.sh will cross compile https://github.com/terrastruct/d2/issues/31
locally. warning: This is only for testing purposes, do not use in production! With --local, build.sh will cross compile locally. warning: This is only for testing
purposes, do not use in production!
--host-only --host-only
Use to build the release archive for the host OS-ARCH only. All logging is done to stderr Use to build the release archive for the host OS-ARCH only. All logging is done to stderr
@ -45,6 +46,13 @@ Flags:
--uninstall --uninstall
Ensure a release using --host-only and uninstall it. Ensure a release using --host-only and uninstall it.
--push-docker
Push the built docker image. Unfortunately dockerx requires the multi-arch images be
pushed if required in the same invocation as build. dockerx cannot load multi-arch
images into the daemon for push later. It's not slow though to use --push-docker after
building the image as nearly all artifacts are cached.
Automatically set if called from release.sh
EOF EOF
} }
@ -69,7 +77,7 @@ main() {
;; ;;
run) run)
flag_reqarg && shift "$FLAGSHIFT" flag_reqarg && shift "$FLAGSHIFT"
JOBFILTER="$FLAGARG" JOBFILTER=$FLAGARG
;; ;;
host-only) host-only)
flag_noarg && shift "$FLAGSHIFT" flag_noarg && shift "$FLAGSHIFT"
@ -96,6 +104,10 @@ main() {
HOST_ONLY=1 HOST_ONLY=1
LOCAL=1 LOCAL=1
;; ;;
push-docker)
flag_noarg && shift "$FLAGSHIFT"
PUSH_DOCKER=1
;;
*) *)
flag_errusage "unrecognized flag $FLAGRAW" flag_errusage "unrecognized flag $FLAGRAW"
;; ;;
@ -108,10 +120,13 @@ main() {
VERSION=${VERSION:-$(git_describe_ref)} VERSION=${VERSION:-$(git_describe_ref)}
BUILD_DIR=ci/release/build/$VERSION BUILD_DIR=ci/release/build/$VERSION
sh_c mkdir -p "$BUILD_DIR"
sh_c rm -f ci/release/build/latest
sh_c ln -s "$VERSION" ci/release/build/latest
if [ -n "${HOST_ONLY-}" ]; then if [ -n "${HOST_ONLY-}" ]; then
ensure_os ensure_os
ensure_arch ensure_arch
runjob "$OS-$ARCH" "build" runjob "$OS/$ARCH" "build"
if [ -n "${INSTALL-}" ]; then if [ -n "${INSTALL-}" ]; then
sh_c make -sC "ci/release/build/$VERSION/$OS-$ARCH/d2-$VERSION" install sh_c make -sC "ci/release/build/$VERSION/$OS-$ARCH/d2-$VERSION" install
@ -121,13 +136,15 @@ main() {
return 0 return 0
fi fi
runjob linux-amd64 'OS=linux ARCH=amd64 build' & runjob linux/amd64 'OS=linux ARCH=amd64 build' &
runjob linux-arm64 'OS=linux ARCH=arm64 build' & runjob linux/arm64 'OS=linux ARCH=arm64 build' &
runjob macos-amd64 'OS=macos ARCH=amd64 build' & runjob macos/amd64 'OS=macos ARCH=amd64 build' &
runjob macos-arm64 'OS=macos ARCH=arm64 build' & runjob macos/arm64 'OS=macos ARCH=arm64 build' &
runjob windows-amd64 'OS=windows ARCH=amd64 build' & runjob windows/amd64 'OS=windows ARCH=amd64 build' &
runjob windows-arm64 'OS=windows ARCH=arm64 build' & runjob windows/arm64 'OS=windows ARCH=arm64 build' &
waitjobs waitjobs
runjob linux/dockerimage 'build_docker_image'
} }
build() { build() {
@ -148,10 +165,10 @@ build() {
macos) macos)
case $ARCH in case $ARCH in
amd64) amd64)
REMOTE_HOST=$TSTRUCT_MACOS_AMD64_BUILDER build_remote_macos REMOTE_HOST=$CI_D2_MACOS_AMD64 build_remote_macos
;; ;;
arm64) arm64)
REMOTE_HOST=$TSTRUCT_MACOS_ARM64_BUILDER build_remote_macos REMOTE_HOST=$CI_D2_MACOS_ARM64 build_remote_macos
;; ;;
*) *)
warn "no builder for OS=$OS ARCH=$ARCH, building locally..." warn "no builder for OS=$OS ARCH=$ARCH, building locally..."
@ -162,10 +179,10 @@ build() {
linux) linux)
case $ARCH in case $ARCH in
amd64) amd64)
REMOTE_HOST=$TSTRUCT_LINUX_AMD64_BUILDER build_remote_linux REMOTE_HOST=$CI_D2_LINUX_AMD64 build_remote_linux
;; ;;
arm64) arm64)
REMOTE_HOST=$TSTRUCT_LINUX_ARM64_BUILDER build_remote_linux REMOTE_HOST=$CI_D2_LINUX_ARM64 build_remote_linux
;; ;;
*) *)
warn "no builder for OS=$OS ARCH=$ARCH, building locally..." warn "no builder for OS=$OS ARCH=$ARCH, building locally..."
@ -218,13 +235,18 @@ VERSION=$VERSION \
OS=$OS \ OS=$OS \
ARCH=$ARCH \ ARCH=$ARCH \
ARCHIVE=$ARCHIVE \ ARCHIVE=$ARCHIVE \
./src/d2/ci/release/build_docker.sh" ./src/d2/ci/release/build_in_docker.sh"
sh_c mkdir -p "$HW_BUILD_DIR" sh_c mkdir -p "$HW_BUILD_DIR"
sh_c rsync --archive --human-readable "$REMOTE_HOST:src/d2/$ARCHIVE" "$ARCHIVE" sh_c rsync --archive --human-readable "$REMOTE_HOST:src/d2/$ARCHIVE" "$ARCHIVE"
)} )}
ssh() { build_docker_image() {
command ssh -o='StrictHostKeyChecking=accept-new' "$@" D2_DOCKER_IMAGE=${D2_DOCKER_IMAGE:-terrastruct/d2}
flags='--load'
if [ -n "${PUSH_DOCKER-}" -o -n "${RELEASE-}" ]; then
flags='--push --platform linux/amd64,linux/arm64'
fi
sh_c docker buildx build $flags -t "$D2_DOCKER_IMAGE:$VERSION" -t "$D2_DOCKER_IMAGE:latest" --build-arg "VERSION=$VERSION" -f ./ci/release/Dockerfile "./ci/release/build/$VERSION"
} }
main "$@" main "$@"

View file

@ -0,0 +1 @@
**/d2*/

View file

@ -1,8 +1,8 @@
#### Features 🚀 #### Features 🚀
- Diagram padding can now can be configured in the CLI (default 100px). - Diagram padding can now can be configured in the CLI (default 100px). [https://github.com/terrastruct/d2/pull/431](https://github.com/terrastruct/d2/pull/431)
[https://github.com/terrastruct/d2/pull/431](https://github.com/terrastruct/d2/pull/431)
- Connection label backgrounds can now be set with the `style.fill` keyword. [https://github.com/terrastruct/d2/pull/452](https://github.com/terrastruct/d2/pull/452) - Connection label backgrounds can now be set with the `style.fill` keyword. [https://github.com/terrastruct/d2/pull/452](https://github.com/terrastruct/d2/pull/452)
- Add official Docker image. See [./docs/INSTALL.md#docker](./docs/INSTALL.md#docker). [#76](https://github.com/terrastruct/d2/issues/76)
#### Improvements 🧹 #### Improvements 🧹
@ -11,10 +11,7 @@
#### Bugfixes ⛑️ #### Bugfixes ⛑️
- Fixed crash when sequence diagrams had no messages. - Fixed crash when sequence diagrams had no messages. [https://github.com/terrastruct/d2/pull/427](https://github.com/terrastruct/d2/pull/427)
[https://github.com/terrastruct/d2/pull/427](https://github.com/terrastruct/d2/pull/427) - Fixed `constraint` keyword setting label. [https://github.com/terrastruct/d2/issues/415](https://github.com/terrastruct/d2/issues/415)
- Fixed `constraint` keyword setting label. - Fixed serialization affecting binary plugins (TALA). [https://github.com/terrastruct/d2/pull/426](https://github.com/terrastruct/d2/pull/426)
[https://github.com/terrastruct/d2/issues/415](https://github.com/terrastruct/d2/issues/415)
- Fixed serialization affecting binary plugins (TALA).
[https://github.com/terrastruct/d2/pull/426](https://github.com/terrastruct/d2/pull/426)
- Fixed a connection rendering bug that could happen in firefox when there were no connection labels. [https://github.com/terrastruct/d2/pull/453](https://github.com/terrastruct/d2/pull/453) - Fixed a connection rendering bug that could happen in firefox when there were no connection labels. [https://github.com/terrastruct/d2/pull/453](https://github.com/terrastruct/d2/pull/453)

2
ci/sub

@ -1 +1 @@
Subproject commit 2f309fd0e35f323dfaafdd0075cc3da565fa630c Subproject commit 93bb2df10f248a30142a651ec57ca64eb0e82e84

View file

@ -216,9 +216,23 @@ under plain Windows.
aka Windows Subsystem for Linux if that's what you prefer. Installation is just like any aka Windows Subsystem for Linux if that's what you prefer. Installation is just like any
other Linux system. other Linux system.
## Docker
https://hub.docker.com/repository/docker/terrastruct/d2
We publish `amd64` and `arm64` images based on `debian:latest` for each release.
Example usage:
```sh
echo 'x -> y' >helloworld.d2
docker run --rm -it -u "$(id -u):$(id -g)" -v "$PWD:/root/src" \
-p 127.0.0.1:8080:8080 terrastruct/d2 --watch helloworld.d2
# Visit http://127.0.0.1:8080
```
## Coming soon ## Coming soon
- Docker image
- rpm and deb packages - rpm and deb packages
- with repositories and standalone - with repositories and standalone
- homebrew core - homebrew core