-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_podman.sh
executable file
·117 lines (103 loc) · 3.57 KB
/
start_podman.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/sh
usage() { echo "USAGE: sh $0 [OPTIONS]
OPTIONS:
-h display help
-b <resultfile> benchmark mode: write timestamp ID to the given file once podman exits
-e <podmanimage> execute the given podman image (should be built from ./Dockerfile)
-i <path/to/image> original image file path
-o <outfilename> write start and end timestamps to the given output file
-p <outdir> write output file and work dir to the given directory
-t <thumbnail> write thumbnail with the given filename
-w <path/to/work/dir> mount this directory to the podman container -- thumbnail will be written here
-x <width> width of thumbnail -- defaults to 150
-y <height> height of thumbnail -- defailts to match width
-c crop the image to exactly fill the given thumbnail dimensions
" 1>&2; exit 1; }
BENCHFILE=
PODMANIMG="rusty-nail-podman"
OUTFILE=
OUTDIR=
IMAGE=
THUMBNAIL=
WORKDIR=
WIDTH=150
HEIGHT=
CROP=
while getopts ":hb:e:i:o:p:t:w:x:y:c" OPT; do
case "$OPT" in
h)
usage
;;
b)
BENCHFILE="$OPTARG"
;;
e)
PODMANIMG="$OPTARG"
;;
i)
IMAGE="$OPTARG"
;;
o)
OUTFILE="$OPTARG"
;;
p)
OUTDIR="$OPTARG"
;;
t)
THUMBNAIL="$OPTARG"
;;
w)
WORKDIR="$OPTARG"
;;
x)
WIDTH="$OPTARG"
;;
y)
HEIGHT="$OPTARG"
;;
c)
CROP="-c"
;;
*)
echo "ERROR: unknown option: $OPT"
usage
;;
esac
done
shift $((OPTIND - 1)) # isolate remaining args (which should be script filenames)
[ -n "$IMAGE" ] || { echo "ERROR: missing required argument: -i <path/to/image>"; usage; }
[ -f "$IMAGE" ] || { echo "ERROR: image file does not exist: $IMAGE"; exit 1; }
[ -n "$HEIGHT" ] || HEIGHT="$WIDTH"
TS="$(date +%s%N)" # get current time in nanoseconds -- good enough for unique timestamp
NAME="podman-$TS"
[ -n "$OUTFILE" ] || OUTFILE="$NAME.output"
[ -n "$THUMBNAIL" ] || THUMBNAIL="thumbnail.png"
[ -n "$OUTDIR" ] && mkdir -p "$OUTDIR" || OUTDIR="$(pwd)"
[ -n "$WORKDIR" ] || WORKDIR="$NAME"
OUTFILE="$OUTDIR/$OUTFILE"
WORKDIR="$OUTDIR/$WORKDIR"
mkdir -p "$WORKDIR"
ORIG="${NAME}_original.png"
cp "$IMAGE" "${WORKDIR}/${ORIG}" # can't use soft links, but don't want to copy the whole image
CWD="$(pwd)"
WORKDIR="$(cd "$(dirname "$WORKDIR")" && pwd)/$(basename "$WORKDIR")" # get absolute path
cd "$WORKDIR"
##### BEGIN RUNNING PODMAN #####
echo "$(date +%s%N) Podman initiated" >> "$OUTFILE"
# Don't run podman as user, since permission problems arise as volumes are
# mounted as root in the container, and workarounds are messy and slow
# This works on Debian-based systems. On RHEL-based systems, workarounds are necessary.
/usr/bin/time -o "$OUTFILE" --append --portability dbus-run-session -- /usr/bin/podman run --rm \
-v "$WORKDIR":/images:Z -w /images \
"$PODMANIMG" "rusty-nail" -i "$ORIG" -t "$THUMBNAIL" -x "$WIDTH" -y "$HEIGHT" $CROP >> "$OUTFILE"
ECODE=$?
END_TS="$(date +%s%N)"
if [ $ECODE -eq 0 ]; then
echo "$END_TS Podman exited successfully" >> "$OUTFILE"
[ -n "$BENCHFILE" ] && echo "$TS" >> "$BENCHFILE"
true
else
echo "$END_TS Podman exited with error code $ECODE" >> "$OUTFILE"
#[ -n "$BENCHFILE" ] && echo "$TS" >> "$BENCHFILE" # don't write failures as successes
true
fi