content: # syntax=docker/dockerfile:1
  
  ARG GO_VERSION="1.23"
  ## Build Image
  FROM golang:${GO_VERSION}-alpine3.20 AS builder
  
  ARG E2E_SCRIPT_NAME
  
  RUN set -eux; apk add --no-cache ca-certificates build-base;
  
  RUN apk add git
  
  # needed by github.com/zondax/hid
  RUN apk add linux-headers
  
  WORKDIR /osmosis
  COPY . /osmosis
  
  # Cosmwasm - Download correct libwasmvm version
  RUN ARCH=$(uname -m) && WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm/v2 | sed 's/.* //') && \
      wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$ARCH.a \
      -O /lib/libwasmvm_muslc.$ARCH.a && \
      # verify checksum
      wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \
      sha256sum /lib/libwasmvm_muslc.$ARCH.a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.$ARCH | cut -d ' ' -f 1) 
  
  
  RUN BUILD_TAGS=muslc LINK_STATICALLY=true E2E_SCRIPT_NAME=${E2E_SCRIPT_NAME} make e2e-build-script
  
  ## Deploy image
  FROM ubuntu
  
  # Args only last for a single build stage - renew
  ARG E2E_SCRIPT_NAME
  
  COPY --from=builder /osmosis/build/${E2E_SCRIPT_NAME} /bin/${E2E_SCRIPT_NAME}
  
  ENV HOME=/osmosis
  WORKDIR $HOME
  
  # Docker ARGs are not expanded in ENTRYPOINT in the exec mode. At the same time,
  # it is impossible to add CMD arguments when running a container in the shell mode.
  # As a workaround, we create the entrypoint.sh script to bypass these issues.
  RUN echo "#!/bin/bash\n${E2E_SCRIPT_NAME} \"\$@\"" >> entrypoint.sh && chmod +x entrypoint.sh
  
  ENTRYPOINT ["./entrypoint.sh"]
  