From d406e47c26935efc539236971b0d5f55470b72ad Mon Sep 17 00:00:00 2001 From: Quinten Stokkink Date: Thu, 22 Aug 2024 10:57:26 +0200 Subject: [PATCH 1/4] Added Docker build action --- .github/workflows/build_docker.yml | 67 ++++++++++++++++++++++ build/docker/build.Dockerfile | 37 ++++++++++++ build/docker/build.Dockerfile.dockerignore | 22 +++++++ build/docker/compose.yml | 11 ++++ build/docker/configuration.json | 28 +++++++++ 5 files changed, 165 insertions(+) create mode 100644 .github/workflows/build_docker.yml create mode 100644 build/docker/build.Dockerfile create mode 100644 build/docker/build.Dockerfile.dockerignore create mode 100644 build/docker/compose.yml create mode 100644 build/docker/configuration.json diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml new file mode 100644 index 0000000000..0c031c9119 --- /dev/null +++ b/.github/workflows/build_docker.yml @@ -0,0 +1,67 @@ +name: Publish Docker Image + +on: + workflow_dispatch: + push: + branches: + - 'main' + - 'docker' + tags: + - 'v*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + attestations: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.ref_name }} + fetch-depth: 0 + submodules: 'true' + fetch-tags: 'true' + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Git Tag Version + id: git_tag_version + run: | + echo "VERSION=$(git describe --tags)" >> $GITHUB_ENV + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@v6 + with: + context: . + file: build/docker/build.Dockerfile + push: true + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }} + build-args: | + GIT_BRANCH=${{ github.ref_name }} + GIT_REPO=https://github.com/${{ github.repository }} + + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true diff --git a/build/docker/build.Dockerfile b/build/docker/build.Dockerfile new file mode 100644 index 0000000000..050b940428 --- /dev/null +++ b/build/docker/build.Dockerfile @@ -0,0 +1,37 @@ +# libtorrent-1.2.19 does not support python 3.11 yet +FROM python:3.10-slim + +RUN apt-get update \ + && apt-get install -y --no-install-recommends libsodium23=1.0.18-1 \ + && rm -rf /var/lib/apt/lists/* + +# Install Xvfb for headless GUI +RUN apt-get update -y \ + && apt-get -y install \ + xvfb nodejs npm git \ + && rm -rf /var/lib/apt/lists/* /var/cache/apt/* + +# Set up a user in the container +RUN useradd -ms /bin/bash --home-dir /home/user user +USER user + +# Clone the repository with arguments +ARG GIT_REPO=${GIT_REPO:-"https://github.com/tribler/tribler.git"} +ARG GIT_BRANCH=${GIT_BRANCH:-"main"} +RUN echo "Cloning $GIT_REPO on branch $GIT_BRANCH" +RUN git clone --recursive --branch "$GIT_BRANCH" "$GIT_REPO" /home/user/tribler + +# Install NPM dependencies +WORKDIR /home/user/tribler/src/tribler/ui +RUN npm install \ + && npm run build + +# Install Python dependencies +WORKDIR /home/user/tribler +RUN pip3 install -r requirements.txt + +# Set IPv8 on pythonpath +ENV PYTHONPATH=pyipv8 + +# Run the application using Xvfb +CMD xvfb-run python3 src/run_tribler.py diff --git a/build/docker/build.Dockerfile.dockerignore b/build/docker/build.Dockerfile.dockerignore new file mode 100644 index 0000000000..44dacac416 --- /dev/null +++ b/build/docker/build.Dockerfile.dockerignore @@ -0,0 +1,22 @@ +.* +build +doc +scripts + +src/run_unit_tests.py +src/tribler/test_integration +src/tribler/test_unit + +pyipv8/.* +pyipv8/*.md +pyipv8/*.ini +pyipv8/create_setup_taskmanager.py +pyipv8/create_test_coverage_report.py +pyipv8/github_increment_version.py +pyipv8/run_all_tests.py +pyipv8/setup.py +pyipv8/doc +pyipv8/scripts +pyipv8/stresstest +pyipv8/systemd +pyipv8/ipv8/test diff --git a/build/docker/compose.yml b/build/docker/compose.yml new file mode 100644 index 0000000000..a25c6a8590 --- /dev/null +++ b/build/docker/compose.yml @@ -0,0 +1,11 @@ + +services: + tribler: + image: ghcr.io/tribler/tribler:main + network_mode: host + environment: + CORE_API_PORT: 8085 + CORE_API_KEY: "changeme" + volumes: + - ~/.Tribler/git:/home/user/.Tribler + - ~/Downloads/TriblerDownloads:/home/user/Downloads/TriblerDownloads diff --git a/build/docker/configuration.json b/build/docker/configuration.json new file mode 100644 index 0000000000..0d92f3d4c5 --- /dev/null +++ b/build/docker/configuration.json @@ -0,0 +1,28 @@ +{ + "api": { + "http_host": "127.0.0.1", + "https_host": "127.0.0.1" + }, + "ipv8": { + "interfaces": [ + { + "interface": "UDPIPv4", + "ip": "0.0.0.0", + "port": 7759, + "worker_threads": 8 + }, + { + "interface": "UDPIPv6", + "ip": "::", + "port": 7760 + } + ] + }, + "libtorrent": { + "port": 0, + "download_defaults": { + "saveas": "/downloads" + } + }, + "state_dir": "/state" +} From 0222f628208f1d29ebec59c0804491359f3780d9 Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Wed, 28 Aug 2024 15:18:26 +0200 Subject: [PATCH 2/4] Remove the unused configuration.json and .dockerignore files --- build/docker/build.Dockerfile.dockerignore | 22 ----------------- build/docker/configuration.json | 28 ---------------------- 2 files changed, 50 deletions(-) delete mode 100644 build/docker/build.Dockerfile.dockerignore delete mode 100644 build/docker/configuration.json diff --git a/build/docker/build.Dockerfile.dockerignore b/build/docker/build.Dockerfile.dockerignore deleted file mode 100644 index 44dacac416..0000000000 --- a/build/docker/build.Dockerfile.dockerignore +++ /dev/null @@ -1,22 +0,0 @@ -.* -build -doc -scripts - -src/run_unit_tests.py -src/tribler/test_integration -src/tribler/test_unit - -pyipv8/.* -pyipv8/*.md -pyipv8/*.ini -pyipv8/create_setup_taskmanager.py -pyipv8/create_test_coverage_report.py -pyipv8/github_increment_version.py -pyipv8/run_all_tests.py -pyipv8/setup.py -pyipv8/doc -pyipv8/scripts -pyipv8/stresstest -pyipv8/systemd -pyipv8/ipv8/test diff --git a/build/docker/configuration.json b/build/docker/configuration.json deleted file mode 100644 index 0d92f3d4c5..0000000000 --- a/build/docker/configuration.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "api": { - "http_host": "127.0.0.1", - "https_host": "127.0.0.1" - }, - "ipv8": { - "interfaces": [ - { - "interface": "UDPIPv4", - "ip": "0.0.0.0", - "port": 7759, - "worker_threads": 8 - }, - { - "interface": "UDPIPv6", - "ip": "::", - "port": 7760 - } - ] - }, - "libtorrent": { - "port": 0, - "download_defaults": { - "saveas": "/downloads" - } - }, - "state_dir": "/state" -} From 56d6cd77417cb6044a7cad5b2ac255361bbb2203 Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Wed, 28 Aug 2024 15:19:53 +0200 Subject: [PATCH 3/4] Trigger docker build only on workflow_dispatch --- .github/workflows/build_docker.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index 0c031c9119..fff46530a0 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -1,14 +1,6 @@ name: Publish Docker Image -on: - workflow_dispatch: - push: - branches: - - 'main' - - 'docker' - tags: - - 'v*' - +on: workflow_dispatch env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} From 134fa6469ee48083a8397402da786eb50c88aa11 Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Wed, 28 Aug 2024 15:22:07 +0200 Subject: [PATCH 4/4] Add latest tag by default on docker build --- .github/workflows/build_docker.yml | 1 + build/docker/compose.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index fff46530a0..d6017454ee 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -47,6 +47,7 @@ jobs: tags: | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest build-args: | GIT_BRANCH=${{ github.ref_name }} GIT_REPO=https://github.com/${{ github.repository }} diff --git a/build/docker/compose.yml b/build/docker/compose.yml index a25c6a8590..0df28afeb4 100644 --- a/build/docker/compose.yml +++ b/build/docker/compose.yml @@ -1,7 +1,7 @@ services: tribler: - image: ghcr.io/tribler/tribler:main + image: ghcr.io/tribler/tribler:latest network_mode: host environment: CORE_API_PORT: 8085