forked from cloudflare/cfssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·40 lines (32 loc) · 1.02 KB
/
build
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
#!/bin/bash
set -e
BUILD_DIR=$(cd "$(dirname $0)"; cd ..; pwd)
relabel() {
chcon -R -t "${1}" "${BUILD_DIR}"
}
if [ -z "$1" ]; then
OS_PLATFORM_ARG=(-os="darwin linux windows")
else
OS_PLATFORM_ARG=($1)
fi
if [ -z "$2" ]; then
OS_ARCH_ARG=(-arch="386 amd64 arm")
else
OS_ARCH_ARG=($2)
fi
# Build Docker image unless we opt out of it
if [[ -z "$SKIP_BUILD" ]]; then
docker build -t cfssl-build -f Dockerfile.build .
fi
# Temporarily change SELinux context of build directory
if [[ "$(command getenforce 2>&1)" == "Enforcing" ]]; then
USER_CONTEXT="$(getfattr --only-values -n security.selinux "${BUILD_DIR}" | awk -F':' '{ print $3 }')"
CONTAINER_CONTEXT="svirt_sandbox_file_t"
trap "relabel '${USER_CONTEXT}'" EXIT
relabel "${CONTAINER_CONTEXT}"
fi
# Get rid of existing binaries
rm -f *-386
rm -f *-amd64
rm -f dist/*
docker run --rm -v `pwd`:/go/src/github.com/cloudflare/cfssl cfssl-build "${OS_PLATFORM_ARG[@]}" "${OS_ARCH_ARG[@]}" -output="dist/{{.Dir}}_{{.OS}}-{{.Arch}}" -ldflags="-w" ./cmd/...