Skip to content

Commit 0740ceb

Browse files
Update garm-provider-common and add build scripts
This change adds build scripts common to all providers maintained by us. Signed-off-by: Gabriel Adrian Samfira <[email protected]>
1 parent 6db5bf6 commit 0740ceb

30 files changed

+460
-31
lines changed

.github/workflows/go-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
- run: go version
2525

2626
- name: Run GARM Go Tests
27-
run: make go-test
27+
run: make test

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
/bin
1+
bin/
2+
release/
3+
build/

Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM docker.io/golang:alpine
2+
3+
WORKDIR /root
4+
USER root
5+
6+
RUN apk add musl-dev gcc libtool m4 autoconf g++ make libblkid util-linux-dev git linux-headers mingw-w64-gcc
7+
8+
RUN wget http://musl.cc/aarch64-linux-musl-cross.tgz -O /tmp/aarch64-linux-musl-cross.tgz && \
9+
tar --strip-components=1 -C /usr/local -xzf /tmp/aarch64-linux-musl-cross.tgz && \
10+
rm /tmp/aarch64-linux-musl-cross.tgz
11+
12+
ADD ./scripts/build-static.sh /build-static.sh
13+
RUN chmod +x /build-static.sh
14+
15+
CMD ["/bin/sh"]

Makefile

+56-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,60 @@
11
SHELL := bash
22

3-
.PHONY: go-test
3+
ROOTDIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
4+
GOPATH ?= $(shell go env GOPATH)
5+
GO ?= go
6+
7+
IMAGE_TAG = garm-provider-build
8+
9+
USER_ID=$(shell ((docker --version | grep -q podman) && echo "0" || id -u))
10+
USER_GROUP=$(shell ((docker --version | grep -q podman) && echo "0" || id -g))
11+
GARM_PROVIDER_NAME := garm-provider-oci
12+
13+
default: build
14+
15+
.PHONY : build build-static test install-lint-deps lint go-test fmt fmtcheck verify-vendor verify create-release-files release
16+
17+
build:
18+
@$(GO) build .
19+
20+
clean: ## Clean up build artifacts
21+
@rm -rf ./bin ./build ./release
22+
23+
build-static:
24+
@echo Building
25+
docker build --tag $(IMAGE_TAG) .
26+
mkdir -p build
27+
docker run --rm -e GARM_PROVIDER_NAME=$(GARM_PROVIDER_NAME) -e USER_ID=$(USER_ID) -e USER_GROUP=$(USER_GROUP) -v $(PWD)/build:/build/output:z -v $(PWD):/build/$(GARM_PROVIDER_NAME):z $(IMAGE_TAG) /build-static.sh
28+
@echo Binaries are available in $(PWD)/build
29+
30+
test: install-lint-deps verify go-test
31+
32+
install-lint-deps:
33+
@$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
34+
35+
lint:
36+
@golangci-lint run --timeout=8m --build-tags testing
437

538
go-test:
6-
go test -v ./... $(TEST_ARGS) -timeout=15m -parallel=4
39+
@$(GO) test -race -mod=vendor -tags testing -v $(TEST_ARGS) -timeout=15m -parallel=4 -count=1 ./...
40+
41+
fmt:
42+
@$(GO) fmt $$(go list ./...)
43+
44+
fmtcheck:
45+
@gofmt -l -s $$(go list ./... | sed -n 's/github.com\/cloudbase\/'$(GARM_PROVIDER_NAME)'\/\(.*\)/\1/p') | grep ".*\.go"; if [ "$$?" -eq 0 ]; then echo "gofmt check failed; please tun gofmt -w -s"; exit 1;fi
46+
47+
verify-vendor: ## verify if all the go.mod/go.sum files are up-to-date
48+
$(eval TMPDIR := $(shell mktemp -d))
49+
@cp -R ${ROOTDIR} ${TMPDIR}
50+
@(cd ${TMPDIR}/$(GARM_PROVIDER_NAME) && ${GO} mod tidy)
51+
@diff -r -u -q ${ROOTDIR} ${TMPDIR}/$(GARM_PROVIDER_NAME) >/dev/null 2>&1; if [ "$$?" -ne 0 ];then echo "please run: go mod tidy && go mod vendor"; exit 1; fi
52+
@rm -rf ${TMPDIR}
53+
54+
verify: verify-vendor lint fmtcheck
55+
56+
##@ Release
57+
create-release-files:
58+
./scripts/make-release.sh
59+
60+
release: build-static create-release-files ## Create a release

go.mod

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
module github.com/cloudbase/garm-provider-oci
22

3-
go 1.21.3
3+
go 1.22
4+
5+
toolchain go1.22.3
46

57
require (
68
github.com/BurntSushi/toml v1.3.2
7-
github.com/cloudbase/garm-provider-common v0.1.2
9+
github.com/cloudbase/garm-provider-common v0.1.3
810
github.com/oracle/oci-go-sdk/v49 v49.2.0
911
github.com/stretchr/testify v1.9.0
1012
github.com/xeipuuv/gojsonschema v1.2.0
@@ -24,8 +26,8 @@ require (
2426
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569 // indirect
2527
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
2628
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
27-
golang.org/x/crypto v0.23.0 // indirect
28-
golang.org/x/sys v0.20.0 // indirect
29+
golang.org/x/crypto v0.25.0 // indirect
30+
golang.org/x/sys v0.22.0 // indirect
2931
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
3032
gopkg.in/yaml.v3 v3.0.1 // indirect
3133
)

go.sum

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
22
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
3-
github.com/cloudbase/garm-provider-common v0.1.2 h1:EqSpUjw9rzo4PiUmteHkFtZNWCnRi0QXHRKZ+VA1IPo=
4-
github.com/cloudbase/garm-provider-common v0.1.2/go.mod h1:igxJRT3OlykERYc6ssdRQXcb+BCaeSfnucg6I0OSoDc=
3+
github.com/cloudbase/garm-provider-common v0.1.3 h1:8pHSRs2ljwLHgtDrge68dZ7ILUW97VF5h2ZA2fQubGQ=
4+
github.com/cloudbase/garm-provider-common v0.1.3/go.mod h1:VIJzbcg5iwyD4ac99tnnwcActfwibn/VOt2MYOFjf2c=
55
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
66
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
77
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -40,11 +40,11 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
4040
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
4141
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
4242
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
43-
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
44-
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
43+
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
44+
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
4545
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
46-
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
47-
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
46+
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
47+
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
4848
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
4949
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5050
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=

internal/spec/spec.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ func GetRunnerSpecFromBootstrapParams(cfg *config.Config, data params.BootstrapI
162162
}
163163

164164
spec.MergeExtraSpecs(extraSpecs)
165-
spec.SetUserData()
165+
if err := spec.SetUserData(); err != nil {
166+
return nil, fmt.Errorf("error setting extra specs: %w", err)
167+
}
166168

167169
return spec, nil
168170
}

main.go

+15
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,22 @@ var signals = []os.Signal{
3131
syscall.SIGTERM,
3232
}
3333

34+
var (
35+
// Version is the version of the application
36+
Version = "v0.0.0-unknown"
37+
)
38+
3439
func main() {
40+
// This is an unofficial command. It will be added into future versions of the
41+
// external provider interface. For now we manually hardcode it here. This is not
42+
// used by GARM itself. It is informative for the user to be able to check the version
43+
// of the provider.
44+
garmCommand := os.Getenv("GARM_COMMAND")
45+
if garmCommand == "GetVersion" {
46+
fmt.Println(Version)
47+
os.Exit(0)
48+
}
49+
3550
ctx, stop := signal.NotifyContext(context.Background(), signals...)
3651
defer stop()
3752

scripts/build-static.sh

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
3+
GARM_PROVIDER_NAME=${GARM_PROVIDER_NAME:-garm-provider-oci}
4+
GARM_SOURCE="/build/$GARM_PROVIDER_NAME"
5+
git config --global --add safe.directory /build/$GARM_PROVIDER_NAME
6+
cd $GARM_SOURCE
7+
8+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
9+
if [ ! -z "$GARM_REF" ] && [ "$GARM_REF" != "$CURRENT_BRANCH" ];then
10+
git checkout $GARM_REF
11+
fi
12+
13+
cd $GARM_SOURCE
14+
15+
OUTPUT_DIR="/build/output"
16+
VERSION=$(git describe --tags --match='v[0-9]*' --dirty --always)
17+
BUILD_DIR="$OUTPUT_DIR/$VERSION"
18+
19+
20+
[ ! -d "$BUILD_DIR/linux" ] && mkdir -p "$BUILD_DIR/linux"
21+
[ ! -d "$BUILD_DIR/windows" ] && mkdir -p "$BUILD_DIR/windows"
22+
23+
export CGO_ENABLED=1
24+
USER_ID=${USER_ID:-$UID}
25+
USER_GROUP=${USER_GROUP:-$(id -g)}
26+
27+
# Garm
28+
cd $GARM_SOURCE
29+
30+
# Linux
31+
GOOS=linux GOARCH=amd64 go build -mod vendor \
32+
-o $BUILD_DIR/linux/amd64/$GARM_PROVIDER_NAME \
33+
-tags osusergo,netgo,sqlite_omit_load_extension \
34+
-ldflags "-extldflags '-static' -s -w -X main.Version=$VERSION" .
35+
GOOS=linux GOARCH=arm64 CC=aarch64-linux-musl-gcc go build \
36+
-mod vendor \
37+
-o $BUILD_DIR/linux/arm64/$GARM_PROVIDER_NAME \
38+
-tags osusergo,netgo,sqlite_omit_load_extension \
39+
-ldflags "-extldflags '-static' -s -w -X main.Version=$VERSION" .
40+
41+
# Windows
42+
GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-cc go build -mod vendor \
43+
-o $BUILD_DIR/windows/amd64/$GARM_PROVIDER_NAME.exe \
44+
-tags osusergo,netgo,sqlite_omit_load_extension \
45+
-ldflags "-s -w -X main.Version=$VERSION" .
46+
47+
git checkout $CURRENT_BRANCH || true
48+
chown $USER_ID:$USER_GROUP -R "$OUTPUT_DIR"

scripts/make-release.sh

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
echo $GARM_REF
4+
GARM_PROVIDER_NAME=${GARM_PROVIDER_NAME:-garm-provider-oci}
5+
6+
VERSION=$(git describe --tags --match='v[0-9]*' --dirty --always)
7+
RELEASE="$PWD/release"
8+
9+
[ ! -d "$RELEASE" ] && mkdir -p "$RELEASE"
10+
11+
if [ ! -z "$GARM_REF" ]; then
12+
VERSION=$(git describe --tags --match='v[0-9]*' --always $GARM_REF)
13+
fi
14+
15+
echo $VERSION
16+
17+
if [ ! -d "build/$VERSION" ]; then
18+
echo "missing build/$VERSION"
19+
exit 1
20+
fi
21+
22+
# Windows
23+
24+
if [ ! -d "build/$VERSION/windows/amd64" ];then
25+
echo "missing build/$VERSION/windows/amd64"
26+
exit 1
27+
fi
28+
29+
if [ ! -f "build/$VERSION/windows/amd64/$GARM_PROVIDER_NAME.exe" ];then
30+
echo "missing build/$VERSION/windows/amd64/$GARM_PROVIDER_NAME.exe"
31+
exit 1
32+
fi
33+
34+
pushd build/$VERSION/windows/amd64
35+
zip $GARM_PROVIDER_NAME-windows-amd64.zip $GARM_PROVIDER_NAME.exe
36+
sha256sum $GARM_PROVIDER_NAME-windows-amd64.zip > $GARM_PROVIDER_NAME-windows-amd64.zip.sha256
37+
mv $GARM_PROVIDER_NAME-windows-amd64.zip $RELEASE
38+
mv $GARM_PROVIDER_NAME-windows-amd64.zip.sha256 $RELEASE
39+
popd
40+
41+
# Linux
42+
OS_ARCHES=("amd64" "arm64")
43+
44+
for arch in ${OS_ARCHES[@]};do
45+
if [ ! -f "build/$VERSION/linux/$arch/$GARM_PROVIDER_NAME" ];then
46+
echo "missing build/$VERSION/linux/$arch/$GARM_PROVIDER_NAME"
47+
exit 1
48+
fi
49+
50+
pushd build/$VERSION/linux/$arch
51+
tar czf $GARM_PROVIDER_NAME-linux-$arch.tgz $GARM_PROVIDER_NAME
52+
sha256sum $GARM_PROVIDER_NAME-linux-$arch.tgz > $GARM_PROVIDER_NAME-linux-$arch.tgz.sha256
53+
mv $GARM_PROVIDER_NAME-linux-$arch.tgz $RELEASE
54+
mv $GARM_PROVIDER_NAME-linux-$arch.tgz.sha256 $RELEASE
55+
popd
56+
done

vendor/github.com/cloudbase/garm-provider-common/cloudconfig/templates.go

+59-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/cloudbase/garm-provider-common/params/github.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)