Skip to content

Commit

Permalink
support for package-customized images
Browse files Browse the repository at this point in the history
ported from https://github.com/piotrminkina/docker-alpine/commit/0727c80559f4aa267b86e5cbe77028201f929e2f

added a -b option to extract alpine-base without dependencies

If /etc/issue, /etc/os-release, /etc/alpine-release are desirable, but
not all of alpine-base's dep, -b can be passed to extract an appropriate
set of these files directly.

The prime example use-case is in a container environment, where the init
system may not be appropriate.
  • Loading branch information
muhmuhten committed Sep 16, 2015
1 parent 907dbc6 commit 74faced
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
4 changes: 3 additions & 1 deletion builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ The builder takes several options:
* `-s`: Outputs the `rootfs.tar.gz` to stdout.
* `-c`: Adds the `apk-install` script to the resulting rootfs.
* `-e`: Adds extra `edge/main` and `edge/testing` pins to the repositories file.
* `-t <timzone>`: Set the timezone. Default is `UTC`.
* `-t <timezone>`: Set the timezone. Default is `UTC`.
* `-p <packages>`: Comma-separated packages list (`tzdata` is always installed). Default is `alpine-base`.
* `-b`: Extracts `alpine-base` to the rootfs without dependencies. For images slimmed down with `-p` which still want `/etc/*-release` and `/etc/issue`.
26 changes: 15 additions & 11 deletions builder/scripts/mkimage-alpine.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set -eo pipefail; [[ "$TRACE" ]] && set -x
}

usage() {
printf >&2 '%s: [-r release] [-m mirror] [-s] [-e] [-c] [-t]\n' "$0" && exit 1
printf >&2 '%s: [-r release] [-m mirror] [-s] [-e] [-c] [-t timezone] [-p packages] [-b]\n' "$0" && exit 1
}

output_redirect() {
Expand All @@ -27,8 +27,8 @@ output_redirect() {
fi
}

build(){
declare mirror="$1" rel="$2" timezone="${3:-UTC}"
build() {
declare mirror="$1" rel="$2" timezone="${3:-UTC}" packages="${4:-alpine-base}"
local repo="$mirror/$rel/main"
local arch="$(uname -m)"

Expand All @@ -40,7 +40,11 @@ build(){
# mkbase
{
apk --repository "$repo" --update-cache \
fetch --recursive --output "$tmp" alpine-base tzdata
fetch --recursive --output "$tmp" \
tzdata ${packages//,/ }
[[ "$ADD_BASELAYOUT" ]] && \
apk --repository "$repo" fetch --stdout alpine-base \
| tar -xvz -C "$rootfs" etc
apk --root "$rootfs" --allow-untrusted add --initdb "$tmp"/*.apk
cp -a "$rootfs/usr/share/zoneinfo/$timezone" "$rootfs/etc/localtime"
apk --root "$rootfs" del tzdata
Expand All @@ -57,27 +61,27 @@ build(){

# save
tar -z -f rootfs.tar.gz --numeric-owner -C "$rootfs" -c .
if [[ "$STDOUT" ]]; then
cat rootfs.tar.gz
else
return 0
fi
[[ "$STDOUT" ]] && cat rootfs.tar.gz

return 0
}

main() {
while getopts "hr:m:t:sec" opt; do
while getopts "hr:m:t:secp:b" opt; do
case $opt in
r) REL="$OPTARG";;
m) MIRROR="$OPTARG";;
s) STDOUT=1;;
e) REPO_EXTRA=1;;
t) TIMEZONE="$OPTARG";;
c) ADD_APK_SCRIPT=1;;
p) PACKAGES="$OPTARG";;
b) ADD_BASELAYOUT=1;;
*) usage;;
esac
done

build "$MIRROR" "$REL" "$TIMEZONE"
build "$MIRROR" "$REL" "$TIMEZONE" "$PACKAGES"
}

main "$@"

0 comments on commit 74faced

Please sign in to comment.