Commit dd6d110e authored by Vitaly Lipatov's avatar Vitaly Lipatov

createbytask: add docker support

parent 61f8dbfd
...@@ -40,7 +40,8 @@ rewrite_if_changed() ...@@ -40,7 +40,8 @@ rewrite_if_changed()
return 1 return 1
fi fi
fi fi
mv -f $NEWFILE $OLDFILE cat $NEWFILE >$OLDFILE
rm -f $NEWFILE
} }
...@@ -66,6 +67,28 @@ EOF ...@@ -66,6 +67,28 @@ EOF
rewrite_if_changed /etc/hosts.tmpCB /etc/hosts && update_chrooted conf 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() tune_hosts_host03()
{ {
cat <<EOF >/etc/hosts.tmpCB cat <<EOF >/etc/hosts.tmpCB
...@@ -296,7 +319,11 @@ rmdir *.tar 2>/dev/null ...@@ -296,7 +319,11 @@ rmdir *.tar 2>/dev/null
# common project # common project
if [ -n "$AUSERID" ] ; then if [ -n "$AUSERID" ] ; then
tune_hosts_azbyka if [ -n "$DOCKID" ] ; then
tune_hosts_azbyka_a05
else
tune_hosts_azbyka
fi
fi fi
PHP7BASE="php7-mbstring php7-pdo php7-curl php7-fileinfo php7-dom php7-exif \ PHP7BASE="php7-mbstring php7-pdo php7-curl php7-fileinfo php7-dom php7-exif \
......
...@@ -21,6 +21,7 @@ hostserver() ...@@ -21,6 +21,7 @@ hostserver()
fi fi
} }
# TODO: from alt's
tune_yandex_mirror() tune_yandex_mirror()
{ {
local APTSDIR=$1/etc/apt/sources.list.d local APTSDIR=$1/etc/apt/sources.list.d
...@@ -46,7 +47,7 @@ TASK="$1" ...@@ -46,7 +47,7 @@ TASK="$1"
[ -n "$NAME" ] || NAME=$(basename $TASK .task) [ -n "$NAME" ] || NAME=$(basename $TASK .task)
# TODO # TODO
VEIP=$BASEIP.$VEID [ -n "$VEIP" ] || VEIP=$BASEIP.$VEID
# Если не указан системный пользователь AUSER # Если не указан системный пользователь AUSER
if [ -z "$AUSER" ] ; then if [ -z "$AUSER" ] ; then
...@@ -78,6 +79,31 @@ assure $NAME ...@@ -78,6 +79,31 @@ assure $NAME
assure $VEID assure $VEID
#assure $VEIDORIG #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 if ! vzlist -a | grep " $VEIP " ; then
vzctl create $VEID --ostemplate=$TEMPLATE || fatal vzctl create $VEID --ostemplate=$TEMPLATE || fatal
vzctl set $VEID --name $NAME --hostname $ADOMAIN --onboot yes --ipadd $VEIP --save || fatal vzctl set $VEID --name $NAME --hostname $ADOMAIN --onboot yes --ipadd $VEIP --save || fatal
...@@ -105,19 +131,26 @@ if [ "$BASENAME" = "azbyka" ] ; then ...@@ -105,19 +131,26 @@ if [ "$BASENAME" = "azbyka" ] ; then
tune_yandex_mirror /var/lib/vz/root/$VEID tune_yandex_mirror /var/lib/vz/root/$VEID
fi 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 fi
st() 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 [ -n "$VEIDORIG" ] ; then
if [ ! -s "apache/$AUSER.conf" ] ; then if [ ! -s "apache/$AUSER.conf" ] ; then
hostserver cat /var/lib/vz/root/$VEIDORIG/etc/httpd2/conf/sites-enabled/$ACONF.conf > apache/$ACONF.conf 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 ...@@ -129,7 +162,10 @@ if [ -n "$VEIDORIG" ] ; then
echo "Empty apache/$ACONF.conf, skipped" echo "Empty apache/$ACONF.conf, skipped"
fi 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" st test -s /tmp/prepend.php || fatal "Empty prepend.php"
fi fi
...@@ -148,7 +184,7 @@ echo "PKGINSTALL='$PKGINSTALL'" | st tee -a $ATASK ...@@ -148,7 +184,7 @@ echo "PKGINSTALL='$PKGINSTALL'" | st tee -a $ATASK
echo "VEIP=$VEIP" | st tee -a $ATASK echo "VEIP=$VEIP" | st tee -a $ATASK
# common projects # common projects
if [ -n "$VEIDORIG" ] ; then if false && [ -n "$VEIDORIG" ] ; then
auserid=$(hostserver vzctl exec $VEIDORIG id -u $AUSER) auserid=$(hostserver vzctl exec $VEIDORIG id -u $AUSER)
[ -n "$auserid" ] || fatal "can't get user id" [ -n "$auserid" ] || fatal "can't get user id"
echo "AUSERID=$auserid" | st tee -a $ATASK echo "AUSERID=$auserid" | st tee -a $ATASK
...@@ -158,10 +194,20 @@ if [ -n "$VEIDORIG" ] ; then ...@@ -158,10 +194,20 @@ if [ -n "$VEIDORIG" ] ; then
echo "AGROUPID=$agroupid" | st tee -a $ATASK echo "AGROUPID=$agroupid" | st tee -a $ATASK
fi 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 #echo "WEBMASTER=$(vzctl exec $VEIDORIG id -g $AUSER)" | st tee -a $ATASK
cat createbytask.int.sh | st tee /tmp/createbytask.int.sh >/dev/null cat createbytask.int.sh | st tee /tmp/createbytask.int.sh >/dev/null
st chmod 0755 /tmp/createbytask.int.sh 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 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