-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from gabriel-samfira/build-windows
Enable Windows builds
- Loading branch information
Showing
6 changed files
with
130 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ bin/ | |
# vendor/ | ||
.vscode | ||
cmd/temp | ||
build/ | ||
release/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,67 @@ | ||
#!/bin/sh | ||
|
||
GARM_SOURCE="/build/garm" | ||
BIN_DIR="$GARM_SOURCE/bin" | ||
git config --global --add safe.directory "$GARM_SOURCE" | ||
git config --global --add safe.directory /build/garm | ||
cd $GARM_SOURCE | ||
|
||
[ ! -d "$BIN_DIR" ] && mkdir -p "$BIN_DIR" | ||
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | ||
if [ ! -z "$GARM_REF" ] && [ "$GARM_REF" != "$CURRENT_BRANCH" ];then | ||
git checkout $GARM_REF | ||
fi | ||
|
||
cd $GARM_SOURCE | ||
|
||
OUTPUT_DIR="/build/output" | ||
VERSION=$(git describe --tags --match='v[0-9]*' --dirty --always) | ||
BUILD_DIR="$OUTPUT_DIR/$VERSION" | ||
|
||
|
||
[ ! -d "$BUILD_DIR/linux" ] && mkdir -p "$BUILD_DIR/linux" | ||
[ ! -d "$BUILD_DIR/windows" ] && mkdir -p "$BUILD_DIR/windows" | ||
|
||
export CGO_ENABLED=1 | ||
USER_ID=${USER_ID:-$UID} | ||
USER_GROUP=${USER_GROUP:-$(id -g)} | ||
|
||
mkdir -p $BIN_DIR/amd64 $BIN_DIR/arm64 | ||
# Garm | ||
cd $GARM_SOURCE/cmd/garm | ||
go build -mod vendor \ | ||
-o $BIN_DIR/amd64/garm \ | ||
|
||
# Linux | ||
GOOS=linux GOARCH=amd64 go build -mod vendor \ | ||
-o $BUILD_DIR/linux/amd64/garm \ | ||
-tags osusergo,netgo,sqlite_omit_load_extension \ | ||
-ldflags "-linkmode external -extldflags '-static' -s -w -X main.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" . | ||
CC=aarch64-linux-musl-gcc GOARCH=arm64 go build \ | ||
-ldflags "-extldflags '-static' -s -w -X main.Version=$VERSION" . | ||
GOOS=linux GOARCH=arm64 CC=aarch64-linux-musl-gcc go build \ | ||
-mod vendor \ | ||
-o $BIN_DIR/arm64/garm \ | ||
-o $BUILD_DIR/linux/arm64/garm \ | ||
-tags osusergo,netgo,sqlite_omit_load_extension \ | ||
-ldflags "-linkmode external -extldflags '-static' -s -w -X main.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" . | ||
# GOOS=windows CC=x86_64-w64-mingw32-cc go build -mod vendor \ | ||
# -o $BIN_DIR/amd64/garm.exe \ | ||
# -tags osusergo,netgo,sqlite_omit_load_extension \ | ||
# -ldflags "-s -w -X main.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" . | ||
-ldflags "-extldflags '-static' -s -w -X main.Version=$VERSION" . | ||
|
||
# Windows | ||
GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-cc go build -mod vendor \ | ||
-o $BUILD_DIR/windows/amd64/garm.exe \ | ||
-tags osusergo,netgo,sqlite_omit_load_extension \ | ||
-ldflags "-s -w -X main.Version=$VERSION" . | ||
|
||
# garm-cli | ||
cd $GARM_SOURCE/cmd/garm-cli | ||
go build -mod vendor \ | ||
-o $BIN_DIR/amd64/garm-cli \ | ||
|
||
# Linux | ||
GOOS=linux GOARCH=amd64 go build -mod vendor \ | ||
-o $BUILD_DIR/linux/amd64/garm-cli \ | ||
-tags osusergo,netgo,sqlite_omit_load_extension \ | ||
-ldflags "-linkmode external -extldflags '-static' -s -w -X github.com/cloudbase/garm/cmd/garm-cli/cmd.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" . | ||
CC=aarch64-linux-musl-gcc GOARCH=arm64 go build -mod vendor \ | ||
-o $BIN_DIR/arm64/garm-cli \ | ||
-ldflags "-extldflags '-static' -s -w -X github.com/cloudbase/garm/cmd/garm-cli/cmd.Version=$VERSION" . | ||
GOOS=linux GOARCH=arm64 CC=aarch64-linux-musl-gcc go build -mod vendor \ | ||
-o $BUILD_DIR/linux/arm64/garm-cli \ | ||
-tags osusergo,netgo,sqlite_omit_load_extension \ | ||
-ldflags "-linkmode external -extldflags '-static' -s -w -X github.com/cloudbase/garm/cmd/garm-cli/cmd.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" . | ||
# GOOS=windows CGO_ENABLED=0 go build -mod vendor \ | ||
# -o $BIN_DIR/amd64/garm-cli.exe \ | ||
# -tags osusergo,netgo,sqlite_omit_load_extension \ | ||
# -ldflags "-s -w -X github.com/cloudbase/garm/cmd/garm-cli/cmd.Version=$(git describe --tags --match='v[0-9]*' --dirty --always)" . | ||
-ldflags "-extldflags '-static' -s -w -X github.com/cloudbase/garm/cmd/garm-cli/cmd.Version=$VERSION" . | ||
|
||
# Windows | ||
GOOS=windows GOARCH=amd64 go build -mod vendor \ | ||
-o $BUILD_DIR/windows/amd64/garm-cli.exe \ | ||
-tags osusergo,netgo,sqlite_omit_load_extension \ | ||
-ldflags "-s -w -X github.com/cloudbase/garm/cmd/garm-cli/cmd.Version=$VERSION" . | ||
|
||
|
||
chown $USER_ID:$USER_GROUP -R "$BIN_DIR" | ||
git checkout $CURRENT_BRANCH || true | ||
chown $USER_ID:$USER_GROUP -R "$OUTPUT_DIR" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
|
||
echo $GARM_REF | ||
|
||
VERSION=$(git describe --tags --match='v[0-9]*' --dirty --always) | ||
RELEASE="$PWD/release" | ||
|
||
[ ! -d "$RELEASE" ] && mkdir -p "$RELEASE" | ||
|
||
if [ ! -z "$GARM_REF" ]; then | ||
VERSION=$(git describe --tags --match='v[0-9]*' --always $GARM_REF) | ||
fi | ||
|
||
echo $VERSION | ||
|
||
if [ ! -d "build/$VERSION" ]; then | ||
echo "missing build/$VERSION" | ||
exit 1 | ||
fi | ||
|
||
# Windows | ||
|
||
if [ ! -d "build/$VERSION/windows/amd64" ];then | ||
echo "missing build/$VERSION/windows/amd64" | ||
exit 1 | ||
fi | ||
|
||
WINDOWS_FILES=("garm.exe" "garm-cli.exe") | ||
|
||
for file in ${WINDOWS_FILES[@]};do | ||
if [ ! -f "build/$VERSION/windows/amd64/$file" ];then | ||
echo "missing build/$VERSION/windows/amd64/$file" | ||
exit 1 | ||
fi | ||
|
||
pushd build/$VERSION/windows/amd64 | ||
zip ${file%%.exe}-windows-amd64.zip $file | ||
sha256sum ${file%%.exe}-windows-amd64.zip > ${file%%.exe}-windows-amd64.zip.sha256 | ||
mv ${file%%.exe}-windows-amd64.zip $RELEASE | ||
mv ${file%%.exe}-windows-amd64.zip.sha256 $RELEASE | ||
popd | ||
done | ||
|
||
# Linux | ||
OS_ARCHES=("amd64" "arm64") | ||
FILES=("garm" "garm-cli") | ||
|
||
for arch in ${OS_ARCHES[@]};do | ||
for file in ${FILES[@]};do | ||
if [ ! -f "build/$VERSION/linux/$arch/$file" ];then | ||
echo "missing build/$VERSION/linux/$arch/$file" | ||
exit 1 | ||
fi | ||
|
||
pushd build/$VERSION/linux/$arch | ||
tar czf ${file}-linux-$arch.tgz $file | ||
sha256sum ${file}-linux-$arch.tgz > ${file}-linux-$arch.tgz.sha256 | ||
mv ${file}-linux-$arch.tgz $RELEASE | ||
mv ${file}-linux-$arch.tgz.sha256 $RELEASE | ||
popd | ||
done | ||
done |