#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

# base image
FROM docker.io/library/centos:latest@sha256:65a4aad1156d8a0679537cb78519a17eb7142e05a968b26a5361153006224fdc

VOLUME /tmp

ENV GEAFLOW_INSTALL_PATH=/opt
ENV GEAFLOW_HOME=$GEAFLOW_INSTALL_PATH/geaflow

ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
RUN sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
RUN yum update -y

# base packages
RUN yum -y install wget vim curl
RUN yum -y install gcc-c++
RUN wget --no-check-certificate http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo

# jdk
RUN yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel \
    && echo "export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk" >> /etc/profile \
    && echo "export JRE_HOME=\${JAVA_HOME}/jre" >> /etc/profile \
    && echo "export CLASSPATH=.:\${JAVA_HOME}/lib:\${JRE_HOME}/lib:\$CLASSPATH" >> /etc/profile \
    && echo "export JAVA_PATH=\${JAVA_HOME}/bin:\${JRE_HOME}/bin" >> /etc/profile \
    && echo "export PATH=\$PATH:\${JAVA_PATH}" >> /etc/profile \
    && source /etc/profile

# mysql
RUN yum install -y libaio numactl net-tools perl
RUN rpm -ivh https://dev.mysql.com/get/mysql-community-icu-data-files-8.0.30-1.el8.aarch64.rpm
RUN rpm -ivh https://dev.mysql.com/get/mysql-community-client-plugins-8.0.30-1.el8.aarch64.rpm
RUN rpm -ivh https://dev.mysql.com/get/mysql-community-common-8.0.30-1.el8.aarch64.rpm
RUN rpm -ivh https://dev.mysql.com/get/mysql-community-libs-8.0.30-1.el8.aarch64.rpm
RUN rpm -ivh https://dev.mysql.com/get/mysql-community-client-8.0.30-1.el8.aarch64.rpm
RUN rpm -ivh https://dev.mysql.com/get/mysql-community-server-8.0.30-1.el8.aarch64.rpm
RUN  mysqld  --initialize-insecure --user=mysql

# redis
RUN yum install -y epel-release \
    && yum install -y redis

# influxdb
RUN curl -O https://dl.influxdata.com/influxdb/releases/influxdb2-2.7.3-1.aarch64.rpm \
    && yum localinstall -y influxdb2-2.7.3-1.aarch64.rpm \
    && mkdir /usr/lib/influxdb2-client-2.7.3-linux-amd64 \
    && cd /usr/lib/influxdb2-client-2.7.3-linux-amd64 \
    && wget https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.7.3-linux-amd64.tar.gz \
    && tar xvzf influxdb2-client-2.7.3-linux-amd64.tar.gz \
    && cp influx /usr/local/bin/ \
    && rm -rf /usr/lib/influxdb2-client-2.7.3-linux-amd64

# copy console jar
WORKDIR $GEAFLOW_HOME/
COPY geaflow-console/target/boot/geaflow-console-bootstrap-*-executable.jar \
    $GEAFLOW_HOME/boot/geaflow-console-bootstrap.jar
COPY geaflow-console/target/config $GEAFLOW_HOME/config
COPY geaflow-console/docker $GEAFLOW_HOME/

# copy geaflow jar
ENV GEAFLOW_LOCAL_VERSION_PATH=/tmp/geaflow/local/versions/defaultVersion/defaultVersion.jar
COPY geaflow/geaflow-deploy/geaflow-assembly/target/geaflow-assembly-*[!-sources].jar \
   $GEAFLOW_LOCAL_VERSION_PATH
RUN md5sum $GEAFLOW_LOCAL_VERSION_PATH |awk '{print $1}' > $GEAFLOW_LOCAL_VERSION_PATH.md5

EXPOSE 8888 3306 6379 8086 2181

ENTRYPOINT ["bash", "/opt/geaflow/bin/start-process.sh"]