Commit dd6d110e authored by Vitaly Lipatov's avatar Vitaly Lipatov

createbytask: add docker support

parent 61f8dbfd
......@@ -40,7 +40,8 @@ rewrite_if_changed()
return 1
fi
fi
mv -f $NEWFILE $OLDFILE
cat $NEWFILE >$OLDFILE
rm -f $NEWFILE
}
......@@ -66,6 +67,28 @@ EOF
rewrite_if_changed /etc/hosts.tmpCB /etc/hosts && update_chrooted conf
}
tune_hosts_azbyka_a05()
{
cat <<EOF >/etc/hosts.tmpCB
127.0.0.1 localhost.localdomain localhost
# Auto-generated hostname. Please do not remove this comment.
$VEIP $AUSER.site.azbyka.ru $AUSER
# Azbyka's hosts
136.243.107.44 sphinx.azbyka
172.20.0.3 memcached.azbyka
172.20.0.3 redis.azbyka
138.201.53.216 mysql.azbyka
138.201.53.216 mysql
138.201.53.216 mysql.$AUSER
138.201.53.216 mariadb.azbyka
138.201.53.216 mariadb
138.201.53.216 mariadb.$AUSER
EOF
rewrite_if_changed /etc/hosts.tmpCB /etc/hosts && update_chrooted conf
}
tune_hosts_host03()
{
cat <<EOF >/etc/hosts.tmpCB
......@@ -296,7 +319,11 @@ rmdir *.tar 2>/dev/null
# common project
if [ -n "$AUSERID" ] ; then
tune_hosts_azbyka
if [ -n "$DOCKID" ] ; then
tune_hosts_azbyka_a05
else
tune_hosts_azbyka
fi
fi
PHP7BASE="php7-mbstring php7-pdo php7-curl php7-fileinfo php7-dom php7-exif \
......
......@@ -21,6 +21,7 @@ hostserver()
fi
}
# TODO: from alt's
tune_yandex_mirror()
{
local APTSDIR=$1/etc/apt/sources.list.d
......@@ -46,7 +47,7 @@ TASK="$1"
[ -n "$NAME" ] || NAME=$(basename $TASK .task)
# TODO
VEIP=$BASEIP.$VEID
[ -n "$VEIP" ] || VEIP=$BASEIP.$VEID
# Если не указан системный пользователь AUSER
if [ -z "$AUSER" ] ; then
......@@ -78,6 +79,31 @@ assure $NAME
assure $VEID
#assure $VEIDORIG
# TODO: do via docker compose
if [ -n "$DOCKID" ] ; then
mkdir -p composers/$AUSER/
cat <<EOF > composers/$AUSER/docker-compose.yml
version: '3.3'
services:
$AUSER:
container_name: $AUSER
restart: always
image: docker.hub.eterfund.ru/2hatokhin/containers/altlinux-p9:latest
command:
- /sbin/systemd
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup
- /azbyka/$AUSER:/home/$AUSER
cap_add:
- SYS_ADMIN
EOF
cd composers/$AUSER
docker-compose create || fatal
cd -
DOCKID=$AUSER
docker start $DOCKID || fatal
else
if ! vzlist -a | grep " $VEIP " ; then
vzctl create $VEID --ostemplate=$TEMPLATE || fatal
vzctl set $VEID --name $NAME --hostname $ADOMAIN --onboot yes --ipadd $VEIP --save || fatal
......@@ -105,19 +131,26 @@ if [ "$BASENAME" = "azbyka" ] ; then
tune_yandex_mirror /var/lib/vz/root/$VEID
fi
# TODO: first time only or force?
if true ; then
vzctl exec $VEID update_chrooted conf
vzctl exec $VEID epmI eepm
vzctl exec $VEID epm --auto upgrade
fi
st()
{
vzctl exec $VEID "$@"
if [ -n "$DOCKID" ] ; then
docker exec -i $DOCKID "$@"
else
vzctl exec $VEID "$@"
fi
}
# common projects
# TODO: first time only or force?
if true ; then
st update_chrooted conf
st epmI eepm
st epm --auto upgrade
fi
# common projects (copy from base container)
if [ -n "$VEIDORIG" ] ; then
if [ ! -s "apache/$AUSER.conf" ] ; then
hostserver cat /var/lib/vz/root/$VEIDORIG/etc/httpd2/conf/sites-enabled/$ACONF.conf > apache/$ACONF.conf
......@@ -129,7 +162,10 @@ if [ -n "$VEIDORIG" ] ; then
echo "Empty apache/$ACONF.conf, skipped"
fi
hostserver cat /var/lib/vz/root/$VEIDORIG/etc/httpd2/conf/include/prepend.php | st tee /tmp/prepend.php >/dev/null
if [ ! -s apache/prepend.php ] ; then
hostserver cat /var/lib/vz/root/$VEIDORIG/etc/httpd2/conf/include/prepend.php > apache/prepend.php
fi
cat apache/prepend.php | st tee /tmp/prepend.php >/dev/null
st test -s /tmp/prepend.php || fatal "Empty prepend.php"
fi
......@@ -148,7 +184,7 @@ echo "PKGINSTALL='$PKGINSTALL'" | st tee -a $ATASK
echo "VEIP=$VEIP" | st tee -a $ATASK
# common projects
if [ -n "$VEIDORIG" ] ; then
if false && [ -n "$VEIDORIG" ] ; then
auserid=$(hostserver vzctl exec $VEIDORIG id -u $AUSER)
[ -n "$auserid" ] || fatal "can't get user id"
echo "AUSERID=$auserid" | st tee -a $ATASK
......@@ -158,10 +194,20 @@ if [ -n "$VEIDORIG" ] ; then
echo "AGROUPID=$agroupid" | st tee -a $ATASK
fi
if true ; then
auserid="$(stat -c "%u" /azbyka/$AUSER/.bashrc)"
[ -n "$auserid" ] || fatal "can't get user id"
echo "AUSERID=$auserid" | st tee -a $ATASK
agroupid="$(stat -c "%g" /azbyka/$AUSER/.bashrc)"
[ -n "$agroupid" ] || fatal "can't get group id"
echo "AGROUPID=$agroupid" | st tee -a $ATASK
fi
#echo "WEBMASTER=$(vzctl exec $VEIDORIG id -g $AUSER)" | st tee -a $ATASK
cat createbytask.int.sh | st tee /tmp/createbytask.int.sh >/dev/null
st chmod 0755 /tmp/createbytask.int.sh
st /tmp/createbytask.int.sh $ATASK || fatal
st bash /tmp/createbytask.int.sh $ATASK || fatal
st epm clean
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment