Skip to content

Commit

Permalink
Merge branch 'master' into alrs-cmd-err
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldwan committed Dec 3, 2020
2 parents 65d0ed3 + 6e6d959 commit 277b3fb
Show file tree
Hide file tree
Showing 25 changed files with 606 additions and 252 deletions.
2 changes: 1 addition & 1 deletion api/resource_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
func (client *Client) GetApps() ([]App, error) {
query := `
query {
apps(type: "container", first: 200) {
apps(type: "container", first: 400) {
nodes {
id
name
Expand Down
2 changes: 2 additions & 0 deletions api/resource_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (c *Client) GetAppStatus(appName string, showCompleted bool) (*AppStatus, e
canary
region
restarts
privateIP
checks {
status
}
Expand Down Expand Up @@ -81,6 +82,7 @@ func (c *Client) GetAllocationStatus(appName string, allocID string, logLimit in
canary
region
restarts
privateIP
checks {
status
output
Expand Down
72 changes: 72 additions & 0 deletions api/resource_wireguard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package api

func (c *Client) GetWireGuardPeers(slug string) ([]*WireGuardPeer, error) {
req := c.NewRequest(`
query($slug: String!) {
organization(slug: $slug) {
wireGuardPeers {
nodes {
id
name
pubkey
region
peerip
}
}
}
}
`)
req.Var("slug", slug)

data, err := c.Run(req)
if err != nil {
return nil, err
}

return *data.Organization.WireGuardPeers.Nodes, nil
}

func (c *Client) CreateWireGuardPeer(org *Organization, region, name string) (*CreatedWireGuardPeer, error) {
req := c.NewRequest(`
mutation($input: AddWireGuardPeerInput!) {
addWireGuardPeer(input: $input) {
pubkey
privkey
peerip
endpointip
}
}
`)
req.Var("input", map[string]interface{}{
"organizationId": org.ID,
"region": region,
"name": name,
})

data, err := c.Run(req)
if err != nil {
return nil, err
}

return &data.AddWireGuardPeer, nil
}

func (c *Client) RemoveWireGuardPeer(org *Organization, name string) error {
req := c.NewRequest(`
mutation($input: RemoveWireGuardPeerInput!) {
removeWireGuardPeer(input: $input) {
organization {
id
}
}
}
`)
req.Var("input", map[string]interface{}{
"organizationId": org.ID,
"name": name,
})

_, err := c.Run(req)

return err
}
31 changes: 31 additions & 0 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ type Query struct {

CreateVolume CreateVolumePayload
DeleteVolume DeleteVolumePayload

AddWireGuardPeer CreatedWireGuardPeer

RemoveWireGuardPeer struct {
Organization Organization
}
}

// carries the privkey; this is the only time it can be retrieved
type CreatedWireGuardPeer struct {
Pubkey string
Privkey string
Peerip string
Endpointip string
}

type Definition map[string]interface{}
Expand Down Expand Up @@ -278,6 +292,14 @@ type Organization struct {
Node *Domain
}
}

WireGuardPeers struct {
Nodes *[]*WireGuardPeer
Edges *[]*struct {
Cursor *string
Node *WireGuardPeer
}
}
}

type OrganizationDetails struct {
Expand Down Expand Up @@ -576,6 +598,7 @@ type AllocationStatus struct {
WarningCheckCount int
CriticalCheckCount int
Transitioning bool
PrivateIP string
RecentLogs []LogEntry
}

Expand Down Expand Up @@ -736,3 +759,11 @@ type ImportDnsWarning struct {
}
Message string
}

type WireGuardPeer struct {
ID string
Pubkey string
Region string
Name string
Peerip string
}
5 changes: 3 additions & 2 deletions builtinsupport/defaultbuiltins.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CMD ["bundle", "exec", "rackup", "--host", "0.0.0.0", "-p", "8080"]
Details: `Uses Debian image from https://github.com/hayd/deno-docker.
runs main.ts with --allow-net set and requires deps.ts for dependencies.
Uses and exposes port 8080 internally.`,
Template: `FROM hayd/debian-deno:1.4.0
Template: `FROM hayd/debian-deno:{{.version}}
ENV PORT=8080
EXPOSE 8080
WORKDIR /app
Expand All @@ -51,7 +51,8 @@ ADD . .
RUN deno cache main.ts
CMD ["run", {{range .perms}}"{{.}}",{{end}} "main.ts"]
`,
Settings: []Setting{{"perms", []string{`--allow-net`}, "Array of command line settings to grant permissions, e.g. [\"--allow-net\",\"--allow-read\"] "}},
Settings: []Setting{{"perms", []string{`--allow-net`}, "Array of command line settings to grant permissions, e.g. [\"--allow-net\",\"--allow-read\"] "},
{"version", "1.5.4", "Version of Deno to use"}},
},
{Name: "go",
Description: "Go Builtin",
Expand Down
5 changes: 5 additions & 0 deletions cmd/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func runListBuiltins(commandContext *cmdctx.CmdContext) error {

sort.Slice(builtins, func(i, j int) bool { return builtins[i].Name < builtins[j].Name })

if commandContext.OutputJSON() {
commandContext.WriteJSON(builtins)
return nil
}

builtintable := helpers.MakeSimpleTable(commandContext.Out, []string{"Name", "Description", "Details"})

for _, builtin := range builtins {
Expand Down
4 changes: 2 additions & 2 deletions cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ func runDashboardMetrics(ctx *cmdctx.CmdContext) error {
}

func runDashboardOpen(ctx *cmdctx.CmdContext, url string) error {
fmt.Println("Opening", docsURL)
return open.Run(docsURL)
fmt.Println("Opening", url)
return open.Run(url)
}
39 changes: 14 additions & 25 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/superfly/flyctl/cmdctx"
"github.com/superfly/flyctl/docker"
"github.com/superfly/flyctl/docstrings"
"github.com/superfly/flyctl/flyname"
"github.com/superfly/flyctl/internal/builds"
"github.com/superfly/flyctl/internal/deployment"
"github.com/superfly/flyctl/terminal"
Expand Down Expand Up @@ -108,16 +107,6 @@ func runDeploy(commandContext *cmdctx.CmdContext) error {
}
}

appcheck, err := commandContext.Client.API().GetApp(commandContext.AppName)

if err != nil {
return err
}

if appcheck.Status == "suspended" {
return fmt.Errorf("app %s is currently suspended - resume it with "+flyname.Name()+" apps resume", commandContext.AppName)
}

var strategy = docker.DefaultDeploymentStrategy
if val, _ := commandContext.Config.GetString("strategy"); val != "" {
strategy, err = docker.ParseDeploymentStrategy(val)
Expand All @@ -128,28 +117,30 @@ func runDeploy(commandContext *cmdctx.CmdContext) error {

var image *docker.Image

configimageRef, _ := commandContext.Config.GetString("image")

var imageRef string
imageRef, _ := commandContext.Config.GetString("image")

if configimageRef != "" {
imageRef = configimageRef
} else if commandContext.AppConfig != nil &&
if imageRef == "" &&
commandContext.AppConfig != nil &&
commandContext.AppConfig.Build != nil &&
commandContext.AppConfig.Build.Image != "" {
imageRef = commandContext.AppConfig.Build.Image
}

if imageRef != "" {
// image specified, resolve it, tagging and pushing if docker+local

commandContext.Statusf("deploy", cmdctx.SINFO, "Deploying image: %s\n", imageRef)

img, err := op.ResolveImage(ctx, commandContext, imageRef)
img, err := op.ResolveImageLocally(ctx, commandContext, imageRef)
if err != nil {
return err
}
image = img
if img != nil {
image = img
} else {
image = &docker.Image{
Tag: imageRef,
}
}
} else {
// no image specified, build one
buildArgs := map[string]string{}
Expand Down Expand Up @@ -301,7 +292,7 @@ func runDeploy(commandContext *cmdctx.CmdContext) error {

commandContext.Status("deploy", cmdctx.SBEGIN, "Optimizing Image")

if err := op.OptimizeImage(*image); err != nil {
if err := op.OptimizeImage(image.Tag); err != nil {
return err
}
commandContext.Status("deploy", cmdctx.SDONE, "Done Optimizing Image")
Expand All @@ -312,7 +303,7 @@ func runDeploy(commandContext *cmdctx.CmdContext) error {
commandContext.Statusf("deploy", cmdctx.SDETAIL, "Deployment Strategy: %s", strategy)
}

release, err := op.Deploy(*image, strategy)
release, err := op.Deploy(image.Tag, strategy)
if err != nil {
return err
}
Expand Down Expand Up @@ -368,7 +359,6 @@ func watchDeployment(ctx context.Context, commandContext *cmdctx.CmdContext) err
}

monitor.DeploymentFailed = func(d *api.DeploymentStatus, failedAllocs []*api.AllocationStatus) error {

commandContext.Statusf("deploy", cmdctx.SDETAIL, "v%d %s - %s\n", d.Version, d.Status, d.Description)

if endmessage == "" && d.Status == "failed" {
Expand All @@ -390,7 +380,7 @@ func watchDeployment(ctx context.Context, commandContext *cmdctx.CmdContext) err
a := a
go func() {
defer wg.Done()
alloc, err := commandContext.Client.API().GetAllocationStatus(commandContext.AppName, a.ID, 20)
alloc, err := commandContext.Client.API().GetAllocationStatus(commandContext.AppName, a.ID, 30)
if err != nil {
commandContext.Status("deploy", cmdctx.SERROR, "Error fetching alloc", a.ID, err)
return
Expand Down Expand Up @@ -441,7 +431,6 @@ func watchDeployment(ctx context.Context, commandContext *cmdctx.CmdContext) err
}

monitor.DeploymentSucceeded = func(d *api.DeploymentStatus) error {

commandContext.Statusf("deploy", cmdctx.SDONE, "v%d deployed successfully\n", d.Version)
return nil
}
Expand Down

0 comments on commit 277b3fb

Please sign in to comment.