From f701e9859d9bab62595726a110290c0cab307465 Mon Sep 17 00:00:00 2001 From: John Hollowell Date: Tue, 5 Sep 2023 21:49:17 +0000 Subject: [PATCH 1/2] Add devcontainer --- .devcontainer/Dockerfile | 9 +++++++++ .devcontainer/devcontainer.json | 14 ++++++++++++++ .devcontainer/setup.sh | 7 +++++++ 3 files changed, 30 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100755 .devcontainer/setup.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..769ba7e --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,9 @@ +ARG VARIANT=1 +FROM mcr.microsoft.com/devcontainers/go:${VARIANT} + +RUN apt-get update && apt-get install -y --no-install-recommends \ + libegl1-mesa-dev \ + libgles2-mesa-dev \ + libx11-dev \ + xvfb \ + && rm -rf /var/lib/apt/lists/* diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..70f8985 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,14 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/go +{ + "name": "golang.design: clipboard", + "build": { + "dockerfile": "Dockerfile", + "args": { + "VARIANT": "1.21-bookworm" + } + }, + // Install dependencies and other setup tasks + "postCreateCommand": ".devcontainer/setup.sh", + "remoteUser": "vscode" +} diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh new file mode 100755 index 0000000..f553ae3 --- /dev/null +++ b/.devcontainer/setup.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# install module dependencies +go get + +# install clipboard +go install golang.design/x/clipboard/cmd/gclip@latest From 8de45064939d9fcf57b8481d987c85e60bc41b17 Mon Sep 17 00:00:00 2001 From: John Hollowell Date: Thu, 7 Sep 2023 22:11:53 +0000 Subject: [PATCH 2/2] Add support for devcontainer environments without default display If the devcontainer is running on a headless system, there is no DISPLAY to pass into the container. This change adds a virtual display/framebuffer for X11 to use to associate with the clipboard --- .devcontainer/Dockerfile | 8 ++++++++ .devcontainer/devcontainer.json | 3 +++ .devcontainer/docker-entrypoint.sh | 12 ++++++++++++ 3 files changed, 23 insertions(+) create mode 100755 .devcontainer/docker-entrypoint.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 769ba7e..bf2488f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -7,3 +7,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libx11-dev \ xvfb \ && rm -rf /var/lib/apt/lists/* + +# run virtual display init on start of the container +COPY .devcontainer/docker-entrypoint.sh / +RUN chmod +x /docker-entrypoint.sh +ENTRYPOINT [ "/docker-entrypoint.sh" ] + +# keep the container running since the devcontainer will start its own processes +CMD [ "sleep", "infinity" ] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 70f8985..53951da 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,6 +3,7 @@ { "name": "golang.design: clipboard", "build": { + "context": "..", "dockerfile": "Dockerfile", "args": { "VARIANT": "1.21-bookworm" @@ -10,5 +11,7 @@ }, // Install dependencies and other setup tasks "postCreateCommand": ".devcontainer/setup.sh", + // Allow the Dockerfile's command to run (creates virtual display for X11 to support clipboard) + "overrideCommand": false, "remoteUser": "vscode" } diff --git a/.devcontainer/docker-entrypoint.sh b/.devcontainer/docker-entrypoint.sh new file mode 100755 index 0000000..60d5a1c --- /dev/null +++ b/.devcontainer/docker-entrypoint.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +echo "Running docker-entrypoint.sh" + +# create a virtual frame buffer for X11 +nohup Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & + +export DISPLAY=:99.0 +echo "export DISPLAY=:99.0" > /etc/profile.d/01-export-virtual-display.sh +chmod +x /etc/profile.d/01-export-virtual-display.sh + +exec "$@"