-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·58 lines (48 loc) · 1.8 KB
/
build.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
VERSION="0.3.1d"
rm -rf bins/*
mkdir -p bins
# Check if .env file exists
if [ ! -f .env ]; then
echo "Error: .env file not found"
exit 1
fi
# Source the .env file
source .env
# Common ldflags for all builds
LDFLAGS="-X main.telemetryToken=${CYBERDOCK_TELEMETRY_TOKEN} -X main.telemetryURL=${CYBERDOCK_TELEMETRY_URL}"
# Build for current platform
echo "Building for $(go env GOOS)/$(go env GOARCH)..."
go build -ldflags="${LDFLAGS}" -o bins/cyberdock-$(go env GOOS)-$(go env GOARCH) cmd/cyberdock/main.go
# Build for Alpine Linux (static build)
echo "Building for Alpine Linux (static)..."
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-linux-musl-gcc \
go build -ldflags="${LDFLAGS} -linkmode external -extldflags '-static'" \
-o bins/cyberdock-linux-alpine-amd64-static cmd/cyberdock/main.go
# Build for Alpine Linux ARM64 (static build)
echo "Building for Alpine Linux ARM64 (static)..."
GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-musl-gcc \
go build -ldflags="${LDFLAGS} -linkmode external -extldflags '-static'" \
-o bins/cyberdock-linux-alpine-arm64-static cmd/cyberdock/main.go
# Build for Linux ARM64
echo "Building for linux/arm64..."
GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-musl-gcc \
go build -ldflags="${LDFLAGS}" \
-o bins/cyberdock-linux-arm64 cmd/cyberdock/main.go
# Generate combined checksums file
echo "Generating combined SHA256SUMS file..."
cd bins
shasum -a 256 cyberdock-* | grep -v '\.sha256' > SHA256SUMS
cd -
echo "Build complete!"
read -p "Push to Docker Hub? (y/n): " push
if [ "$push" = "y" ]; then
# Building Docker Image
echo "Building for Linux platform..."
docker buildx build \
--push \
--platform linux/amd64,linux/arm64 \
-t mattrogers/cyberdock:latest \
-t mattrogers/cyberdock:${VERSION} \
-f Dockerfile.multi .
fi