mirror of
https://github.com/YunoHost-Apps/vaultwarden_ynh.git
synced 2024-09-03 18:26:31 +02:00
Merge pull request #212 from YunoHost-Apps/testing
Implement ynh_docker_image_extract
This commit is contained in:
commit
8d39c75d8c
5 changed files with 86 additions and 21 deletions
|
@ -1,7 +0,0 @@
|
||||||
SOURCE_URL=https://codeload.github.com/jjlin/docker-image-extract/tar.gz/a9e455e44bbbfba897bf3342d9661b182cee67a9
|
|
||||||
SOURCE_SUM=9eb0c734e83a3fd7102fc7209af4977024ec467fbc819782491af47295675f67
|
|
||||||
SOURCE_SUM_PRG=sha256sum
|
|
||||||
SOURCE_FORMAT=tar.gz
|
|
||||||
SOURCE_IN_SUBDIR=true
|
|
||||||
SOURCE_FILENAME=
|
|
||||||
SOURCE_EXTRACT=true
|
|
|
@ -7,6 +7,8 @@
|
||||||
# dependencies used by the app
|
# dependencies used by the app
|
||||||
pkg_dependencies="libpq5"
|
pkg_dependencies="libpq5"
|
||||||
|
|
||||||
|
pkg_image="vaultwarden/server"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# PERSONAL HELPERS
|
# PERSONAL HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source ynh_docker_image_extract
|
||||||
source ynh_send_readme_to_admin__2
|
source ynh_send_readme_to_admin__2
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
@ -92,7 +93,7 @@ ynh_script_progression --message="Setting up source files..."
|
||||||
|
|
||||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
ynh_setup_source --dest_dir="$final_path/build/" --source_id="docker-image-extract"
|
ynh_docker_image_extract --dest_dir="$final_path/build/" --image_spec="$pkg_image:$(ynh_app_upstream_version)"
|
||||||
mkdir -p "$final_path/live/"
|
mkdir -p "$final_path/live/"
|
||||||
|
|
||||||
chmod 750 "$final_path"
|
chmod 750 "$final_path"
|
||||||
|
@ -128,12 +129,8 @@ chown -R $app:$app "$datadir"
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Making install..."
|
ynh_script_progression --message="Making install..."
|
||||||
|
|
||||||
pushd "$final_path"/build
|
mv -f "$final_path/build/vaultwarden" "$final_path/live/vaultwarden"
|
||||||
./docker-image-extract vaultwarden/server:$(ynh_app_upstream_version)
|
rsync -a "$final_path/build/web-vault/" "$final_path/live/web-vault/"
|
||||||
popd
|
|
||||||
|
|
||||||
mv -f "$final_path/build/output/vaultwarden" "$final_path/live/vaultwarden"
|
|
||||||
rsync -a "$final_path/build/output/web-vault/" "$final_path/live/web-vault/"
|
|
||||||
ynh_secure_remove --file="$final_path/build"
|
ynh_secure_remove --file="$final_path/build"
|
||||||
|
|
||||||
chmod 750 "$final_path"
|
chmod 750 "$final_path"
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source ynh_docker_image_extract
|
||||||
source ynh_handle_app_migration
|
source ynh_handle_app_migration
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
@ -142,7 +143,7 @@ then
|
||||||
ynh_script_progression --message="Upgrading source files..."
|
ynh_script_progression --message="Upgrading source files..."
|
||||||
|
|
||||||
# Download, check integrity, uncompress the source of vaultwarden from app.src to his build directory
|
# Download, check integrity, uncompress the source of vaultwarden from app.src to his build directory
|
||||||
ynh_setup_source --dest_dir="$final_path/build/" --source_id="docker-image-extract"
|
ynh_docker_image_extract --dest_dir="$final_path/build/" --image_spec="$pkg_image:$(ynh_app_upstream_version)"
|
||||||
mkdir -p "$final_path/live/"
|
mkdir -p "$final_path/live/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -174,13 +175,9 @@ ynh_script_progression --message="Making upgrade..."
|
||||||
|
|
||||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||||
then
|
then
|
||||||
pushd "$final_path"/build
|
mv -f "$final_path/build/vaultwarden" "$final_path/live/vaultwarden"
|
||||||
./docker-image-extract vaultwarden/server:$(ynh_app_upstream_version)
|
|
||||||
popd
|
|
||||||
|
|
||||||
mv -f "$final_path/build/output/vaultwarden" "$final_path/live/vaultwarden"
|
|
||||||
ynh_secure_remove --file="$final_path/live/web-vault/"
|
ynh_secure_remove --file="$final_path/live/web-vault/"
|
||||||
rsync -a "$final_path/build/output/web-vault/" "$final_path/live/web-vault/"
|
rsync -a "$final_path/build/web-vault/" "$final_path/live/web-vault/"
|
||||||
ynh_secure_remove --file="$final_path/build"
|
ynh_secure_remove --file="$final_path/build"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
76
scripts/ynh_docker_image_extract
Normal file
76
scripts/ynh_docker_image_extract
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# This script pulls and extracts all files from an image in Docker Hub.
|
||||||
|
#
|
||||||
|
# usage: ynh_docker_image_extract --dest_dir=dest_dir --image_spec=image_spec [--os_arch_variant=os_arch_variant]
|
||||||
|
# | arg: -d, --dest_dir= - Directory where to setup sources
|
||||||
|
# | arg: -i, --image_spec= - Image specification
|
||||||
|
# | arg: -o, --os_arch_variant= - OS, architecture and variant seen as OS/ARCH on Docker Hub default:linux/$YNH_ARCH.
|
||||||
|
#
|
||||||
|
# Pull and extract all files from the 'hello-world' image tagged 'latest'.
|
||||||
|
# example: ynh_docker_image_extract --dest_dir="dest_dir" --image_spec="hello-world:latest"
|
||||||
|
#
|
||||||
|
# Same as above; tag defaults to 'latest'.
|
||||||
|
# example: ynh_docker_image_extract --dest_dir="dest_dir" --image_spec="hello-world"
|
||||||
|
#
|
||||||
|
# Same as above; tag defaults from 'latest' for a specific OS/ARCH.
|
||||||
|
# example: ynh_docker_image_extract --dest_dir="dest_dir" --image_spec="hello-world "--os_arch_variant=="linux/arm/v6"
|
||||||
|
#
|
||||||
|
# Same as above, but specify the image by digest, don't require the specific OS/ARCH.
|
||||||
|
# example: ynh_docker_image_extract --dest_dir="dest_dir" --image_spec="hello-world:sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042"
|
||||||
|
#
|
||||||
|
# This helper will pulls and extracts all files from the image $image_spec in Docker Hub.
|
||||||
|
#
|
||||||
|
# The helper will:
|
||||||
|
# - Download `$image_spec` and extract it to `$dest_dir`.
|
||||||
|
# - Patches named `sources/patches/${src_id}-*.patch` will be applied to `$dest_dir`
|
||||||
|
# - Extra files in `sources/extra_files/$src_id` will be copied to dest_dir
|
||||||
|
#
|
||||||
|
# Requires YunoHost version *.*.* or higher.
|
||||||
|
ynh_docker_image_extract() {
|
||||||
|
# Declare an array to define the options of this helper.
|
||||||
|
local legacy_args=dio
|
||||||
|
local -A args_array=([d]=dest_dir= [i]=image_spec= [o]=os_arch_variant=)
|
||||||
|
local dest_dir
|
||||||
|
local image_spec
|
||||||
|
local os_arch_variant
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
os_arch_variant="${os_arch_variant:-"linux/$YNH_ARCH"}"
|
||||||
|
|
||||||
|
# Extract source into the app dir
|
||||||
|
mkdir --parents "$dest_dir"
|
||||||
|
|
||||||
|
if [ -n "${final_path:-}" ] && [ "$dest_dir" == "$final_path" ]; then
|
||||||
|
_ynh_apply_default_permissions $dest_dir
|
||||||
|
fi
|
||||||
|
|
||||||
|
tempdir="$(mktemp -d)"
|
||||||
|
pushd $tempdir
|
||||||
|
git init -q
|
||||||
|
git remote add -f -t main origin https://github.com/jjlin/docker-image-extract.git > /dev/null 2>&1
|
||||||
|
git checkout -q -b main origin/main
|
||||||
|
./docker-image-extract -p $os_arch_variant -o $dest_dir $image_spec 2>&1
|
||||||
|
popd
|
||||||
|
rm -rf $tempdir
|
||||||
|
|
||||||
|
# Apply patches
|
||||||
|
if [ -d "$YNH_APP_BASEDIR/sources/patches/" ]; then
|
||||||
|
local patches_folder=$(realpath $YNH_APP_BASEDIR/sources/patches/)
|
||||||
|
if (($(find $patches_folder -type f -name "${image_spec}-*.patch" 2>/dev/null | wc --lines) > "0")); then
|
||||||
|
(
|
||||||
|
cd "$dest_dir"
|
||||||
|
for p in $patches_folder/${image_spec}-*.patch; do
|
||||||
|
echo $p
|
||||||
|
patch --strip=1 <$p
|
||||||
|
done
|
||||||
|
) || ynh_die --message="Unable to apply patches"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add supplementary files
|
||||||
|
if test -e "$YNH_APP_BASEDIR/sources/extra_files/${image_spec}"; then
|
||||||
|
cp --archive $YNH_APP_BASEDIR/sources/extra_files/$image_spec/. "$dest_dir"
|
||||||
|
fi
|
||||||
|
}
|
Loading…
Reference in a new issue