ARG BUILD_FROM
FROM ${BUILD_FROM}

# The add-on version in config.yaml is the Bamboo release it installs (0.1.7 installs v0.1.7).
ARG BUILD_ARCH
ARG BUILD_VERSION=0.1.7

# Download the release for this CPU and check it against the release's SHA256SUMS before installing.
RUN set -eu; \
    case "${BUILD_ARCH}" in \
      amd64) arch=amd64 ;; \
      aarch64) arch=arm64 ;; \
      armv7) arch=arm ;; \
      *) echo "unsupported architecture: ${BUILD_ARCH}" >&2; exit 1 ;; \
    esac; \
    tag="v${BUILD_VERSION}"; \
    name="bamboo_${tag}_linux_${arch}"; \
    base="https://git.veillax.com/Veillax/bamboo/releases/download/${tag}"; \
    cd /tmp; \
    curl -fsSLO "${base}/${name}.tar.gz"; \
    curl -fsSLO "${base}/SHA256SUMS"; \
    grep " ${name}.tar.gz\$" SHA256SUMS | sha256sum -c -; \
    tar xzf "${name}.tar.gz"; \
    install -m 0755 "${name}/bamboo" /usr/local/bin/bamboo; \
    rm -rf /tmp/*

COPY run.sh /run.sh
RUN chmod a+x /run.sh

CMD [ "/run.sh" ]
