Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/superfly/flyctl into msir…
Browse files Browse the repository at this point in the history
…abella/idomatic_buildinfo
  • Loading branch information
tvdfly committed May 12, 2023
2 parents dcc91a2 + 0fb42c3 commit e2fc139
Show file tree
Hide file tree
Showing 189 changed files with 6,015 additions and 6,894 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Expand Up @@ -80,15 +80,15 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
- name: Upload checksums as artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: checksums
path: dist/checksums.txt

sync_docs:
needs: release
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/master' }}
if: ${{ !contains(github.ref, 'pre') }}
steps:
- name: Checkout flyctl
uses: actions/checkout@v3
Expand Down Expand Up @@ -136,7 +136,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
- name: Upload checksums as artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: checksums
path: dist/checksums.txt
Expand All @@ -149,7 +149,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Download checksums
uses: actions/download-artifact@v2.0.8
uses: actions/download-artifact@v3
with:
name: checksums
- name: Generate PKGBUILD
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Expand Up @@ -29,6 +29,7 @@ linters:
enable:
# - gofumpt
# - goimports
- gofmt
- gosimple
- govet
- ineffassign
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -16,7 +16,7 @@ test: FORCE
# to run one test, use: make preflight-test T=TestAppsV2ConfigSave
preflight-test: build
if [ -r .direnv/preflight ]; then . .direnv/preflight; fi; \
go test ./test/preflight --tags=integration -v --run=$(T)
go test ./test/preflight --tags=integration -v -timeout 30m --run=$(T)

cmddocs: generate
@echo Running Docs Generation
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -62,19 +62,19 @@ Download the appropriate version from the [Releases](https://github.com/superfly
1. Sign into your fly account

```bash
flyctl auth login
fly auth login
```

2. List your apps

```bash
flyctl apps list
fly apps list
```

2. View app status

```bash
flyctl status -a {app-name}
fly status -a {app-name}
```

## App Settings
Expand Down
6 changes: 4 additions & 2 deletions agent/start.go
Expand Up @@ -97,10 +97,12 @@ func (alreadyStartingError) Error() string {
return "another process is already starting the agent"
}

var lockPath = filepath.Join(os.TempDir(), "flyctl.agent.start.lock")
func lockPath() string {
return filepath.Join(flyctl.ConfigDir(), "flyctl.agent.start.lock")
}

func lock(ctx context.Context) (unlock filemu.UnlockFunc, err error) {
switch unlock, err = filemu.Lock(ctx, lockPath); {
switch unlock, err = filemu.Lock(ctx, lockPath()); {
case err == nil:
break // all done
case ctx.Err() != nil:
Expand Down
21 changes: 19 additions & 2 deletions api/client.go
Expand Up @@ -10,15 +10,17 @@ import (
"os"
"regexp"
"strings"
"time"

genq "github.com/Khan/genqlient/graphql"
"github.com/superfly/graphql"
"golang.org/x/exp/slices"
)

var (
baseURL string
errorLog bool
baseURL string
errorLog bool
instrumenter InstrumentationService
)

// SetBaseURL - Sets the base URL for the API
Expand All @@ -31,6 +33,14 @@ func SetErrorLog(log bool) {
errorLog = log
}

func SetInstrumenter(i InstrumentationService) {
instrumenter = i
}

type InstrumentationService interface {
ReportCallTiming(duration time.Duration)
}

// Client - API client encapsulating the http and GraphQL clients
type Client struct {
httpClient *http.Client
Expand Down Expand Up @@ -108,6 +118,13 @@ func (c *Client) Logger() Logger { return c.logger }

// RunWithContext - Runs a GraphQL request within a Go context
func (c *Client) RunWithContext(ctx context.Context, req *graphql.Request) (Query, error) {
if instrumenter != nil {
start := time.Now()
defer func() {
instrumenter.ReportCallTiming(time.Since(start))
}()
}

var resp Query
err := c.client.Run(ctx, req, &resp)

Expand Down
83 changes: 56 additions & 27 deletions api/machine_types.go
Expand Up @@ -17,6 +17,7 @@ const (
MachineFlyPlatformVersion2 = "v2"
MachineProcessGroupApp = "app"
MachineProcessGroupFlyAppReleaseCommand = "fly_app_release_command"
MachineProcessGroupFlyAppConsole = "fly_app_console"
MachineStateDestroyed = "destroyed"
MachineStateDestroying = "destroying"
MachineStateStarted = "started"
Expand Down Expand Up @@ -81,6 +82,10 @@ func (m *Machine) IsFlyAppsReleaseCommand() bool {
return m.IsFlyAppsPlatform() && m.IsReleaseCommandMachine()
}

func (m *Machine) IsFlyAppsConsole() bool {
return m.IsFlyAppsPlatform() && m.HasProcessGroup(MachineProcessGroupFlyAppConsole)
}

func (m *Machine) IsActive() bool {
return m.State != MachineStateDestroyed && m.State != MachineStateDestroying
}
Expand Down Expand Up @@ -209,7 +214,7 @@ type StopMachineInput struct {

type RestartMachineInput struct {
ID string `json:"id,omitempty"`
Signal *Signal `json:"signal,omitempty"`
Signal string `json:"signal,omitempty"`
Timeout time.Duration `json:"timeout,omitempty"`
ForceStop bool `json:"force_stop,omitempty"`
SkipHealthChecks bool `json:"skip_health_checks,omitempty"`
Expand All @@ -223,10 +228,8 @@ type MachineIP struct {
}

type RemoveMachineInput struct {
AppID string `json:"appId,omitempty"`
ID string `json:"id,omitempty"`

Kill bool `json:"kill,omitempty"`
ID string `json:"id,omitempty"`
Kill bool `json:"kill,omitempty"`
}

type MachineRestartPolicy string
Expand Down Expand Up @@ -356,13 +359,14 @@ type MachineCheckStatus struct {
}

type MachinePort struct {
Port *int `json:"port,omitempty" toml:"port,omitempty"`
StartPort *int `json:"start_port,omitempty" toml:"start_port,omitempty"`
EndPort *int `json:"end_port,omitempty" toml:"end_port,omitempty"`
Handlers []string `json:"handlers,omitempty" toml:"handlers,omitempty"`
ForceHTTPS bool `json:"force_https,omitempty" toml:"force_https,omitempty"`
TLSOptions *TLSOptions `json:"tls_options,omitempty" toml:"tls_options,omitempty"`
HTTPOptions *HTTPOptions `json:"http_options,omitempty" toml:"tls_options,omitempty"`
Port *int `json:"port,omitempty" toml:"port,omitempty"`
StartPort *int `json:"start_port,omitempty" toml:"start_port,omitempty"`
EndPort *int `json:"end_port,omitempty" toml:"end_port,omitempty"`
Handlers []string `json:"handlers,omitempty" toml:"handlers,omitempty"`
ForceHTTPS bool `json:"force_https,omitempty" toml:"force_https,omitempty"`
TLSOptions *TLSOptions `json:"tls_options,omitempty" toml:"tls_options,omitempty"`
HTTPOptions *HTTPOptions `json:"http_options,omitempty" toml:"http_options,omitempty"`
ProxyProtoOptions *ProxyProtoOptions `json:"proxy_proto_options,omitempty" toml:"proxy_proto_options,omitempty"`
}

func (mp *MachinePort) ContainsPort(port int) bool {
Expand Down Expand Up @@ -413,9 +417,14 @@ func (mp *MachinePort) HasNonHttpPorts() bool {
return false
}

type ProxyProtoOptions struct {
Version string `json:"version,omitempty" toml:"version,omitempty"`
}

type TLSOptions struct {
Alpn []string `json:"alpn,omitempty" toml:"alpn,omitempty"`
Versions []string `json:"versions,omitempty" toml:"version,omitempty"`
ALPN []string `json:"alpn,omitempty" toml:"alpn,omitempty"`
Versions []string `json:"versions,omitempty" toml:"versions,omitempty"`
DefaultSelfSigned *bool `json:"default_self_signed,omitempty" toml:"default_self_signed,omitempty"`
}

type HTTPOptions struct {
Expand All @@ -428,13 +437,16 @@ type HTTPResponseOptions struct {
}

type MachineService struct {
Protocol string `json:"protocol,omitempty" toml:"protocol,omitempty"`
InternalPort int `json:"internal_port,omitempty" toml:"internal_port,omitempty"`
Autostop *bool `json:"autostop,omitempty"`
Autostart *bool `json:"autostart,omitempty"`
Ports []MachinePort `json:"ports,omitempty" toml:"ports,omitempty"`
Checks []MachineCheck `json:"checks,omitempty" toml:"checks,omitempty"`
Concurrency *MachineServiceConcurrency `json:"concurrency,omitempty" toml:"concurrency"`
Protocol string `json:"protocol,omitempty" toml:"protocol,omitempty"`
InternalPort int `json:"internal_port,omitempty" toml:"internal_port,omitempty"`
Autostop *bool `json:"autostop,omitempty"`
Autostart *bool `json:"autostart,omitempty"`
MinMachinesRunning *int `json:"min_machines_running,omitempty"`
Ports []MachinePort `json:"ports,omitempty" toml:"ports,omitempty"`
Checks []MachineCheck `json:"checks,omitempty" toml:"checks,omitempty"`
Concurrency *MachineServiceConcurrency `json:"concurrency,omitempty" toml:"concurrency"`
ForceInstanceKey *string `json:"force_instance_key" toml:"force_instance_key"`
ForceInstanceDescription *string `json:"force_instance_description,omitempty" toml:"force_instance_description"`
}

type MachineServiceConcurrency struct {
Expand Down Expand Up @@ -541,16 +553,15 @@ type MachineStartResponse struct {
}

type LaunchMachineInput struct {
AppID string `json:"appId,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
OrgSlug string `json:"organizationId,omitempty"`
Region string `json:"region,omitempty"`
Config *MachineConfig `json:"config,omitempty"`
Region string `json:"region,omitempty"`
Name string `json:"name,omitempty"`
SkipLaunch bool `json:"skip_launch,omitempty"`
LeaseTTL int `json:"lease_ttl,omitempty"`

// Client side only
SkipHealthChecks bool
ID string `json:"-"`
SkipHealthChecks bool `json:"-"`
}

type MachineProcess struct {
Expand All @@ -571,3 +582,21 @@ type MachineExecResponse struct {
StdOut string `json:"stdout,omitempty"`
StdErr string `json:"stderr,omitempty"`
}

type MachinePsResponse []ProcessStat

type ProcessStat struct {
Pid int32 `json:"pid"`
Stime uint64 `json:"stime"`
Rtime uint64 `json:"rtime"`
Command string `json:"command"`
Directory string `json:"directory"`
Cpu uint64 `json:"cpu"`
Rss uint64 `json:"rss"`
ListenSockets []ListenSocket `json:"listen_sockets"`
}

type ListenSocket struct {
Proto string `json:"proto"`
Address string `json:"address"`
}
34 changes: 34 additions & 0 deletions api/resource_releases.go
Expand Up @@ -105,3 +105,37 @@ func (c *Client) GetAppReleaseNomad(ctx context.Context, appName string, id stri

return data.App.Release, nil
}

func (c *Client) GetAppCurrentReleaseMachines(ctx context.Context, appName string) (*Release, error) {
query := `
query ($appName: String!) {
app(name: $appName) {
currentRelease: currentReleaseUnprocessed {
id
version
description
reason
status
imageRef
stable
user {
id
email
name
}
createdAt
}
}
}
`

req := c.NewRequest(query)
req.Var("appName", appName)

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

return data.App.CurrentRelease, nil
}
5 changes: 0 additions & 5 deletions api/types.go
Expand Up @@ -2,7 +2,6 @@ package api

import (
"fmt"
"syscall"
"time"
)

Expand Down Expand Up @@ -857,10 +856,6 @@ type DeployImageInput struct {
Strategy *string `json:"strategy"`
}

type Signal struct {
syscall.Signal
}

type Service struct {
Description string `json:"description"`
Protocol string `json:"protocol,omitempty"`
Expand Down
32 changes: 32 additions & 0 deletions client/client.go
Expand Up @@ -59,3 +59,35 @@ func FromToken(token string) *Client {
func NewClient(token string) *api.Client {
return api.NewClient(token, buildinfo.Name(), buildinfo.Version().String(), logger.FromEnv(iostreams.System().ErrOut))
}

type NewClientOpts struct {
Token string
ClientName string
ClientVersion string
Logger api.Logger
}

// non-flyctl libraries use this when needing to specify logger, client name, and client version
func NewClientWithOptions(opts *NewClientOpts) *Client {
var log api.Logger
if opts.Logger != nil {
log = opts.Logger
} else {
log = logger.FromEnv(iostreams.System().ErrOut)
}
clientName := buildinfo.Name()
if opts.ClientName != "" {
clientName = opts.ClientName
}
clientVersion := buildinfo.Version().String()
if opts.ClientVersion != "" {
clientVersion = opts.ClientVersion
}
var apiClient *api.Client
if opts.Token != "" {
apiClient = api.NewClient(opts.Token, clientName, clientVersion, log)
}
return &Client{
api: apiClient,
}
}

0 comments on commit e2fc139

Please sign in to comment.