-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild
More file actions
executable file
·49 lines (40 loc) · 1.15 KB
/
Copy pathbuild
File metadata and controls
executable file
·49 lines (40 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
set -eo pipefail
echo "---> Go Buildpack"
# 1. GET ARGS
layers_dir=$1
plan_path=$3
# shellcheck source=/dev/null
. generate-layers.sh "${layers_dir}"
generate_deps_layer build-deps
generate_deps_layer run-deps
# 2. DOWNLOAD go
generate_stack_layer go "${plan_path}" false
go_cache_layer_dir="${layers_dir}/go_cache"
# shellcheck source=/dev/null
. init-stack
# Compares previous go.mod checksum to the current go.mod
local_mod_checksum=$(sha256sum go.mod | cut -d ' ' -f 1 || echo 'not found')
remote_mod_checksum='not found'
if [[ -f "${go_cache_layer_dir}.toml" ]]; then
remote_mod_checksum=$(yj <"${go_cache_layer_dir}.toml" -t | jq -r .metadata 2>/dev/null || echo 'not found')
fi
mkdir -p "${go_cache_layer_dir}"
if [[ -f go.mod && "${local_mod_checksum}" == "${remote_mod_checksum}" ]]; then
echo "---> Reusing go.mod"
else
echo "---> Installing go.mod with go mod vendor"
rm "${go_cache_layer_dir}/pkg" -rf
go mod download
fi
cat >"${go_cache_layer_dir}.toml" <<EOL
[types]
cache = true
build = true
launch = false
[metadata]
version = "${local_mod_checksum}"
EOL
go mod vendor
go build -o main -v .
generate-launch.sh "${layers_dir}"