From 78c67f76cfcc72ed2a03a7ab13c9f9c2493886e2 Mon Sep 17 00:00:00 2001 From: Jonathan Boulle Date: Thu, 13 Nov 2014 13:39:31 -0800 Subject: [PATCH] rkt: add basic main + build script --- .gitignore | 2 ++ build | 17 +++++++++++++ rkt/rkt.go | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 .gitignore create mode 100755 build create mode 100644 rkt/rkt.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d098fb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bin/ +gopath/ diff --git a/build b/build new file mode 100755 index 0000000..2362c4b --- /dev/null +++ b/build @@ -0,0 +1,17 @@ +#!/bin/bash -e + +ORG_PATH="github.com/coreos-inc" +REPO_PATH="${ORG_PATH}/rkt" + +if [ ! -h gopath/src/${REPO_PATH} ]; then + mkdir -p gopath/src/${ORG_PATH} + ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255 +fi + +export GOBIN=${PWD}/bin +export GOPATH=${PWD}/gopath + +eval $(go env) + +echo "Building rkt..." +go build -o $GOBIN/rkt ${REPO_PATH}/rkt diff --git a/rkt/rkt.go b/rkt/rkt.go new file mode 100644 index 0000000..fb6de73 --- /dev/null +++ b/rkt/rkt.go @@ -0,0 +1,73 @@ +package main + +// +// Rocket is a reference implementation of the app container specification. +// +// Execution on Rocket is divided into a number of stages, and the `rkt` +// binary implements the first stage (stage 0), which consists of the +// following tasks: +// - Generating the Container Unique ID (UID) +// - Generating the container document +// - Creating a directory for the container +// - Copying the stage1 into the container directory +// - Copying the RAFs for each app into the stage2 directories +// +// Given a run command such as: +// rkt run --volume bind:/opt/tenant1/database \ +// example.com/data-downloader-1.0.0 \ +// example.com/ourapp-1.0.0 \ +// example.com/logbackup-1.0.0 +// +// the container doc generated will be compliant with the ACE spec. +// + +import ( + "flag" + "fmt" + "os" + "strings" +) + +var ( + fs = flag.NewFlagSet("rkt", flag.ExitOnError) + + flagVolumes stringSlice +) + +func init() { + fs.Var(&flagVolumes, "volume", "volumes to mount into the shared container environment") +} + +func main() { + fs.Parse(os.Args[1:]) + args := fs.Args() + if len(args) < 1 { + fmt.Fprintf(os.Stderr, "usage: rkt run [image...]\n") + os.Exit(0) + } + cmd := args[0] + switch cmd { + case "run": + default: + fmt.Fprintf(os.Stderr, "rkt: unknown subcommand: %q\n", cmd) + os.Exit(1) + } + fs.Parse(args[1:]) + images := fs.Args() + fmt.Println("run rocket run") + fmt.Printf("images: %s\n", images) + fmt.Printf("volumes: %s\n", flagVolumes) +} + +// stringSlice implements the flag.Value interface +type stringSlice []string + +func (ss *stringSlice) Set(s string) error { + // TODO(jonboulle): validate + *ss = append(*ss, s) + return nil +} + +func (ss *stringSlice) String() string { + return strings.Join(*ss, ",") +}