#syntax=docker/dockerfile:1.2@sha256:e2a8561e419ab1ba6b2fe6cbdf49fd92b95912df1cf7d313c3e2230a333fdbcc
FROM ghcr.io/certusone/solana:1.10.31

# This image builds an environment to initialize and use a local
# devnet multisig. It uses Pyth's Mesh client.

RUN apt-get update && apt-get install -yq python3 libudev-dev ncat

RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs

WORKDIR /root

# Also used by the multisig provisioning script
ENV MULTISIG_SCRIPT_DIR=/root/pyth/multisig-wh-message-builder

WORKDIR $MULTISIG_SCRIPT_DIR

ENV LOCAL_MULTISIG_SCRIPT_DIR=third_party/pyth/multisig-wh-message-builder

# Add a barebones representation of our deps for Docker layer caching
ADD $LOCAL_MULTISIG_SCRIPT_DIR/package.json \
    $LOCAL_MULTISIG_SCRIPT_DIR/package-lock.json \
    $LOCAL_MULTISIG_SCRIPT_DIR/tsconfig.json \
    .

RUN mkdir src # tsc is run as part of the install, add minimal placeholders to satisfy it
RUN touch src/index.ts

RUN --mount=type=cache,target=/home/node/.cache \
    npm ci && cp -r node_modules node_modules_cached
RUN rm -rf node_modules && mv node_modules_cached node_modules

# Add the rest of the code. This ensures that real code changes do not affect the layer caching of `npm ci`
ADD third_party/pyth /root/pyth
ADD solana/keys /usr/src/solana/keys

RUN npm install
