Skip to content

Commit

Permalink
add useful testing script to quickly update stemcells with local agen…
Browse files Browse the repository at this point in the history
…t binary

Signed-off-by: Brian Cunnie <[email protected]>
  • Loading branch information
cppforlife authored and Brian Cunnie committed Mar 21, 2017
1 parent 21b4c2d commit 7210b81
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
25 changes: 25 additions & 0 deletions bin/repack-stemcell/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Repacking Stemcell with Updated Agent

!!! For debugging only !!!

This Concourse task allows the customization of a stemcell's `bosh-agent`, typically used when testing bootstrapping stage. Consider scp-ing Agent binary onto running machine as a quicker alternative.

Override STEMCELL_URL (must be heavy stemcell, raw) and STEMCELL_SHA1 to the stemcell you want (or leave as is):

```
export STEMCELL_URL=https://s3.amazonaws.com/bosh-core-stemcells/aws/bosh-stemcell-3312.15-aws-xen-ubuntu-trusty-go_agent.tgz
export STEMCELL_SHA1=d5252cdd6b07763ed989fcfeff47d06afa164065
./run.sh
```

Assumes your Concourse target is named _production_. If not, edit `run.sh` and adjust.

### Optional SSH debugging

Set your SSH key:

```
export BOSH_DEBUG_PUB_KEY="ssh-rsa blahblah"
```

This will bake your SSH public key into the stemcell; you will be able to ssh in as user `bosh_debug`.
68 changes: 68 additions & 0 deletions bin/repack-stemcell/repack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

set -e -x

env

stemcell_tgz=/tmp/stemcell.tgz
stemcell_dir=/tmp/stemcell
image_dir=/tmp/image

mkdir -p $stemcell_dir $image_dir
wget -O- $STEMCELL_URL > $stemcell_tgz
echo "$STEMCELL_SHA1 $stemcell_tgz" | shasum -c -

# Expose loopbacks in concourse container
(
set -e
mount_path=/tmp/self-cgroups
cgroups_path=`cat /proc/self/cgroup|grep devices|cut -d: -f3`
[ -d $mount_path ] && umount $mount_path && rmdir $mount_path
mkdir -p $mount_path
mount -t cgroup -o devices none $mount_path
echo 'b 7:* rwm' > $mount_path/$cgroups_path/devices.allow
umount $mount_path
rmdir $mount_path
for i in $(seq 0 260); do
mknod -m660 /dev/loop${i} b 7 $i 2>/dev/null || true
done
)

# Repack stemcell
(
set -e;
cd $stemcell_dir
tar xvf $stemcell_tgz
new_ver=`date +%s`

# Update stemcell with new agent
(
set -e;
cd $image_dir
tar xvf $stemcell_dir/image
mnt_dir=/mnt/stemcell
mkdir $mnt_dir
mount -o loop,offset=32256 root.img $mnt_dir
echo -n 0.0.${new_ver} > $mnt_dir/var/vcap/bosh/etc/stemcell_version
cp /tmp/build/*/agent-src/bin/bosh-agent $mnt_dir/var/vcap/bosh/bin/bosh-agent

if [ -z "$BOSH_DEBUG_PUB_KEY" ]; then
sudo chroot $mnt_dir /bin/bash <<EOF
useradd -m -s /bin/bash bosh_debug -G bosh_sudoers
cd ~bosh_debug
mkdir .ssh
echo $BOSH_DEBUG_PUB_KEY >> .ssh/authorized_keys
chmod go-rw -R .
chown -R bosh_debug:bosh_debug .
EOF
fi

umount $mnt_dir
tar czvf $stemcell_dir/image *
)

sed -i.bak "s/version: .*/version: 0.0.${new_ver}/" stemcell.MF
tar czvf $stemcell_tgz *
)

cp $stemcell_tgz /tmp/build/*/stemcell/
10 changes: 10 additions & 0 deletions bin/repack-stemcell/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e -x

bin=$(dirname $0)
cd $bin/../..
./bin/build-linux-amd64
mv out/bosh-agent bin/bosh-agent # necessary so that fly -x can be used
time fly -t production execute -x -p -i agent-src=. -o stemcell=out/ -c ./bin/build-stemcell/task.yml
ls -la out/stemcell.tgz
21 changes: 21 additions & 0 deletions bin/repack-stemcell/task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
platform: linux

image_resource:
type: docker-image
source:
repository: bosh/os-image-stemcell-builder

inputs:
- name: agent-src

outputs:
- name: stemcell

run:
path: agent-src/bin/build-stemcell/repack.sh

params:
STEMCELL_URL: "https://s3.amazonaws.com/bosh-core-stemcells/aws/bosh-stemcell-3312.15-aws-xen-ubuntu-trusty-go_agent.tgz"
STEMCELL_SHA1: "d5252cdd6b07763ed989fcfeff47d06afa164065"
BOSH_DEBUG_PUB_KEY: ""

0 comments on commit 7210b81

Please sign in to comment.