Files
nginx-proxy-manager/scripts/docker-gobuild
2021-06-14 22:41:57 +10:00

51 lines
1.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash -e
# This script is run as part of the Dockerfile
# It will conduct golang testing and vuln lookups
# unless SKIP_TESTS=1 is defined
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
. "$DIR/.common.sh"
echo -e "${BLUE} ${CYAN}docker-gobuild${RESET}"
echo -e " ${YELLOW}BUILD_COMMIT: ${BUILD_COMMIT:-not set}${RESET}"
echo -e " ${YELLOW}BUILD_VERSION: ${BUILD_VERSION:-not set}${RESET}"
echo -e " ${YELLOW}CGO_ENABLED: ${CGO_ENABLED:-not set}${RESET}"
echo -e " ${YELLOW}GOPROXY: ${GOPROXY:-not set}${RESET}"
echo -e " ${YELLOW}GOPRIVATE: ${GOPRIVATE:-not set}${RESET}"
echo -e " ${YELLOW}GO111MODULE: ${GO111MODULE:-not set}${RESET}"
echo -e " ${YELLOW}SKIP_TESTS: ${SKIP_TESTS:-not set}${RESET}"
echo -e "${BLUE} ${CYAN}Downloading backend go modules${RESET}"
cd /app/backend
go mod download
# Testing and vulnerability lookup
if ! [ "${SKIP_TESTS:-}" = "1" ]; then
mkdir -p /workspace
echo -e "${BLUE} ${CYAN}Nancy setup${RESET}"
cd /workspace
go get github.com/sonatype-nexus-community/nancy
cp /app/backend/go.mod /app/backend/go.sum /app/backend/.nancy-ignore .
go mod download
echo -e "${BLUE} ${CYAN}Nancy testing${RESET}"
go list -json -m all | nancy sleuth --quiet --username "${NANCY_USER}" --token "${NANCY_TOKEN:-}"
rm -rf /workspace
echo -e "${BLUE} ${CYAN}Testing backend code${RESET}"
cd /app/backend
[ -z "$(go tool fix -diff ./internal)" ]
richgo test -cover -v ./internal/...
richgo test -bench=. ./internal/...
golangci-lint -v run ./...
fi
echo -e "${BLUE} ${CYAN}Building backend binary${RESET}"
go build \
-ldflags "-w -s -X main.commit=${BUILD_COMMIT} -X main.version=${BUILD_VERSION} -X main.sentryDSN=${SENTRY_DSN:-}" \
-o ../dist/bin/server \
-v ./cmd/server
echo -e "${BLUE} ${CYAN}docker-gobuild ${GREEN}completed${RESET}"