-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from heroku/automate-releases
Adding tools for converting docker stack to heroku stack in travis pipeline.
- Loading branch information
Showing
24 changed files
with
342 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
sudo cp tools/bin/* /usr/local/bin | ||
sudo convert-to-heroku-stack-image $STACK |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM ubuntu:16.04 | ||
|
||
RUN apt-get update | ||
RUN apt-get install docker.io -y | ||
RUN apt-get install jq -y | ||
RUN apt-get install curl -y | ||
|
||
COPY bin /usr/local/bin | ||
|
||
VOLUME ["/var/run/docker.sock"] | ||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
echo "$@" | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
|
||
set -e -o pipefail | ||
|
||
[ $# -ge 1 ] || abort usage: $(basename $0) STACK [VERSION] | ||
[ $UID = 0 ] || abort fatal: must be called with sudo | ||
|
||
STACK=$1 | ||
STACK_NAME=$(echo $STACK | cut -d '-' -f 1) | ||
STACK_VERSION=$(echo $STACK | cut -d '-' -f 2-) | ||
|
||
DOCKER_IMAGE=heroku/$STACK_NAME:$STACK_VERSION | ||
DOCKER_IMAGE_VERSION=$(docker inspect $DOCKER_IMAGE | jq .[].Id | cut -d ':' -f 2 | cut -b 1-12) | ||
|
||
IMG_BASE=${STACK_NAME}64-$STACK_VERSION-$DOCKER_IMAGE_VERSION | ||
IMG=/tmp/$IMG_BASE.img | ||
IMG_MNT=/tmp/$IMG_BASE | ||
IMG_GZ=/tmp/$IMG_BASE.img.gz | ||
IMG_SHA256=/tmp/$IMG_BASE.img.sha256 | ||
IMG_MANIFEST=/tmp/$IMG_BASE.manifest | ||
SIG=/tmp/$IMG_BASE.img.signature | ||
PRIVATE_KEY=/tmp/stack.key | ||
IMG_PKG_VERSIONS=/tmp/$IMG_BASE.pkg.versions | ||
|
||
display Starting capture for $STACK $DOCKER_IMAGE_VERSION at $(date) | ||
|
||
display Creating image file $IMG | ||
make-filesystem-image $IMG |& indent | ||
|
||
display Mounting image $IMG_MNT | ||
mount-filesystem-image $IMG $IMG_MNT |& indent | ||
|
||
display Copying stack to image | ||
export-docker-image $DOCKER_IMAGE $IMG_MNT |& indent | ||
|
||
display Modifying image directories and files | ||
install-heroku-files $IMG_MNT |& indent | ||
|
||
display Unmounting image | ||
umount $IMG_MNT |& indent | ||
|
||
display Signing image | ||
sign-image $IMG $SIG $PRIVATE_KEY | ||
|
||
display SHA256ing and gzipping image | ||
make-image-archive $IMG $IMG_SHA256 |& indent | ||
cat $IMG_SHA256 | ||
|
||
if update-manifest; then | ||
display Starting push at $(date) | ||
display Capture Package Versions | ||
capture-package-versions $DOCKER_IMAGE $IMG_PKG_VERSIONS | ||
display Uploading files | ||
upload-image $IMG_GZ $IMG_SHA256 $IMG_MANIFEST $STACK $DOCKER_IMAGE_VERSION $SIG $IMG_PKG_VERSIONS |& indent | ||
display Updating staging manifest | ||
publish-manifests | ||
else | ||
display Skipping push and manifest update | ||
fi | ||
|
||
display Finished capture for $STACK $DOCKER_IMAGE_VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
set -e -o pipefail | ||
|
||
DOCKER_IMAGE=$1 | ||
OUTPUT_FILE=$2 | ||
|
||
docker run --rm -ti heroku/heroku:16 dpkg-query -W -f "\${package},\${version}\n" | jq -s -R -f /usr/local/bin/csv-to-array.jq > $OUTPUT_FILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
set -e -o pipefail | ||
VERSION_PREFIX=$(date '+%Y%m%d-%H%M%S') | ||
|
||
while [ $# -gt 0 ]; do | ||
case "$1" in | ||
cedar-14) | ||
capture-docker-stack "$1" "$VERSION_PREFIX" | ||
;; | ||
*) | ||
capture-docker-stack "$1" "$VERSION_PREFIX" | ||
capture-docker-stack "$1-build" "$VERSION_PREFIX" | ||
;; | ||
esac | ||
shift | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[ | ||
[ | ||
split("\r\n")[] # transform csv input into array | ||
| split(",") # where first element has key names | ||
| select(length==2) # and other elements have values | ||
] | ||
| {h:.[0], v:.[1:][]} # {h:[keys], v:[values]} | ||
| [.h, .v] # [ [keys], [values] ] | ||
| [ transpose[] # [ [key,value], [key,value], ... ] | ||
| {key:.[0], value:.[1]} # [ {"key":key, "value":value}, ... ] | ||
] | ||
| from_entries # { key:value, key:value, ... } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
exec echo $'\n----->' "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
set -e -o pipefail | ||
convert-to-heroku-stack-image "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
DOCKER_IMAGE="$1" | ||
MNT="$2" | ||
|
||
CONTAINER="$(docker create "$DOCKER_IMAGE")" | ||
trap 'docker rm "$CONTAINER" > /dev/null' EXIT | ||
|
||
docker export "$CONTAINER" | tar -x -C "$MNT" --exclude=lib/modules bin etc lib lib64 sbin usr var/lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
exec sed -u "s/^/ /" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
IMG_MNT="$1" | ||
|
||
# etc/heroku is a mountpoint for runtime dyno information | ||
# sys is there so users of the stack can mount a sysfs on it (/sys is the default location) | ||
for d in app tmp proc sys dev var var/log var/tmp etc/heroku; do | ||
mkdir -p "$IMG_MNT/$d" | ||
done | ||
|
||
echo "127.0.0.1 localhost localhost.localdomain" > "$IMG_MNT/etc/hosts" | ||
|
||
echo "heroku-runtime" > "$IMG_MNT/etc/hostname" | ||
|
||
for f in etc/profile etc/bash.bashrc; do | ||
echo "export PS1='\\[\\033[01;34m\\]\\w\\[\\033[00m\\] \\[\\033[01;32m\\]$ \\[\\033[00m\\]'" > "$IMG_MNT/$f" | ||
done | ||
|
||
cat >"$IMG_MNT/etc/resolv.conf" <<'EOF' | ||
nameserver 172.16.0.23 | ||
domain z-2.compute-1.internal | ||
search z-2.compute-1.internal | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
IMG="$1" | ||
|
||
mkdir -p "$(dirname "$IMG")" | ||
dd if=/dev/zero of="$IMG" bs=100M count=24 | ||
yes | mkfs -t ext3 -m 1 "$IMG" | ||
tune2fs -c 0 -i 0 "$IMG" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
IMG="$1" | ||
IMG_SHA256="$2" | ||
|
||
sha256sum "$IMG" | cut -d ' ' -f 1 | tr -d '\n' > "$IMG_SHA256" | ||
gzip "$IMG" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
IMG="$1" | ||
IMG_MNT="$2" | ||
|
||
mkdir -p "$IMG_MNT" | ||
mount -o loop,noatime,nodiratime "$IMG" "$IMG_MNT" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if ls /tmp/*64-*.manifest >& /dev/null; then | ||
jq --null-input \ | ||
'[inputs] | ||
| map({ | ||
name: .name, | ||
id: .id, | ||
sha256: .sha256, | ||
signature: .signature | ||
}) | {stacks: .}' \ | ||
/tmp/*64-*.manifest | | ||
curl \ | ||
--fail --user-agent 'Stack Image Tools' \ | ||
--header "Authorization: Bearer $MANIFEST_APP_TOKEN" \ | ||
--header "Content-Type: application/json" \ | ||
--request PATCH \ | ||
--data @- \ | ||
"$MANIFEST_APP_URL/manifest/staging" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
# This script will create a digital signature for a stack image. The signature is written to | ||
# a temporary file (base64 encoded) so that it is accessable to other scripts. It uses the | ||
# Usage: sign-image <image file name> <signature file name> <private key file> | ||
# Preconditions: The environment variable SIGNING_KEY_PASSWORD should be defined and contain the passphrase | ||
# for the private key. | ||
|
||
if [ "$#" -ne 3 ]; then | ||
|
||
if [ ! -e "$1" ]; then | ||
echo "Image file name parameter (1) is missing." | ||
fi | ||
|
||
if [ ! -e "$2" ]; then | ||
echo "Signature file name parameter (2) is missing." | ||
fi | ||
|
||
if [ ! -e "$3" ]; then | ||
echo "Private key file parameter (3) is missing." | ||
fi | ||
|
||
echo "Usage: sign-image <image file name> <signature file name> <private key file> " | ||
exit 1 | ||
fi | ||
|
||
# Create digital signature | ||
binary_sig_file=$(mktemp /tmp/sig.XXXXXX) | ||
trap "{ rm -f $binary_sig_file; }" EXIT | ||
|
||
openssl dgst -sha256 -sign "$3" -passin env:SIGNING_KEY_PASSWORD "$1" > "$binary_sig_file" | ||
# Base 64 encode the signature and write encoded signature to a file | ||
openssl enc -a -e -out "$2" -in "$binary_sig_file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
[ -z "$MANIFEST_APP_URL" ] && echo "Missing manifest app url" && exit 1 | ||
[ -z "$MANIFEST_APP_TOKEN" ] && echo "Missing manifest app token" && exit 1 | ||
|
||
exit 0 |
Oops, something went wrong.