Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
support space or comma separated packages as argument to -p

send TRACE to builder, don't remove builder cache

slimmer edge / 3.3

NO_PUSH to suppress pushing

parallel rootfs pushes
  • Loading branch information
Andy Shinn committed Dec 20, 2015
1 parent 9762ff4 commit ab4337c
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 75 deletions.
102 changes: 49 additions & 53 deletions build
Original file line number Diff line number Diff line change
@@ -1,105 +1,101 @@
#!/usr/bin/env bash

declare BUILD_IMAGE="${BUILD_IMAGE:-alpine-builder}"
declare BUILD_PREFIX="${BUILD_PREFIX:-alpine-build-}"
declare OPTIONS="${OPTIONS:-versions/**/options}"

build() {
declare build_files="${*:-$OPTIONS}"
: "${build_files:?}"
declare build_files="${*:-versions/**/options}"

docker build -t "$BUILD_IMAGE" builder
[[ "$BUILDER_IMAGE" ]] || {
BUILDER_IMAGE="alpine-builder"
docker build -t "$BUILDER_IMAGE" builder
}

for file in $build_files; do
( source "$file"
local release="$RELEASE"
local build="${BUILD_PREFIX}${release}"
local build_options="$BUILD_OPTIONS"
local version_dir="$(dirname "$file")"
local tags="$TAGS"

: "${build:?}" "${tags:?}" "${build_options:?}" "${release:?}"

docker rm "$build" 2>/dev/null || true

docker run --name "${build}" "$BUILD_IMAGE" $build_options \
> "./$version_dir/rootfs.tar.gz"
( # shellcheck source=versions/gliderlabs-3.2/options
source "$file"
local version_dir
version_dir="$(dirname "$file")"
: "${TAGS:?}" "${BUILD_OPTIONS:?}" "${RELEASE:?}"
docker run -e "TRACE=$TRACE" --rm "$BUILDER_IMAGE" "${BUILD_OPTIONS[@]}" \
> "$version_dir/rootfs.tar.gz"

for tag in $tags; do
for tag in "${TAGS[@]}"; do
docker build -t "$tag" "$version_dir"
if [[ "$CIRCLE_BUILD_NUM" ]]; then
mkdir -p images \
&& docker tag -f "$tag" "${tag}-${CIRCLE_BUILD_NUM}" \
&& docker save "${tag}-${CIRCLE_BUILD_NUM}" \
| gzip -c > "images/${tag//\//_}-${CIRCLE_BUILD_NUM}.tar.gz" \
&& docker rmi "${tag}-${CIRCLE_BUILD_NUM}" || true
{
mkdir -p images \
&& docker tag -f "$tag" "${tag}-${CIRCLE_BUILD_NUM}" \
&& docker save "${tag}-${CIRCLE_BUILD_NUM}" \
| gzip -c > "images/${tag//\//_}-${CIRCLE_BUILD_NUM}.tar.gz" \
&& docker rmi "${tag}-${CIRCLE_BUILD_NUM}"
} || true
fi
done
docker rm "$build" 2>/dev/null || true )
done )
done
}

commit() {
[[ "$CIRCLE_BRANCH" == "release" ]] || return 0
declare rootfs_files="${*:-versions/**/rootfs.tar.gz}"

declare rootfs_files="versions/**/rootfs.tar.gz"
local build_num="${CIRCLE_BUILD_NUM:-nobuild}"
local current_branch
current_branch=$(git rev-parse --abbrev-ref HEAD)
: "${current_branch:?}"

for file in $rootfs_files; do
local release version_dir
release="$(basename "$(dirname "$file")")"
version_dir="$(dirname "$file")"

: "${release:?}" "${current_branch:?}"

git checkout -B "rootfs-$release"
: "${release:?}" "${version_dir:?}"
git checkout -B "rootfs/$release" "$current_branch"
git add -f -- "$file"
git commit -m "pushing release $release for build $build_num"
git push -f origin "rootfs-$release"
git checkout "$current_branch"
git commit -m "release image version $release for build $build_num"
done
[[ "$NO_PUSH" ]] || git push -f origin 'refs/heads/rootfs/*'
git checkout "$current_branch"
}

run_tests() {
declare build_files="${*:-$OPTIONS}"
declare build_files="${*:-versions/**/options}"
declare -a test_files
for file in $build_files; do
# shellcheck source=versions/gliderlabs-3.2/options
source "$file"
local tag
tag="$(echo "$TAGS" | cut -d' ' -f1)"
tag="${tag//:/-}"
tag="${tag//\//_}"
tag="${TAGS[0]}" tag="${tag//:/-}" tag="${tag//\//_}"
test_files+=("test/test_${tag}.bats")
done
bats "${test_files[@]}"
}

push() {
[[ "$CIRCLE_BRANCH" == "release" ]] || return 0
declare build_files="${*:-$OPTIONS}"
[[ "$NO_PUSH" ]] && return 0

declare build_files="${*:-versions/**/options}"
for file in $build_files; do
( source "$file"
for tag in $TAGS; do
if docker history $tag &> /dev/null; then
[[ $PUSH_IMAGE ]] && docker push $tag
( #shellcheck source=versions/gliderlabs-3.2/options
source "$file"
for tag in "${TAGS[@]}"; do
if docker history "$tag" &> /dev/null; then
[[ "$PUSH_IMAGE" ]] && docker push "$tag"
fi
done
exit 0 )
done
}

library() {
local refs="$(git ls-remote --heads origin)"
echo "# maintainer: Glider Labs <team@gliderlabs.com> (@gliderlabs)"
local refs
refs="$(git ls-remote --exit-code --heads origin rootfs)"
: "${refs:?}"

for file in versions/library-*/options; do
# shellcheck source=versions/library-3.2/options
source "$file"
local version="${RELEASE#v}"
echo
for tag in $TAGS; do
local tag="$(echo "$tag" | cut -d: -f2)"
read sha _ <<< $(echo "$refs" | grep rootfs-library-$version)
echo "$tag:" "git://github.com/gliderlabs/docker-alpine@$sha" "versions/library-$version"
for tag in "${TAGS[@]}"; do
echo "${tag#*:}:" \
"git://github.com/gliderlabs/docker-alpine@${refs:0:40}" \
"versions/library-${RELEASE#v}"
done
done
}
Expand Down
5 changes: 3 additions & 2 deletions builder/scripts/mkimage-alpine.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ usage() {
}

build() {
declare mirror="$1" rel="$2" packages="${3:-alpine-base}"
declare mirror="$1" rel="$2" packages=("${3:-alpine-base}")

local rootfs
rootfs="$(mktemp -d "${TMPDIR:-/var/tmp}/alpine-docker-rootfs-XXXXXXXXXX")"
Expand All @@ -37,8 +37,9 @@ build() {

# mkbase
{
# shellcheck disable=SC2086
apk --root "$rootfs" --update-cache --keys-dir /etc/apk/keys \
add --initdb "${packages//,/ }"
add --initdb ${packages[*]//,/ }
[[ "$ADD_BASELAYOUT" ]] && \
apk --root "$rootfs" --keys-dir /etc/apk/keys \
fetch --stdout alpine-base | tar -xvz -C "$rootfs" etc
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ general:
- "images"
branches:
ignore:
- /rootfs-.*/
- /rootfs\/.*/

machine:
pre:
Expand Down
20 changes: 20 additions & 0 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ The image is built using a builder Docker container based on the `debian` image.

The build script takes a glob of `options` files as an argument. Each of these files lives in a folder that describes the version of Alpine Linux to build. Each line of the `options` file are the options that will be applied to the resulting image. By default, we use the included glob of `versions/**/options`.

### Example

To build all the images simply run:

```console
$ ./build
```

Pass version files to the `build` script to build specific versions:

```console
$ ./build version/library-3.2/options versions/gliderlabs-3.2/options
```

With `parallel` available you can speed up building a bit:

```console
$ parallel -m ./build ::: versions/**/options
```

## Differences

As we maintain the [official Alpine Linux image in the Docker Library][library], we have specific `options` files for library versions. These contain options that may differ slightly from the `gliderlabs/alpine` image. Compare the `BUILD_OPTIONS` variable to see differences between versions.
Expand Down
4 changes: 2 additions & 2 deletions versions/gliderlabs-2.6/options
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export RELEASE="v2.6"
export MIRROR="http://alpine.gliderlabs.com/alpine"
export BUILD_OPTIONS="-d -s -E -c -t UTC -r $RELEASE -m $MIRROR"
export TAGS="gliderlabs/alpine:2.6"
export BUILD_OPTIONS=(-d -s -E -c -t UTC -r $RELEASE -m $MIRROR)
export TAGS=(gliderlabs/alpine:2.6)
export PUSH_IMAGE="true"
2 changes: 1 addition & 1 deletion versions/gliderlabs-2.7/options
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export RELEASE="v2.7"
export MIRROR="http://alpine.gliderlabs.com/alpine"
export BUILD_OPTIONS="-d -s -E -c -t UTC -r $RELEASE -m $MIRROR"
export BUILD_OPTIONS=(-d -s -E -c -t UTC -r $RELEASE -m $MIRROR)
export TAGS="gliderlabs/alpine:2.7"
export PUSH_IMAGE="true"
4 changes: 2 additions & 2 deletions versions/gliderlabs-3.1/options
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export RELEASE="v3.1"
export MIRROR="http://alpine.gliderlabs.com/alpine"
export BUILD_OPTIONS="-d -s -E -c -t UTC -r $RELEASE -m $MIRROR"
export TAGS="gliderlabs/alpine:3.1"
export BUILD_OPTIONS=(-d -s -E -c -t UTC -r $RELEASE -m $MIRROR)
export TAGS=(gliderlabs/alpine:3.1)
export PUSH_IMAGE="true"
4 changes: 2 additions & 2 deletions versions/gliderlabs-3.2/options
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export RELEASE="v3.2"
export MIRROR="http://alpine.gliderlabs.com/alpine"
export BUILD_OPTIONS="-d -s -E -c -t UTC -r $RELEASE -m $MIRROR"
export TAGS="gliderlabs/alpine:3.2 gliderlabs/alpine:latest"
export BUILD_OPTIONS=(-d -s -E -c -t UTC -r $RELEASE -m $MIRROR)
export TAGS=(gliderlabs/alpine:3.2 gliderlabs/alpine:latest)
export PUSH_IMAGE="true"
5 changes: 3 additions & 2 deletions versions/gliderlabs-edge/options
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export RELEASE="edge"
export MIRROR="http://alpine.gliderlabs.com/alpine"
export BUILD_OPTIONS="-d -s -c -t UTC -r $RELEASE -m $MIRROR"
export TAGS="gliderlabs/alpine:edge"
export PACKAGES="alpine-baselayout,apk-tools,alpine-keys"
export BUILD_OPTIONS=(-b -d -s -c -t UTC -r $RELEASE -m $MIRROR -p $PACKAGES)
export TAGS=(gliderlabs/alpine:edge)
export PUSH_IMAGE="true"
4 changes: 2 additions & 2 deletions versions/library-2.6/options
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export RELEASE="v2.6"
export BUILD_OPTIONS="-d -s -E -t UTC -r ${RELEASE} -m http://dl-4.alpinelinux.org/alpine"
export TAGS="alpine:2.6"
export BUILD_OPTIONS=(-d -s -E -t UTC -r ${RELEASE} -m http://dl-4.alpinelinux.org/alpine)
export TAGS=(alpine:2.6)
4 changes: 2 additions & 2 deletions versions/library-2.7/options
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export RELEASE="v2.7"
export BUILD_OPTIONS="-d -s -E -t UTC -r ${RELEASE} -m http://dl-4.alpinelinux.org/alpine"
export TAGS="alpine:2.7"
export BUILD_OPTIONS=(-d -s -E -t UTC -r ${RELEASE} -m http://dl-4.alpinelinux.org/alpine)
export TAGS=(alpine:2.7)
4 changes: 2 additions & 2 deletions versions/library-3.1/options
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export RELEASE="v3.1"
export MIRROR="http://dl-4.alpinelinux.org/alpine"
export BUILD_OPTIONS="-d -s -E -t UTC -r $RELEASE -m $MIRROR"
export TAGS="alpine:3.1"
export BUILD_OPTIONS=(-d -s -E -t UTC -r $RELEASE -m $MIRROR)
export TAGS=(alpine:3.1)
4 changes: 2 additions & 2 deletions versions/library-3.2/options
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export RELEASE="v3.2"
export MIRROR="http://dl-4.alpinelinux.org/alpine"
export BUILD_OPTIONS="-d -s -E -t UTC -r $RELEASE -m $MIRROR"
export TAGS="alpine:3.2 alpine:latest"
export BUILD_OPTIONS=(-d -s -E -t UTC -r $RELEASE -m $MIRROR)
export TAGS=(alpine:3.2 alpine:latest)
5 changes: 3 additions & 2 deletions versions/library-edge/options
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export RELEASE="edge"
export MIRROR="http://dl-4.alpinelinux.org/alpine"
export BUILD_OPTIONS="-d -s -t UTC -r $RELEASE -m $MIRROR"
export TAGS="alpine:edge"
export PACKAGES="alpine-baselayout,apk-tools,alpine-keys"
export BUILD_OPTIONS=(-b -d -s -t UTC -r $RELEASE -m $MIRROR -p $PACKAGES)
export TAGS=(alpine:edge)

0 comments on commit ab4337c

Please sign in to comment.