Last active
December 13, 2015 18:49
-
-
Save jasonpincin/4958050 to your computer and use it in GitHub Desktop.
Helper utility for smartos-image-server (https://github.com/nshalman/smartos-image-server) that makes publishing new images a one-line breeze! For the global-zone companion script, see: https://gist.github.com/jasonpincin/4958099
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
#!/usr/bin/bash | |
# | |
# import-image (https://gist.github.com/jasonpincin/4958050) | |
# | |
# Helper utility for smartos-image-server | |
# https://github.com/nshalman/smartos-image-server | |
# | |
# Global-zone companion script available: | |
# https://gist.github.com/jasonpincin/4958099 | |
# | |
# This takes an stdin stream (a zfs snapshot), and updates a | |
# smartos-image-server with the files (zfs.gz, manifest.json) | |
# it needs to serve the image. | |
# | |
# Afterwards, it restarts the image server. | |
# | |
# Usage: | |
# import_image <name> <version> <description> | |
# | |
# From the global zone (into an image server zone): | |
# | |
# Stop your zone and create a snapshot of it. | |
# vmadm stop <uuid> | |
# zfs snapshot zones/<uuid>@image | |
# | |
# Then send the image to the import-image script | |
# located on your image server: | |
# | |
# zfs send zones/<uuid>@image | gzip | ssh datasets.yourdomain.local './import-image <name> <version> "description"' | |
# | |
# Once complete, you can: | |
# | |
# imgadm update | |
# Configure these variables to match your organization | |
CREATOR="MYORG" # UPDATE THIS | |
CREATOR_UUID="" # Generate a UUID and put it in these quotes (there's a uuid utility in smartos) | |
VENDOR_UUID="" # Generate a UUID and put it in these quotes | |
IMGSERVER="datasets.myorg.com" # Put the domain name of your smartos-image-server host here | |
IMGSERVERDIR="/home/node/smartos-image-server" # Put the path to the image server here | |
# Should not need to modify anything below here | |
UUID=`uuid` | |
NAME=$1 | |
VER=$2 | |
DESC=$3 | |
IMGDIR="$IMGSERVERDIR/$UUID" | |
FILENAME="$NAME-$VER.zfs.gz" | |
FILEPATH="$IMGDIR/$FILENAME" | |
STAMP=`date +%Y-%m-%dT%H:%MZ` | |
mkdir $IMGDIR > /dev/null 2>&1 | |
cat - > $FILEPATH | |
DIGEST=`digest -a sha1 $FILEPATH` | |
SIZE=`stat -c '%s' $FILEPATH` | |
# Generate the manifest for smartos-image-server | |
cat > $IMGSERVERDIR/$UUID/manifest.json << END | |
{ | |
"uuid": "$UUID", | |
"name": "$NAME", | |
"version": "$VER", | |
"description": "$DESC", | |
"os": "smartos", | |
"type": "zone-dataset", | |
"platform_type": "smartos", | |
"cloud_name": "$CREATOR", | |
"urn": "$CREATOR:$CREATOR:$NAME:$VER", | |
"creator_name": "$CREATOR", | |
"creator_uuid": "$CREATOR_UUID", | |
"vendor_uuid": "$VENDOR_UUID", | |
"created_at": "$STAMP", | |
"updated_at": "$STAMP", | |
"published_at": "$STAMP", | |
"files": [ | |
{ | |
"path": "$FILENAME", | |
"sha1": "$DIGEST", | |
"size": $SIZE, | |
"url": "https://$IMGSERVER/datasets/$UUID/$FILENAME" | |
} | |
] | |
} | |
END | |
# Restart smartos-image-server | |
kill `ps -f -u node -o pid,args |grep $IMGSERVERDIR/server.js |grep -v grep |cut -d " " -f 1` > /dev/null 2>&1 | |
cd $IMGSERVERDIR | |
nohup $IMGSERVERDIR/server.js > /dev/null 2>&1 & | |
# Output the UUID we created | |
echo $UUID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment