Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldwan committed Jun 16, 2021
2 parents 9210a2e + 7f329fe commit fddbc7f
Show file tree
Hide file tree
Showing 40 changed files with 953 additions and 354 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: 1.16.x
- name: Get go version
id: go-version
run: echo "::set-output name=version::$(go env GOVERSION)"
- uses: actions/cache@v2
with:
# In order:
Expand All @@ -24,7 +27,7 @@ jobs:
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
key: ${{ runner.os }}-${{ steps.go-version.outputs.version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go
- name: go mod download
Expand Down Expand Up @@ -54,6 +57,9 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: 1.16.x
- name: Get go version
id: go-version
run: echo "::set-output name=version::$(go env GOVERSION)"
- name: Docker Login
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
Expand All @@ -72,16 +78,20 @@ jobs:
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
key: ${{ runner.os }}-${{ steps.go-version.outputs.version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go
- name: Place wintun.dll
run: cp -r deps/wintun/bin/amd64/wintun.dll ./
- name: generate release notes
run: |
mkdir -p ./tmp
./scripts/changelog.sh > ./tmp/changelog.txt
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
args: release --rm-dist --release-notes=./tmp/changelog.txt
env:
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
- name: Upload checksums as artifact
Expand All @@ -93,7 +103,7 @@ jobs:
aur-publish:
name: Build & publish to AUR
needs: release
if: startsWith(github.ref, 'refs/tags/v') && github.ref == 'refs/heads/master'
if: ${{ !contains(github.ref, 'pre') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ dist/
# Local environment settings
.envrc

tmp/

# generated docs
out
#docstrings/gen.go
Expand Down
30 changes: 12 additions & 18 deletions api/http.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package api

import (
"bytes"
"context"
"io"
"net/http"
"strings"
"time"

"github.com/PuerkitoBio/rehttp"
Expand All @@ -20,21 +21,7 @@ func newHTTPClient() (*http.Client, error) {
rehttp.RetryMaxRetries(3),
rehttp.RetryAny(
rehttp.RetryTemporaryErr(),
rehttp.RetryStatuses(502),
rehttp.RetryIsErr(func(err error) bool {
return err != nil && strings.Contains(err.Error(), "INTERNAL_ERROR")
// Below code was part of retry strategy
// if err == nil {
// return true
// }
// msg := err.Error()
// for _, retryError := range retryErrors {
// if strings.Contains(msg, retryError) {
// return true
// }
// }
// return false
}),
rehttp.RetryStatuses(502, 503),
),
),
rehttp.ExpJitterDelay(100*time.Millisecond, 1*time.Second),
Expand Down Expand Up @@ -83,9 +70,16 @@ func (t *LoggingTransport) logRequest(req *http.Request) {

func (t *LoggingTransport) logResponse(resp *http.Response) {
ctx := resp.Request.Context()
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
terminal.Debug("error reading response body:", err)
}
if start, ok := ctx.Value(contextKeyRequestStart).(time.Time); ok {
terminal.Debugf("<-- %d %s (%s)\n", resp.StatusCode, resp.Request.URL, helpers.Duration(time.Now().Sub(start), 2))
terminal.Debugf("<-- %d %s (%s) %s\n", resp.StatusCode, resp.Request.URL, helpers.Duration(time.Since(start), 2), string(data))
} else {
terminal.Debugf("<-- %d %s\n", resp.StatusCode, resp.Request.URL)
terminal.Debugf("<-- %d %s %s %s\n", resp.StatusCode, resp.Request.URL, string(data))
}

resp.Body = io.NopCloser(bytes.NewReader(data))
}
48 changes: 45 additions & 3 deletions api/resource_organizations.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package api

func (client *Client) GetOrganizations() ([]Organization, error) {
type OrganizationType string

const (
OrganizationTypePersonal OrganizationType = "PERSONAL"
OrganizationTypeShared OrganizationType = "SHARED"
)

func (client *Client) GetOrganizations(typeFilter *OrganizationType) ([]Organization, error) {
q := `
{
organizations {
query($orgType: OrganizationType) {
organizations(type: $orgType) {
nodes {
id
slug
Expand All @@ -15,6 +22,9 @@ func (client *Client) GetOrganizations() ([]Organization, error) {
`

req := client.NewRequest(q)
if typeFilter != nil {
req.Var("orgType", *typeFilter)
}

data, err := client.Run(req)
if err != nil {
Expand Down Expand Up @@ -166,3 +176,35 @@ func (c *Client) DeleteOrganization(id string) (deletedid string, err error) {

return data.DeleteOrganization.DeletedOrganizationId, nil
}

func (c *Client) CreateOrganizationInvite(id, email string) (*Invitation, error) {
query := `
mutation($input: CreateOrganizationInvitationInput!){
createOrganizationInvitation(input: $input){
invitation {
id
email
createdAt
redeemed
organization {
slug
}
}
}
}
`

req := c.NewRequest(query)

req.Var("input", map[string]string{
"organizationId": id,
"email": email,
})

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

return &data.CreateOrganizationInvitation.Invitation, nil
}
10 changes: 4 additions & 6 deletions api/resource_scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,9 @@ func (c *Client) SetAppVMCount(appID string, count int) ([]TaskGroupCount, []str
query := `
mutation ($input: SetVMCountInput!) {
setVmCount(input: $input) {
app {
taskGroupCounts {
name
count
}
taskGroupCounts {
name
count
}
warnings
}
Expand All @@ -207,5 +205,5 @@ func (c *Client) SetAppVMCount(appID string, count int) ([]TaskGroupCount, []str
return []TaskGroupCount{}, []string{}, err
}

return data.SetVMCount.App.TaskGroupCounts, data.SetVMCount.Warnings, nil
return data.SetVMCount.TaskGroupCounts, data.SetVMCount.Warnings, nil
}
21 changes: 19 additions & 2 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ type Query struct {
}

SetVMCount struct {
App App
Warnings []string
App App
TaskGroupCounts []TaskGroupCount
Warnings []string
}

ConfigureRegions struct {
Expand Down Expand Up @@ -179,6 +180,8 @@ type Query struct {
CreatePostgresCluster *CreatePostgresClusterPayload

AttachPostgresCluster *AttachPostgresClusterPayload

CreateOrganizationInvitation CreateOrganizationInvitation
}

type CreatedWireGuardPeer struct {
Expand Down Expand Up @@ -930,6 +933,7 @@ type CreatePostgresClusterInput struct {
Password *string `json:"password,omitempty"`
VMSize *string `json:"vmSize,omitempty"`
VolumeSizeGB *int `json:"volumeSizeGb,omitempty"`
ImageRef *string `json:"imageRef,omitempty"`
}

type CreatePostgresClusterPayload struct {
Expand Down Expand Up @@ -993,3 +997,16 @@ type ReleaseCommand struct {
Succeeded bool
Failed bool
}

type Invitation struct {
ID string
Email string
CreatedAt time.Time
Redeemed bool
Inviter *User
Organization *Organization
}

type CreateOrganizationInvitation struct {
Invitation Invitation
}
2 changes: 1 addition & 1 deletion cmd/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func runCreateChecksHandler(ctx *cmdctx.CmdContext) error {

orgSlug := ctx.Config.GetString("organization")

org, err := selectOrganization(ctx.Client.API(), orgSlug)
org, err := selectOrganization(ctx.Client.API(), orgSlug, nil)
if err != nil {
return err
}
Expand Down
17 changes: 11 additions & 6 deletions cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,17 @@ func BuildCommand(parent *Command, fn RunFn, usageText string, shortHelpText str
}

if fn != nil {
flycmd.Run = func(cmd *cobra.Command, args []string) {
flycmd.RunE = func(cmd *cobra.Command, args []string) error {
ctx, err := cmdctx.NewCmdContext(client, namespace(cmd), args)
checkErr(err)
if err != nil {
return err
}

for _, init := range initializers {
if init.Setup != nil {
checkErr(init.Setup(ctx))
if err := init.Setup(ctx); err != nil {
return err
}
}
}

Expand All @@ -205,12 +209,13 @@ func BuildCommand(parent *Command, fn RunFn, usageText string, shortHelpText str

for _, init := range initializers {
if init.PreRun != nil {
checkErr(init.PreRun(ctx))
if err := init.PreRun(ctx); err != nil {
return err
}
}
}

err = fn(ctx)
checkErr(err)
return fn(ctx)
}
}

Expand Down
41 changes: 41 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"

"github.com/superfly/flyctl/cmd/presenters"
"github.com/superfly/flyctl/cmdctx"
"github.com/superfly/flyctl/internal/client"

Expand All @@ -30,6 +31,9 @@ func newConfigCommand(client *client.Client) *Command {
configValidateStrings := docstrings.Get("config.validate")
BuildCommandKS(cmd, runValidateConfig, configValidateStrings, client, requireSession, requireAppName)

configEnvStrings := docstrings.Get("config.env")
BuildCommandKS(cmd, runEnvConfig, configEnvStrings, client, requireSession, requireAppName)

return cmd
}

Expand Down Expand Up @@ -102,6 +106,43 @@ func runValidateConfig(commandContext *cmdctx.CmdContext) error {
return errors.New("App configuration is not valid")
}

func runEnvConfig(ctx *cmdctx.CmdContext) error {
secrets, err := ctx.Client.API().GetAppSecrets(ctx.AppName)
if err != nil {
return err
}

if len(secrets) > 0 {
err = ctx.Frender(cmdctx.PresenterOption{Presentable: &presenters.Secrets{Secrets: secrets},
Title: "Secrets",
})
if err != nil {
return err
}
}

cfg, err := ctx.Client.API().GetConfig(ctx.AppName)
if err != nil {
return err
}

if cfg.Definition != nil {
vars, ok := cfg.Definition["env"].(map[string]interface{})
if !ok {
return nil
}

err = ctx.Frender(cmdctx.PresenterOption{Presentable: &presenters.Environment{
Envs: vars,
}, Title: "Environment variables"})

if err != nil {
return err
}
}
return nil
}

func printAppConfigErrors(cfg api.AppConfig) {
fmt.Println()
for _, error := range cfg.Errors {
Expand Down
3 changes: 2 additions & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/superfly/flyctl/internal/cmdutil"
"github.com/superfly/flyctl/internal/deployment"
"github.com/superfly/flyctl/internal/monitor"
"github.com/superfly/flyctl/terminal"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -78,7 +79,6 @@ func newDeployCommand(client *client.Client) *Command {
cmd.AddStringFlag(StringFlagOpts{
Name: "build-target",
Description: "Set the target build stage to build if the Dockerfile has more than one stage",
Hidden: true,
})
cmd.AddBoolFlag(BoolFlagOpts{
Name: "no-cache",
Expand Down Expand Up @@ -240,6 +240,7 @@ func runDeploy(cmdCtx *cmdctx.CmdContext) error {
}

if release.DeploymentStrategy == "IMMEDIATE" {
terminal.Debug("immediate deployment strategy, nothing to monitor")
return nil
}

Expand Down

0 comments on commit fddbc7f

Please sign in to comment.