-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate_volume.sh
More file actions
executable file
·60 lines (49 loc) · 1.52 KB
/
create_volume.sh
File metadata and controls
executable file
·60 lines (49 loc) · 1.52 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
#!/usr/bin/env bash
# Construct and fill volumes needed by the ANMS compose config.
# Use:
# ./create_volume {optional tls file source path}
#
set -e
set -x
# Full name of the volume
VOLNAME=ammos-tls
# Directory to which the volume is mounted, and from which files are copied
VOLPATH=/ammos/etc/pki/tls
SRCPATH=$1
if [ -z "${SRCPATH}" ]
then
SRCPATH=$VOLPATH
elif [ ! -e "$SRCPATH" ]; then
echo "Error: '$SRCPATH' does not exist."
exit 1
fi
# Determine base command (docker or podman)
if [ -n "$DOCKER_CMD" ]; then
echo "Using defined DOCKER_CMD=${DOCKER_CMD}"
elif command -v podman &> /dev/null; then
echo "Podman is installed"
DOCKER_CMD="podman"
EXTRA_FLAGS="--ignore"
elif command -v docker &> /dev/null; then
echo "Docker is installed"
DOCKER_CMD="docker"
else
echo "Neither Docker nor Podman is installed"
exit 1
fi
${DOCKER_CMD} volume create ${EXTRA_FLAGS} ${VOLNAME}
# Delete our created volume if there is an error to prevent issues on retry
trap '${DOCKER_CMD} volume rm ${VOLNAME}' ERR
CTRNAME=$(${DOCKER_CMD} run --detach --rm \
-v ${VOLNAME}:${VOLPATH} \
docker.io/redhat/ubi9 tail -f /dev/null)
# Ensure container is stopped with script, even if there is an error
trap '${DOCKER_CMD} stop ${CTRNAME} >/dev/null' EXIT
${DOCKER_CMD} exec ${CTRNAME} rm -rf ${VOLPATH}/*
for FN in ${SRCPATH}/*
do
echo "Copying from ${FN}"
${DOCKER_CMD} cp ${FN} ${CTRNAME}:${VOLPATH}/
done
# creating socket volume
${DOCKER_CMD} volume create ${EXTRA_FLAGS} sockdir