diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..cc458223 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,21 @@ +{ + "name": "PLT", + "privileged": false, + "remoteUser": "plt", + "service": "plt", + "dockerComposeFile": "../docker-compose.yml", + "workspaceFolder": "/app", + "customizations": { + "jetbrains": { + "settings": { + "Docker:app:DockerSettings.dockerComposePath": "/usr/local/bin/docker-compose", + "Docker:app:DockerSettings.dockerPath": "/usr/bin/docker" + } + }, + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools" + ] + } + } +} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d842cf5c..ae26f484 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: run: | set -x sudo apt-get update - sudo apt-get install -yy libsfml-dev libboost-test-dev libmicrohttpd-dev libxml2-dev xvfb lcov gcovr + sudo apt-get install -yy libsfml-dev libboost1.74-all-dev libmicrohttpd-dev libxml2-dev xvfb lcov gcovr - name: switch to gcc-12 on linux run: | @@ -43,7 +43,7 @@ jobs: set -x mkdir build cd build - cmake -DBOOST_ROOT=$BOOST_ROOT_1_69_0 -DBoost_ARCHITECTURE=-x64 .. + cmake -DBOOST_ROOT=$BOOST_ROOT_1_74_0 -DBoost_ARCHITECTURE=-x64 .. # Compile project - name: Compile project diff --git a/.gitignore b/.gitignore index 9af4afb8..e7cb5197 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,11 @@ *~ build cmake-build-debug +build-docker bin nbproject src/**/*.h .idea *.autosave tmp +.env diff --git a/Dockerfile b/Dockerfile index 2b1be15d..d5bbb895 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,28 @@ -FROM debian:stable-slim +FROM debian:stable-slim AS plt-base + +ARG USERNAME +ARG USER_UID +ARG USER_GID +ARG DISPLAY + + +RUN groupadd --gid $USER_GID $USERNAME && \ + useradd --uid $USER_UID --gid $USER_GID -m $USERNAME + +RUN if [ -n "$DISPLAY" ]; then \ + export DISPLAY=$DISPLAY; \ + fi + # Install dependencies + + RUN apt-get update && apt-get install -y \ build-essential \ cmake \ lcov \ - gcovr + gcovr \ + git RUN apt-get update && apt-get install -y \ libsfml-dev \ @@ -13,15 +30,29 @@ RUN apt-get update && apt-get install -y \ libboost-all-dev RUN apt-get update && apt-get install -y \ - dia - -# Set the working directory + dia libcanberra-gtk3-module \ + python3-gi gir1.2-gtk-3.0 + +# Set up user and working directory +RUN chsh -s /bin/bash $USERNAME +USER $USERNAME WORKDIR /app +COPY --exclude=build --exclude=cmake-build-debug --chown=$USERNAME:$USERNAME . /app -COPY . /app +# Set environment variables for GUI support +RUN export GDK_BACKEND=$(if [ ! $WAYLAND_DISPLAY ]; then echo x11; else echo wayland; fi) +RUN export QT_QPA_PLATFORM=$(if [ ! $WAYLAND_DISPLAY ]; then echo xcb; else echo wayland; fi) # Build the project -RUN mkdir docker-build && cd docker-build && cmake .. && make client +ENV LC_ALL="C.UTF-8" +ENV LANG="C.UTF-8" + +RUN mkdir docker-build && cd docker-build && cmake .. && make client && cd .. + +RUN chmod u+x ./entrypoint.sh + +SHELL ["/bin/bash", "--login", "-c"] # Run the application -CMD ["./bin/client"] +ENTRYPOINT ["./entrypoint.sh"] +CMD ["tail", "-f", "/dev/null"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..1d45b13e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +services: + plt: + container_name: plt + working_dir: /app + build: + context: . + args: + USERNAME: ${username:-plt} + USER_UID: ${USER_UID:-1000} # $(id -u) + USER_GID: ${USER_GID:-1000} # $(id -g) + DISPLAY: ${DISPLAY} + dockerfile: Dockerfile + # user: $(id -u):$(id -g) + user: $USER_UID:$USER_GID + volumes: + - ./:/app + - /tmp/($WAYLAND_DISPLAY-):/tmp/($WAYLAND_DISPLAY-):rw + - /tmp/.X11-unix:/tmp/.X11-unix:rw + # - /dev/dri:/dev/dri:cached + tty: true + environment: + WAYLAND_DISPLAY: ${WAYLAND_DISPLAY:-} + env_file: + - .env + stdin_open: true \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..526b9078 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +export GDK_BACKEND=$(if [ ! $WAYLAND_DISPLAY ]; then echo x11; else echo wayland; fi) +export QT_QPA_PLATFORM=$(if [ ! $WAYLAND_DISPLAY ]; then echo xcb; else echo wayland; fi) + +exec "$@" \ No newline at end of file diff --git a/setup_docker.sh b/setup_docker.sh new file mode 100755 index 00000000..f8340265 --- /dev/null +++ b/setup_docker.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +set -e + +echo USERNAME=plt > ./.env +echo USER_UID=$(id -u) >> ./.env +echo USER_GID=$(id -g) >> ./.env + +echo "Checking for display server..." +if [ "$XDG_SESSION_TYPE" != "wayland" ]; then + xhost +SI:localuser:$(id -un) + echo DISPLAY=$DISPLAY >> ./.env +fi