build-docker 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. set -e
  3. CDIR=$(cd `dirname "$0"`/.. && pwd)
  4. cd "$CDIR"
  5. ORG_PATH="github.com/cloudflare"
  6. REPO_PATH="${ORG_PATH}/cfssl"
  7. relabel() {
  8. chcon -R -t "${1}" "${CDIR}"
  9. }
  10. if [ -z "$1" ]; then
  11. OS_PLATFORM_ARG=(-os="darwin linux windows")
  12. else
  13. OS_PLATFORM_ARG=($1)
  14. fi
  15. if [ -z "$2" ]; then
  16. OS_ARCH_ARG=(-arch="386 amd64 arm ppc64le")
  17. else
  18. OS_ARCH_ARG=($2)
  19. fi
  20. # Build Docker image unless we opt out of it
  21. if [[ -z "$SKIP_BUILD" ]]; then
  22. docker build --build-arg HTTP_PROXY=${HTTP_PROXY} --build-arg HTTPS_PROXY=${HTTPS_PROXY} -t cfssl-build -f Dockerfile.build .
  23. fi
  24. # Temporarily change SELinux context of build directory
  25. if [[ "$(command getenforce 2>&1)" == "Enforcing" ]]; then
  26. USER_CONTEXT="$(getfattr --only-values -n security.selinux "${CDIR}" | awk -F':' '{ print $3 }')"
  27. CONTAINER_CONTEXT="svirt_sandbox_file_t"
  28. trap "relabel '${USER_CONTEXT}'" EXIT
  29. relabel "${CONTAINER_CONTEXT}"
  30. fi
  31. # Get rid of existing binaries
  32. rm -f *-386
  33. rm -f *-amd64
  34. rm -f dist/*
  35. docker run --rm -v "${CDIR}":/go/src/${REPO_PATH} -u $(id -u):$(id -g) cfssl-build "${OS_PLATFORM_ARG[@]}" "${OS_ARCH_ARG[@]}" -output="dist/{{.Dir}}_{{.OS}}-{{.Arch}}" -ldflags="-w" ./cmd/...