ARG TAG=main
FROM git.plabble.org/job79/base:${TAG}
USER root

RUN set -o pipefail && \
  GO_VERSION=$(curl -fsSL --retry 3 "https://go.dev/VERSION?m=text" | head -n 1 | tr -d '\r\n') && \
  curl -fsSL --retry 3 "https://go.dev/dl/${GO_VERSION}.linux-amd64.tar.gz" | tar xz -C /usr/local && \
  ln -sf /usr/local/go/bin/go /usr/local/go/bin/gofmt /usr/local/bin/

# Build caches live in cache mounts so they don't end up in the image.
RUN --mount=type=cache,id=go-mod,target=/root/go/pkg/mod \
  --mount=type=cache,id=go-build,target=/root/.cache/go-build \
  for pkg in \
    golang.org/x/tools/gopls \
    golang.org/x/tools/cmd/goimports \
    mvdan.cc/gofumpt \
    github.com/go-delve/delve/cmd/dlv; \
  do GOBIN=/usr/local/bin go install "$pkg@latest" || exit 1; done

RUN --mount=type=cache,id=bun-cache,target=/root/.bun-cache \
  BUN_INSTALL=/usr/local BUN_INSTALL_CACHE_DIR=/root/.bun-cache bun install -g \
    typescript typescript-language-server @tailwindcss/language-server svelte-language-server @biomejs/biome

USER user
