FROM centos:centos7

# Init ENV
ENV PENTAHO_VERSION 8.3
ENV PENTAHO_TAG 8.3.0.0-371
ENV PENTAHO_HOME /opt/pentaho

# Update and install common packages
RUN        yum -y update
RUN        yum -y install wget git tar zip unzip vim java-1.8.0-openjdk java-1.8.0-openjdk-devel

#Cleanup
# RUN rm -rf /tmp/*

#User creation
RUN        mkdir ${PENTAHO_HOME}
RUN        useradd pentaho -s /bin/bash
RUN        chown -R pentaho:pentaho ${PENTAHO_HOME}

#DEV VERSION
COPY pdi-ce-8.3.0.0-371.zip /tmp/pdi-ce-8.3.0.0-371.zip
RUN chown pentaho:pentaho /tmp/pdi-ce-8.3.0.0-371.zip

# Download Pentaho BI Server
# RUN wget --progress=dot:giga --content-disposition -c  https://sourceforge.net/projects/pentaho/files/Pentaho%20${PENTAHO_VERSION}/client-tools/pdi-ce-${PENTAHO_TAG}.zip -O /tmp/pdi-ce-${PENTAHO_TAG}.zip
RUN   unzip -q /tmp/pdi-ce-${PENTAHO_TAG}.zip -d  $PENTAHO_HOME
RUN   rm /tmp/pdi-ce-${PENTAHO_TAG}.zip

#Download Snowflake plugin
RUN wget https://github.com/inquidia/PentahoSnowflakePlugin/releases/download/v1.1.4/SnowflakePlugin-1.1.4.zip -O /tmp/SnowflakePlugin-1.1.4.zip; \
    unzip -q /tmp/SnowflakePlugin-1.1.4.zip -d $PENTAHO_HOME/data-integration/plugins; \
    rm /tmp/SnowflakePlugin-1.1.4.zip

#Download Neo4j plugin
RUN wget https://github.com/knowbi/knowbi-pentaho-pdi-neo4j-output/releases/download/5.0.6/Neo4JOutput-5.0.6.zip -O /tmp/Neo4JOutput-5.0.6.zip; \
    unzip -q /tmp/Neo4JOutput-5.0.6.zip -d $PENTAHO_HOME/data-integration/plugins; \
    rm /tmp/Neo4JOutput-5.0.6.zip

#Download Needful plugins
RUN wget https://github.com/mattcasters/kettle-needful-things/releases/download/0.13.0/kettle-needful-things-0.13.0.zip -O /tmp/kettle-needful-things-0.13.0.zip; \
    unzip -q /tmp/kettle-needful-things-0.13.0.zip -d $PENTAHO_HOME/data-integration/plugins; \
    rm /tmp/kettle-needful-things-0.13.0.zip

# Setup Needful plugins
RUN cp $PENTAHO_HOME/data-integration/plugins/kettle-needful-things/kettle-needful-things-0.13.0-SNAPSHOT.jar $PENTAHO_HOME/data-integration/lib
RUN cp $PENTAHO_HOME/data-integration/plugins/kettle-needful-things/lib/picocli-3.7.0.jar $PENTAHO_HOME/data-integration/lib
RUN cp $PENTAHO_HOME/data-integration/plugins/kettle-needful-things/maitre.sh $PENTAHO_HOME/data-integration

RUN chown -R pentaho:pentaho ${PENTAHO_HOME}

WORKDIR /opt/pentaho/data-integration

CMD ["./maitre.sh"]

# Get the transform job
COPY neo4j-to-snowflake-centos.ktr ${PENTAHO_HOME}

# Setup the metastore
COPY dev-cluster.xml ${PENTAHO_HOME}
COPY .type.xml ${PENTAHO_HOME}

RUN mkdir -p "/home/pentaho/.pentaho/metastore/Neo4j/Neo4j Connection/"
RUN cp ${PENTAHO_HOME}/dev-cluster.xml /home/pentaho/.pentaho/metastore/Neo4j/Neo4j\ Connection/
RUN cp ${PENTAHO_HOME}/.type.xml /home/pentaho/.pentaho/metastore/Neo4j/Neo4j\ Connection/
RUN chown -R pentaho:pentaho /home/pentaho/.pentaho/metastore

RUN chown -R pentaho:pentaho ${PENTAHO_HOME}

USER pentaho
