# To build the image, navigate to the folder where this Dockerfile is located, and run command at next line.
# docker build --tag=psft-tw-build-machine .

# To run container from the image, run command at the next line:
# docker run -d --name psft-tw --rm -v d:\Prosoft\workspace:/home/user/workspace -p 4422:22 -e SSH_KEY="$(cat ~/.ssh/id_rsa.pub)" psft-tw-build-machine

#FROM i386/ubuntu
FROM i386/debian

RUN apt-get update -y

RUN apt-get install -y cmake
RUN apt-get install -y build-essential

RUN apt-get update -y

RUN apt-get install -y libssl-dev
RUN apt-get install -y wget
RUN apt-get install -y python
RUN apt-get install -y git
RUN apt-get install -y unzip
RUN apt-get install -y openssh-server
RUN apt-get install -y whois
RUN apt-get install -y sudo 
RUN apt-get install -y gdb
# socat is required by visual GDB
RUN apt-get install -y socat
# cifs-utils is to access Windows shared folders
RUN apt-get install -y cifs-utils
RUN apt-get install -y gdbserver
RUN apt-get install -y nano

# For OPC UA project:
RUN apt-get install -y zlib1g-dev
RUN apt-get install -y libpcap-dev

ARG SHARED_FOLDER
ARG SHARED_FOLDER_USER=user
ARG SHARED_FOLDER_PASSWORD=password

#Create user with encrypted password (to encrypt it, the mkpasswd command is used), and grant it sudo user rights:
RUN useradd -m -p $(mkpasswd -m sha-512 ${SHARED_FOLDER_PASSWORD}) -s /bin/bash user
RUN usermod -aG sudo user

#Create folder workspace:
RUN mkdir -p /home/user/workspace
RUN chown user /home/user/workspace
RUN mkdir -p /home/user/ws
RUN chown user /home/user/ws

# Install toolchain:
COPY tc.tar.gz /home/user/tc.tar.gz
RUN cd / && tar -xhzvf /home/user/tc.tar.gz
RUN rm /home/user/tc.tar.gz

#create symbolic links to actual location of the toolchain to locations expected by other projects (for mvi56e-datm3)
RUN ln -s /opt/timesys/datm3 /root/datm3
RUN ln -s /opt/timesys/datm3 /home/user/datm3
# Change access rights to the folder /root to regular user connected over SSH can access it:
RUN chmod 764 /root

# Port 22 is required to access container over ssh.
EXPOSE 22
EXPOSE 4840

ENV SHARED_FOLDER_NAME ${SHARED_FOLDER:-//192.168.1.73/WorkSpace}
ENV SHARED_FOLDER_P ${SHARED_FOLDER_PASSWORD:-password}
ENV SHARED_FOLDER_U ${SHARED_FOLDER_USER:-user}

CMD (mount.cifs $SHARED_FOLDER_NAME /home/user/workspace -o user=$SHARED_FOLDER_U,pass=$SHARED_FOLDER_P,uid=1000,gid=1000,forceuid,forcegid,vers=3.0,mfsymlinks,noserverino || echo failed to mount) && /etc/init.d/ssh start && tail -f /dev/null
