-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_and_push.sh
More file actions
executable file
·96 lines (86 loc) · 3.14 KB
/
build_and_push.sh
File metadata and controls
executable file
·96 lines (86 loc) · 3.14 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
TAG="dev"
PUSH=0
RUN_CONTAINER=0
REBUILD_CONTAINER=0
cd -- "$( dirname -- "$BASH_SOURCE[0]" )"
cd ..
# make dockerignore from .gitignore
if [ ! -f .gitignore ]; then
echo "No .gitignore file found, exiting."
exit 1
fi
cp .gitignore .dockerignore
for option in "$@"; do
case $option in
-t|--tag)
TAG="$2"
shift
echo "$TAG"
;;
-p|--push)
PUSH=1
shift
echo "Push the container to GCR."
;;
-r|--run)
shift
echo "Run the container after building it."
RUN_CONTAINER=1
;;
-b|--rebuild)
shift
echo "Rebuild the container even if it already exists."
REBUILD_CONTAINER=1
;;
--help|--info|-h)
echo "Build the current repository state as a container and optionally publish them to"
echo "gcr.io/diamond-privreg/daq-config-server/<container-name>."
echo " "
echo " -t, --tag <tag> Specify the tag for the container. Default is 'dev'."
echo " -p, --push Push the container to GCR. Requires a GitHub token, followed by"
echo " podman login ghcr.io --username <your gh login> --password-stdin"
echo " -r, --run Run the container after building it."
echo " -b, --rebuild Rebuild the container even if it already exists."
echo " -h, --help, --info Show this help message."
echo " "
shift
exit 0
;;
-*|--*)
echo "Unknown option ${option}. Use --help for info on option usage."
exit 1
;;
esac
done
# set container and tag names:
BASE_CONTAINER_NAME="daq-config-server"
BASE_REPO_ADDR="gcr.io/diamond-privreg/daq-config-server/"
MAIN_CONTAINER_NAME="${BASE_CONTAINER_NAME}"
MAIN_CONTAINER_TAG="${BASE_REPO_ADDR}${MAIN_CONTAINER_NAME}:${TAG}"
if [ -z "$(podman images -q $MAIN_CONTAINER_NAME:$TAG 2> /dev/null)" ] || [ $REBUILD_CONTAINER -gt 0 ]; then
echo " "
echo "========================================="
echo "==== Building ===="
echo "========================================="
echo " "
echo "Building ${MAIN_CONTAINER_NAME}:${TAG}"
echo " "
podman build -t "${MAIN_CONTAINER_NAME}:${TAG}" .
else
echo "Local image found, using existing image."
fi
rm .dockerignore
if [ $PUSH -gt 0 ]; then
podman tag $MAIN_CONTAINER_NAME $MAIN_CONTAINER_TAG
podman push $MAIN_CONTAINER_TAG $BASE_REPO_ADDR:$MAIN_CONTAINER_TAG
fi
if [ $RUN_CONTAINER -gt 0 ]; then
echo "Running container ${MAIN_CONTAINER_NAME}:${TAG}..."
# if the container is already running, stop it first
if [ -n "$(podman ps -q --filter "name=$MAIN_CONTAINER_NAME")" ] ; then
echo "Container $MAIN_CONTAINER_NAME is already running, stopping it first..."
podman stop $MAIN_CONTAINER_NAME
fi
podman run -d -v ./tests/test_data:/tests/test_data:z --replace --name $MAIN_CONTAINER_NAME -p 8555:8555 "${MAIN_CONTAINER_NAME}:${TAG}"
fi