forked from AppImageCommunity/pkg2appimage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkg2appimage-with-docker
executable file
·103 lines (86 loc) · 2.26 KB
/
pkg2appimage-with-docker
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
#! /bin/bash
set -e
log() {
(echo -e "\e[91m\e[1m$*\e[0m")
}
cleanup() {
if [ "$containerid" == "" ]; then
return 0
fi
if [ "$1" == "error" ]; then
log "error occurred, cleaning up..."
elif [ "$1" != "" ]; then
log "$1 received, please wait a few seconds for cleaning up..."
else
log "cleaning up..."
fi
docker ps -a | grep -q $containerid && docker rm -f $containerid
}
trap "cleanup SIGINT" SIGINT
trap "cleanup SIGTERM" SIGTERM
trap "cleanup error" 0
trap "cleanup" EXIT
CACHE=0
RECIPE=""
ARGS=""
for var in $@; do
case "$1" in
-c|--cache)
if [ $CACHE -ne 0 ]; then
log "warning: caching already enabled"
fi
CACHE=1
;;
*)
if [ "$RECIPE" != "" ]; then
log "warning: ignoring argument: $1"
else
RECIPE="$1"
fi
;;
esac
shift
done
if [ "$RECIPE" == "" ]; then
log "usage: $0 [-c] name.yml"
log ""
log "\t-c, --cache\tEnable pkg2appimage's caching by mounting the build cache directory into the container"
exit 1
fi
if [ $(basename $RECIPE .yml) == "$RECIPE" ]; then
RECIPE="$RECIPE.yml"
fi
if [ ! -f $RECIPE ]; then
if [ -f recipes/"$RECIPE" ]; then
RECIPE=recipes/"$RECIPE"
else
log "error: no such file or directory: $RECIPE"
exit 1
fi
fi
if [ $CACHE -ne 0 ]; then
recipe_name=$(basename "$RECIPE" .yml)
mkdir -p "$recipe_name"
ARGS="-v $(readlink -f $recipe_name):/workspace/$recipe_name"
fi
log "Building $RECIPE in a container..."
randstr=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)
containerid=appimage-build-$randstr
imageid=appimage-build-$(id -u)
log "Building Docker container"
(set -xe; docker build -t $imageid .)
log "Running container"
mkdir -p out
set -xe
docker run -it \
--name $containerid \
--cap-add SYS_ADMIN \
--device /dev/fuse \
--security-opt apparmor:unconfined \
--user $(id -u):$(id -g) \
-v "$(readlink -f out):/workspace/out" \
-v "$(readlink -f pkg2appimage):/workspace/pkg2appimage:ro" \
-v "$(readlink -f $RECIPE):/workspace/$RECIPE:ro" \
$ARGS \
$imageid \
./pkg2appimage $RECIPE || cleanup error