mirror of https://github.com/perkeep/perkeep.git
gce: use systemd-docker on CoreOS
Change-Id: I4f5a169c78ca3806aa40b3716b267b539c8bfbca
This commit is contained in:
parent
7265cff8de
commit
1ca6a739cd
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -21,7 +22,7 @@ var (
|
||||||
proj = flag.String("project", "", "name of Project")
|
proj = flag.String("project", "", "name of Project")
|
||||||
zone = flag.String("zone", "us-central1-a", "GCE zone")
|
zone = flag.String("zone", "us-central1-a", "GCE zone")
|
||||||
mach = flag.String("machinetype", "g1-small", "e.g. n1-standard-1, f1-micro, g1-small")
|
mach = flag.String("machinetype", "g1-small", "e.g. n1-standard-1, f1-micro, g1-small")
|
||||||
instance = flag.String("instance_name", "camlistore-server", "Name of VM instance.")
|
instName = flag.String("instance_name", "camlistore-server", "Name of VM instance.")
|
||||||
sshPub = flag.String("ssh_public_key", "", "ssh public key file to authorize. Can modify later in Google's web UI anyway.")
|
sshPub = flag.String("ssh_public_key", "", "ssh public key file to authorize. Can modify later in Google's web UI anyway.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -62,6 +63,27 @@ func main() {
|
||||||
Config: config,
|
Config: config,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tokenCache := oauth.CacheFile("token.dat")
|
||||||
|
token, err := tokenCache.Token()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error getting token from %s: %v", string(tokenCache), err)
|
||||||
|
log.Printf("Get auth code from %v", config.AuthCodeURL("my-state"))
|
||||||
|
os.Stdout.Write([]byte("\nEnter auth code: "))
|
||||||
|
sc := bufio.NewScanner(os.Stdin)
|
||||||
|
sc.Scan()
|
||||||
|
authCode := strings.TrimSpace(sc.Text())
|
||||||
|
token, err = tr.Exchange(authCode)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error exchanging auth code for a token: %v", err)
|
||||||
|
}
|
||||||
|
tokenCache.PutToken(token)
|
||||||
|
}
|
||||||
|
|
||||||
|
tr.Token = token
|
||||||
|
oauthClient := &http.Client{Transport: tr}
|
||||||
|
computeService, _ := compute.New(oauthClient)
|
||||||
|
storageService, _ := storage.New(oauthClient)
|
||||||
|
|
||||||
cloudConfig := `#cloud-config
|
cloudConfig := `#cloud-config
|
||||||
write_files:
|
write_files:
|
||||||
- path: /tmp/camlistore-tmp/README
|
- path: /tmp/camlistore-tmp/README
|
||||||
|
@ -70,9 +92,6 @@ write_files:
|
||||||
This is the Camlistore /tmp directory.
|
This is the Camlistore /tmp directory.
|
||||||
coreos:
|
coreos:
|
||||||
units:
|
units:
|
||||||
- name: systemd-journal-gatewayd.socket
|
|
||||||
command: start
|
|
||||||
enable: true
|
|
||||||
- name: cam-journal-gatewayd.service
|
- name: cam-journal-gatewayd.service
|
||||||
content: |
|
content: |
|
||||||
[Unit]
|
[Unit]
|
||||||
|
@ -112,9 +131,12 @@ coreos:
|
||||||
Requires=docker.service
|
Requires=docker.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/bin/docker run --name=db google/mysql
|
ExecStartPre=/usr/bin/docker run --rm -v /opt/bin:/opt/bin ibuildthecloud/systemd-docker
|
||||||
RestartSec=500ms
|
ExecStart=/opt/bin/systemd-docker run --rm --name %n google/mysql
|
||||||
|
RestartSec=1s
|
||||||
Restart=always
|
Restart=always
|
||||||
|
Type=notify
|
||||||
|
NotifyAccess=all
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
@ -127,9 +149,12 @@ coreos:
|
||||||
Requires=docker.service mysql.service
|
Requires=docker.service mysql.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/bin/docker run -p 80:80 -p 443:443 -v /run/camjournald.sock:/run/camjournald.sock -v /tmp/camlistore-tmp:/tmp --link=db:mysqldb camlistore/camlistored
|
ExecStartPre=/usr/bin/docker run --rm -v /opt/bin:/opt/bin ibuildthecloud/systemd-docker
|
||||||
RestartSec=500ms
|
ExecStart=/opt/bin/systemd-docker run --rm -p 80:80 -p 443:443 --name %n -v /run/camjournald.sock:/run/camjournald.sock -v /tmp/camlistore-tmp:/tmp --link=mysql.service:mysqldb camlistore/camlistored
|
||||||
|
RestartSec=1s
|
||||||
Restart=always
|
Restart=always
|
||||||
|
Type=notify
|
||||||
|
NotifyAccess=all
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
@ -144,27 +169,6 @@ coreos:
|
||||||
cloudConfig += fmt.Sprintf("\nssh_authorized_keys:\n - %s\n", key)
|
cloudConfig += fmt.Sprintf("\nssh_authorized_keys:\n - %s\n", key)
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenCache := oauth.CacheFile("token.dat")
|
|
||||||
token, err := tokenCache.Token()
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error getting token from %s: %v", string(tokenCache), err)
|
|
||||||
log.Printf("Get auth code from %v", config.AuthCodeURL("my-state"))
|
|
||||||
os.Stdout.Write([]byte("\nEnter auth code: "))
|
|
||||||
sc := bufio.NewScanner(os.Stdin)
|
|
||||||
sc.Scan()
|
|
||||||
authCode := strings.TrimSpace(sc.Text())
|
|
||||||
token, err = tr.Exchange(authCode)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error exchanging auth code for a token: %v", err)
|
|
||||||
}
|
|
||||||
tokenCache.PutToken(token)
|
|
||||||
}
|
|
||||||
|
|
||||||
tr.Token = token
|
|
||||||
oauthClient := &http.Client{Transport: tr}
|
|
||||||
computeService, _ := compute.New(oauthClient)
|
|
||||||
storageService, _ := storage.New(oauthClient)
|
|
||||||
|
|
||||||
blobBucket := *proj + "-camlistore-blobs"
|
blobBucket := *proj + "-camlistore-blobs"
|
||||||
configBucket := *proj + "-camlistore-config"
|
configBucket := *proj + "-camlistore-config"
|
||||||
needBucket := map[string]bool{
|
needBucket := map[string]bool{
|
||||||
|
@ -202,7 +206,7 @@ coreos:
|
||||||
}
|
}
|
||||||
|
|
||||||
instance := &compute.Instance{
|
instance := &compute.Instance{
|
||||||
Name: *instance,
|
Name: *instName,
|
||||||
Description: "Camlistore server",
|
Description: "Camlistore server",
|
||||||
MachineType: machType,
|
MachineType: machType,
|
||||||
Disks: []*compute.AttachedDisk{
|
Disks: []*compute.AttachedDisk{
|
||||||
|
@ -211,7 +215,7 @@ coreos:
|
||||||
Boot: true,
|
Boot: true,
|
||||||
Type: "PERSISTENT",
|
Type: "PERSISTENT",
|
||||||
InitializeParams: &compute.AttachedDiskInitializeParams{
|
InitializeParams: &compute.AttachedDiskInitializeParams{
|
||||||
DiskName: *instance + "-coreos-stateless-pd",
|
DiskName: *instName + "-coreos-stateless-pd",
|
||||||
SourceImage: imageURL,
|
SourceImage: imageURL,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -286,6 +290,7 @@ coreos:
|
||||||
}
|
}
|
||||||
opName := op.Name
|
opName := op.Name
|
||||||
log.Printf("Created. Waiting on operation %v", opName)
|
log.Printf("Created. Waiting on operation %v", opName)
|
||||||
|
OpLoop:
|
||||||
for {
|
for {
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
op, err := computeService.ZoneOperations.Get(*proj, *zone, opName).Do()
|
op, err := computeService.ZoneOperations.Get(*proj, *zone, opName).Do()
|
||||||
|
@ -304,9 +309,16 @@ coreos:
|
||||||
log.Fatalf("Failed to start.")
|
log.Fatalf("Failed to start.")
|
||||||
}
|
}
|
||||||
log.Printf("Success. %+v", op)
|
log.Printf("Success. %+v", op)
|
||||||
return
|
break OpLoop
|
||||||
default:
|
default:
|
||||||
log.Fatalf("Unknown status %q: %+v", op.Status, op)
|
log.Fatalf("Unknown status %q: %+v", op.Status, op)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inst, err := computeService.Instances.Get(*proj, *zone, *instName).Do()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error getting instance after creation: %v", err)
|
||||||
|
}
|
||||||
|
ij, _ := json.MarshalIndent(inst, "", " ")
|
||||||
|
log.Printf("Instance: %s", ij)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue