-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
82 lines (69 loc) · 2.71 KB
/
build.ps1
File metadata and controls
82 lines (69 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright 2025 Optonic GmbH
# Author: Martin Rotzinger
#
# This work is based on the project at:
# https://github.com/wandelbotsgmbh/zivid-nova
#
# The original project or parts thereof may be copyrighted by Wandelbots GmbH.
#
# This work is subject to German copyright law.
# Copyright and related rights are held by Optonic GmbH.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
param(
[switch]$PushRemote,
[string]$Version
)
# Default: no remote push
$PUSH_REMOTE = $PushRemote.IsPresent
# If no version provided, read from pyproject.toml
if ([string]::IsNullOrWhiteSpace($Version)) {
$versionLine = Get-Content "pyproject.toml" | Select-String '^version =' | Select-Object -First 1
if ($versionLine) {
$Version = $versionLine -replace '^version = "([^"]+)"', '$1'
} else {
throw "Could not read version from pyproject.toml"
}
}
# Get Git metadata
$COMMIT = git rev-parse --short HEAD | ForEach-Object { $_ -replace '\r|\n', '' }
$BRANCH = git rev-parse --abbrev-ref HEAD | ForEach-Object { $_ -replace '\r|\n', '' }
$TAG = git describe --tags --abbrev=0 2>$null
if (-not $TAG) { $TAG = "no-tag" }
$TAG = $TAG -replace '\r|\n', ''
$IMAGE_NAME = "ensenso-nova-image"
$REGISTRY = "ghcr.io/ensenso"
Write-Host "Building ${IMAGE_NAME}:${Version} with Git commit ${COMMIT}, branch ${BRANCH}, tag ${TAG}"
# Build image
podman build `
--build-arg APP_VERSION=${Version} `
--build-arg GIT_COMMIT=${COMMIT} `
--build-arg GIT_BRANCH=${BRANCH} `
--build-arg GIT_TAG=${TAG} `
-t "${IMAGE_NAME}:${Version}" .
# Tag latest
podman tag "${IMAGE_NAME}:${Version}" "${IMAGE_NAME}:latest"
if ($PUSH_REMOTE) {
Write-Host "Pushing tags to remote registry ${REGISTRY}..."
# Login to registry
podman login $REGISTRY
# Tag and push version
podman tag "${IMAGE_NAME}:${Version}" "${REGISTRY}/${IMAGE_NAME}:${Version}"
podman push "${REGISTRY}/${IMAGE_NAME}:${Version}"
# Tag and push latest
podman tag "${IMAGE_NAME}:latest" "${REGISTRY}/${IMAGE_NAME}:latest"
podman push "${REGISTRY}/${IMAGE_NAME}:latest"
} else {
Write-Host "Skipping remote push. Use -PushRemote to enable."
}
Write-Host "Build script completed."