FROM amazon/aws-sam-cli-emulation-image-java8

# Install build tools
# The base image essentially corrupts the RPM DB,
#  so we need to make changes for yum to run successfully.
RUN chmod 1777 /tmp && \
  /usr/bin/python3 -c "from configparser import SafeConfigParser; \
  yum_conf = SafeConfigParser(); \
  yum_conf.read('/etc/yum.conf'); \
  yum_conf.has_section('main') or yum_conf.add_section('main'); \
  yum_conf.set('main', 'plugins', '1'); \
  f = open('/etc/yum.conf', 'w'); \
  yum_conf.write(f); \
  f.close();" && \
  rpm --rebuilddb && \
  yum groupinstall -y development && \
  yum install -d1 -y \
  tar \
  gzip \
  unzip \
  python3 \
  jq \
  grep \
  curl \
  make \
  gcc-c++ \
  binutils \
  procps \
  libgmp3-dev \
  zlib1g-dev \
  liblzma-dev \
  libxslt-devel \
  libmpc-devel \
  java-1.8.0-openjdk-devel \
  && yum clean all

# Include build tools for the Function Build image.
# /opt is used for Lambda Layers. To avoid any potential confusion or
# conflict in the future, the build tools are installed in /usr/local/opt

# Install AWS CLI

RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install && rm -rf awscliv2.zip && rm -rf ./aws

# Install SAM CLI in a dedicated Python virtualenv
ARG SAM_CLI_VERSION
RUN curl -L "https://github.com/awslabs/aws-sam-cli/archive/v$SAM_CLI_VERSION.zip" -o "samcli.zip" && \
  unzip samcli.zip && python3 -m venv /usr/local/opt/sam-cli && \
  /usr/local/opt/sam-cli/bin/pip3 --no-cache-dir install -r ./aws-sam-cli-$SAM_CLI_VERSION/requirements/reproducible-linux.txt && \
  /usr/local/opt/sam-cli/bin/pip3 --no-cache-dir install ./aws-sam-cli-$SAM_CLI_VERSION && \
  rm samcli.zip && rm -rf aws-sam-cli-$SAM_CLI_VERSION

ENV PATH=$PATH:/usr/local/opt/sam-cli/bin

ENV LANG=en_US.UTF-8

# Wheel is required by SAM CLI to build libraries like cryptography. It needs to be installed in the system
# Python for it to be picked up during `sam build`
RUN pip3 install wheel

# Install Java buld tools

RUN mkdir /usr/local/gradle && curl -L -o gradle.zip https://downloads.gradle-dn.com/distributions/gradle-6.2.2-bin.zip && \
  unzip -d /usr/local/gradle gradle.zip && rm gradle.zip && mkdir /usr/local/maven && \
  curl -L http://mirror.cc.columbia.edu/pub/software/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz | \
  tar -zx -C /usr/local/maven

ENV PATH="/usr/local/gradle/gradle-6.2.2/bin:/usr/local/maven/apache-maven-3.6.3/bin:${PATH}"

ENV JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk"

COPY ATTRIBUTION.txt /