From 5bd1e8941c8579b4b72450304f1fdc6a0e2c0e3b Mon Sep 17 00:00:00 2001 From: QcFe <10742159+QcFe@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:37:46 +0200 Subject: [PATCH] VSCode + java -Changed JDK -Fixed workspace folders permission issue Co-authored-by: Marco Torchiano Co-authored-by: Stefano Mancini <722523+steccothal@users.noreply.github.com> --- .github/workflows/build-matrix.json | 21 +---- provisioning/standalone/vscode/README.md | 12 +-- .../standalone/vscode/base/Dockerfile | 23 +++--- provisioning/standalone/vscode/base/start.sh | 32 ++++---- .../standalone/vscode/c-cpp/Dockerfile | 8 +- .../standalone/vscode/c-cpp/settings.json | 4 + .../standalone/vscode/golang/Dockerfile | 16 ++-- .../standalone/vscode/golang/settings.json | 4 + .../standalone/vscode/java/Dockerfile | 33 ++++++++ .../standalone/vscode/java/settings.json | 8 ++ .../vscode/java/triggerproject/pom.xml | 77 +++++++++++++++++++ .../vscode/java/triggerproject/src/Main.java | 5 ++ .../java/triggerproject/test/MainTest.java | 10 +++ .../standalone/vscode/python/Dockerfile | 6 +- .../vscode/python/project/vscode/launch.json | 15 ---- .../standalone/vscode/python/settings.json | 18 ++++- 16 files changed, 200 insertions(+), 92 deletions(-) create mode 100755 provisioning/standalone/vscode/java/Dockerfile create mode 100755 provisioning/standalone/vscode/java/settings.json create mode 100755 provisioning/standalone/vscode/java/triggerproject/pom.xml create mode 100755 provisioning/standalone/vscode/java/triggerproject/src/Main.java create mode 100755 provisioning/standalone/vscode/java/triggerproject/test/MainTest.java delete mode 100644 provisioning/standalone/vscode/python/project/vscode/launch.json diff --git a/.github/workflows/build-matrix.json b/.github/workflows/build-matrix.json index 8e2522a5a..f39c7fc7f 100644 --- a/.github/workflows/build-matrix.json +++ b/.github/workflows/build-matrix.json @@ -137,26 +137,9 @@ "optional": true }, { - "component": "vscode-python-codetogether", - "build-args": "CODETOGETHER_ENABLED_ARG=true", + "component": "vscode-java", "context": "./provisioning/standalone/vscode", - "dockerfile": "./provisioning/standalone/vscode/python/Dockerfile", - "harbor-project": "crownlabs-standalone", - "optional": true - }, - { - "component": "vscode-c-cpp-codetogether", - "build-args": "CODETOGETHER_ENABLED_ARG=true", - "context": "./provisioning/standalone/vscode", - "dockerfile": "./provisioning/standalone/vscode/c-cpp/Dockerfile", - "harbor-project": "crownlabs-standalone", - "optional": true - }, - { - "component": "vscode-golang-codetogether", - "build-args": "CODETOGETHER_ENABLED_ARG=true", - "context": "./provisioning/standalone/vscode", - "dockerfile": "./provisioning/standalone/vscode/golang/Dockerfile", + "dockerfile": "./provisioning/standalone/vscode/java/Dockerfile", "harbor-project": "crownlabs-standalone", "optional": true } diff --git a/provisioning/standalone/vscode/README.md b/provisioning/standalone/vscode/README.md index 4614f0748..b3b981465 100644 --- a/provisioning/standalone/vscode/README.md +++ b/provisioning/standalone/vscode/README.md @@ -85,7 +85,7 @@ harbor.crownlabs.polito.it/crownlabs-standalone/vscode-golang **Extensions** can be installed from the command line using: ```Dockerfile -code-server --extensions-dir /config/extensions --install-extension ${EXTENSION_NAME} +code-server --extensions-dir ${VSCODE_SRV_DIR}/extensions --install-extension ${EXTENSION_NAME} ``` The `EXTENSION_NAME` can be either a local `.vsix` file or a reference to an extension on [https://open-vsx.org/](https://open-vsx.org/) marketplace. @@ -100,16 +100,6 @@ For example: docker run -e CROWNLABS_LISTEN_PORT=8001 -it --rm -p 8001:8001 vscode-c-cpp --disable-marketplace ``` -## Codetogether - -**Vscode images** support [**codetogether**](https://www.codetogether.com/) extension and API, which allow **social-coding** between multiple vscode instances (similarly to **[liveshare](https://visualstudio.microsoft.com/it/services/live-share/)** by **Microsoft®**. This [video](https://youtu.be/l4yTfduxptw) shows what it can do. To enable an image to use **codetogether** it is necessary to build it with the `CODETOGETHER_ENABLED_ARG=true` build argument. - -For example: - -``` -docker build --build-arg=CODETOGETHER_ENABLED_ARG=true -t vscode-c-cpp-codetogether -``` - ## Reset persistent instances **Persistent** standalone applications can be **paused/started**. Is possible to reset workspace directory to the initial state by deleting the `.vscode/.startup` file and **restarting** the instance. diff --git a/provisioning/standalone/vscode/base/Dockerfile b/provisioning/standalone/vscode/base/Dockerfile index 508dc45c7..09661584e 100644 --- a/provisioning/standalone/vscode/base/Dockerfile +++ b/provisioning/standalone/vscode/base/Dockerfile @@ -1,7 +1,7 @@ FROM ubuntu:22.04 ENV DEBIAN_FRONTEND=noninteractive -ENV CODESERVER_VERSION=4.7.0 +ENV CODESERVER_VERSION=4.22.0 ARG CODETOGETHER_ENABLED_ARG=false ENV CODETOGETHER_ENABLED=$CODETOGETHER_ENABLED_ARG ENV SERVICE_URL=https://open-vsx.org/vscode/gallery @@ -17,20 +17,19 @@ RUN apt-get update &&\ # Define user and user id default arguments ARG USER=crownlabs ARG UID=1010 +ARG VSCODE_SRV_DIR=/vscode +ENV VSCODE_SRV_DIR=${VSCODE_SRV_DIR} # Create new user, setup home folder, .bashrc, .profile and .bash_aliases RUN useradd -ms /bin/bash -u ${UID} $USER && \ - usermod -d /config $USER && \ - mkdir -p /config/extensions && \ - mkdir -p /config/data && \ - mkdir -p /config/workspace && \ - cp /root/.bashrc /config/.bashrc && \ - cp /root/.profile /config/.profile && \ - echo 'alias code=code-server' >> /config/.bashrc && \ - echo 'export PS1="\[\e]0;\u@\h: \w\a\]\[\033[0;00m\][\A]\[\033[00;00m\]\[\033[01;34m\]\u👑\[\033[00m\]:\[\033[01;34m\]\w\[\e[91m\]\[\033[00m\]$ "' >> /config/.bashrc - -# Install codetogether if specified -RUN if [ "${CODETOGETHER_ENABLED}" = "true" ]; then code-server --extensions-dir /config/extensions --install-extension genuitecllc.codetogether; fi + usermod -d ${VSCODE_SRV_DIR} $USER && \ + mkdir -p ${VSCODE_SRV_DIR}/extensions && \ + mkdir -p ${VSCODE_SRV_DIR}/data && \ + mkdir -p ${VSCODE_SRV_DIR}/workspace && \ + cp /root/.bashrc ${VSCODE_SRV_DIR}/.bashrc && \ + cp /root/.profile ${VSCODE_SRV_DIR}/.profile && \ + echo 'alias code=code-server' >> ${VSCODE_SRV_DIR}/.bashrc && \ + echo 'export PS1="\[\e]0;\u@\h: \w\a\]\[\033[0;00m\][\A]\[\033[00;00m\]\[\033[01;34m\]\u👑\[\033[00m\]:\[\033[01;34m\]\w\[\e[91m\]\[\033[00m\]$ "' >> ${VSCODE_SRV_DIR}/.bashrc COPY ./base/start.sh start.sh RUN chmod 755 start.sh diff --git a/provisioning/standalone/vscode/base/start.sh b/provisioning/standalone/vscode/base/start.sh index 442e68dc7..011752a03 100644 --- a/provisioning/standalone/vscode/base/start.sh +++ b/provisioning/standalone/vscode/base/start.sh @@ -1,35 +1,29 @@ #!/usr/bin/env bash shopt -s dotglob -if [ ! -f "/config/workspace/.vscode/.startup" ]; then - rm -rf /config/workspace/* - mkdir -p /config/workspace/.vscode/ - cp -R /example_project/* /config/workspace - echo "[Persistent Only Feature]" > /config/workspace/.vscode/.startup - echo "If your CrownLabs instance is persistent, delete this file if you want to reset the workspace on next startup." >> /config/workspace/.vscode/.startup -fi - # Check if in the passed arguments is specified to disable workspace through the option --disable-marketplace for ARGUMENT in "$@"; do if [ "$ARGUMENT" == "--disable-marketplace" ] ; then export EXTENSIONS_GALLERY='{"serviceUrl": ""}' fi -done + if [ "$ARGUMENT" == "--load-example" ] ; then + if [ ! -f "$VSCODE_SRV_DIR/workspace/.vscode/.startup" ]; then + rm -rf $VSCODE_SRV_DIR/workspace/* + mkdir -p $VSCODE_SRV_DIR/workspace/.vscode/ + cp -R /example_project/* $VSCODE_SRV_DIR/workspace + echo "[Persistent Only Feature]" > $VSCODE_SRV_DIR/workspace/.vscode/.startup + echo "If your CrownLabs instance is persistent, delete this file if you want to reset the workspace on next startup." >> $VSCODE_SRV_DIR/workspace/.vscode/.startup + fi -if [ "${CODETOGETHER_ENABLED}" == "true" ]; then - CODETOGETHER_ENABLED_ARG="--enable-proposed-api=genuitecllc.codetogether" -else - CODETOGETHER_ENABLED_ARG="" -fi + fi +done exec \ code-server \ --disable-update-check \ --auth none \ -"${CODETOGETHER_ENABLED_ARG}" \ --bind-addr 0.0.0.0:"${CROWNLABS_LISTEN_PORT}" \ ---user-data-dir /config/data \ ---extensions-dir /config/extensions \ +--user-data-dir $VSCODE_SRV_DIR/data \ +--extensions-dir $VSCODE_SRV_DIR/extensions \ --disable-telemetry \ ---new-window \ -/config/workspace +$VSCODE_SRV_DIR/workspace diff --git a/provisioning/standalone/vscode/c-cpp/Dockerfile b/provisioning/standalone/vscode/c-cpp/Dockerfile index e31aedc85..52f8fd110 100644 --- a/provisioning/standalone/vscode/c-cpp/Dockerfile +++ b/provisioning/standalone/vscode/c-cpp/Dockerfile @@ -22,7 +22,7 @@ ENV CPPTOOLS_VERSION=v1.12.4 COPY ./c-cpp/project/main.c /example_project/main.c COPY ./c-cpp/project/main.cpp /example_project/main.cpp COPY ./c-cpp/project/vscode /example_project/.vscode -COPY ./c-cpp/settings.json /config/data/User/settings.json +COPY ./c-cpp/settings.json ${VSCODE_SRV_DIR}/data/User/settings.json # Install required packages and remove apt and useless/dangerous packages RUN apt-get update && apt-get install -y build-essential cmake gdb && \ @@ -36,7 +36,7 @@ RUN apt-get update && apt-get install -y build-essential cmake gdb && \ ADD "https://github.com/microsoft/vscode-cpptools/releases/download/${CPPTOOLS_VERSION}/cpptools-linux.vsix" "./cpptools-linux.vsix" # Setup permissions -RUN chown -R $USER:$USER /config && \ +RUN chown -R $USER:$USER ${VSCODE_SRV_DIR} && \ chown -R $USER:$USER /example_project && \ chown $USER:$USER cpptools-linux.vsix && \ chmod 400 cpptools-linux.vsix @@ -44,6 +44,6 @@ RUN chown -R $USER:$USER /config && \ USER $USER # Install extensions -RUN code-server --extensions-dir /config/extensions --install-extension cpptools-linux.vsix && \ - code-server --extensions-dir /config/extensions --install-extension formulahendry.code-runner +RUN code-server --extensions-dir ${VSCODE_SRV_DIR}/extensions --install-extension cpptools-linux.vsix && \ + code-server --extensions-dir ${VSCODE_SRV_DIR}/extensions --install-extension formulahendry.code-runner ENTRYPOINT [ "/start.sh" ] diff --git a/provisioning/standalone/vscode/c-cpp/settings.json b/provisioning/standalone/vscode/c-cpp/settings.json index f6d6fd36d..4ae812917 100644 --- a/provisioning/standalone/vscode/c-cpp/settings.json +++ b/provisioning/standalone/vscode/c-cpp/settings.json @@ -1,4 +1,8 @@ { + "security.workspace.trust.enabled": false, + "workbench.colorTheme": "Default Dark Modern", + "workbench.startupEditor": "none", + "window.menuBarVisibility": "visible", "code-runner.executorMap": { "cpp": "cd $dir && g++ -std=c++2a $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt" }, diff --git a/provisioning/standalone/vscode/golang/Dockerfile b/provisioning/standalone/vscode/golang/Dockerfile index b428f27c4..5060ec4f5 100644 --- a/provisioning/standalone/vscode/golang/Dockerfile +++ b/provisioning/standalone/vscode/golang/Dockerfile @@ -3,11 +3,11 @@ INCLUDE+ ./base/Dockerfile ENV SUDO_FORCE_REMOVE yes -ENV GOPATH=/config/go +ENV GOPATH=${VSCODE_SRV_DIR}/go COPY ./golang/project/main.go /example_project/main.go COPY ./golang/project/go.mod /example_project/go.mod -COPY ./golang/settings.json /config/data/User/settings.json +COPY ./golang/settings.json ${VSCODE_SRV_DIR}/data/User/settings.json # Install required packages RUN apt-get update && \ @@ -18,8 +18,8 @@ ADD https://go.dev/dl/go1.19.linux-amd64.tar.gz /usr/local/go.tar.gz ADD https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh install.sh RUN tar -xzf /usr/local/go.tar.gz -C /usr/local && \ echo 'export PATH=$PATH:/usr/local/go/bin'>>/root/.bashrc && \ - echo 'export PATH=$PATH:/config/go/bin'>>/root/.bashrc && \ - echo 'export GOPATH=/config/go'>>/root/.bashrc && \ + echo 'export PATH=$PATH:'"${VSCODE_SRV_DIR}"'/go/bin'>>/root/.bashrc && \ + echo 'export GOPATH='"${VSCODE_SRV_DIR}"'/go'>>/root/.bashrc && \ rm /usr/local/go.tar.gz && \ /usr/local/go/bin/go install golang.org/x/tools/gopls@latest && \ /usr/local/go/bin/go install github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest && \ @@ -27,7 +27,7 @@ RUN tar -xzf /usr/local/go.tar.gz -C /usr/local && \ /usr/local/go/bin/go install github.com/go-delve/delve/cmd/dlv@latest && \ /usr/local/go/bin/go install honnef.co/go/tools/cmd/staticcheck@latest && \ /usr/local/go/bin/go env GOPATH && \ - cp /config/go/bin/dlv /config/go/bin/dlv-dap && \ + cp ${VSCODE_SRV_DIR}/go/bin/dlv ${VSCODE_SRV_DIR}/go/bin/dlv-dap && \ /bin/bash ./install.sh -b $(/usr/local/go/bin/go env GOPATH)/bin v1.49.0 && \ rm install.sh @@ -36,11 +36,11 @@ RUN apt-get clean && \ apt-get --autoremove purge -y apt wget sudo --allow-remove-essential # Install extensions -RUN code-server --extensions-dir /config/extensions --install-extension golang.Go && \ - code-server --extensions-dir /config/extensions --install-extension formulahendry.code-runner +RUN code-server --extensions-dir ${VSCODE_SRV_DIR}/extensions --install-extension golang.Go && \ + code-server --extensions-dir ${VSCODE_SRV_DIR}/extensions --install-extension formulahendry.code-runner # Setup permissions -RUN chown -R ${USER}:${USER} /config && \ +RUN chown -R ${USER}:${USER} ${VSCODE_SRV_DIR} && \ chown -R ${USER}:${USER} /example_project USER ${USER} diff --git a/provisioning/standalone/vscode/golang/settings.json b/provisioning/standalone/vscode/golang/settings.json index d1d3400f0..8c72b80c2 100644 --- a/provisioning/standalone/vscode/golang/settings.json +++ b/provisioning/standalone/vscode/golang/settings.json @@ -1,4 +1,8 @@ { + "security.workspace.trust.enabled": false, + "workbench.colorTheme": "Default Dark Modern", + "workbench.startupEditor": "none", + "window.menuBarVisibility": "visible", "go.toolsManagement.autoUpdate": true, "[go]": { "editor.insertSpaces": false, diff --git a/provisioning/standalone/vscode/java/Dockerfile b/provisioning/standalone/vscode/java/Dockerfile new file mode 100755 index 000000000..89b401d18 --- /dev/null +++ b/provisioning/standalone/vscode/java/Dockerfile @@ -0,0 +1,33 @@ +# syntax = edrevo/dockerfile-plus + +INCLUDE+ ./base/Dockerfile + + +# Setup permissions + +# Install required packages +RUN apt-get update && apt-get install -y openjdk-17-jdk openjdk-17-source maven --no-install-recommends + +# Install VS code extension +RUN code-server --extensions-dir ${VSCODE_SRV_DIR}/extensions --install-extension vscjava.vscode-java-pack + +# Remove apt and useless/dangerous packages +RUN apt-get clean && \ + apt-get remove --autoremove --purge -y apt sudo --allow-remove-essential + +COPY ./java/settings.json ${VSCODE_SRV_DIR}/data/User/settings.json + +RUN chown -R ${USER}:${USER} ${VSCODE_SRV_DIR} + +USER ${USER} + +WORKDIR ${VSCODE_SRV_DIR} + +# Forces Maven to preload dependencies +RUN --mount=type=bind,source=./java/triggerproject/,target=./triggerproject cd ${VSCODE_SRV_DIR}/triggerproject && mvn test && rm -rf /tmp/target + +RUN git config --global credential.helper 'cache --timeout=10800'&&\ + git config --global user.email student@crownlabs.polito.it &&\ + git config --global user.name crownlabs + +ENTRYPOINT [ "/start.sh" ] diff --git a/provisioning/standalone/vscode/java/settings.json b/provisioning/standalone/vscode/java/settings.json new file mode 100755 index 000000000..c1d455717 --- /dev/null +++ b/provisioning/standalone/vscode/java/settings.json @@ -0,0 +1,8 @@ +{ + "security.workspace.trust.enabled": false, + "workbench.colorTheme": "Default Dark Modern", + "workbench.startupEditor": "none", + "window.menuBarVisibility": "visible", + "java.project.importHint": false, + "redhat.telemetry.enabled": false +} \ No newline at end of file diff --git a/provisioning/standalone/vscode/java/triggerproject/pom.xml b/provisioning/standalone/vscode/java/triggerproject/pom.xml new file mode 100755 index 000000000..48b0cb82a --- /dev/null +++ b/provisioning/standalone/vscode/java/triggerproject/pom.xml @@ -0,0 +1,77 @@ + + 4.0.0 + it.polito.oop.lab + sample + 1.0.0 + + + UTF-8 + + + + + + junit + junit + 4.13.2 + test + + + + + src + test + /tmp/target + + + ${project.basedir}/src + + **/*.java + + + + + + + maven-compiler-plugin + 3.8.1 + + 17 + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.0 + + + org.apache.maven.surefire + surefire-junit4 + 2.22.0 + + + + + org.jacoco + jacoco-maven-plugin + 0.8.7 + + + + prepare-agent + + + + report + test + + report + + + + + + + \ No newline at end of file diff --git a/provisioning/standalone/vscode/java/triggerproject/src/Main.java b/provisioning/standalone/vscode/java/triggerproject/src/Main.java new file mode 100755 index 000000000..849f51ea4 --- /dev/null +++ b/provisioning/standalone/vscode/java/triggerproject/src/Main.java @@ -0,0 +1,5 @@ +public class Main{ + public static int m(){ + return 1; + } +} \ No newline at end of file diff --git a/provisioning/standalone/vscode/java/triggerproject/test/MainTest.java b/provisioning/standalone/vscode/java/triggerproject/test/MainTest.java new file mode 100755 index 000000000..f530c6b75 --- /dev/null +++ b/provisioning/standalone/vscode/java/triggerproject/test/MainTest.java @@ -0,0 +1,10 @@ +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class MainTest { + @Test + public void test(){ + assertEquals(1,Main.m()); + } +} diff --git a/provisioning/standalone/vscode/python/Dockerfile b/provisioning/standalone/vscode/python/Dockerfile index dad4d9f8c..fa5b458c7 100644 --- a/provisioning/standalone/vscode/python/Dockerfile +++ b/provisioning/standalone/vscode/python/Dockerfile @@ -6,7 +6,7 @@ ENV SUDO_FORCE_REMOVE yes COPY ./python/project/main.py /example_project/main.py COPY ./python/project/vscode /example_project/.vscode -COPY ./python/settings.json /config/data/User/settings.json +COPY ./python/settings.json ${VSCODE_SRV_DIR}/data/User/settings.json # Install required packages and remove apt and useless/dangerous packages RUN apt-get update && \ @@ -16,10 +16,10 @@ RUN apt-get update && \ apt-get remove --autoremove --purge -y apt sudo --allow-remove-essential # Install extension -RUN code-server --extensions-dir /config/extensions --install-extension ms-python.python +RUN code-server --extensions-dir ${VSCODE_SRV_DIR}/extensions --install-extension ms-python.python # Setup permissions -RUN chown -R ${USER}:${USER} /config && \ +RUN chown -R ${USER}:${USER} ${VSCODE_SRV_DIR} && \ chown -R ${USER}:${USER} /example_project USER ${USER} diff --git a/provisioning/standalone/vscode/python/project/vscode/launch.json b/provisioning/standalone/vscode/python/project/vscode/launch.json deleted file mode 100644 index 17e15f27e..000000000 --- a/provisioning/standalone/vscode/python/project/vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Python: Current File", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal" - } - ] -} \ No newline at end of file diff --git a/provisioning/standalone/vscode/python/settings.json b/provisioning/standalone/vscode/python/settings.json index 4f1a22482..2535fa552 100644 --- a/provisioning/standalone/vscode/python/settings.json +++ b/provisioning/standalone/vscode/python/settings.json @@ -1,5 +1,21 @@ { + "security.workspace.trust.enabled": false, + "workbench.colorTheme": "Default Dark Modern", + "workbench.startupEditor": "none", + "window.menuBarVisibility": "visible", "python.linting.enabled": true, "python.linting.lintOnSave": true, - "python.linting.pylintEnabled": true + "python.linting.pylintEnabled": true, + "launch": { + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] + } } \ No newline at end of file