-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·72 lines (63 loc) · 1.72 KB
/
build.sh
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
#!/bin/bash
usage() {
echo "Usage: $0 [-d <docker image>] [-v <version>]"
echo " -d Docker image (required)"
echo " -v Version for building the Docker image (required, must be a valid SemVer format)"
exit 1
}
validate_semver() {
local version=$1
# SemVer format: major.minor.patch, optionally with pre-release or build metadata
# Example valid versions: 1.0.0, 1.0.0-beta, 1.0.0+build123
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$ ]]; then
return 1
fi
return 0
}
while getopts ":d:v:" opt; do
case $opt in
d)
docker_image=$OPTARG
;;
v)
version=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
# Check if the docker image argument is provided
if [ -z "$docker_image" ]; then
echo "Docker image is required." >&2
usage
fi
# Check if the version argument is provided
if [ -z "$version" ]; then
echo "Version is required." >&2
usage
fi
# Validate the version argument
if ! validate_semver "$version"; then
echo "Invalid version format. Must be in SemVer format (e.g., '1.0.0')."
exit 1
fi
# Remove _build folder
rm -r _build/
# Build PDF & HTML
# The PDF document is copied to `_static` to allow PDF export from the HTML
docker run --rm \
--volume "$(pwd):/docs" \
git.unepgrid.ch/mapx/sphinx-latexpdf-mapx:1.0.3 sh -c \
"make latexpdf && cp _build/latex/mapx.pdf _static/ && make html"
# Build Docker image and push to online repository
docker buildx build \
--platform linux/amd64,linux/arm64 \
-f Dockerfile.docs \
-t "$docker_image:$version" \
--push .