Skip to content

Commit 3e6ce45

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 bf5e27f commit 3e6ce45

23 files changed

+400
-25
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-aws
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,6 +1,8 @@
11
module github.com/cloudbase/garm-provider-aws
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.4.0
@@ -9,7 +11,7 @@ require (
911
github.com/aws/aws-sdk-go-v2/credentials v1.17.20
1012
github.com/aws/aws-sdk-go-v2/service/ec2 v1.165.0
1113
github.com/aws/smithy-go v1.20.2
12-
github.com/cloudbase/garm-provider-common v0.1.2
14+
github.com/cloudbase/garm-provider-common v0.1.3
1315
github.com/stretchr/testify v1.9.0
1416
github.com/xeipuuv/gojsonschema v1.2.0
1517
)
@@ -37,8 +39,8 @@ require (
3739
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569 // indirect
3840
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
3941
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
40-
golang.org/x/crypto v0.24.0 // indirect
41-
golang.org/x/sys v0.21.0 // indirect
42+
golang.org/x/crypto v0.25.0 // indirect
43+
golang.org/x/sys v0.22.0 // indirect
4244
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
4345
gopkg.in/yaml.v3 v3.0.1 // indirect
4446
)

go.sum

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.29.0 h1:dqW4XRwPE/poWSqVntpeXLHzpPK6
2828
github.com/aws/aws-sdk-go-v2/service/sts v1.29.0/go.mod h1:j8+hrxlmLR8ZQo6ytTAls/JFrt5bVisuS6PD8gw2VBw=
2929
github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q=
3030
github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
31-
github.com/cloudbase/garm-provider-common v0.1.2 h1:EqSpUjw9rzo4PiUmteHkFtZNWCnRi0QXHRKZ+VA1IPo=
32-
github.com/cloudbase/garm-provider-common v0.1.2/go.mod h1:igxJRT3OlykERYc6ssdRQXcb+BCaeSfnucg6I0OSoDc=
31+
github.com/cloudbase/garm-provider-common v0.1.3 h1:8pHSRs2ljwLHgtDrge68dZ7ILUW97VF5h2ZA2fQubGQ=
32+
github.com/cloudbase/garm-provider-common v0.1.3/go.mod h1:VIJzbcg5iwyD4ac99tnnwcActfwibn/VOt2MYOFjf2c=
3333
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3434
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3535
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -66,11 +66,11 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
6666
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
6767
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
6868
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
69-
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
70-
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
69+
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
70+
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
7171
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
72-
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
73-
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
72+
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
73+
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
7474
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
7575
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
7676
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=

main.go

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

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

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-aws}
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-aws}
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)