#!/bin/bash

set -euo pipefail

VERSION=0.75.0

SRC_DIR=$(realpath $(dirname -- "${BASH_SOURCE[0]}"))

# TODO(mitya): group for files created in docker container is still incorrect

mkdir -p ${HOME}/.devp/ci-builder-golang/${VERSION}/go

docker run -w /work \
    -v $(pwd):/work \
    -e HOST_USER=${USER} \
    -e HOST_UID=$(id -u ${USER}) \
    -e HOST_GID=$(id -g ${USER}) \
    -v ${SRC_DIR}/dockerentry.sh:/dockerentry.sh:ro \
    -v ${HOME}/.devp/ci-builder-golang/${VERSION}/go:/tmp/go:rw \
    -e GOCACHE=/tmp/go/.cache \
    -e GOMODCACHE=/tmp/go/.modcache \
    -e GOLANGCI_LINT_CACHE=/tmp/go/.lintcache \
    -e BIN_PATH=/work/bin/docker \
    --rm -it harbor.mws-team.ru/mws-devp/infra/ci-builder-golang:${VERSION} \
     /dockerentry.sh $@
     
