forked from diddlesnaps/snapcraft-container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·117 lines (101 loc) · 3.15 KB
/
entrypoint.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/bash
systemctl="$(command -v systemctl)"
CMD="$1"
shift
args=""
if [ $# -gt 0 ]; then
args="$(printf "%q " "$@")"
fi
case "$CMD" in
snapcraft|/snap/bin/snapcraft)
CMD="snap run snapcraft"
stdin_mode=null
;;
esac
. /etc/lsb-release
if [ -z "$USE_SNAPCRAFT_CHANNEL" ]; then
case "$DISTRIB_CODENAME" in
xenial)
# core/xenial disabled in snapcraft 5+.
USE_SNAPCRAFT_CHANNEL="4.x/stable"
;;
bionic)
# core18/bionic disabled in snapcraft 6+.
USE_SNAPCRAFT_CHANNEL="5.x/stable"
;;
*)
USE_SNAPCRAFT_CHANNEL="latest/stable"
;;
esac
else
case "$USE_SNAPCRAFT_CHANNEL" in
stable|candidate|beta|edge)
USE_SNAPCRAFT_CHANNEL="latest/$USE_SNAPCRAFT_CHANNEL"
;;
esac
fi
if [ ! -e /var/lib/apt/lists ]; then
apt-get update
fi
cat > /usr/local/bin/docker_commandline.sh <<EOF
#!/bin/bash
# Default environment variables
export SNAPCRAFT_VERBOSITY_LEVEL=verbose
# Recreate the initial environment from docker run
$(export -p)
# Force these environment variables
export PATH="/snap/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export SNAPCRAFT_BUILD_ENVIRONMENT=host
export SNAPCRAFT_MANAGED_MODE=y
# Run the command
echo "Executing: '$CMD $args'"
$CMD $args
/bin/systemctl exit \$?
EOF
chmod +x /usr/local/bin/docker_commandline.sh
cat > /etc/systemd/system/docker-exec.service <<EOF
[Unit]
Description=Docker commandline
Wants=snapd.seeded.service
After=snapd.service snapd.socket snapd.seeded.service
[Service]
ExecStartPre=/bin/bash -c '/usr/bin/snap install /snapd.snap --dangerous < /dev/null'
ExecStartPre=/bin/bash -c '/usr/bin/snap install snapcraft --classic --channel $USE_SNAPCRAFT_CHANNEL < /dev/null'
ExecStart=/usr/local/bin/docker_commandline.sh
Environment="SNAPPY_LAUNCHER_INSIDE_TESTS=true"
Environment="LANG=C.UTF-8"
Restart=no
Type=oneshot
StandardInput=tty
StandardOutput=tty
StandardError=tty
WorkingDirectory=$PWD
[Install]
WantedBy=default.target
EOF
"$systemctl" enable docker-exec.service
if [ "$DISTRIB_CODENAME" = "xenial" ]; then
if grep -q cgroup2 /proc/mounts; then
echo "This container is incompatible with cgroups2. Refusing to continue."
echo "You can try re-running this container with '--tmpfs /sys/fs/cgroup' as a possible workaround."
echo "The workaround may not work on all systems, and will screw up the hosts' cgroups until a reboot of the system."
exit 1
fi
mkdir /sys/fs/cgroup/systemd
mount -t cgroup cgroup -o none,name=systemd,xattr /sys/fs/cgroup/systemd
fi
# The presence of either .dockerenv or /run/.containerenv cause snapcraft to
# incorrectly stage more than it should (e.g. libc and systemd). Remove them.
if [ -f /.dockerenv ]; then
rm -f /.dockerenv
fi
if [ -f /run/.containerenv ]; then
umount /run/.containerenv
rm -f /run/.containerenv
fi
if grep -q securityfs /proc/filesystems; then
mount -o rw,nosuid,nodev,noexec,relatime securityfs -t securityfs /sys/kernel/security
fi
mount -t tmpfs tmpfs /run
mount -t tmpfs tmpfs /run/lock
exec /lib/systemd/systemd --system --system-unit docker-exec.service