# Dockerfile for https://github.com/adnanh/webhook
FROM        docker.io/golang:1-bookworm AS build

#MAINTAINER  Almir Dzinovic <almir@dzinovic.net>

WORKDIR     /go/src/github.com/adnanh/webhook
ENV         WEBHOOK_VERSION 2.8.1
#RUN         apk add --update -t build-deps curl libc-dev gcc libgcc
RUN set -eux; \
  apt-get update; \
  apt-get install -y --no-install-recommends curl 
RUN         curl -L --silent -o webhook.tar.gz https://github.com/adnanh/webhook/archive/${WEBHOOK_VERSION}.tar.gz && \
  tar -xzf webhook.tar.gz --strip 1 &&  \
  go get -d && \
  go build -o /usr/local/bin/webhook && \
  #apk del --purge build-deps && \
  apt-get purge -y build-deps && \
  #rm -rf /var/cache/apk/* && \
  apt-get remove -y --auto-remove \
  ; \
  rm -rf /var/lib/apt/lists/*; \
  rm -rf /go

#FROM docker.io/alpine:edge
#FROM docker.io/rust:bookworm
FROM docker.io/debian:bookworm-slim

ENV RESTIC_VERSION=0.17.1
ENV RESTIC_ARCH=linux_amd64

ENV K8S_VERSION=1.31.1
ENV K8S_ARCH=linux-amd64

ENV JQ_VERSION=1.7,1
ENV JQ_ARCH=linux64

ENV YQ_VERSION=4.44.3
ENV YQ_ARCH=linux_amd64

#RUN apk add --update \
RUN set -eux; \
  apt-get update; \
  apt-get install -y --no-install-recommends \
  ca-certificates \
  bash \
  vim \
  git \
  bzip2 \
  sed \
#  openssh \
  openssl \
#  libressl \
  curl \
  jq \
  zlib1g \
  gnupg \
  wget \
#  python3-pip \
#  python3-jinja2 \
#  python3-s3cmd \
#  pipx \
  ; \
  update-ca-certificates; \
#  python3 -m ensurepip; \
#  rm -r /usr/lib/python*/ensurepip; \
#  pip install jinja2 s3cmd ; \
	curl -fSL "https://dl.k8s.io/v${K8S_VERSION}/kubernetes-client-${K8S_ARCH}.tar.gz" -o /tmp/kubernetes-client-${K8S_ARCH}.tar.gz; \
  tar -C /tmp -xvzf /tmp/kubernetes-client-${K8S_ARCH}.tar.gz ;\
	if [ -f /tmp/kubernetes/client/bin/kubectl ]; then mv /tmp/kubernetes/client/bin/kubectl /usr/local/bin; fi ;\
	rm -rf /tmp/kubernetes*; \
	chmod +x /usr/local/bin/kubectl; \
  curl -fSL "https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_${YQ_ARCH}" -o /usr/local/bin/yq; \
  chmod +x /usr/local/bin/yq; \
	wget -q "https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_${RESTIC_ARCH}.bz2" -O /tmp/restic-${RESTIC_VERSION}.bz2; \
  bunzip2 /tmp/restic-${RESTIC_VERSION}.bz2; \
  mv /tmp/restic-${RESTIC_VERSION} /usr/local/bin/restic; \
  chmod +x /usr/local/bin/restic; \
  rm -f /tmp/restic*;

COPY        --from=build /usr/local/bin/webhook /usr/local/bin/webhook
COPY        bin.tar.gz /tmp
RUN         tar -C /usr/local -xvzf /tmp/bin.tar.gz 
WORKDIR     /home/webhook
VOLUME      ["/etc/webhook"]
EXPOSE      9000
ENTRYPOINT  ["/usr/local/bin/webhook"]
