-
Notifications
You must be signed in to change notification settings - Fork 239
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
1 parent
137bca4
commit 55192a0
Showing
4 changed files
with
164 additions
and
5 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
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 |
---|---|---|
@@ -1,11 +1,75 @@ | ||
package v2 | ||
|
||
import "context" | ||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
api "github.com/porter-dev/porter/api/client" | ||
"github.com/porter-dev/porter/cli/cmd/config" | ||
) | ||
|
||
// AppPushInput is the input to the AppPush function | ||
type AppPushInput struct{} | ||
type AppPushInput struct { | ||
// CLIConfig is the CLI configuration | ||
CLIConfig config.CLIConfig | ||
// Client is the Porter API client | ||
Client api.Client | ||
// AppName is the name of the app | ||
AppName string | ||
// DeploymentTargetName is the name of the deployment target, if provided | ||
DeploymentTargetName string | ||
// ImageTag is the image tag to use for the app build | ||
ImageTag string | ||
} | ||
|
||
// AppPush pushes an app to a remote registry | ||
func AppPush(ctx context.Context, inp AppPushInput) error { | ||
cliConf := inp.CLIConfig | ||
client := inp.Client | ||
|
||
if cliConf.Project == 0 { | ||
return errors.New("project must be set") | ||
} | ||
|
||
if cliConf.Cluster == 0 { | ||
return errors.New("cluster must be set") | ||
} | ||
|
||
latest, err := client.CurrentAppRevision(ctx, api.CurrentAppRevisionInput{ | ||
ProjectID: cliConf.Project, | ||
ClusterID: cliConf.Cluster, | ||
AppName: inp.AppName, | ||
DeploymentTargetName: inp.DeploymentTargetName, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("error getting latest app revision: %s", err) | ||
} | ||
|
||
settings, err := client.GetBuildFromRevision(ctx, api.GetBuildFromRevisionInput{ | ||
ProjectID: cliConf.Project, | ||
ClusterID: cliConf.Cluster, | ||
AppName: inp.AppName, | ||
AppRevisionID: latest.AppRevision.ID, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("error getting build from revision: %w", err) | ||
} | ||
|
||
tagForPush, err := tagFromCommitSHAOrFlag(inp.ImageTag) | ||
if err != nil { | ||
return fmt.Errorf("error getting tag for build: %w", err) | ||
} | ||
|
||
// push the image to the remote registry | ||
err = push(ctx, client, pushInput{ | ||
ProjectID: cliConf.Project, | ||
ImageTag: tagForPush, | ||
RepositoryURL: settings.Image.Repository, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("error pushing image: %w", err) | ||
} | ||
|
||
return nil | ||
} |
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