Buildx improvements

This commit is contained in:
Jamie Curnow
2021-06-14 21:21:06 +10:00
parent fbc453b816
commit 48df0eeb0a
7 changed files with 99 additions and 98 deletions

50
scripts/docker-gobuild Executable file
View File

@@ -0,0 +1,50 @@
#!/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}"