|
| 1 | +FROM public.ecr.aws/amazonlinux/amazonlinux:2023 |
| 2 | +ARG REGION |
| 3 | +ENV AWS_REGION ${REGION} |
| 4 | + |
| 5 | +RUN rpm -q system-release --qf '%{VERSION}' |
| 6 | + |
| 7 | +RUN dnf clean all \ |
| 8 | + && dnf update -y \ |
| 9 | + && dnf install -y awscli vim gcc gzip unzip zip tar wget liblapack* libblas* libopenblas* \ |
| 10 | + && dnf install -y openssl openssl-devel \ |
| 11 | + && dnf install -y kernel kernel-headers kernel-devel \ |
| 12 | + && dnf install -y bzip2-devel libffi-devel sqlite-devel xz-devel \ |
| 13 | + && dnf install -y ncurses ncurses-compat-libs binutils \ |
| 14 | + && dnf install -y nss-softokn-freebl avahi-libs avahi dbus dbus-libs \ |
| 15 | + && dnf install -y python-pillow |
| 16 | + |
| 17 | +# Install python 3.9 |
| 18 | +ARG PYTHON_BASE_VERSION=3.9 |
| 19 | +ARG PYTHON_WITH_BASE_VERSION=python${PYTHON_BASE_VERSION} |
| 20 | +ARG PIP_WITH_BASE_VERSION=pip${PYTHON_BASE_VERSION} |
| 21 | +ARG PYTHON_VERSION=${PYTHON_BASE_VERSION}.18 |
| 22 | +RUN dnf groupinstall -y 'Development Tools' \ |
| 23 | + && wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz \ |
| 24 | + && tar xzf Python-${PYTHON_VERSION}.tgz \ |
| 25 | + && cd Python-*/ \ |
| 26 | + && ./configure --enable-optimizations \ |
| 27 | + && make altinstall \ |
| 28 | + && echo -e 'alias python3=python3.9\nalias pip3=pip3.9' >> ~/.bashrc \ |
| 29 | + && ln -s $(which ${PYTHON_WITH_BASE_VERSION}) /usr/local/bin/python3 \ |
| 30 | + && ln -s $(which ${PIP_WITH_BASE_VERSION}) /usr/local/bin/pip3 \ |
| 31 | + && cd .. \ |
| 32 | + && rm Python-${PYTHON_VERSION}.tgz \ |
| 33 | + && rm -rf Python-${PYTHON_VERSION} |
| 34 | + |
| 35 | +#Amazon Linux 2023 uses dnf instead of yum as pacakge management tool: https://docs.aws.amazon.com/linux/al2023/ug/package-management.html |
| 36 | + |
| 37 | +# Copied from EMR: https://tiny.amazon.com/kycbidpc/codeamazpackAwsCblob51c8src |
| 38 | +RUN dnf install -y java-1.8.0-amazon-corretto-devel nginx python3-virtualenv \ |
| 39 | + && dnf -y clean all && rm -rf /var/cache/dnf |
| 40 | + |
| 41 | +ENV PYTHONDONTWRITEBYTECODE=1 |
| 42 | +ENV PYTHONUNBUFFERED=1 |
| 43 | +# http://blog.stuart.axelbrooke.com/python-3-on-spark-return-of-the-pythonhashseed |
| 44 | +ENV PYTHONHASHSEED 0 |
| 45 | +ENV PYTHONIOENCODING UTF-8 |
| 46 | +ENV PIP_DISABLE_PIP_VERSION_CHECK 1 |
| 47 | + |
| 48 | +# Install EMR Spark/Hadoop |
| 49 | +ENV HADOOP_HOME /usr/lib/hadoop |
| 50 | +ENV HADOOP_CONF_DIR /usr/lib/hadoop/etc/hadoop |
| 51 | +ENV SPARK_HOME /usr/lib/spark |
| 52 | + |
| 53 | +COPY yum/emr-apps.repo /etc/yum.repos.d/emr-apps.repo |
| 54 | + |
| 55 | +# Install hadoop / spark dependencies from EMR's yum repository for Spark optimizations. |
| 56 | +# replace placeholder with region in repository URL |
| 57 | +RUN sed -i "s/REGION/${AWS_REGION}/g" /etc/yum.repos.d/emr-apps.repo |
| 58 | +RUN ls /etc/yum.repos.d/emr-apps.repo |
| 59 | +RUN cat /etc/yum.repos.d/emr-apps.repo |
| 60 | +RUN adduser -N hadoop |
| 61 | + |
| 62 | +# These packages are a subset of what EMR installs in a cluster with the |
| 63 | +# "hadoop", "spark", and "hive" applications. |
| 64 | +# They include EMR-optimized libraries and extras. |
| 65 | +RUN dnf install -y aws-hm-client \ |
| 66 | + aws-java-sdk \ |
| 67 | + emr-goodies \ |
| 68 | + emr-scripts \ |
| 69 | + emr-s3-select \ |
| 70 | + emrfs \ |
| 71 | + hadoop \ |
| 72 | + hadoop-client \ |
| 73 | + hadoop-hdfs \ |
| 74 | + hadoop-hdfs-datanode \ |
| 75 | + hadoop-hdfs-namenode \ |
| 76 | + hadoop-httpfs \ |
| 77 | + hadoop-kms \ |
| 78 | + hadoop-lzo \ |
| 79 | + hadoop-mapreduce \ |
| 80 | + hadoop-yarn \ |
| 81 | + hadoop-yarn-nodemanager \ |
| 82 | + hadoop-yarn-proxyserver \ |
| 83 | + hadoop-yarn-resourcemanager \ |
| 84 | + hadoop-yarn-timelineserver \ |
| 85 | + hive \ |
| 86 | + hive-hcatalog \ |
| 87 | + hive-hcatalog-server \ |
| 88 | + hive-jdbc \ |
| 89 | + hive-server2 \ |
| 90 | + s3-dist-cp \ |
| 91 | + spark-core \ |
| 92 | + spark-datanucleus \ |
| 93 | + spark-history-server \ |
| 94 | + spark-python \ |
| 95 | + && dnf -y clean all \ |
| 96 | + && rm -rf /var/cache/dnf /var/lib/dnf/* /etc/yum.repos.d/emr-* |
| 97 | + |
| 98 | +# Point Spark at proper python binary |
| 99 | +ENV PYSPARK_PYTHON=/usr/local/bin/python3.9 |
| 100 | + |
| 101 | +# Setup Spark/Yarn/HDFS user as root |
| 102 | +ENV PATH="/usr/bin:/opt/program:${PATH}" |
| 103 | +ENV YARN_RESOURCEMANAGER_USER="root" |
| 104 | +ENV YARN_NODEMANAGER_USER="root" |
| 105 | +ENV HDFS_NAMENODE_USER="root" |
| 106 | +ENV HDFS_DATANODE_USER="root" |
| 107 | +ENV HDFS_SECONDARYNAMENODE_USER="root" |
| 108 | + |
| 109 | +# Set up bootstrapping program and Spark configuration |
| 110 | +COPY hadoop-config /opt/hadoop-config |
| 111 | +COPY nginx-config /opt/nginx-config |
| 112 | +COPY aws-config /opt/aws-config |
| 113 | +COPY Pipfile Pipfile.lock setup.py *.whl /opt/program/ |
| 114 | +ENV PIPENV_PIPFILE=/opt/program/Pipfile |
| 115 | +# Use --system flag, so it will install all packages into the system python, |
| 116 | +# and not into the virtualenv. Since docker containers do not need to have virtualenvs |
| 117 | +# pipenv > 2022.4.8 fails to build smspark |
| 118 | +RUN /usr/local/bin/python3.9 -m pip --version |
| 119 | +RUN /usr/local/bin/python3.9 -m pip install --upgrade pip |
| 120 | +RUN /usr/local/bin/python3.9 -m pip install --upgrade pip setuptools wheel |
| 121 | + |
| 122 | +RUN /usr/local/bin/python3.9 -m pip install pipenv==2022.4.8 \ |
| 123 | + && pipenv install --system \ |
| 124 | + && /usr/local/bin/python3.9 -m pip install /opt/program/*.whl |
| 125 | + |
| 126 | +# Setup container bootstrapper |
| 127 | +COPY container-bootstrap-config /opt/container-bootstrap-config |
| 128 | +RUN chmod +x /opt/container-bootstrap-config/bootstrap.sh \ |
| 129 | + && /opt/container-bootstrap-config/bootstrap.sh |
| 130 | + |
| 131 | +# With this config, spark history server will not run as daemon, otherwise there |
| 132 | +# will be no server running and container will terminate immediately |
| 133 | +ENV SPARK_NO_DAEMONIZE TRUE |
| 134 | + |
| 135 | +WORKDIR $SPARK_HOME |
| 136 | + |
| 137 | +# Install the sagemaker feature store spark connector |
| 138 | +# https://docs.aws.amazon.com/sagemaker/latest/dg/batch-ingestion-spark-connector-setup.html |
| 139 | +# Feature store connector library currently does not support spark 3.4 so commenting out this line |
| 140 | +# RUN /usr/local/bin/python3.9 -m pip install sagemaker-feature-store-pyspark-3.3==1.1.2 --no-binary :all: |
| 141 | + |
| 142 | +ENTRYPOINT ["smspark-submit"] |
0 commit comments