From 363cd76fa2f4a16824e18ae58ee07e6694fe0439 Mon Sep 17 00:00:00 2001 From: Chris F Ravenscroft Date: Wed, 24 Nov 2021 23:55:59 -0800 Subject: [PATCH] Makefiles: platform releases (#241) --- .github/workflows/ci.yml | 2 +- Dockerfile-standalone | 2 +- v2/Dockerfile-plugins | 4 +-- v2/Dockerfile-standalone | 6 ++--- v2/Makefile | 42 ++++++++++++++++--------------- v2/pkg/plugins/Makefile | 23 ++++++++++++----- v2/scripts/ci/integration-test.sh | 6 ++--- 7 files changed, 49 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a6de41a..1ad9771 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: run: make all - name: Output hashes to the build log working-directory: ./v2 - run: cat bin/*.sha256 + run: cat bin/*/glauth.sha256 - name: Integration test with compiled binary working-directory: ./v2 run: make test diff --git a/Dockerfile-standalone b/Dockerfile-standalone index afb850d..95c92b3 100644 --- a/Dockerfile-standalone +++ b/Dockerfile-standalone @@ -22,7 +22,7 @@ RUN apk add --no-cache git make busybox-static dumb-init # Install deps RUN go get -d -v ./... -# Build and copy final result +# Build and copy final result -- wrong file BTW RUN uname -a RUN if [ $(uname -m) == x86_64 ]; then make linux64 && cp ./bin/glauth64 /app/glauth; fi RUN if [ $(uname -m) == aarch64 ]; then make linuxarm64 && cp ./bin/glauth-arm64 /app/glauth; fi diff --git a/v2/Dockerfile-plugins b/v2/Dockerfile-plugins index 47c482c..8e3f2ab 100644 --- a/v2/Dockerfile-plugins +++ b/v2/Dockerfile-plugins @@ -25,8 +25,8 @@ RUN go get -d -v ./... # Build and copy final result RUN uname -a RUN uname -m -RUN bash -c '[[ $(uname -m) == x86_64 ]] && { make linux64 && cp ./bin/glauth64 /app/glauth; export PLUGIN_OS=linux PLUGIN_ARCH=amd64; make bin/sqlite.so bin/postgres.so bin/mysql.so && cp ./bin/*.so /app/; } || { true; }' -RUN bash -c '[[ $(uname -m) == aarch64 ]] && { make linuxarm64 && cp ./bin/glauth-arm64 /app/glauth; export PLUGIN_OS=linux PLUGIN_ARCH=arm64; make bin/sqlite.so bin/postgres.so bin/mysql.so && cp ./bin/*.so /app/; } || { true; }' +RUN bash -c '[[ $(uname -m) == x86_64 ]] && { make linuxamd64 && cp ./bin/linuxamd64/glauth /app/glauth; export PLUGIN_OS=linux PLUGIN_ARCH=amd64; make bin/linuxamd64/sqlite.so bin/linuxamd64/postgres.so bin/linuxamd64/mysql.so && cp ./bin/linuxamd64/*.so /app/; } || { true; }' +RUN bash -c '[[ $(uname -m) == aarch64 ]] && { make linuxarm64 && cp ./bin/linuxarm64/glauth /app/glauth; export PLUGIN_OS=linux PLUGIN_ARCH=arm64; make bin/linuxarm64/sqlite.so bin/linuxarm64/postgres.so bin/linuxarm64/mysql.so && cp ./bin/linuxarm64/*.so /app/; } || { true; }' # Check glauth works RUN /app/glauth --version diff --git a/v2/Dockerfile-standalone b/v2/Dockerfile-standalone index afb850d..de062e5 100644 --- a/v2/Dockerfile-standalone +++ b/v2/Dockerfile-standalone @@ -24,9 +24,9 @@ RUN go get -d -v ./... # Build and copy final result RUN uname -a -RUN if [ $(uname -m) == x86_64 ]; then make linux64 && cp ./bin/glauth64 /app/glauth; fi -RUN if [ $(uname -m) == aarch64 ]; then make linuxarm64 && cp ./bin/glauth-arm64 /app/glauth; fi -RUN if [ $(uname -m) == armv7l ]; then make linuxarm32 && cp ./bin/glauth-arm32 /app/glauth; fi +RUN if [ $(uname -m) == x86_64 ]; then make linuxamd64 && cp ./bin/linuxamd64/glauth /app/glauth; fi +RUN if [ $(uname -m) == aarch64 ]; then make linuxarm64 && cp ./bin/linuxarm64/glauth /app/glauth; fi +RUN if [ $(uname -m) == armv7l ]; then make linuxarm && cp ./bin/linuxarm/glauth /app/glauth; fi # Check glauth works RUN /app/glauth --version diff --git a/v2/Makefile b/v2/Makefile index 117ecb7..3e787e1 100644 --- a/v2/Makefile +++ b/v2/Makefile @@ -1,4 +1,4 @@ -VERSION=$(shell bin/glauth64 --version) +VERSION=$(shell bin/linuxamd64/glauth --version) GIT_COMMIT=$(shell git rev-list -1 HEAD ) BUILD_TIME=$(shell date -u +%Y%m%d_%H%M%SZ) @@ -28,17 +28,17 @@ include pkg/plugins/Makefile # Build and run - used for development run: setup devrun -# Run the integration test on linux64 (eventually allow the binary to be set) +# Run the integration test on linuxamd64 (eventually allow the binary to be set) test: runtest # Run build process for all binaries all: setup binaries verify -# Run build process for only linux64 -fast: setup linux64 verify +# Run build process for only linuxamd64 +fast: setup linuxamd64 verify # list of binary formats to build -binaries: linux32 linux64 linuxarm32 linuxarm64 darwin64 win32 win64 +binaries: linux386 linuxamd64 linuxarm linuxarm64 darwinamd64 darwinarm64 win386 winamd64 # Setup commands to always run setup: getdeps format @@ -64,30 +64,32 @@ format: devrun: go run ${BUILD_FILES} -c sample-simple.cfg -linux32: - GOOS=linux GOARCH=386 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/glauth32 ${BUILD_FILES} && cd bin && sha256sum glauth32 > glauth32.sha256 +linux386: + mkdir -p bin/$@ && GOOS=linux GOARCH=386 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256 -linux64: - GOOS=linux GOARCH=amd64 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/glauth64 ${BUILD_FILES} && cd bin && sha256sum glauth64 > glauth64.sha256 +linuxamd64: + mkdir -p bin/$@ && GOOS=linux GOARCH=amd64 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256 -linuxarm32: - GOOS=linux GOARCH=arm go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/glauth-arm32 ${BUILD_FILES} && cd bin && sha256sum glauth-arm32 > glauth-arm32.sha256 +linuxarm: + mkdir -p bin/$@ && GOOS=linux GOARCH=arm go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256 linuxarm64: - GOOS=linux GOARCH=arm64 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/glauth-arm64 ${BUILD_FILES} && cd bin && sha256sum glauth-arm64 > glauth-arm64.sha256 + mkdir -p bin/$@ && GOOS=linux GOARCH=arm64 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256 -darwin64: - GOOS=darwin GOARCH=amd64 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/glauthOSX ${BUILD_FILES} && cd bin && sha256sum glauthOSX > glauthOSX.sha256 +darwinamd64: + mkdir -p bin/$@ && GOOS=darwin GOARCH=amd64 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256 darwinarm64: - GOOS=darwin GOARCH=arm64 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/glauthOSX-arm64 ${BUILD_FILES} && cd bin && sha256sum glauthOSX-arm64 > glauthOSX-arm64.sha256 + mkdir -p bin/$@ && GOOS=darwin GOARCH=arm64 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256 -win32: - GOOS=windows GOARCH=386 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/glauth-win32 ${BUILD_FILES} && cd bin && sha256sum glauth-win32 > glauth-win32.sha256 +win386: + mkdir -p bin/$@ && GOOS=windows GOARCH=386 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256 -win64: - GOOS=windows GOARCH=amd64 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/glauth-win64 ${BUILD_FILES} && cd bin && sha256sum glauth-win64 > glauth-win64.sha256 +winamd64: + mkdir -p bin/$@ && GOOS=windows GOARCH=amd64 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256 verify: - cd bin && sha256sum *.sha256 -c && cd ../; + @for binary in linux386 linuxamd64 linuxarm linuxarm64 darwinamd64 darwinarm64 win386 winamd64; do cd bin/$$binary && sha256sum glauth.sha256 -c && cd ../..; done + +release: linux386 linuxamd64 linuxarm linuxarm64 darwinamd64 darwinarm64 win386 winamd64 diff --git a/v2/pkg/plugins/Makefile b/v2/pkg/plugins/Makefile index b9d3015..5329bb2 100644 --- a/v2/pkg/plugins/Makefile +++ b/v2/pkg/plugins/Makefile @@ -9,17 +9,28 @@ PLUGIN_ARCH ?= amd64 plugins: plugin_mysql plugin_postgres plugin_sqlite -plugin_mysql: bin/mysql.so +plugin_mysql: bin/$(PLUGIN_OS)$(PLUGIN_ARCH)/mysql.so -bin/mysql.so: pkg/plugins/mysql.go pkg/plugins/basesqlhandler.go +bin/$(PLUGIN_OS)$(PLUGIN_ARCH)/mysql.so: pkg/plugins/mysql.go pkg/plugins/basesqlhandler.go GOOS=$(PLUGIN_OS) GOARCH=$(PLUGIN_ARCH) go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -buildmode=plugin -o $@ $^ -plugin_postgres: bin/postgres.so +plugin_postgres: bin/$(PLUGIN_OS)$(PLUGIN_ARCH)/postgres.so -bin/postgres.so: pkg/plugins/postgres.go pkg/plugins/basesqlhandler.go +bin/$(PLUGIN_OS)$(PLUGIN_ARCH)/postgres.so: pkg/plugins/postgres.go pkg/plugins/basesqlhandler.go GOOS=$(PLUGIN_OS) GOARCH=$(PLUGIN_ARCH) go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -buildmode=plugin -o $@ $^ -plugin_sqlite: bin/sqlite.so +plugin_sqlite: bin/$(PLUGIN_OS)$(PLUGIN_ARCH)/sqlite.so -bin/sqlite.so: pkg/plugins/sqlite.go pkg/plugins/basesqlhandler.go +bin/$(PLUGIN_OS)$(PLUGIN_ARCH)/sqlite.so: pkg/plugins/sqlite.go pkg/plugins/basesqlhandler.go GOOS=$(PLUGIN_OS) GOARCH=$(PLUGIN_ARCH) go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -buildmode=plugin -o $@ $^ + +plugins_darwin: plugins_darwin_amd64 plugins_darwin_arm64 + +plugins_linux_amd64: + PLUGIN_OS=linux PLUGIN_ARCH=amd64 make plugins + +plugins_darwin_amd64: + PLUGIN_OS=darwin PLUGIN_ARCH=amd64 make plugins + +plugins_darwin_arm64: + PLUGIN_OS=darwin PLUGIN_ARCH=arm64 make plugins diff --git a/v2/scripts/ci/integration-test.sh b/v2/scripts/ci/integration-test.sh index 5fd7a69..b062082 100755 --- a/v2/scripts/ci/integration-test.sh +++ b/v2/scripts/ci/integration-test.sh @@ -33,14 +33,14 @@ fi echo ""; echo "" echo "Version string of tested binary:" -"$CI_BUILD_DIR/bin/glauth64" --version +"$CI_BUILD_DIR/bin/linuxamd64/glauth" --version echo "" # Start in background, capture PID -"$CI_BUILD_DIR/bin/glauth64" -c "$CI_BUILD_DIR/scripts/ci/test-config.cfg" &> /dev/null & +"$CI_BUILD_DIR/bin/linuxamd64/glauth" -c "$CI_BUILD_DIR/scripts/ci/test-config.cfg" &> /dev/null & # Use this instead to see glauth logs while running -# "$CI_BUILD_DIR/bin/glauth64" -c "$CI_BUILD_DIR/scripts/ci/test-config.cfg" & +# "$CI_BUILD_DIR/bin/linuxamd64/glauth" -c "$CI_BUILD_DIR/scripts/ci/test-config.cfg" & glauthPid="$!" echo "Running glauth at PID=$glauthPid"