Skip to content

Commit

Permalink
VSCode + java
Browse files Browse the repository at this point in the history
-Changed JDK
-Fixed workspace folders permission issue

Co-authored-by: Marco Torchiano <[email protected]>
Co-authored-by: Stefano Mancini <[email protected]>
  • Loading branch information
3 people authored and air-31 committed Sep 18, 2024
1 parent f9a1b72 commit b815541
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 96 deletions.
21 changes: 2 additions & 19 deletions .github/workflows/build-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 1 addition & 13 deletions provisioning/standalone/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ This is an example of how to build the **c-cpp vscode** version:
- Go inside the `/provisioning/standalone/vscode` folder
- Run: `docker build -f ./c-cpp/Dockerfile -t harbor.crownlabs.polito.it/crownlabs-standalone/vscode-c-cpp`

*Optionally*, you can install **codetogether** providing the **build-arg** `CODETOGETHER_ENABLED_ARG` (see more [here](#codetogether))

## Ready-to-use images available

This is a list of **ready-to-use images**, built by the **CrownLabs** team :
Expand All @@ -85,7 +83,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.
Expand All @@ -100,16 +98,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.
Expand Down
25 changes: 11 additions & 14 deletions provisioning/standalone/vscode/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive
ENV CODESERVER_VERSION=4.7.0
ARG CODETOGETHER_ENABLED_ARG=false
ENV CODETOGETHER_ENABLED=$CODETOGETHER_ENABLED_ARG
ENV CODESERVER_VERSION=4.22.0
ENV SERVICE_URL=https://open-vsx.org/vscode/gallery
ENV ITEM_URL=https://open-vsx.org/vscode/item

Expand All @@ -17,20 +15,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
32 changes: 13 additions & 19 deletions provisioning/standalone/vscode/base/start.sh
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 4 additions & 4 deletions provisioning/standalone/vscode/c-cpp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand All @@ -36,14 +36,14 @@ 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

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" ]
4 changes: 4 additions & 0 deletions provisioning/standalone/vscode/c-cpp/settings.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
16 changes: 8 additions & 8 deletions provisioning/standalone/vscode/golang/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand All @@ -18,16 +18,16 @@ 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 && \
/usr/local/go/bin/go install github.com/ramya-rao-a/go-outline@latest && \
/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

Expand All @@ -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}
Expand Down
4 changes: 4 additions & 0 deletions provisioning/standalone/vscode/golang/settings.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
33 changes: 33 additions & 0 deletions provisioning/standalone/vscode/java/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 [email protected] &&\
git config --global user.name crownlabs

ENTRYPOINT [ "/start.sh" ]
8 changes: 8 additions & 0 deletions provisioning/standalone/vscode/java/settings.json
Original file line number Diff line number Diff line change
@@ -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
}
77 changes: 77 additions & 0 deletions provisioning/standalone/vscode/java/triggerproject/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it.polito.oop.lab</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<directory>/tmp/target</directory>
<resources>
<resource>
<directory>${project.basedir}/src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>

<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.22.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Main{
public static int m(){
return 1;
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Loading

0 comments on commit b815541

Please sign in to comment.