|
| 1 | +# syntax=docker/dockerfile:1 |
| 2 | + |
| 3 | +# Explaining order of ARGS in Dockerfiles: https://stackoverflow.com/a/53683625/9068781 |
| 4 | + |
| 5 | +ARG RONDB_TARBALL_LOCAL_REMOTE=remote |
| 6 | + |
| 7 | +# Download all required Ubuntu dependencies |
| 8 | +FROM ubuntu:22.04 AS rondb_runtime_dependencies |
| 9 | + |
| 10 | +ARG BUILDPLATFORM |
| 11 | +ARG TARGETPLATFORM |
| 12 | + |
| 13 | +ARG TARGETARCH |
| 14 | +ARG TARGETVARIANT |
| 15 | + |
| 16 | +RUN echo "Running on $BUILDPLATFORM, building for $TARGETPLATFORM" |
| 17 | +RUN echo "TARGETARCH: $TARGETARCH; TARGETVARIANT: $TARGETVARIANT" |
| 18 | + |
| 19 | +# Fail the build if TARGETARCH is not arm64 or amd64 |
| 20 | +RUN if [ "$TARGETARCH" != "arm64" ] && [ "$TARGETARCH" != "amd64" ]; then \ |
| 21 | + echo "Unsupported architecture: $TARGETARCH" && exit 1; \ |
| 22 | + fi |
| 23 | + |
| 24 | +RUN --mount=type=cache,target=/var/cache/apt,id=ubuntu22-apt-$TARGETPLATFORM \ |
| 25 | + --mount=type=cache,target=/var/lib/apt/lists,id=ubuntu22-apt-lists-$TARGETPLATFORM \ |
| 26 | + apt-get update -y \ |
| 27 | + && apt-get install -y wget tar gzip vim \ |
| 28 | + libaio1 libaio-dev \ |
| 29 | + libncurses5 libnuma-dev \ |
| 30 | + bc default-jdk maven \ |
| 31 | + sudo iproute2 dnsutils |
| 32 | + # Java & Maven are required by YCSB |
| 33 | + # bc is required by dbt2 |
| 34 | + # libaio is a dynamic library used by RonDB |
| 35 | + # libncurses5 & libnuma-dev are required for x86 only |
| 36 | + # sudo is required in the entrypoint |
| 37 | + # iproute2 is for using the command `ss` |
| 38 | + # dnsutils is for using the command `nslookup` in K8s |
| 39 | + |
| 40 | +# Let PATH survive through sudo |
| 41 | +RUN sed -ri '/secure_path/d' /etc/sudoers |
| 42 | + |
| 43 | +# Creating a cache dir for downloads to avoid redownloading |
| 44 | +ENV DOWNLOADS_CACHE_DIR=/tmp/downloads |
| 45 | +RUN mkdir $DOWNLOADS_CACHE_DIR |
| 46 | + |
| 47 | +# Copying bare minimum of Hopsworks cloud environment for now |
| 48 | +FROM rondb_runtime_dependencies AS cloud_preparation |
| 49 | +ARG RONDB_VERSION=21.04.16 |
| 50 | +ENV HOPSWORK_DIR=/srv/hops |
| 51 | +ENV RONDB_BIN_DIR=$HOPSWORK_DIR/mysql-$RONDB_VERSION |
| 52 | +RUN mkdir -p $RONDB_BIN_DIR |
| 53 | + |
| 54 | +# Get RonDB tarball from local path & unpack it |
| 55 | +FROM cloud_preparation AS local_tarball |
| 56 | +ARG RONDB_X86_TARBALL_URI |
| 57 | +ARG RONDB_ARM_TARBALL_URI |
| 58 | + |
| 59 | +RUN case "$TARGETARCH" in \ |
| 60 | + amd64) echo "export TARBALL_PATH=$RONDB_X86_TARBALL_URI" >> /env.sh;; \ |
| 61 | + arm64) echo "export TARBALL_PATH=$RONDB_ARM_TARBALL_URI" >> /env.sh;; \ |
| 62 | + esac |
| 63 | + |
| 64 | +RUN --mount=type=bind,source=.,target=/context \ |
| 65 | + . /env.sh \ |
| 66 | + && tar xfz /context/${TARBALL_PATH} -C $RONDB_BIN_DIR --strip-components=1 |
| 67 | + |
| 68 | +# Get RonDB tarball from remote url & unpack it |
| 69 | +FROM cloud_preparation AS remote_tarball |
| 70 | +ARG RONDB_X86_TARBALL_URI |
| 71 | +ARG RONDB_ARM_TARBALL_URI |
| 72 | + |
| 73 | +RUN case "$TARGETARCH" in \ |
| 74 | + amd64) TARBALL_URL=$RONDB_X86_TARBALL_URI;; \ |
| 75 | + arm64) TARBALL_URL=$RONDB_ARM_TARBALL_URI;; \ |
| 76 | + esac \ |
| 77 | + && wget $TARBALL_URL -O ./temp_tarball.tar.gz \ |
| 78 | + && tar xfz ./temp_tarball.tar.gz -C $RONDB_BIN_DIR --strip-components=1 \ |
| 79 | + && rm ./temp_tarball.tar.gz |
| 80 | + |
| 81 | +FROM ${RONDB_TARBALL_LOCAL_REMOTE}_tarball |
| 82 | + |
| 83 | +WORKDIR $HOPSWORK_DIR |
| 84 | + |
| 85 | +# We use symlinks in case we want to exchange binaries |
| 86 | +ENV RONDB_BIN_DIR_SYMLINK=$HOPSWORK_DIR/mysql |
| 87 | +RUN ln -s $RONDB_BIN_DIR $RONDB_BIN_DIR_SYMLINK |
| 88 | + |
| 89 | +ENV PATH=$RONDB_BIN_DIR_SYMLINK/bin:$PATH |
| 90 | + |
| 91 | +# Add RonDB libs to system path (cannot use env variables here) |
| 92 | +COPY <<-"EOF" /etc/ld.so.conf.d/rondb.conf |
| 93 | +/srv/hops/mysql/lib |
| 94 | +/srv/hops/mysql/lib/private |
| 95 | +EOF |
| 96 | +RUN ldconfig --verbose |
| 97 | + |
| 98 | +ENV RONDB_DATA_DIR=$HOPSWORK_DIR/mysql-cluster |
| 99 | +ENV MGMD_DATA_DIR=$RONDB_DATA_DIR/mgmd |
| 100 | +ENV MYSQLD_DATA_DIR=$RONDB_DATA_DIR/mysql |
| 101 | +ENV NDBD_DATA_DIR=$RONDB_DATA_DIR/ndb_data |
| 102 | + |
| 103 | +RUN mkdir -p $MGMD_DATA_DIR $NDBD_DATA_DIR $MYSQLD_DATA_DIR |
| 104 | + |
| 105 | +ENV MYSQL_FILES_DIR=$RONDB_DATA_DIR/mysql-files |
| 106 | +RUN mkdir -p $MYSQL_FILES_DIR |
| 107 | + |
| 108 | +ENV LOG_DIR=$RONDB_DATA_DIR/log |
| 109 | +ENV RONDB_SCRIPTS_DIR=$RONDB_DATA_DIR/ndb/scripts |
| 110 | +ENV BACKUP_DATA_DIR=$RONDB_DATA_DIR/ndb/backups |
| 111 | +ENV DISK_COLUMNS_DIR=$RONDB_DATA_DIR/ndb_disk_columns |
| 112 | +ENV MYSQL_UNIX_PORT=$RONDB_DATA_DIR/mysql.sock |
| 113 | + |
| 114 | +RUN mkdir -p $LOG_DIR $RONDB_SCRIPTS_DIR $BACKUP_DATA_DIR $DISK_COLUMNS_DIR |
| 115 | + |
| 116 | +COPY ./resources/rondb_scripts $RONDB_SCRIPTS_DIR |
| 117 | +ENV PATH=$RONDB_SCRIPTS_DIR:$PATH |
| 118 | + |
| 119 | +RUN touch $MYSQL_UNIX_PORT |
| 120 | + |
| 121 | +# We expect this image to be used as base image to other |
| 122 | +# images with additional files specific to Docker |
| 123 | +COPY ./resources/entrypoints ./docker/rondb_standalone/entrypoints |
| 124 | +COPY ./resources/healthcheck.sh ./docker/rondb_standalone/healthcheck.sh |
| 125 | + |
| 126 | +# Can be used to mount SQL init scripts |
| 127 | +ENV SQL_INIT_SCRIPTS_DIR=$HOPSWORK_DIR/docker/rondb_standalone/sql_init_scripts |
| 128 | +RUN mkdir $SQL_INIT_SCRIPTS_DIR |
| 129 | + |
| 130 | +# Creating benchmarking files/directories |
| 131 | +# When using load balancers, "sysbench" can be used for both _single and _multi |
| 132 | +ENV BENCHMARKS_DIR=$HOPSWORK_DIR/benchmarks |
| 133 | +RUN mkdir $BENCHMARKS_DIR && cd $BENCHMARKS_DIR \ |
| 134 | + && mkdir -p sysbench sysbench_single sysbench_multi dbt2_single dbt2_multi dbt2_data |
| 135 | + |
| 136 | +# These directories have to have 777 permissions if we want to |
| 137 | +# run RonDB containers with arbitrary users |
| 138 | +RUN chmod 777 -R $RONDB_DATA_DIR \ |
| 139 | + && chmod 777 -R $HOPSWORK_DIR/docker \ |
| 140 | + && chmod 777 -R $BENCHMARKS_DIR |
| 141 | + |
| 142 | +# Remove awkward message when using arbitrary user |
| 143 | +RUN echo "PS1='${debian_chroot:+(\$debian_chroot)}\h:\w\$ '" >> /etc/bash.bashrc |
| 144 | + |
| 145 | +ENTRYPOINT ["./docker/rondb_standalone/entrypoints/main.sh"] |
| 146 | +EXPOSE 3306 33060 11860 1186 4406 5406 |
| 147 | +CMD ["mysqld"] |
0 commit comments