Skip to content

Commit

Permalink
Added Docker build action
Browse files Browse the repository at this point in the history
Add docker build with GH action

Set docker filename on build

Add docker tag based on branch and version

Update docker/metadata-action to v5

Add tag version and support workflow dispatch

Set fetc-depth to 0 on docker build

Update builder_docker github action

Set fetch depth to zero

Define version of actions on build_docker workflow

Fix version issue

Pass docker args

Add an echo log on dockerfile for repo and branch

Fix build args GIT_REPO URL

Set pyvipv8 on docker pythonpath

Update compose.yml file

Always use the full tag for version

Remove extra metadata tags; instead use branch and version

Remove configuration file
  • Loading branch information
qstokkink authored and xoriole committed Aug 28, 2024
1 parent e8f8f91 commit e0d44ff
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 34 deletions.
70 changes: 58 additions & 12 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,67 @@
name: Build Docker Image
name: Publish Docker Image

on: workflow_dispatch
on:
workflow_dispatch:
push:
branches:
- 'main'
- 'docker'
tags:
- 'v*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
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: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and export
- 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:
tags: tribler:latest
outputs: type=docker,dest=/tmp/tribler.tar
context: .
file: build/docker/build.Dockerfile
- name: Upload artifact
uses: actions/upload-artifact@v4
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:
name: tribler
path: /tmp/tribler.tar
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
47 changes: 25 additions & 22 deletions build/docker/build.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,33 @@ RUN apt-get update \
&& apt-get install -y --no-install-recommends libsodium23=1.0.18-1 \
&& rm -rf /var/lib/apt/lists/*

# Then, install pip dependencies so that it can be cached and does not
# need to be built every time the source code changes.
# This reduces the docker build time.
COPY ./pyipv8/requirements.txt /app/tribler/pyipv8/requirements.txt
COPY ./requirements.txt /app/tribler/requirements.txt
RUN pip3 install -r /app/tribler/requirements.txt

RUN useradd -ms /bin/bash user

# Create default state and download directories and set the permissions
RUN chown -R user:user /app
RUN mkdir /state /downloads && chown -R user:user /state /downloads
# 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

# Copy the source code and set the working directory
COPY ./src /app/tribler/src/
WORKDIR /app/tribler/
# 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

ENV CORE_API_PORT=20100
ENV TSTATEDIR=/state
# Install NPM dependencies
WORKDIR /home/user/tribler/src/tribler/ui
RUN npm install \
&& npm run build

VOLUME /state
VOLUME /downloads
COPY ./build/docker/configuration.json /state/git/configuration.json
# Install Python dependencies
WORKDIR /home/user/tribler
RUN pip3 install -r requirements.txt

USER user
# Set IPv8 on pythonpath
ENV PYTHONPATH=pyipv8

CMD exec python3 /app/tribler/src/run_tribler.py
# Run the application using Xvfb
CMD xvfb-run python3 src/run_tribler.py
11 changes: 11 additions & 0 deletions build/docker/compose.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e0d44ff

Please sign in to comment.