FROM ubuntu:18.04

ENV DEBIAN_FRONTEND=noninteractive
RUN apt update -y
RUN apt install -y software-properties-common

# install python, libmysqlclient-dev, java, bats, git ruby, perl, cpan
RUN add-apt-repository ppa:deadsnakes/ppa -y
RUN apt update -y
RUN apt install -y \
	python3.8 \
	python3-pip \
	curl \
	wget \
	pkg-config \
	mysql-client \
	libmysqlclient-dev \
	openjdk-8-jdk \
	ant \
	ca-certificates-java \
	bats \
        perl \
	cpanminus \
	cmake \
	g++ \
	libmysqlcppconn-dev \
	git \
	ruby\
	gem

# install go
WORKDIR /root
ENV GO_VERSION=1.15.1
RUN curl -O "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz"
RUN sha256sum "go${GO_VERSION}.linux-amd64.tar.gz"
RUN tar -xvf "go${GO_VERSION}.linux-amd64.tar.gz" -C /usr/local
RUN chown -R root:root /usr/local/go
RUN mkdir -p $HOME/go/{bin,src}
ENV GOPATH=$HOME/go
ENV PATH=$PATH:$GOPATH/bin
ENV PATH=$PATH:$GOPATH/bin:/usr/local/go/bin
RUN go version

# go get the MySQL dependency
RUN go get -u github.com/go-sql-driver/mysql

# install dotnet
RUN wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN apt-get update; \
      apt-get install -y apt-transport-https && \
      apt-get update && \
      apt-get install -y dotnet-sdk-5.0

# install node
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt install -y nodejs

# install mysql connector and pymsql
RUN pip3 install mysql-connector-python PyMySQL sqlalchemy

# Fix certificate issues
RUN update-ca-certificates -f

# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
 
# install mysql connector java
RUN mkdir -p /mysql-client-tests/java
RUN curl -L -o /mysql-client-tests/java/mysql-connector-java-8.0.21.jar \
  https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.21/mysql-connector-java-8.0.21.jar

# install node deps
COPY mysql-client-tests/node/package.json /mysql-client-tests/node/
COPY mysql-client-tests/node/package-lock.json /mysql-client-tests/node/
WORKDIR /mysql-client-tests/node
RUN npm install

# install cpan dependencies
RUN cpanm DBD::mysql

# install ruby dependencies
COPY mysql-client-tests/ruby/Gemfile /mysql-client-tests/ruby/
COPY mysql-client-tests/ruby/Gemfile.lock /mysql-client-tests/ruby/
WORKDIR /mysql-client-tests/ruby
RUN gem install bundler -v 2.1.4
RUN bundle install

# install elixir
RUN apt-get install wget
RUN wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && dpkg -i erlang-solutions_2.0_all.deb
RUN apt-get update && apt-get -y upgrade
RUN apt-get install -y esl-erlang
RUN apt-get install -y elixir

# install postgres and psql
RUN apt-get install -y postgresql postgresql-contrib libpq-dev postgresql-server-dev-all
RUN service postgresql start

# install mysql_fdw
WORKDIR /mysql-client-tests/mysql_fdw
RUN git clone https://github.com/EnterpriseDB/mysql_fdw
WORKDIR /mysql-client-tests/mysql_fdw/mysql_fdw
RUN make USE_PGXS=1
RUN make USE_PGXS=1 install

# install dolt from source
WORKDIR /root/building
COPY ./go .
ENV GOFLAGS="-mod=readonly"
RUN go build -o /usr/local/bin/dolt ./cmd/dolt

COPY mysql-client-tests /mysql-client-tests
COPY mysql-client-tests/mysql-client-tests-entrypoint.sh /mysql-client-tests/entrypoint.sh

WORKDIR /mysql-client-tests
ENTRYPOINT ["/mysql-client-tests/entrypoint.sh"]
