From f6da4a1132e98557dc5427240ff02aa645665575 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Tue, 8 Oct 2024 09:50:19 +0000 Subject: [PATCH 1/7] devcontainer added --- .devcontainer/devcontainer.json | 42 +++++++++++++++++++++++++++++++++ Dockerfile | 25 ++++++++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..d911d4a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,42 @@ +// For format details, see https://containers.dev/implementors/json_reference/ +{ + "name": "Java Developer Container", + "build": { + "dockerfile": "../Dockerfile", + "target": "developer" + }, + "remoteEnv": { + // Allow X11 apps to run inside the container + "DISPLAY": "${localEnv:DISPLAY}" + }, + "customizations": { + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": {}, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-python.python", + "vscjava.vscode-java-pack", + "vmware.vscode-boot-dev-pack", + "github.vscode-github-actions", + "redhat.vscode-yaml", + "ms-azuretools.vscode-docker" + ] + } + }, + "features": { + // Some default things like git config + "ghcr.io/devcontainers/features/common-utils:2": { + "upgradePackages": false + } + }, + "runArgs": [ + // Allow the container to access the host X11 display and EPICS CA + "--net=host", + // Make sure SELinux does not disable with access to host filesystems like tmp + "--security-opt=label=disable" + ], + // Mount the parent as /workspaces so we can pip install peers as editable + "workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind", + // After the container is created, install the python project in editable form +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 384078f..98a118d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,27 @@ -FROM eclipse-temurin:17-jre +# Stage 1: Development stage +FROM eclipse-temurin:17-jdk AS developer -# deployment unit +# Install any development tools you need, for example, Maven, Git, etc. +RUN apt-get update && \ + apt-get install -y maven git && \ + apt-get clean + +# Set the working directory for development +WORKDIR /workspace + +# Optionally, you can clone or copy the source code if needed (e.g., for devcontainers) +# If using a local dev environment, you might mount your code with volumes instead. +# Example: +# COPY . /workspace + +# Open a shell for interactive development +CMD ["/bin/bash"] + +# Stage 2: Production deployment stage +FROM eclipse-temurin:17-jre AS production + +# Copy the JAR from the build context COPY target/ChannelFinder-*.jar /channelfinder/ChannelFinder-*.jar +# Set the CMD to run the application in production mode CMD ["java", "-jar", "/channelfinder/ChannelFinder-*.jar", "--spring.config.name=application"] From e96394f50d4ba755132aba2485ca043348063aa0 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Tue, 8 Oct 2024 10:35:44 +0000 Subject: [PATCH 2/7] delete misleading line --- .devcontainer/devcontainer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d911d4a..d893b7e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -38,5 +38,4 @@ ], // Mount the parent as /workspaces so we can pip install peers as editable "workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind", - // After the container is created, install the python project in editable form } \ No newline at end of file From fffdd77109b8fe1c7c5cf21d4ef19b2b93d08bae Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Wed, 9 Oct 2024 09:44:38 +0100 Subject: [PATCH 3/7] delete x11 from the devcontianer setup --- .devcontainer/devcontainer.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d893b7e..649b302 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,10 +5,6 @@ "dockerfile": "../Dockerfile", "target": "developer" }, - "remoteEnv": { - // Allow X11 apps to run inside the container - "DISPLAY": "${localEnv:DISPLAY}" - }, "customizations": { "vscode": { // Set *default* container specific settings.json values on container create. From 8fdd3b202f6e8aac1eb57030edd4ec6ea4bcd82a Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Tue, 29 Oct 2024 12:54:58 +0000 Subject: [PATCH 4/7] three stage Dockerfile --- Dockerfile | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 98a118d..554cc4e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Stage 1: Development stage FROM eclipse-temurin:17-jdk AS developer -# Install any development tools you need, for example, Maven, Git, etc. +# Install Maven and Git for development purposes RUN apt-get update && \ apt-get install -y maven git && \ apt-get clean @@ -9,19 +9,24 @@ RUN apt-get update && \ # Set the working directory for development WORKDIR /workspace -# Optionally, you can clone or copy the source code if needed (e.g., for devcontainers) -# If using a local dev environment, you might mount your code with volumes instead. -# Example: -# COPY . /workspace - -# Open a shell for interactive development +# Optionally, start an interactive shell for development CMD ["/bin/bash"] -# Stage 2: Production deployment stage +# Stage 2: Build stage +FROM eclipse-temurin:17-jdk AS builder + +# Copy the application code from the developer workspace or local context +COPY . /workspace +WORKDIR /workspace + +# Run Maven to clean and build the application JAR +RUN mvn clean install + +# Stage 3: Production deployment stage FROM eclipse-temurin:17-jre AS production -# Copy the JAR from the build context -COPY target/ChannelFinder-*.jar /channelfinder/ChannelFinder-*.jar +# Copy only the built JAR from the builder stage +COPY --from=builder /workspace/target/ChannelFinder-*.jar /channelfinder/ChannelFinder-*.jar # Set the CMD to run the application in production mode CMD ["java", "-jar", "/channelfinder/ChannelFinder-*.jar", "--spring.config.name=application"] From 7d01d74727d2064c75f0ca974705404e3e9c9169 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Tue, 29 Oct 2024 13:11:20 +0000 Subject: [PATCH 5/7] join the stages --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 554cc4e..4d5b292 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ WORKDIR /workspace CMD ["/bin/bash"] # Stage 2: Build stage -FROM eclipse-temurin:17-jdk AS builder +FROM developer as builder # Copy the application code from the developer workspace or local context COPY . /workspace From 6b60c7c51d9e018bf6bdbc68a21baf8391dd72a3 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Mon, 25 Nov 2024 14:15:47 +0000 Subject: [PATCH 6/7] add docker-in-docker? --- .devcontainer/devcontainer.json | 8 +++++++- Dockerfile | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 649b302..1b7332e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -30,8 +30,14 @@ // Allow the container to access the host X11 display and EPICS CA "--net=host", // Make sure SELinux does not disable with access to host filesystems like tmp - "--security-opt=label=disable" + "--security-opt=label=disable", + // add the docker socket environment variable to the container + "-e=DOCKER_HOST=${localEnv:DOCKER_HOST}" ], // Mount the parent as /workspaces so we can pip install peers as editable "workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind", + // for rootless we must not to mess with user ids inside the container + "updateRemoteUserUID": false, + // for rootless we are root inside the container + "remoteUser": "root" } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4d5b292..e52f8df 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,20 @@ # Stage 1: Development stage FROM eclipse-temurin:17-jdk AS developer +ENV DOCKER=docker-27.3.1 + # Install Maven and Git for development purposes RUN apt-get update && \ apt-get install -y maven git && \ apt-get clean + +# install the docker ce cli binary +RUN curl -O https://download.docker.com/linux/static/stable/x86_64/${DOCKER}.tgz && \ + tar xvf ${DOCKER}.tgz && \ + cp docker/docker /usr/bin && \ + rm -r ${DOCKER}.tgz docker + # Set the working directory for development WORKDIR /workspace From 7ccb58f7b48d430611c6472ea86a8a20e46e6b96 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Wed, 27 Nov 2024 18:48:35 +0000 Subject: [PATCH 7/7] add the mounting of user sockets --- .devcontainer/devcontainer.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1b7332e..eb8bff3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -31,12 +31,14 @@ "--net=host", // Make sure SELinux does not disable with access to host filesystems like tmp "--security-opt=label=disable", - // add the docker socket environment variable to the container + // Mount the user sockets folder + "-v${localEnv:XDG_RUNTIME_DIR}:${localEnv:XDG_RUNTIME_DIR}", + // add the docker socket environment variable to the container "-e=DOCKER_HOST=${localEnv:DOCKER_HOST}" ], // Mount the parent as /workspaces so we can pip install peers as editable "workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind", - // for rootless we must not to mess with user ids inside the container + // for rootless we must not to mess with user ids inside the container "updateRemoteUserUID": false, // for rootless we are root inside the container "remoteUser": "root"