# Use CentOS 8 as base image
FROM centos:8

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

# Test users
RUN useradd -m -s /bin/bash ccarbone
RUN useradd -m -s /bin/bash szorba
RUN useradd -m -s /bin/bash sbertocco
RUN useradd -m -s /bin/bash curban

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

# Copy source code and config file of the server app
COPY wait-for-it.sh *.py vos_ts.conf ./
RUN chown transfer_service wait-for-it.sh *.py && \ 
    chmod 755 wait-for-it.sh *.py        

# Install epel repo
RUN dnf update -y && dnf -y install epel-release

# Install nano and openssh
RUN dnf -y install nano openssh-clients

# Install pika, redis, psycopg2 and paramiko
RUN dnf -y install python3-pika python3-redis python3-psycopg2 python3-paramiko
    
# Run commands as transfer_service user
#USER transfer_service

# Create a 'store' directory with some files for various users
RUN mkdir /home/transfer_service/store && touch /home/transfer_service/store/foo1.txt && \
    chown -R transfer_service:transfer_service /home/transfer_service/store && \
    chmod -R 755 /home/transfer_service/store && \
    mkdir /home/curban/store && echo "foo?!" > /home/curban/store/foo2.txt && \
    mkdir /home/curban/store/mydir && \
    echo "Another foo!" > /home/curban/store/mydir/another_foo2.txt && \
    chown -R curban:curban /home/curban/store && \
    chmod -R 755 /home/curban/store && \
    mkdir /home/ccarbone/store && touch /home/ccarbone/store/foo3.txt && \
    chown -R ccarbone:ccarbone /home/ccarbone/store && \
    chmod -R 755 /home/ccarbone/store && \
    mkdir /home/sbertocco/store && touch /home/sbertocco/store/foo4.txt && \
    chown -R sbertocco:sbertocco /home/sbertocco/store && \
    chmod -R 755 /home/sbertocco/store && \
    mkdir /home/szorba/store && touch /home/szorba/store/foo5.txt && \
    chown -R szorba:szorba /home/szorba/store && \
    chmod -R 755 /home/szorba/store

# Run a shell
CMD /bin/bash