Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] multiarch: Pull tarballs #337

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ea02a45
Add -a flag for multiarch support in alpine-builder.
alexkreidler Aug 15, 2017
849e396
Add ARCHS variable for building different architectures.
alexkreidler Aug 16, 2017
bff6d50
Add an example of multi-arch
alexkreidler Aug 16, 2017
1e628d9
Update docs for multi-arch
alexkreidler Aug 16, 2017
30c3026
Fix typo in library-edge options
alexkreidler Aug 17, 2017
1ff565c
Update library spec generator for multi-arch
alexkreidler Aug 17, 2017
8d0364a
Fix tagging of images for multi-arch
alexkreidler Aug 19, 2017
8bc9dc9
Fix style shellcheck issues, add comments
alexkreidler Aug 20, 2017
51e4e16
Fix rootfs commit glob issue by adding globstar option.
alexkreidler Aug 20, 2017
6498f39
Update .gitignore for new multi-arch structure.
alexkreidler Aug 20, 2017
c2585bf
Rewrite commit loop based on options files, fix commit issues.
alexkreidler Aug 20, 2017
2ac88ef
Fix library spec issues
alexkreidler Aug 22, 2017
92e868f
Fix multi-arch builds using binfmt_misc and cross-docker
alexkreidler Sep 4, 2017
fa25e94
More binfmt_misc, CI test
alexkreidler Sep 10, 2017
bc8f92b
Revert "More binfmt_misc, CI test"
alexkreidler Sep 10, 2017
baf05c5
Revert "Fix multi-arch builds using binfmt_misc and cross-docker"
alexkreidler Sep 18, 2017
e87c348
Merge remote-tracking branch 'gliderlabs/master'
alexkreidler Sep 18, 2017
31d2112
Merge branch 'master' into multi-arch
alexkreidler Sep 18, 2017
6fe6421
[ci skip] begin to split the build script
alexkreidler Sep 19, 2017
538e0f2
WIP, more pulling tarballs [ci skip]
alexkreidler Sep 23, 2017
3a439c0
Update .gitignore
alexkreidler Sep 25, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/images
/versions/**/rootfs.tar.xz

# Matches all directories (x86, armhf, etc) in each version directory. Does not match files.
# Ignore everything under 'versions/'... (rootfs.tar.xz, etc)
/versions/**/

# ...except 'options' and 'Dockerfile'
!versions/**/options
!versions/**/Dockerfile
149 changes: 112 additions & 37 deletions build
Original file line number Diff line number Diff line change
@@ -1,53 +1,128 @@
#!/usr/bin/env bash

build_image() {
echo "Building image with options file $1"

# local file="$1"
#
# source "$file"
# local version_dir arch
# version_dir="$(dirname "$file")"
# : "${TAGS:?}" "${BUILD_OPTIONS:?}" "${RELEASE:?}"
#
# arch="x86_64" # amd64 images are built using the builder, others are pulled from upstream tarballs
#
# # Generate rootfs
# mkdir -p "$version_dir/$arch"
# docker run -e "TRACE=$TRACE" --rm "$BUILDER_IMAGE" -a "$arch" "${BUILD_OPTIONS[@]}" \
# > "$version_dir/$arch/rootfs.tar.xz"
# cp "$version_dir/Dockerfile" "$version_dir/$arch/Dockerfile" # so we can point the builder bots at one directory to build our image. AFAIK docker doesn't follow symlinks

# Build + tag images
for tag in "${TAGS[@]}"; do
echo "tagging $tag"
# # Currently, we just tag the x86_64 images as they were before, and tag the others with their architecture
# # This means that the gliderlabs repos/orgs will not have multi-arch images yet, but they have the options to do so in the future.
# if [[ "$arch" = "x86_64" ]]; then
# docker build -t "$tag" "$version_dir/$arch"
# else
# docker build -t "$tag-$arch" "$version_dir/$arch"
# fi
#
# if [[ "$CIRCLE_BUILD_NUM" ]]; then
# {
# mkdir -p images \
# && docker tag -f "$tag" "${tag}-${CIRCLE_BUILD_NUM}" \
# && docker save "${tag}-${CIRCLE_BUILD_NUM}" \
# | xz -9e > "images/${tag//\//_}-${CIRCLE_BUILD_NUM}.tar.xz" \
# && docker rmi "${tag}-${CIRCLE_BUILD_NUM}"
# } || true
# fi
done
}

should_pull() { # Errors if no PULL_URL is found in file
if [ -f "$1" ]; then
source "$1"
echo "$PULL_URL"
if [[ "$PULL_URL" == "" ]]; then
echo "n"
return 1
fi
else
echo "No file found at $1"
return 1
fi
}

pull_image() {
if should_pull "$1"; then
echo "Pulling image with options file $1"
source "$1"
dir="$(dirname "$1")"
local file="$(basename "$PULL_URL")"

echo file $file
echo "hi"
pwd
# Generate rootfs
echo "$dir"
mkdir -p "$dir"
curl -fSsL "$PULL_URL" > "$dir/rootfs.tar.gz"
cp "$dir/Dockerfile" "$dir/original.Dockerfile" # so we can point the builder bots at one directory to build our image. AFAIK docker doesn't follow symlinks
sed -i -- 's/.tar.xz/.tar.gz/g' "$dir/Dockerfile"

else
echo "No PULL_URL is found in options file $1"
return 1
fi
}

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

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

for file in $build_files; do
( # shellcheck source=versions/gliderlabs-3.2/options
source "$file"
local version_dir
for file in ${options_files[@]}; do
local release version_dir
release="$(basename "$(dirname "$file")")"
version_dir="$(dirname "$file")"
: "${TAGS:?}" "${BUILD_OPTIONS:?}" "${RELEASE:?}" # Maybe require $ARCHS in the future?
local arch_dirs="$version_dir/**/"

[[ "$ARCHS" ]] || { # compatability with older configs that were only written for x86_64 architectures
ARCHS=("x86_64")
}
: "${release:?}" "${version_dir:?}"
# git checkout -B "rootfs/$release" "$current_branch"

for arch in "${ARCHS[@]}"; do
# Generate rootfs
mkdir -p "$version_dir/$arch"
docker run -e "TRACE=$TRACE" --rm "$BUILDER_IMAGE" -a "$arch" "${BUILD_OPTIONS[@]}" \
> "$version_dir/$arch/rootfs.tar.xz"
cp "$version_dir/Dockerfile" "$version_dir/$arch/Dockerfile" # so we can point the builder bots at one directory to build our image. AFAIK docker doesn't follow symlinks

# Build + tag images
for tag in "${TAGS[@]}"; do
# Currently, we just tag the x86_64 images as they were before, and tag the others with their architecture
# This means that the gliderlabs repos/orgs will not have multi-arch images yet, but they have the options to do so in the future.
if [[ "$arch" = "x86_64" ]]; then
docker build -t "$tag" "$version_dir/$arch"
else
docker build -t "$tag-$arch" "$version_dir/$arch"
fi

if [[ "$CIRCLE_BUILD_NUM" ]]; then
{
mkdir -p images \
&& docker tag -f "$tag" "${tag}-${CIRCLE_BUILD_NUM}" \
&& docker save "${tag}-${CIRCLE_BUILD_NUM}" \
| xz -9e > "images/${tag//\//_}-${CIRCLE_BUILD_NUM}.tar.xz" \
&& docker rmi "${tag}-${CIRCLE_BUILD_NUM}"
} || true
fi
done
done )
check_build() { # Checks to either pull or build, then runs
if [ ! -f "$1" ]; then
return
fi
should_pull "$1"
echo $?
{
should_pull "$1" && echo "Pulling"; pull_image "$1";
} || {
echo "Pulling"; build_image "$1";
}
}

built=0 # check if some image has been built
# determine if glob has matches
if compgen -G "$arch_dirs" > /dev/null; then # e.g. library-3.6/x86_64/options
for arch in ${arch_dirs[@]}; do
check_build "$arch/options"
done
built=1
fi
if [[ -f "$version_dir/options" ]]; then # image is just under version, e.g. library-3.6/options
check_build "$version_dir/options"
built=1
fi
if [[ "$built" == "0" ]]; then
echo "No option files found for release: $release"
fi
done
}

Expand Down
3 changes: 3 additions & 0 deletions versions/gliderlabs-3.1/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
3 changes: 3 additions & 0 deletions versions/gliderlabs-3.2/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
3 changes: 3 additions & 0 deletions versions/gliderlabs-3.3/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
3 changes: 3 additions & 0 deletions versions/gliderlabs-3.4/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
3 changes: 3 additions & 0 deletions versions/gliderlabs-3.5/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
3 changes: 3 additions & 0 deletions versions/gliderlabs-3.6/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
3 changes: 3 additions & 0 deletions versions/gliderlabs-edge/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
3 changes: 3 additions & 0 deletions versions/library-3.1/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
3 changes: 3 additions & 0 deletions versions/library-3.2/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
3 changes: 3 additions & 0 deletions versions/library-3.3/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
3 changes: 3 additions & 0 deletions versions/library-3.4/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
3 changes: 3 additions & 0 deletions versions/library-3.5/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
3 changes: 3 additions & 0 deletions versions/library-3.6/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
2 changes: 1 addition & 1 deletion versions/library-edge/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
ADD rootfs.tar.gz /
CMD ["/bin/sh"]
3 changes: 3 additions & 0 deletions versions/library-edge/armhf/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.gz /
CMD ["/bin/sh"]
7 changes: 7 additions & 0 deletions versions/library-edge/armhf/options
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export RELEASE="edge"
export MIRROR="http://dl-cdn.alpinelinux.org/alpine"
export PACKAGES="alpine-baselayout,apk-tools,alpine-keys,libc-utils"
export ARCHS=(armhf)
export PULL_URL="http://dl-cdn.alpinelinux.org/alpine/v3.6/releases/armhf/alpine-minirootfs-3.6.2-armhf.tar.gz"
export BUILD_OPTIONS=(-b -s -t UTC -r $RELEASE -m $MIRROR -p $PACKAGES)
export TAGS=(alpine:edge)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.gz /
CMD ["/bin/sh"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.gz /
CMD ["/bin/sh"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
Binary file not shown.
3 changes: 3 additions & 0 deletions versions/library-edge/versions/library-edge/armhf/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.gz /
CMD ["/bin/sh"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
Binary file not shown.
3 changes: 3 additions & 0 deletions versions/library-edge/versions/library-edge/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.gz /
CMD ["/bin/sh"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
Binary file not shown.
3 changes: 3 additions & 0 deletions versions/library-edge/x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]