mirror of
https://github.com/YunoHost/yunohost-ci.git
synced 2024-09-03 20:05:53 +02:00
can rebuild during a build
This commit is contained in:
parent
3c51fdbf9c
commit
adeaf4143a
1 changed files with 37 additions and 22 deletions
57
utils.sh
57
utils.sh
|
@ -44,6 +44,34 @@ wait_container()
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rotate_image()
|
||||||
|
{
|
||||||
|
local instance_to_publish=$1
|
||||||
|
local alias_image=$2
|
||||||
|
|
||||||
|
# Save the finger print to delete the old image later
|
||||||
|
local finger_print_to_delete=$(lxc image info "$alias_image" | grep Fingerprint | awk '{print $2}')
|
||||||
|
local should_restart=0
|
||||||
|
|
||||||
|
# If the container is running, stop it
|
||||||
|
if [ $(lxc info $instance_to_publish | grep Status | awk '{print $2}') = "Running" ]
|
||||||
|
then
|
||||||
|
should_restart=1
|
||||||
|
lxc stop "$instance_to_publish"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create image before install
|
||||||
|
lxc publish "$instance_to_publish" --alias "$alias_image"
|
||||||
|
# Remove old image
|
||||||
|
lxc image delete "$finger_print_to_delete"
|
||||||
|
|
||||||
|
if [ $should_restart = 1 ]
|
||||||
|
then
|
||||||
|
lxc start "$instance_to_publish"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
rebuild_base_containers()
|
rebuild_base_containers()
|
||||||
{
|
{
|
||||||
local debian_version=$1
|
local debian_version=$1
|
||||||
|
@ -51,8 +79,6 @@ rebuild_base_containers()
|
||||||
local arch=$3
|
local arch=$3
|
||||||
local base_image_to_rebuild="yunohost-$debian_version-$ynh_version"
|
local base_image_to_rebuild="yunohost-$debian_version-$ynh_version"
|
||||||
|
|
||||||
clean_containers $base_image_to_rebuild
|
|
||||||
|
|
||||||
lxc launch images:debian/$debian_version/$arch "$base_image_to_rebuild-tmp"
|
lxc launch images:debian/$debian_version/$arch "$base_image_to_rebuild-tmp"
|
||||||
|
|
||||||
wait_container "$base_image_to_rebuild-tmp"
|
wait_container "$base_image_to_rebuild-tmp"
|
||||||
|
@ -65,11 +91,8 @@ rebuild_base_containers()
|
||||||
# Install gitlab-runner binary since we need for cache/artifacts.
|
# Install gitlab-runner binary since we need for cache/artifacts.
|
||||||
lxc exec "$base_image_to_rebuild-tmp" -- /bin/bash -c "curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | bash"
|
lxc exec "$base_image_to_rebuild-tmp" -- /bin/bash -c "curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | bash"
|
||||||
lxc exec "$base_image_to_rebuild-tmp" -- /bin/bash -c "apt-get install gitlab-runner -y"
|
lxc exec "$base_image_to_rebuild-tmp" -- /bin/bash -c "apt-get install gitlab-runner -y"
|
||||||
lxc stop "$base_image_to_rebuild-tmp"
|
|
||||||
|
|
||||||
# Create image before install
|
rotate_image "$base_image_to_rebuild-tmp" "$base_image_to_rebuild-before-install"
|
||||||
lxc publish "$base_image_to_rebuild-tmp" --alias "$base_image_to_rebuild-before-install"
|
|
||||||
lxc start "$base_image_to_rebuild-tmp"
|
|
||||||
|
|
||||||
wait_container "$base_image_to_rebuild-tmp"
|
wait_container "$base_image_to_rebuild-tmp"
|
||||||
|
|
||||||
|
@ -81,20 +104,17 @@ rebuild_base_containers()
|
||||||
fi
|
fi
|
||||||
# Install yunohost
|
# Install yunohost
|
||||||
lxc exec "$base_image_to_rebuild-tmp" -- /bin/bash -c "curl $INSTALL_SCRIPT | bash -s -- -a -d $ynh_version"
|
lxc exec "$base_image_to_rebuild-tmp" -- /bin/bash -c "curl $INSTALL_SCRIPT | bash -s -- -a -d $ynh_version"
|
||||||
lxc stop "$base_image_to_rebuild-tmp"
|
|
||||||
|
|
||||||
# Create image before postinstall
|
rotate_image "$base_image_to_rebuild-tmp" "$base_image_to_rebuild-before-postinstall"
|
||||||
lxc publish "$base_image_to_rebuild-tmp" --alias "$base_image_to_rebuild-before-postinstall"
|
|
||||||
lxc start "$base_image_to_rebuild-tmp"
|
|
||||||
|
|
||||||
wait_container "$base_image_to_rebuild-tmp"
|
wait_container "$base_image_to_rebuild-tmp"
|
||||||
|
|
||||||
# Running post Install
|
# Running post Install
|
||||||
lxc exec "$base_image_to_rebuild-tmp" -- /bin/bash -c "yunohost tools postinstall -d domain.tld -p the_password --ignore-dyndns"
|
lxc exec "$base_image_to_rebuild-tmp" -- /bin/bash -c "yunohost tools postinstall -d domain.tld -p the_password --ignore-dyndns"
|
||||||
lxc stop "$base_image_to_rebuild-tmp"
|
|
||||||
|
|
||||||
# Create image after postinstall
|
rotate_image "$base_image_to_rebuild-tmp" "$base_image_to_rebuild-after-postinstall"
|
||||||
lxc publish "$base_image_to_rebuild-tmp" --alias "$base_image_to_rebuild-after-postinstall"
|
|
||||||
|
lxc stop "$base_image_to_rebuild-tmp"
|
||||||
|
|
||||||
lxc delete "$base_image_to_rebuild-tmp"
|
lxc delete "$base_image_to_rebuild-tmp"
|
||||||
}
|
}
|
||||||
|
@ -108,8 +128,6 @@ update_image() {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local finger_print_to_delete=$(lxc image info "$image_to_update" | grep Fingerprint | cut -d' ' -f2)
|
|
||||||
|
|
||||||
# Start and run upgrade
|
# Start and run upgrade
|
||||||
lxc launch "$image_to_update" "$image_to_update-tmp"
|
lxc launch "$image_to_update" "$image_to_update-tmp"
|
||||||
|
|
||||||
|
@ -117,13 +135,10 @@ update_image() {
|
||||||
|
|
||||||
lxc exec "$image_to_update-tmp" -- /bin/bash -c "apt-get update"
|
lxc exec "$image_to_update-tmp" -- /bin/bash -c "apt-get update"
|
||||||
lxc exec "$image_to_update-tmp" -- /bin/bash -c "apt-get upgrade -y"
|
lxc exec "$image_to_update-tmp" -- /bin/bash -c "apt-get upgrade -y"
|
||||||
|
|
||||||
|
rotate_image "$image_to_update-tmp" "$image_to_update"
|
||||||
|
|
||||||
lxc stop "$image_to_update-tmp"
|
lxc stop "$image_to_update-tmp"
|
||||||
|
|
||||||
# Add new image updated
|
|
||||||
lxc publish "$image_to_update-tmp" --alias "$image_to_update"
|
|
||||||
|
|
||||||
# Remove old image
|
|
||||||
lxc image delete "$finger_print_to_delete"
|
|
||||||
|
|
||||||
lxc delete "$image_to_update-tmp"
|
lxc delete "$image_to_update-tmp"
|
||||||
}
|
}
|
Loading…
Reference in a new issue