diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..eb8bff3 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,45 @@ +// For format details, see https://containers.dev/implementors/json_reference/ +{ + "name": "Java Developer Container", + "build": { + "dockerfile": "../Dockerfile", + "target": "developer" + }, + "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 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 + "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 384078f..e52f8df 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,41 @@ -FROM eclipse-temurin:17-jre +# Stage 1: Development stage +FROM eclipse-temurin:17-jdk AS developer -# deployment unit -COPY target/ChannelFinder-*.jar /channelfinder/ChannelFinder-*.jar +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 + +# Optionally, start an interactive shell for development +CMD ["/bin/bash"] + +# Stage 2: Build stage +FROM developer 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 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"]