From 67b9f85a6ea285ddfdf0ba76ba09c4fff7b29168 Mon Sep 17 00:00:00 2001 From: nereboss Date: Thu, 16 May 2024 12:08:03 +0200 Subject: [PATCH 1/7] Add args to change default user #3308 This was caused by sapmachine who decided to add a user in a patch :) --- analysis/Dockerfile | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/analysis/Dockerfile b/analysis/Dockerfile index 3e8ce1f4c2..d616f123e1 100644 --- a/analysis/Dockerfile +++ b/analysis/Dockerfile @@ -1,5 +1,10 @@ FROM sapmachine:11.0.23 +ARG USER_ADD +ARG USER_ID=1000 +ARG USER_GID=$USER_UID +ARG USERNAME=nonroot-docker-user + COPY ./build/distributions/codecharta-analysis-*.tar /usr/local/ RUN cd /usr/local; \ @@ -34,12 +39,13 @@ RUN wget -qO /tmp/sonar-scanner.zip https://binaries.sonarsource.com/Distributio mkdir --parents /usr/local/conf ; cp ./conf/sonar-scanner.properties /usr/local/conf/; \ cp -r ./jre/ /usr/local/jre; cd /; rm /tmp/sonar-scanner.zip; rm -rf /tmp/sonar-scanner-*-linux; -ARG USERNAME=nonroot-docker-user -ARG USER_UID=1000 -ARG USER_GID=$USER_UID -RUN groupadd --gid $USER_GID $USERNAME \ - && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME; +RUN if [ -n "$USER_ADD" ]; then \ + groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_ID --gid $USER_GID -m $USERNAME; \ + else \ + USERNAME=ubuntu; \ + fi USER $USERNAME From 1c3258edf6638b551d33ecfc22973e01bb014b3b Mon Sep 17 00:00:00 2001 From: nereboss Date: Thu, 16 May 2024 12:48:23 +0200 Subject: [PATCH 2/7] Change default user to ubuntu #3308 --- .github/workflows/test.yml | 4 ++-- analysis/Dockerfile | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ff3530c6d2..f98d918c50 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -150,9 +150,9 @@ jobs: - name: Docker Test Analysis run: | - docker build ./analysis -t local-ccsh --build-arg USER_UID=1001 + docker build ./analysis -t local-ccsh --build-arg USER_ADD=true USER_ID=1001 current_version=$(node -pe "require('./analysis/node-wrapper/package.json').version") - docker run -w /home/nonroot-docker-user/cc/analysis/test -v $(pwd):/home/nonroot-docker-user/cc local-ccsh bash ./golden_test.sh ${current_version} /home/nonroot-docker-user/tmp-files/ /usr/local/bin/ccsh + docker run -w /home/ubuntu/cc/analysis/test -v $(pwd):/home/ubuntu/cc local-ccsh bash ./golden_test.sh ${current_version} /home/ubuntu/tmp-files/ /usr/local/bin/ccsh working-directory: ${{env.project-directory}} - name: Setup Java JDK diff --git a/analysis/Dockerfile b/analysis/Dockerfile index d616f123e1..b1129bea71 100644 --- a/analysis/Dockerfile +++ b/analysis/Dockerfile @@ -3,7 +3,7 @@ FROM sapmachine:11.0.23 ARG USER_ADD ARG USER_ID=1000 ARG USER_GID=$USER_UID -ARG USERNAME=nonroot-docker-user +ARG USERNAME=ubuntu COPY ./build/distributions/codecharta-analysis-*.tar /usr/local/ @@ -43,8 +43,6 @@ RUN wget -qO /tmp/sonar-scanner.zip https://binaries.sonarsource.com/Distributio RUN if [ -n "$USER_ADD" ]; then \ groupadd --gid $USER_GID $USERNAME \ && useradd --uid $USER_ID --gid $USER_GID -m $USERNAME; \ - else \ - USERNAME=ubuntu; \ fi USER $USERNAME From 93436d5c82d070b477f6a3cf5873bafd7d46338b Mon Sep 17 00:00:00 2001 From: nereboss Date: Thu, 16 May 2024 12:59:23 +0200 Subject: [PATCH 3/7] Fix arg error #3308 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f98d918c50..0fa0dac65d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -150,7 +150,7 @@ jobs: - name: Docker Test Analysis run: | - docker build ./analysis -t local-ccsh --build-arg USER_ADD=true USER_ID=1001 + docker build ./analysis -t local-ccsh --build-arg USER_ADD=true --build-arg USER_ID=1001 current_version=$(node -pe "require('./analysis/node-wrapper/package.json').version") docker run -w /home/ubuntu/cc/analysis/test -v $(pwd):/home/ubuntu/cc local-ccsh bash ./golden_test.sh ${current_version} /home/ubuntu/tmp-files/ /usr/local/bin/ccsh working-directory: ${{env.project-directory}} From 6ba457181a4b6a58149f2ca5ceaf8e7d7b0a4bff Mon Sep 17 00:00:00 2001 From: nereboss Date: Thu, 16 May 2024 13:11:00 +0200 Subject: [PATCH 4/7] Fix another arg error #3308 --- analysis/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analysis/Dockerfile b/analysis/Dockerfile index b1129bea71..77ff7e7de6 100644 --- a/analysis/Dockerfile +++ b/analysis/Dockerfile @@ -2,7 +2,7 @@ FROM sapmachine:11.0.23 ARG USER_ADD ARG USER_ID=1000 -ARG USER_GID=$USER_UID +ARG USER_GID=$USER_ID ARG USERNAME=ubuntu COPY ./build/distributions/codecharta-analysis-*.tar /usr/local/ From ddb095a576c721b388d36809696fd2bd9202c93d Mon Sep 17 00:00:00 2001 From: nereboss Date: Thu, 16 May 2024 14:12:14 +0200 Subject: [PATCH 5/7] Change username because ubuntu doesnt work #3308 --- .github/workflows/test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0fa0dac65d..9872d3dd8f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -150,9 +150,10 @@ jobs: - name: Docker Test Analysis run: | - docker build ./analysis -t local-ccsh --build-arg USER_ADD=true --build-arg USER_ID=1001 + user_instance="docker_runner" + docker build ./analysis -t local-ccsh --build-arg USER_ADD=true --build-arg USER_ID=1001 --build-arg USERNAME=${user_instance} current_version=$(node -pe "require('./analysis/node-wrapper/package.json').version") - docker run -w /home/ubuntu/cc/analysis/test -v $(pwd):/home/ubuntu/cc local-ccsh bash ./golden_test.sh ${current_version} /home/ubuntu/tmp-files/ /usr/local/bin/ccsh + docker run -w /home/${user_instance}/cc/analysis/test -v $(pwd):/home/${user_instance}/cc local-ccsh bash ./golden_test.sh ${current_version} /home/${user_instance}/tmp-files/ /usr/local/bin/ccsh working-directory: ${{env.project-directory}} - name: Setup Java JDK From 1b59f016d75254a5f6c4cbd8d733944139146ae4 Mon Sep 17 00:00:00 2001 From: nereboss Date: Thu, 16 May 2024 14:58:32 +0200 Subject: [PATCH 6/7] Add docs about new docker build and run functionality #3308 --- .github/workflows/test.yml | 3 +- DEV_START_GUIDE.md | 4 +++ gh-pages/_docs/01-04-docker-containers.md | 36 ++++++++++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9872d3dd8f..3678524c51 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -151,9 +151,10 @@ jobs: - name: Docker Test Analysis run: | user_instance="docker_runner" - docker build ./analysis -t local-ccsh --build-arg USER_ADD=true --build-arg USER_ID=1001 --build-arg USERNAME=${user_instance} + docker build ./analysis -t local-ccsh --build-arg USER_ADD=true --build-arg USER_ID=1001 --build-arg USERNAME=${user_instance} --no-cache current_version=$(node -pe "require('./analysis/node-wrapper/package.json').version") docker run -w /home/${user_instance}/cc/analysis/test -v $(pwd):/home/${user_instance}/cc local-ccsh bash ./golden_test.sh ${current_version} /home/${user_instance}/tmp-files/ /usr/local/bin/ccsh + docker build ./analysis -t local-ccsh --no-cache working-directory: ${{env.project-directory}} - name: Setup Java JDK diff --git a/DEV_START_GUIDE.md b/DEV_START_GUIDE.md index 06c38166e2..3aa56907e7 100644 --- a/DEV_START_GUIDE.md +++ b/DEV_START_GUIDE.md @@ -98,6 +98,10 @@ For the visualisation, we utilize Jest and puppeteer for unit- and e2e-tests. To When opening a pull requests, all tests are executed automatically using GitHub-actions and a branch can only be merged if all tests are successful. However, it is highly recommended to test changes before pushing them! +# Docker + +For deployment and usage of the docker images, check out our documentation page [here](https://maibornwolff.github.io/codecharta/docs/docker-containers/). + # Troubleshooting We mainly use IntelliJ for our development. The project generally works right away, but sometimes issues can occur: diff --git a/gh-pages/_docs/01-04-docker-containers.md b/gh-pages/_docs/01-04-docker-containers.md index 1946d556ee..760bdb0667 100644 --- a/gh-pages/_docs/01-04-docker-containers.md +++ b/gh-pages/_docs/01-04-docker-containers.md @@ -83,5 +83,39 @@ docker run -it -v $(pwd):/src -w /src codecharta/codecharta-analysis ccsh gitlog # gitlogparser [...] : check the gitlogparser documentation for more info ``` -> Be aware, that by default the user inside the docker image is 'nonroot-docker-user' with an ID of 1000. You may +> Be aware, that by default the user inside the docker image is 'ubuntu' with an ID of 1000. You may > encounter errors with `git` when you try to execute commands inside a repository cloned by a different `UID` + +> For **macOS users**, it is necessary to add `--user=501:dialout` Before the image name. Why? because docker on mac is fun :) + +### Build it yourself + +You can also build a docker image from the locally installed instance of codecharta. To do this, you would execute the following commands: + +```bash +# to build the container you need to navigate into the analysis folder +cd analysis + +# makes a clean build to ensure everything will be built correctly +./gradlew clean build + +# builds the docker container with an image name of your choice +docker build . -t your-image-name + +# executes bash inside of the created container +docker run -it your-image-name bash + +# to run the docker container with your current working directory mounted into it, +# you can alternatively run this +docker run -it -v $(pwd):/src -w /src your-image-name bash +``` + +There is also the option to customize the used docker user during the build. +This will create a new user with the given name and IDs. + +```bash +#USER_ADD: set it to any value to to add a new user +#USERNAME: the name of the user to be created +#USER_ID: the ID that is used for the new user and for its group +docker build ./analysis -t local-ccsh --build-arg USER_ADD=true --build-arg USER_ID=1001 --build-arg USERNAME=your_name +``` From 44ed0ff3eb0c17c74385086d7c6fc8c7a2b68cb2 Mon Sep 17 00:00:00 2001 From: nereboss Date: Thu, 16 May 2024 15:05:42 +0200 Subject: [PATCH 7/7] Update Changelog #3308 --- analysis/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/analysis/CHANGELOG.md b/analysis/CHANGELOG.md index 903552b4d9..1a65d39b49 100644 --- a/analysis/CHANGELOG.md +++ b/analysis/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/) ## [unreleased] (Added 🚀 | Changed | Removed 🗑 | Fixed 🐞 | Chore 👨‍💻 👩‍💻) +### Changed + +- Update GH-Pages and dev guide on how to use our docker images [#3621](https://github.com/MaibornWolff/codecharta/pull/3621/files) + ### Fixed 🐞 - Add default Docker user to mitigate `GitLogParser` issues during repo-scan [#3571](https://github.com/MaibornWolff/codecharta/pull/3571)