From 29aae679453fcfec67f85f99d3a0bffc48ebcbb6 Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Tue, 18 Jul 2023 18:32:34 -0700 Subject: [PATCH] Add ability to override default layout in Docker image (#6400) **User-Facing Changes** The Docker image now supports specifying a default layout via bind mount (`-v /path/to/custom_layout.json:/foxglove/default-layout.json`). **Description** Relates to: #4716, https://github.com/orgs/foxglove/discussions/217 Resolves FG-3318 --- .dockerignore | 1 + Dockerfile | 15 ++++ README.md | 8 ++ .../CurrentLayoutProvider/defaultLayout.ts | 76 ++++++++++--------- packages/studio-web/src/webpackConfigs.ts | 1 + 5 files changed, 67 insertions(+), 34 deletions(-) diff --git a/.dockerignore b/.dockerignore index d2e4938104..a80b92784b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,3 +4,4 @@ .webpack/ dist/ node_modules/ +Dockerfile diff --git a/Dockerfile b/Dockerfile index b378f2cfce..00212f5b66 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,19 @@ WORKDIR /src COPY --from=build /src/web/.webpack ./ EXPOSE 8080 + +COPY < index.html + +# Continue executing the CMD +exec "\$@" +EOF + +ENTRYPOINT ["/bin/sh", "/entrypoint.sh"] CMD ["caddy", "file-server", "--listen", ":8080"] diff --git a/README.md b/README.md index fe2e898709..d4a75d9ca3 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,14 @@ docker run --rm -p "8080:8080" ghcr.io/foxglove/studio:latest Foxglove Studio will be accessible in your browser at [localhost:8080](http://localhost:8080/). +### Overriding the default layout + +[Bind-mount](https://docs.docker.com/storage/bind-mounts/) a layout JSON file at `/foxglove/default-layout.json` to set the default layout used when loading Studio from the Docker image. + +```sh +docker run --rm -p "8080:8080" -v /path/to/custom_layout.json:/foxglove/default-layout.json ghcr.io/foxglove/studio:latest +``` + ## Contributing Foxglove Studio is written in TypeScript – contributions are welcome! diff --git a/packages/studio-base/src/providers/CurrentLayoutProvider/defaultLayout.ts b/packages/studio-base/src/providers/CurrentLayoutProvider/defaultLayout.ts index dcd33c2832..c9856c3ba9 100644 --- a/packages/studio-base/src/providers/CurrentLayoutProvider/defaultLayout.ts +++ b/packages/studio-base/src/providers/CurrentLayoutProvider/defaultLayout.ts @@ -5,45 +5,53 @@ import { LayoutData } from "@foxglove/studio-base/context/CurrentLayoutContext/actions"; import { defaultPlaybackConfig } from "@foxglove/studio-base/providers/CurrentLayoutProvider/reducers"; +/** + * Overridden default layout that may have been provided when self-hosting via Docker + * */ +const staticDefaultLayout = (globalThis as { FOXGLOVE_STUDIO_DEFAULT_LAYOUT?: LayoutData }) + .FOXGLOVE_STUDIO_DEFAULT_LAYOUT; + /** * This is loaded when the user has no layout selected on application launch * to avoid presenting the user with a blank layout. */ -export const defaultLayout: LayoutData = { - configById: { - "3D!18i6zy7": { - layers: { - "845139cb-26bc-40b3-8161-8ab60af4baf5": { - visible: true, - frameLocked: true, - label: "Grid", - instanceId: "845139cb-26bc-40b3-8161-8ab60af4baf5", - layerId: "foxglove.Grid", - size: 10, - divisions: 10, - lineWidth: 1, - color: "#248eff", - position: [0, 0, 0], - rotation: [0, 0, 0], - order: 1, +export const defaultLayout: LayoutData = + staticDefaultLayout ?? + ({ + configById: { + "3D!18i6zy7": { + layers: { + "845139cb-26bc-40b3-8161-8ab60af4baf5": { + visible: true, + frameLocked: true, + label: "Grid", + instanceId: "845139cb-26bc-40b3-8161-8ab60af4baf5", + layerId: "foxglove.Grid", + size: 10, + divisions: 10, + lineWidth: 1, + color: "#248eff", + position: [0, 0, 0], + rotation: [0, 0, 0], + order: 1, + }, }, }, + "RawMessages!os6rgs": {}, + "Image!3mnp456": {}, }, - "RawMessages!os6rgs": {}, - "Image!3mnp456": {}, - }, - globalVariables: {}, - userNodes: {}, - playbackConfig: { ...defaultPlaybackConfig }, - layout: { - first: "3D!18i6zy7", - second: { - first: "Image!3mnp456", - second: "RawMessages!os6rgs", - direction: "column", - splitPercentage: 30, + globalVariables: {}, + userNodes: {}, + playbackConfig: { ...defaultPlaybackConfig }, + layout: { + first: "3D!18i6zy7", + second: { + first: "Image!3mnp456", + second: "RawMessages!os6rgs", + direction: "column", + splitPercentage: 30, + }, + direction: "row", + splitPercentage: 70, }, - direction: "row", - splitPercentage: 70, - }, -} as const; + } as const); diff --git a/packages/studio-web/src/webpackConfigs.ts b/packages/studio-web/src/webpackConfigs.ts index 4c8af5be74..ca8e0669f6 100644 --- a/packages/studio-web/src/webpackConfigs.ts +++ b/packages/studio-web/src/webpackConfigs.ts @@ -136,6 +136,7 @@ export const mainConfig =