-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
801 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package appbackend | ||
|
||
import ( | ||
"fmt" | ||
"github.com/graphql-go/graphql" | ||
) | ||
|
||
var packageType = graphql.NewObject(graphql.ObjectConfig{ | ||
Name: "Package", | ||
Fields: graphql.Fields{ | ||
"goos": &graphql.Field{Type: graphql.NewNonNull(graphql.String)}, | ||
"goarch": &graphql.Field{Type: graphql.NewNonNull(graphql.String)}, | ||
"version": &graphql.Field{Type: graphql.NewNonNull(graphql.String)}, | ||
"goarm": &graphql.Field{Type: graphql.String}, | ||
}, | ||
}) | ||
|
||
var listPackages = &graphql.Field{ | ||
Type: graphql.NewList(packageType), | ||
Args: graphql.FieldConfigArgument{}, | ||
Resolve: wrapper(func(rctx resolveContext[any]) (any, error) { | ||
return rctx.packages.GetLatestPackages(rctx) | ||
}), | ||
} | ||
|
||
var buildDeployAgentCommand = &graphql.Field{ | ||
Type: graphql.NewNonNull(graphql.String), | ||
Args: graphql.FieldConfigArgument{ | ||
"projectId": &graphql.ArgumentConfig{Type: graphql.NewNonNull(graphql.String)}, | ||
"goos": &graphql.ArgumentConfig{Type: graphql.NewNonNull(graphql.String)}, | ||
"goarch": &graphql.ArgumentConfig{Type: graphql.NewNonNull(graphql.String)}, | ||
"generatePsk": &graphql.ArgumentConfig{Type: graphql.NewNonNull(graphql.Boolean)}, | ||
}, | ||
Resolve: wrapper(func(rctx resolveContext[any]) (string, error) { | ||
goos := rctx.getStringArg("goos") | ||
projectId := rctx.getStringArg("projectId") | ||
err := rctx.canAccessProject(projectId) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// Optionally generate a pre-shared key for the agent to use | ||
var psk string | ||
if rctx.getBoolArg("generatePsk") { | ||
psk, err = rctx.db.GeneratePreSharedKey(rctx, projectId) | ||
if err != nil { | ||
return "", fmt.Errorf("generating psk: %w", err) | ||
} | ||
} | ||
|
||
switch goos { | ||
case "linux": | ||
// We can use the same command for all linux architectures | ||
// and the installation script will handle the nuances and | ||
// platform detection processes that need to happen. | ||
return buildLinuxInstallCommand(psk), nil | ||
default: | ||
return "", fmt.Errorf("unsupported goos: %s", goos) | ||
} | ||
}), | ||
} | ||
|
||
func buildLinuxInstallCommand(psk string) string { | ||
if len(psk) == 0 { | ||
return fmt.Sprintf("curl -fsSL https://raw.githubusercontent.com/clarkmcc/cloudcore/main/scripts/linux/install.sh | sh") | ||
} else { | ||
return fmt.Sprintf("curl -fsSL https://raw.githubusercontent.com/clarkmcc/cloudcore/main/scripts/linux/install.sh | sh -s -- --psk %s", psk) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useState } from "react"; | ||
import { ClipboardCopy } from "lucide-react"; | ||
|
||
export function CommandCopy(props: { command: string }) { | ||
const [copied, setCopied] = useState(false); | ||
|
||
const handleCopy = async () => { | ||
await navigator.clipboard.writeText(props.command); | ||
setCopied(true); | ||
setTimeout(() => setCopied(false), 2000); | ||
}; | ||
|
||
return ( | ||
<div className="relative p-4 bg-neutral-100 dark:bg-neutral-900 dark:text-white font-mono text-sm rounded-md overflow-auto"> | ||
<div className="overflow-x-auto whitespace-nowrap scroll-auto"> | ||
{props.command} | ||
</div> | ||
<button | ||
onClick={handleCopy} | ||
className="absolute top-2 right-2 flex items-center gap-2 p-1 text-xs bg-neutral-200 hover:bg-neutral-300 dark:bg-neutral-700 dark:hover:bg-neutral-600 rounded" | ||
> | ||
<ClipboardCopy className="h-4 w-4" /> | ||
{copied ? "Copied" : "Copy"} | ||
</button> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.