content: FROM node:12.16-slim as builder
  
  ARG DEVELOPER
  ENV STANDALONE=1
  
  # Install build c-lightning for third-party packages (c-lightning/bitcoind)
  RUN apt-get update && apt-get install -y --no-install-recommends git wget ca-certificates \
      qemu qemu-user-static qemu-user binfmt-support
  
  RUN npm config set unsafe-perm true
  
  # Install tini
  RUN mkdir /opt/bin && wget -qO /opt/bin/tini "https://github.com/krallin/tini/releases/download/v0.18.0/tini-arm64" \
      && echo "7c5463f55393985ee22357d976758aaaecd08defb3c5294d353732018169b019 /opt/bin/tini" | sha256sum -c - \
      && chmod +x /opt/bin/tini
  
  # Install Spark
  WORKDIR /opt/spark/client
  COPY client/package.json client/npm-shrinkwrap.json ./
  COPY client/fonts ./fonts
  RUN npm install
  
  WORKDIR /opt/spark
  COPY package.json npm-shrinkwrap.json ./
  RUN npm install
  COPY . .
  
  # Build production NPM package
  RUN npm run dist:npm \
   && npm prune --production \
   && find . -mindepth 1 -maxdepth 1 \
             ! -name '*.json' ! -name dist ! -name LICENSE ! -name node_modules ! -name scripts \
             -exec rm -r "{}" \;
  
  # Prepare final image
  
  FROM arm64v8/node:12.16-slim
  
  ENV STANDALONE=1
  
  WORKDIR /opt/spark
  COPY --from=builder /usr/bin/qemu-aarch64-static /usr/bin/qemu-aarch64-static
  RUN apt-get update && apt-get install -y --no-install-recommends xz-utils inotify-tools netcat-openbsd \
      && rm -rf /var/lib/apt/lists/* \
      && ln -s /opt/spark/dist/cli.js /usr/bin/spark-wallet \
      && mkdir /data \
      && ln -s /data/lightning $HOME/.lightning
  
  COPY --from=builder /opt/bin /usr/bin
  COPY --from=builder /opt/spark /opt/spark
  
  ENV CONFIG=/data/spark/config TLS_PATH=/data/spark/tls TOR_PATH=/data/spark/tor COOKIE_FILE=/data/spark/cookie HOST=0.0.0.0
  
  # link the granax (Tor Control client) node_modules installation directory
  # inside /data/spark/tor/, to persist the Tor Bundle download in the user-mounted volume
  RUN ln -s $TOR_PATH/tor-installation/node_modules dist/transport/granax-dep/node_modules
  
  VOLUME /data
  ENTRYPOINT [ "tini", "-g", "--", "scripts/docker-entrypoint.sh" ]
  
  EXPOSE 9737
  