FROM golang:1.18-buster

ENV DEBIAN_FRONTEND=noninteractive

# Get sysbench installed
RUN apt update
RUN apt install -y curl
RUN curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | bash
RUN apt -y install sysbench

# Install sqlite3 from source
RUN \
  apt-get install -y \
  build-essential \
  tcl \
  lsb-release \
  && wget \
    -O sqlite.tar.gz \
    https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release \
  && tar xvfz sqlite.tar.gz \
  # Configure and make SQLite3 binary
  && ./sqlite/configure --prefix=/usr \
  && make \
  && make install \
  # Smoke test
  && sqlite3 --version

WORKDIR /
COPY ./go /dolt/go
COPY ./config.json /config.json
COPY ./tpcc-config.json /tpcc-config.json
COPY ./sysbench-runner-tests-entrypoint.sh /entrypoint.sh
RUN git clone https://github.com/dolthub/sysbench-lua-scripts.git
RUN git clone https://github.com/Percona-Lab/sysbench-tpcc.git

WORKDIR /mysql
RUN curl -L -O https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb
RUN dpkg -i mysql-apt-config_0.8.22-1_all.deb
RUN apt-get update && apt-get install -y mysql-server
RUN mysql --version

# Install dolt
WORKDIR /dolt/go/cmd/dolt
RUN go build -o /usr/local/bin/dolt .

ENV DOLT_TRANSACTION_MERGE_STOMP=1
WORKDIR /dolt/go/performance/utils/sysbench_runner/cmd
ENTRYPOINT ["/entrypoint.sh"]
