# Use python 3.9.5-slim as base image
FROM python:3.9.5-slim

# Install psql client to be able to connect manually to the file_catalog container
# Install also redis-tools to be able to access the redis container via redis-cli
RUN apt-get -y update && apt-get -y install nano screen postgresql-client redis-tools 

# Create a new user called 'client', create the home directory and set the default shell
RUN useradd -m -s /bin/bash client

# Copy the source code of all client apps
RUN mkdir -p /usr/bin/vos_cli
COPY *.py \
     vos_data \
     vos_import \
     vos_job \
     vos_storage /usr/bin/vos_cli/
RUN chmod -R 755 /usr/bin/vos_cli

# Copy bash-completion scripts
COPY config/bash_completion/* /usr/share/bash-completion/completions/

# Copy configuration file
RUN mkdir -p /etc/vos_cli
COPY config/vos_cli.conf /etc/vos_cli/
RUN chmod -R 755 /etc/vos_cli

# Set the PAH environment variable
ENV PATH "$PATH:/usr/bin/vos_cli"
    
# Run commands as 'client' user
USER client

# Set up a workdir for the container
WORKDIR /home/client/

# Source bash-completion scripts
RUN echo ". /usr/share/bash-completion/completions/vos_data" >> .bashrc && \
    echo ". /usr/share/bash-completion/completions/vos_job" >> .bashrc && \
    echo ". /usr/share/bash-completion/completions/vos_storage" >> .bashrc
    
# Install python dependencies
RUN pip3.9 install --no-cache-dir redis tabulate
