diff --git a/Dockerfile b/Dockerfile index 1ab6a17..647dd2f 100755 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,7 @@ COPY go.* /app/ COPY templates /app/templates/ COPY static /app/static/ RUN cd /app && \ - go build -a -o server + go build -ldflags="-s -w" -a -o server FROM ubuntu:23.04 COPY --from=builder /etc/passwd /etc/passwd diff --git a/README.md b/README.md index 627c7f2..5394de1 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ ## Run server ```sh go build -o server && ./server + +# If you are really conscious about the size. You can run this instead: +go build -ldflags="-s -w" -a -o server && ./server ``` --- diff --git a/generate-binaries.sh b/generate-binaries.sh index 17b4ac0..b8369dc 100755 --- a/generate-binaries.sh +++ b/generate-binaries.sh @@ -6,16 +6,15 @@ set -x -eou pipefail echo "Proceeding with generating the binaries..." platforms=("linux/arm64" "linux/amd64" "darwin/amd64") -VERSION=`grep -E "MAJOR|MINOR|PATCH" version.go | cut -d '"' -f 2 | xargs echo -n | tr -s " " "."` +VERSION=$(grep -E "MAJOR|MINOR|PATCH" version.go | cut -d '"' -f 2 | xargs echo -n | tr -s " " ".") -for platform in "${platforms[@]}" -do +for platform in "${platforms[@]}"; do platform_split=(${platform//\// }) GOOS=${platform_split[0]} GOARCH=${platform_split[1]} output_name=hello-universe'-v'$VERSION'-'$GOOS'-'$GOARCH - env GOOS=$GOOS GOARCH=$GOARCH go build -o $output_name . + env GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-s -w" -a -o $output_name . if [ $? -ne 0 ]; then echo 'An error has occurred! Aborting the script execution...' exit 1