Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions src/usr/local/buildpack/tools/golang.sh

This file was deleted.

55 changes: 55 additions & 0 deletions src/usr/local/buildpack/tools/v2/golang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash


function prepare_tool() {

# go suggests: git svn bzr mercurial
apt_install bzr mercurial

export_env GOPATH "/go"
export_env CGO_ENABLED 0
export_env GOSUMDB off
export_path "\$GOPATH/bin"

mkdir -p "$GOPATH/src" "$GOPATH/bin" "$GOPATH/pkg"

chown -R "${USER_ID}" "$GOPATH"
chmod -R g+w "$GOPATH"
create_tool_path
}

function install_tool () {
local versioned_tool_path
local file
local ARCH
local GOLANG_FILE_VERSION

if [[ ! -d "$(find_tool_path)" ]]; then
if [[ $(is_root) -ne 0 ]]; then
echo "${TOOL_NAME} not prepared"
exit 1
fi
prepare_tool
fi

versioned_tool_path=$(create_versioned_tool_path)
ARCH=linux-amd64
# fix version
GOLANG_FILE_VERSION=${TOOL_VERSION}
if [[ "${PATCH}" == "0" ]]; then
GOLANG_FILE_VERSION="${MAJOR}.${MINOR}"
fi

file=$(get_from_url "https://dl.google.com/go/go${GOLANG_FILE_VERSION}.${ARCH}.tar.gz")
tar --strip 1 -C "${versioned_tool_path}" -xf "${file}"
}

function link_tool () {
local versioned_tool_path
versioned_tool_path=$(find_versioned_tool_path)

shell_wrapper go "${versioned_tool_path}/bin"

go version
go env
}
35 changes: 35 additions & 0 deletions test/golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
ARG IMAGE=containerbase/buildpack
ARG APT_HTTP_PROXY
ARG BUILDPACK_DEBUG

FROM ${IMAGE} as build


Expand All @@ -13,6 +16,9 @@ WORKDIR /test
#--------------------------------------
FROM build as testa

ARG APT_HTTP_PROXY
ARG BUILDPACK_DEBUG

# renovate: datasource=docker versioning=docker
RUN install-tool golang 1.19.0

Expand All @@ -39,6 +45,9 @@ RUN set -ex; cd c; go get -d ./...; cat go.sum
#--------------------------------------
FROM build as testb

ARG APT_HTTP_PROXY
ARG BUILDPACK_DEBUG

# do not update patch version
RUN install-tool golang 1.11.0

Expand All @@ -52,10 +61,36 @@ USER 1000
SHELL [ "/bin/sh", "-c" ]
RUN go env

#--------------------------------------
# test: golang (non-root)
#--------------------------------------
FROM build as testc

ARG APT_HTTP_PROXY
ARG BUILDPACK_DEBUG

RUN prepare-tool golang

USER 1000

# renovate: datasource=docker versioning=docker
RUN install-tool golang 1.19.0


RUN set -ex; cd a; go get -d ./...; cat go.sum; go mod tidy; cat go.sum

RUN set -ex; cd b; cat go.sum; go mod tidy; cat go.sum

RUN set -ex; \
cd d; \
go get -d ./...; \
go mod tidy;

#--------------------------------------
# final
#--------------------------------------
FROM build

COPY --from=testa /.dummy /.dummy
COPY --from=testb /.dummy /.dummy
COPY --from=testc /.dummy /.dummy