Skip to content

Commit

Permalink
feat: added containerized tdp-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
SteBaum committed Sep 27, 2024
1 parent de8296e commit bc5d76e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

## Pre-requisites

To use `tdp-lib`, ensure you have the following prerequisites:
To use `tdp-lib` on your host, ensure you have the following prerequisites:

- Python 3.9 or higher. Higher version are not guarantee to work, only 3.9 is tested.
- A relational database management system (RDBMS), such as [PostgreSQL](https://www.postgresql.org/) or [SQLite](https://www.sqlite.org/index.html).
Expand All @@ -21,6 +21,8 @@ Optional dependencies for DAG visualization:

- [Graphviz](https://graphviz.org/) for graphical representation of DAGs.

For the containerized `tdp-lib` you only need Docker.

## Installation

Set the following environment variables:
Expand All @@ -40,6 +42,8 @@ inventory=your_inventory,..,~/tdp_vars
enable_plugins = tosit.tdp.inventory,..,your_plugins
```

### Host installation

Install the library:

```sh
Expand All @@ -52,6 +56,20 @@ pip install "tdp-lib[visualization]@https://github.com/TOSIT-IO/tdp-lib/tarball/
tdp init
```

### Containerized installation

Build the image:

```sh
docker build -t tdp-lib --build-arg USER_NAME=$(whoami) --build-arg USER_UID=$(id -u) --build-arg USER_GID=$(id -g) . -f dev/Dockerfile
```

Run and enter the container:

```
docker run -it --rm --network=host -v $PWD:/home/$(whoami)/tdp tdp-lib
```

## CLI Usage

> [!NOTE]
Expand Down
56 changes: 56 additions & 0 deletions dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
FROM python:3.9-slim

# Set arguments for UID and GID
ARG USER_NAME=tdp-lib
ARG USER_UID=1000
ARG USER_GID=1000

# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
git \
openssh-client \
sudo \
vim \
&& rm -rf /var/lib/apt/lists/*

# Create a group with the same GID as the host user
RUN groupadd --gid $USER_GID $USER_NAME

# Create a user with the same UID as the host user and add them to the sudo group
RUN useradd --uid $USER_UID --gid $USER_GID --create-home $USER_NAME && \
echo "$USER_NAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# Switch to the new user
USER $USER_NAME

# Set environment variables for virtual environment
ENV VIRTUAL_ENV="/home/$USER_NAME/venv"
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Create a virtual environment
RUN python -m venv $VIRTUAL_ENV

# Create the tdp directory
RUN mkdir /home/$USER_NAME/tdp

# Set tdp as working directory
WORKDIR /home/$USER_NAME/tdp

# Copy all files
COPY . .

# Install Poetry
RUN curl -sSL https://install.python-poetry.org | python3 -

# Add Poetry to PATH
ENV PATH="/home/$USER_NAME/.local/bin:$PATH"

# Set environment variables for Poetry
ENV POETRY_VIRTUALENVS_CREATE=false \
POETRY_NO_INTERACTION=1

# Install python libraries
RUN poetry install -E postgresql-binary -E mysql -E visualization

CMD ["/bin/bash"]

0 comments on commit bc5d76e

Please sign in to comment.