Skip to content

Commit

Permalink
ci(github): Run Docker as the GitHub user to simplify code
Browse files Browse the repository at this point in the history
The `all-tools` target of the Docker image contains a `/home/ort`
directory that belongs to the Docker image's "ort" user (UID 1000), but
it does not contain a `/home/ort/.gradle` directory yet. Ideally, one
would like to simply mount `/home/runner/.gradle:/home/ort/.gradle`
without any `chown` magic, but that does not work as the Docker image's
user does not exist on the host and thus the directory is not
accessible. Also just running the Docker image as the host user does not
work, as the mount point's parent directory (`/home/ort`) belongs to
the Docker image's "ort" user, so Gradle cannot create any sub-directories
below `.gradle` as the host user.

As a solution, simply mount to a non-existing home directory in the
Docker image, and just choose that to be the same directory as on the
host (`/home/runner`). As now `HOME` needs to be set, let Gradle deduce
`GRADLE_USER_HOME` from it automatically.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Apr 23, 2024
1 parent 12f1d50 commit 5888ba5
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,15 @@ jobs:
gradle-home-cache-cleanup: true
- name: Run functional tests that do require external tools
run: |
# Change the ownership of the Gradle user home and the workspace to the user in the Docker container.
sudo chown -R 1000:1000 /home/runner/.gradle
sudo chown -R 1000:1000 ${{ github.workspace }}
# Run the functional tests in the Docker container.
docker run \
-v /home/runner/.gradle:/home/ort/.gradle \
-u $(id -u):$(id -g) \
-v /home/runner:/home/runner \
-v ${{ github.workspace }}:/workspace \
-w /workspace \
-e GRADLE_USER_HOME=/home/ort/.gradle \
-e HOME=/home/runner \
${{ env.TEST_IMAGE_TAG }} \
-c "./gradlew --scan -Ptests.include=org.ossreviewtoolkit.plugins.packagemanagers.* funTest jacocoFunTestReport"
# Change the ownership of the Gradle user home and the workspace back to the user in the GitHub Actions runner.
sudo chown -R 1001:121 /home/runner/.gradle
sudo chown -R 1001:121 ${{ github.workspace }}
- name: Upload code coverage data
uses: codecov/codecov-action@v4
with:
Expand Down

0 comments on commit 5888ba5

Please sign in to comment.