First working cut
This commit is contained in:
parent
608290c74e
commit
db918f12ad
4 changed files with 436 additions and 0 deletions
79
main.go
Normal file
79
main.go
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "tarpoon",
|
||||
Short: "Build Docker images",
|
||||
Long: "`docker build && docker push` without the `docker`. Push a tarball to a registry for distribution",
|
||||
Run: rootRun,
|
||||
}
|
||||
|
||||
var (
|
||||
baseImage string
|
||||
workDir string
|
||||
exec []string
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().StringVarP(&baseImage, "base-image", "b", "scratch", "Base image to append the tar to")
|
||||
rootCmd.PersistentFlags().StringVarP(&workDir, "workdir", "w", "/", "Working directory of the new container")
|
||||
rootCmd.PersistentFlags().StringSliceVarP(&exec, "exec", "e", []string{"/bin/sh", "-c"}, "What to exec in the newly built container")
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
||||
func rootRun(cmd *cobra.Command, args []string) {
|
||||
if len(args) < 2 {
|
||||
fmt.Println("tarpoon TARFILE DOCKER_PATH")
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("** Creating build dir\n")
|
||||
dir, err := NewBuildDir()
|
||||
defer dir.Close()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("** Build dir is %s\n", dir.dir)
|
||||
fmt.Printf("** Loading base image %s\n", baseImage)
|
||||
err = dir.LoadBase(baseImage)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("** Applying tarball %s\n", args[0])
|
||||
err = dir.AddTarLayer(args[0])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("** Preparing image\n")
|
||||
err = dir.DumpImageConfig()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = dir.WriteManifest()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("** Pushing image\n")
|
||||
err = dir.Push(args[1])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue