diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml new file mode 100644 index 0000000000..d6017454ee --- /dev/null +++ b/.github/workflows/build_docker.yml @@ -0,0 +1,60 @@ +name: Publish Docker Image + +on: workflow_dispatch +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 }} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + 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/compose.yml b/build/docker/compose.yml new file mode 100644 index 0000000000..0df28afeb4 --- /dev/null +++ b/build/docker/compose.yml @@ -0,0 +1,11 @@ + +services: + tribler: + image: ghcr.io/tribler/tribler:latest + network_mode: host + environment: + CORE_API_PORT: 8085 + CORE_API_KEY: "changeme" + volumes: + - ~/.Tribler/git:/home/user/.Tribler + - ~/Downloads/TriblerDownloads:/home/user/Downloads/TriblerDownloads