adding builds for rootless containers

This commit is contained in:
Colin 2024-04-30 22:11:55 -04:00
parent 8dde1883cf
commit 474c17f44a
7 changed files with 10 additions and 14 deletions

View File

@ -11,12 +11,11 @@ prepare_build() {
# Create necessary directories if they don't exist # Create necessary directories if they don't exist
mkdir -p dist mkdir -p dist
mkdir -p build_logs mkdir -p build_logs
mkdir -p test_logs # Directory for test logs
# Initialize go modules if go.mod does not exist # Initialize go modules if go.mod does not exist
if [ ! -f go.mod ]; then if [ ! -f go.mod ]; then
echo "Initializing Go modules" echo "Initializing Go modules"
go mod init ssh-timeout # Replace 'yourmodule' with your actual module name or path go mod init yourmodule # Replace 'yourmodule' with your actual module name or path
fi fi
# Fetch and ensure all dependencies are up to date # Fetch and ensure all dependencies are up to date
@ -36,33 +35,30 @@ build_binary() {
output_name="dist/${output_name}" output_name="dist/${output_name}"
echo "Building for ${os}/${arch} -> ${output_name}" # Dynamic Linking
echo "Building dynamically linked for ${os}/${arch} -> ${output_name}"
GOOS=${os} GOARCH=${arch} go build -o ${output_name} main.go 2>build_logs/${os}_${arch}_build.log GOOS=${os} GOARCH=${arch} go build -o ${output_name} main.go 2>build_logs/${os}_${arch}_build.log
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Successfully built ${output_name}" echo "Successfully built ${output_name}"
else else
echo "Failed to build ${output_name}. Check build_logs/${os}_${arch}_build.log for errors." echo "Failed to build ${output_name}. Check build_logs/${os}_${arch}_build.log for errors."
fi fi
}
# Test function # Static Linking
run_tests() { if [[ "$os" == "linux" ]]; then # Typically, static linking is most relevant for Linux environments
if ls *.go | grep '_test.go$' >/dev/null; then static_output_name="${output_name}_static"
echo "Running tests..." echo "Building statically linked for ${os}/${arch} -> ${static_output_name}"
go test ./... > test_logs/test_output.log 2>&1 CGO_ENABLED=0 GOOS=${os} GOARCH=${arch} go build -a -ldflags '-extldflags "-static"' -o ${static_output_name} main.go 2>build_logs/${os}_${arch}_static_build.log
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Tests completed successfully." echo "Successfully built ${static_output_name}"
else else
echo "Tests failed. Check test_logs/test_output.log for details." echo "Failed to build ${static_output_name}. Check build_logs/${os}_${arch}_static_build.log for errors."
fi fi
else
echo "No test files found, skipping tests."
fi fi
} }
# Main Build Process # Main Build Process
prepare_build prepare_build
run_tests # Run tests optionally before the build
for arch in "${ARCHITECTURES[@]}"; do for arch in "${ARCHITECTURES[@]}"; do
IFS='/' read -r -a parts <<< "$arch" # Split architecture string IFS='/' read -r -a parts <<< "$arch" # Split architecture string
os=${parts[0]} os=${parts[0]}

View File

View File

View File

BIN
dist/ssh-timeout_linux_arm64_static vendored Executable file

Binary file not shown.

BIN
dist/ssh-timeout_linux_arm_static vendored Executable file

Binary file not shown.

BIN
dist/ssh-timeout_static vendored Executable file

Binary file not shown.