Skip to content

Instantly share code, notes, and snippets.

@otiai10 otiai10/main.go
Last active Mar 22, 2018

Embed
What would you like to do?
daapミドルウェアを使ったGoのソースコードからのNFSサーバの起動
package main
import (
"context"
"fmt"
"os"
"os/signal"
"github.com/otiai10/daap"
"github.com/otiai10/dkmachine/v0/dkmachine"
)
func main() {
ctx := context.Background()
machine, err := dkmachine.Create(&dkmachine.CreateOptions{
Name: "otiai10-nfs-server",
Driver: "amazonec2",
AmazonEC2Region: "ap-northeast-1",
AmazonEC2InstanceType: "t2.micro",
AmazonEC2SecurityGroup: "otiai10-test",
})
if err != nil {
fmt.Println("001:", err)
return
}
defer func() {
fmt.Println("Remove Machine", machine.Remove())
}()
c1 := daap.NewContainer("otiai10/nfs-server", daap.Args{
Machine: &daap.MachineConfig{
CertPath: machine.CertPath(),
Host: machine.Host(),
},
})
logs, err := c1.PullImage(ctx)
if err != nil {
fmt.Println("003:", err)
return
}
for payload := range logs {
fmt.Printf("\r%s", payload.Progress)
}
fmt.Printf("\n")
if err := c1.Create(ctx); err != nil {
fmt.Println("004:", err)
return
}
if err := c1.Start(ctx); err != nil {
fmt.Println("005:", err)
return
}
fmt.Println("NFS Server is up. Interrupt with Ctrl+C if you want to stop.")
fmt.Printf("You might do next:\n\n\tsudo mount %s:/ /your/path\n\n", machine.Inspection.Driver.PrivateIPAddress)
interrupted := make(chan os.Signal, 1)
signal.Notify(interrupted, os.Interrupt)
for _ = range interrupted {
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.