diff --git a/.github/workflows/staticbuild.yml b/.github/workflows/staticbuild.yml index 91371c2e000..81853bb2ea5 100644 --- a/.github/workflows/staticbuild.yml +++ b/.github/workflows/staticbuild.yml @@ -41,9 +41,15 @@ jobs: - arch: ubuntu-latest image: ghcr.io/viamrobotics/antique2:amd64-cache platform: linux/amd64 + target: static-release - arch: ubuntu-small-arm image: ghcr.io/viamrobotics/antique2:arm64-cache platform: linux/arm64 + target: static-release + - arch: ubuntu-latest + image: ghcr.io/viamrobotics/antique2:amd64-cache + platform: linux/amd64 + target: static-release-win runs-on: ${{ matrix.arch }} container: image: ${{ matrix.image }} @@ -89,7 +95,7 @@ jobs: - name: Build (PR) if: contains(github.event.pull_request.labels.*.name, 'static-build') || contains(github.event.pull_request.labels.*.name, 'static-ignore-tests') run: | - sudo -Hu testbot bash -lc 'make BUILD_CHANNEL="pr-${{ github.event.pull_request.number }}" static-release' + sudo -Hu testbot bash -lc 'make BUILD_CHANNEL="pr-${{ github.event.pull_request.number }}" ${{ matrix.target }}' - name: Upload Files (PR) if: contains(github.event.pull_request.labels.*.name, 'static-build') || contains(github.event.pull_request.labels.*.name, 'static-ignore-tests') @@ -105,12 +111,12 @@ jobs: - name: Build (Latest) if: inputs.release_type == 'latest' run: | - sudo -Hu testbot bash -lc 'make RELEASE_TYPE="latest" BUILD_CHANNEL="${{needs.build_timestamp.outputs.date}}" static-release' + sudo -Hu testbot bash -lc 'make RELEASE_TYPE="latest" BUILD_CHANNEL="${{needs.build_timestamp.outputs.date}}" ${{ matrix.target }}' - name: Build (Tagged) if: inputs.release_type == 'stable' || inputs.release_type == 'rc' run: | - sudo -Hu testbot bash -lc 'make RELEASE_TYPE="${{ inputs.release_type }}" BUILD_CHANNEL="${{ github.ref_name }}" static-release' + sudo -Hu testbot bash -lc 'make RELEASE_TYPE="${{ inputs.release_type }}" BUILD_CHANNEL="${{ github.ref_name }}" ${{ matrix.target }}' - name: Set Date id: build_date diff --git a/etc/subsystem_manifest/main.go b/etc/subsystem_manifest/main.go index 8c492e4f826..9e4d8bf7b76 100644 --- a/etc/subsystem_manifest/main.go +++ b/etc/subsystem_manifest/main.go @@ -44,6 +44,7 @@ type substemManifest struct { func main() { subsystem := flag.String("subsystem", viamServer, "subsystem type") // default to viam-server binaryPath := flag.String("binary-path", "", "path to subsystem binary") + resourcesJSON := flag.String("resources-json", "", "optional pre-dumped resource json") uploadPath := flag.String("upload-path", "", "path where this binary will be stored in gcs") outputPath := flag.String("output-path", "", "path where this manifest json file will be written") version := flag.String("version", "", "version") @@ -63,7 +64,7 @@ func main() { } var metadata *viamServerMetadata if *subsystem == viamServer { - metadata, err = getViamServerMetadata(*binaryPath) + metadata, err = getViamServerMetadata(*binaryPath, *resourcesJSON) if err != nil { log.Fatalf("failed to get viam-server metadata: %v", err) } @@ -93,18 +94,24 @@ func main() { } } -func getViamServerMetadata(path string) (*viamServerMetadata, error) { - resourcesOutputFile, err := os.CreateTemp("", "resources-") - if err != nil { - return nil, err - } - resourcesOutputFileName := resourcesOutputFile.Name() - //nolint:errcheck - defer os.Remove(resourcesOutputFileName) - //nolint:gosec - command := exec.Command(path, "--dump-resources", resourcesOutputFileName) - if err := command.Run(); err != nil { - return nil, err +// `path` is the path to the binary. +// `resourcesOutputFileName` is an optional pre-dumped resource json. +// note: we pre-dump for the windows build so that we are not bound to a windows runner. (we can cross-compile, +// but we can't run the cross-compiled artifact). +func getViamServerMetadata(path, resourcesOutputFileName string) (*viamServerMetadata, error) { + if resourcesOutputFileName == "" { + resourcesOutputFile, err := os.CreateTemp("", "resources-") + if err != nil { + return nil, err + } + resourcesOutputFileName = resourcesOutputFile.Name() + //nolint:errcheck + defer os.Remove(resourcesOutputFileName) + + command := exec.Command(path, "--dump-resources", resourcesOutputFileName) + if err := command.Run(); err != nil { + return nil, err + } } //nolint:gosec resourcesBytes, err := os.ReadFile(resourcesOutputFileName) diff --git a/packaging.make b/packaging.make index 4cc40faeccf..9a8b1b1f74d 100644 --- a/packaging.make +++ b/packaging.make @@ -54,3 +54,30 @@ static-release: server-static-compressed --version ${BUILD_CHANNEL} \ --arch ${UNAME_M} \ --output-path etc/packaging/static/manifest/viam-server-${BUILD_CHANNEL}-${UNAME_M}.json + +static-release-win: FILENAME_OS=-windows +static-release-win: + # note: FILENAME_OS will be -windows for windows builds; for backwards compatibility, we don't do this for linux. + rm -f bin/static/viam-server-windows.exe + GOOS=windows GOARCH=amd64 go build -tags no_cgo,osusergo,netgo -ldflags="-extldflags=-static $(COMMON_LDFLAGS)" -o bin/static/viam-server-windows.exe ./web/cmd/server + upx --best --lzma bin/static/viam-server-windows.exe + + rm -rf etc/packaging/static/deploy/ + mkdir -p etc/packaging/static/deploy/ + cp bin/static/viam-server-windows.exe etc/packaging/static/deploy/viam-server$(FILENAME_OS)-${BUILD_CHANNEL}-${UNAME_M}.exe + if [ "${RELEASE_TYPE}" = "stable" ] || [ "${RELEASE_TYPE}" = "latest" ]; then \ + cp bin/static/viam-server-windows.exe etc/packaging/static/deploy/viam-server$(FILENAME_OS)-${RELEASE_TYPE}-${UNAME_M}.exe; \ + fi + + # note: GOOS=windows would break this on a linux runner + go run -tags no_cgo ./web/cmd/server --dump-resources win-resources.json + + rm -rf etc/packaging/static/manifest/ + mkdir -p etc/packaging/static/manifest/ + go run ./etc/subsystem_manifest \ + --binary-path etc/packaging/static/deploy/viam-server$(FILENAME_OS)-${BUILD_CHANNEL}-${UNAME_M}.exe \ + --upload-path packages.viam.com/apps/viam-server/viam-server$(FILENAME_OS)-${BUILD_CHANNEL}-${UNAME_M}.exe \ + --version ${BUILD_CHANNEL} \ + --arch ${UNAME_M} \ + --resources-json win-resources.json \ + --output-path etc/packaging/static/manifest/viam-server$(FILENAME_OS)-${BUILD_CHANNEL}-${UNAME_M}.json