# Dependencies and linters for build:
FROM golang:1.20.8@sha256:6e1a67ec11cc4eaa7a9699bc6e5385b00001669531284005ebd2ada4129138d9
# Need gcc for -race test (and some linters though those work with CGO_ENABLED=0)
RUN apt-get -y update && \
  apt-get --no-install-recommends -y upgrade && \
  DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y install libc6-dev apt-transport-https ssh \
  ruby-dev build-essential rpm gnupg zip netcat-traditional

# Install FPM
RUN gem install --no-document fpm
RUN go version # check it's indeed the version we expect

# golangci-lint
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
RUN golangci-lint version

# Docker:
RUN set -x; if [ x"$(dpkg --print-architecture)" != x"s390x" ]; then \
    curl -fsSL "https://download.docker.com/linux/debian/gpg" | apt-key add; \
    echo "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/debian bullseye stable" > /etc/apt/sources.list.d/docker.list && \
    apt-get -y update && apt-get install --no-install-recommends -y docker-ce docker-buildx-plugin; \
    fi

# govulncheck
RUN go install golang.org/x/vuln/cmd/govulncheck@latest
WORKDIR /build
COPY .golangci.yml .
VOLUME /build
RUN useradd -m build -d /build
RUN chown -R build:build /build
RUN chown -R build:build /go
USER build
