Skip to content

Commit

Permalink
support project and app directory arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jfeodor committed Jun 7, 2024
1 parent d205a10 commit 0e605ec
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
11 changes: 7 additions & 4 deletions cli/cmd/deploy/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ be pushed to the organization "organization-slug-a3ecfh2b", and the app name
}

var (
slug string
appName string
verbose bool
slug string
appName string
verbose bool
appDir string = "."
projectDir string = "."
)

func run(cmd *cobra.Command, args []string) {
service := app.New(gql.NewClient(), gql.NewSubscriptionClient(), http.DefaultClient)
err := Deploy(cmd.Context(), ".", slug, verbose, appName, service)
err := Deploy(cmd.Context(), service, appDir, projectDir, slug, appName, verbose)

if err != nil {
os.Exit(1)
Expand All @@ -57,6 +59,7 @@ func init() {
flags.StringVarP(&slug, "organization", "o", "", "The organization slug identifier. List available organizations with 'numerous organization list'.")
flags.StringVarP(&appName, "name", "n", "", "A unique name for the application to deploy.")
flags.BoolVarP(&verbose, "verbose", "v", false, "Display detailed information about the app deployment.")
flags.StringVarP(&projectDir, "project-dir", "p", "", "The project directory, which is the build context if using a custom Dockerfile.")

if err := DeployCmd.MarkFlagRequired("organization"); err != nil {
panic(err.Error())
Expand Down
14 changes: 9 additions & 5 deletions cli/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
ErrInvalidAppName = errors.New("invalid app name")
)

func Deploy(ctx context.Context, dir string, slug string, verbose bool, appName string, apps AppService) error {
func Deploy(ctx context.Context, apps AppService, appDir, projectDir, slug string, appName string, verbose bool) error {
if !validate.IsValidIdentifier(slug) {
output.PrintError("Error: Invalid organization %q.", "Must contain only lower-case alphanumerical characters and dashes.", slug)
return ErrInvalidSlug
Expand All @@ -45,15 +45,15 @@ func Deploy(ctx context.Context, dir string, slug string, verbose bool, appName
}

task := output.StartTask("Loading app configuration")
manifest, err := manifest.LoadManifest(filepath.Join(dir, manifest.ManifestPath))
manifest, err := manifest.LoadManifest(filepath.Join(appDir, manifest.ManifestPath))
if err != nil {
task.Error()
output.PrintErrorAppNotInitialized()

return err
}

secrets := loadSecretsFromEnv(dir)
secrets := loadSecretsFromEnv(appDir)
task.Done()

task = output.StartTask("Registering new version")
Expand All @@ -74,8 +74,12 @@ func Deploy(ctx context.Context, dir string, slug string, verbose bool, appName
task.Done()

task = output.StartTask("Creating app archive")
tarPath := path.Join(dir, ".tmp_app_archive.tar")
err = archive.TarCreate(dir, tarPath, manifest.Exclude)
tarPath := path.Join(appDir, ".tmp_app_archive.tar")
tarSrcDir := appDir
if projectDir != "" {
tarSrcDir = projectDir
}
err = archive.TarCreate(tarSrcDir, tarPath, manifest.Exclude)
if err != nil {
task.Error()
output.PrintErrorDetails("Error archiving app source", err)
Expand Down
18 changes: 9 additions & 9 deletions cli/cmd/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestDeploy(t *testing.T) {
const deployVersionID = "deploy-version-id"

t.Run("give no existing app then happy path can run", func(t *testing.T) {
dir := t.TempDir()
copyTo(t, "../../testdata/streamlit_app", dir)
appDir := t.TempDir()
copyTo(t, "../../testdata/streamlit_app", appDir)

apps := &mockAppService{}
apps.On("ReadApp", mock.Anything, mock.Anything).Return(app.ReadAppOutput{}, app.ErrAppNotFound)
Expand All @@ -37,14 +37,14 @@ func TestDeploy(t *testing.T) {
apps.On("DeployApp", mock.Anything, mock.Anything).Return(app.DeployAppOutput{DeploymentVersionID: deployVersionID}, nil)
apps.On("DeployEvents", mock.Anything, mock.Anything).Return(nil)

err := Deploy(context.TODO(), dir, slug, false, appName, apps)
err := Deploy(context.TODO(), apps, appDir, "", slug, appName, false)

assert.NoError(t, err)
})

t.Run("give existing app then it does not create app", func(t *testing.T) {
dir := t.TempDir()
copyTo(t, "../../testdata/streamlit_app", dir)
appDir := t.TempDir()
copyTo(t, "../../testdata/streamlit_app", appDir)

apps := &mockAppService{}
apps.On("ReadApp", mock.Anything, mock.Anything).Return(app.ReadAppOutput{AppID: appID}, nil)
Expand All @@ -54,27 +54,27 @@ func TestDeploy(t *testing.T) {
apps.On("DeployApp", mock.Anything, mock.Anything).Return(app.DeployAppOutput{DeploymentVersionID: deployVersionID}, nil)
apps.On("DeployEvents", mock.Anything, mock.Anything).Return(nil)

err := Deploy(context.TODO(), dir, slug, false, appName, apps)
err := Deploy(context.TODO(), apps, appDir, "", slug, appName, false)

assert.NoError(t, err)
})

t.Run("given dir without numerous.toml then it returns error", func(t *testing.T) {
dir := t.TempDir()

err := Deploy(context.TODO(), dir, slug, false, appName, nil)
err := Deploy(context.TODO(), nil, dir, "", slug, appName, false)

assert.EqualError(t, err, "open "+dir+"/numerous.toml: no such file or directory")
})

t.Run("given invalid slug then it returns error", func(t *testing.T) {
err := Deploy(context.TODO(), ".", "Some Invalid Organization Slug", false, appName, nil)
err := Deploy(context.TODO(), nil, ".", "", "Some Invalid Organization Slug", appName, false)

assert.ErrorIs(t, err, ErrInvalidSlug)
})

t.Run("given invalid app name then it returns error", func(t *testing.T) {
err := Deploy(context.TODO(), ".", slug, false, "Some Invalid App Name", nil)
err := Deploy(context.TODO(), nil, ".", "", slug, "Some Invalid App Name", false)

assert.ErrorIs(t, err, ErrInvalidAppName)
})
Expand Down
1 change: 1 addition & 0 deletions python/src/numerous/generated/graphql/input_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class AppCreateInfo(BaseModel):


class AppDeployInput(BaseModel):
app_relative_path: Optional[str] = Field(alias="appRelativePath", default=None)
secrets: Optional[List["AppSecret"]] = None


Expand Down
1 change: 1 addition & 0 deletions shared/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ input AppCreateInfo {
}

input AppDeployInput {
appRelativePath: String
secrets: [AppSecret!]
}

Expand Down

0 comments on commit 0e605ec

Please sign in to comment.