[lxc-devel] [PATCH] lxc-alpine: download statically compiled package manager if not available on host

Natanael Copa ncopa at alpinelinux.org
Wed May 15 06:15:54 UTC 2013


On Tue, 14 May 2013 19:27:32 +0300
Kaarle Ritvanen <kaarle.ritvanen at datakunkku.fi> wrote:

> Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen at datakunkku.fi>

I have looked over it and tested it on Alpine Linux.

It should make it very simple to test an Alpine Linux container on any
x86/x86_64 GNU Linux.

Acked-by: Natanael Copa <ncopa at alpinelinux.org>


> ---
>  templates/lxc-alpine.in | 30 +++++++++++++++++++++++++++---
>  1 file changed, 27 insertions(+), 3 deletions(-)
> 
> diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
> index 98347ed..528ebca 100644
> --- a/templates/lxc-alpine.in
> +++ b/templates/lxc-alpine.in
> @@ -1,6 +1,9 @@
>  #!/bin/sh
>  
>  install_alpine() {
> +    apk=${APK:-apk}
> +    apk_opts=
> +    
>      rootfs="$1"
>      shift
>      mkdir -p "$rootfs"/etc/apk || return 1
> @@ -10,11 +13,32 @@ install_alpine() {
>      else
>          cp /etc/apk/repositories "$rootfs"/etc/apk/repositories || return 1
>      fi
> -    opt_arch=
> +    
>      if [ -n "$apk_arch" ]; then
> -        opt_arch="--arch $apk_arch"
> +        apk_opts="--arch $apk_arch"
>      fi
> -    ${APK:-apk} add -U --initdb --root $rootfs $opt_arch "$@" alpine-base
> +    
> +    if ! which $apk &> /dev/null; then
> +        wget="wget -O - $repository/x86"
> +        
> +        apk_version=$($wget/APKINDEX.tar.gz | \
> +            tar -Oxz APKINDEX | \
> +            sed 's/^$//;Ta;x;
> +                 s/^\(.*\n\)P:apk-tools-static\(\n.*\)$/\1\2/;Tb;
> +                 s/^\(.*\n\)V:\([^\n]\+\)\(\n.*\)$/\2/;t;
> +                 :a;H;:b;d')
> +        [ "$apk_version" ] || return 1
> +        
> +        apk=$(mktemp /tmp/apk.static.XXXXXX)
> +        trap "rm -f $apk" EXIT
> +        $wget/apk-tools-static-$apk_version.apk | \
> +            tar -Oxz sbin/apk.static > $apk || return 1
> +        chmod u+x $apk
> +        
> +        apk_opts="$apk_opts --allow-untrusted"
> +    fi
> +    
> +    $apk add -U --initdb --root $rootfs $apk_opts "$@" alpine-base
>  }
>  
>  configure_alpine() {





More information about the lxc-devel mailing list