Skip to content

Commit

Permalink
Add flag to force push repositories to gitea during deployment
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Neville <jimmyeneville@gmail.com>
  • Loading branch information
Jneville0815 committed Sep 24, 2024
1 parent 000eee3 commit dcae8e4
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions site/src/content/docs/commands/zarf_package_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ zarf package deploy [ PACKAGE_SOURCE ] [flags]
--adopt-existing-resources Adopts any pre-existing K8s resources into the Helm charts managed by Zarf. ONLY use when you have existing deployments you want Zarf to takeover.
--components string Comma-separated list of components to deploy. Adding this flag will skip the prompts for selected components. Globbing component names with '*' and deselecting 'default' components with a leading '-' are also supported.
--confirm Confirms package deployment without prompting. ONLY use with packages you trust. Skips prompts to review SBOM, configure variables, select optional components and review potential breaking changes.
--force-push-repos Force push all repositories to gitea during deployment
-h, --help help for deploy
--retries int Number of retries to perform for Zarf deploy operations like git/image pushes or Helm installs (default 3)
--set stringToString Specify deployment variables to set on the command line (KEY=value) (default [])
Expand Down Expand Up @@ -52,5 +53,4 @@ zarf package deploy [ PACKAGE_SOURCE ] [flags]

### SEE ALSO

* [zarf package](/commands/zarf_package/) - Zarf package commands for creating, deploying, and inspecting packages

- [zarf package](/commands/zarf_package/) - Zarf package commands for creating, deploying, and inspecting packages
2 changes: 2 additions & 0 deletions src/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ var packageMirrorCmd = &cobra.Command{
GitInfo: pkgConfig.InitOpts.GitServer,
NoImageChecksum: pkgConfig.MirrorOpts.NoImgChecksum,
Retries: pkgConfig.PkgOpts.Retries,
ForcePushRepos: pkgConfig.DeployOpts.ForcePushRepos,
}
err = packager2.Mirror(cmd.Context(), mirrorOpt)
if err != nil {
Expand Down Expand Up @@ -501,6 +502,7 @@ func bindDeployFlags(v *viper.Viper) {
deployFlags.StringVar(&pkgConfig.PkgOpts.Shasum, "shasum", v.GetString(common.VPkgDeployShasum), lang.CmdPackageDeployFlagShasum)
deployFlags.StringVar(&pkgConfig.PkgOpts.SGetKeyPath, "sget", v.GetString(common.VPkgDeploySget), lang.CmdPackageDeployFlagSget)
deployFlags.BoolVar(&pkgConfig.PkgOpts.SkipSignatureValidation, "skip-signature-validation", false, lang.CmdPackageFlagSkipSignatureValidation)
deployFlags.BoolVar(&pkgConfig.DeployOpts.ForcePushRepos, "force-push-repos", false, lang.CmdPackageForcePushRepos)

deployFlags.MarkHidden("sget")
}
Expand Down
1 change: 1 addition & 0 deletions src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ $ zarf init --artifact-push-password={PASSWORD} --artifact-push-username={USERNA
CmdPackageFlagConcurrency = "Number of concurrent layer operations to perform when interacting with a remote package."
CmdPackageFlagFlagPublicKey = "Path to public key file for validating signed packages"
CmdPackageFlagSkipSignatureValidation = "Skip validating the signature of the Zarf package"
CmdPackageForcePushRepos = "Force push all repositories to gitea during deployment"
CmdPackageFlagRetries = "Number of retries to perform for Zarf deploy operations like git/image pushes or Helm installs"

CmdPackageCreateShort = "Creates a Zarf package from a given directory or the current directory"
Expand Down
4 changes: 2 additions & 2 deletions src/internal/git/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (r *Repository) Path() string {
}

// Push pushes the repository to the remote git server.
func (r *Repository) Push(ctx context.Context, address, username, password string) error {
func (r *Repository) Push(ctx context.Context, address, username, password string, forcePushRepos bool) error {
repo, err := git.PlainOpen(r.path)
if err != nil {
return fmt.Errorf("not a valid git repo or unable to open: %w", err)
Expand Down Expand Up @@ -208,7 +208,7 @@ func (r *Repository) Push(ctx context.Context, address, username, password strin
RemoteName: offlineRemoteName,
Auth: &gitCred,
// TODO: (@JEFFMCCOY) add the parsing for the `+` force prefix (see https://github.com/zarf-dev/zarf/issues/1410)
//Force: isForce,
Force: forcePushRepos,
// If a provided refspec doesn't push anything, it is just ignored
RefSpecs: []config.RefSpec{
"refs/heads/*:refs/heads/*",
Expand Down
9 changes: 5 additions & 4 deletions src/internal/packager2/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type MirrorOptions struct {
GitInfo types.GitServerInfo
NoImageChecksum bool
Retries int
ForcePushRepos bool
}

// Mirror mirrors the package contents to the given registry and git server.
Expand All @@ -47,7 +48,7 @@ func Mirror(ctx context.Context, opt MirrorOptions) error {
if err != nil {
return err
}
err = pushReposToRepository(ctx, opt.Cluster, opt.PackagePaths, opt.Filter, opt.GitInfo, opt.Retries)
err = pushReposToRepository(ctx, opt.Cluster, opt.PackagePaths, opt.Filter, opt.GitInfo, opt.Retries, opt.ForcePushRepos)
if err != nil {
return err
}
Expand Down Expand Up @@ -171,7 +172,7 @@ func pushImagesToRegistry(ctx context.Context, c *cluster.Cluster, pkgPaths layo
return nil
}

func pushReposToRepository(ctx context.Context, c *cluster.Cluster, pkgPaths layout.PackagePaths, filter filters.ComponentFilterStrategy, gitInfo types.GitServerInfo, retries int) error {
func pushReposToRepository(ctx context.Context, c *cluster.Cluster, pkgPaths layout.PackagePaths, filter filters.ComponentFilterStrategy, gitInfo types.GitServerInfo, retries int, forcePushRepos bool) error {
pkg, _, err := pkgPaths.ReadZarfYAML()
if err != nil {
return err
Expand All @@ -191,7 +192,7 @@ func pushReposToRepository(ctx context.Context, c *cluster.Cluster, pkgPaths lay
err = retry.Do(func() error {
if !dns.IsServiceURL(gitInfo.Address) {
message.Infof("Pushing repository %s to server %s", repoURL, gitInfo.Address)
err = repository.Push(ctx, gitInfo.Address, gitInfo.PushUsername, gitInfo.PushPassword)
err = repository.Push(ctx, gitInfo.Address, gitInfo.PushUsername, gitInfo.PushPassword, forcePushRepos)
if err != nil {
return err
}
Expand Down Expand Up @@ -220,7 +221,7 @@ func pushReposToRepository(ctx context.Context, c *cluster.Cluster, pkgPaths lay
}
return tunnel.Wrap(func() error {
message.Infof("Pushing repository %s to server %s", repoURL, tunnel.HTTPEndpoint())
err = repository.Push(ctx, tunnel.HTTPEndpoint(), gitInfo.PushUsername, gitInfo.PushPassword)
err = repository.Push(ctx, tunnel.HTTPEndpoint(), gitInfo.PushUsername, gitInfo.PushPassword, forcePushRepos)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ func (p *Packager) pushReposToRepository(ctx context.Context, reposPath string,
return err
}
return tunnel.Wrap(func() error {
err = repository.Push(ctx, tunnel.HTTPEndpoint(), p.state.GitServer.PushUsername, p.state.GitServer.PushPassword)
err = repository.Push(ctx, tunnel.HTTPEndpoint(), p.state.GitServer.PushUsername, p.state.GitServer.PushPassword, p.cfg.DeployOpts.ForcePushRepos)
if err != nil {
return err
}
Expand All @@ -640,7 +640,7 @@ func (p *Packager) pushReposToRepository(ctx context.Context, reposPath string,
})
}

err = repository.Push(ctx, p.state.GitServer.Address, p.state.GitServer.PushUsername, p.state.GitServer.PushPassword)
err = repository.Push(ctx, p.state.GitServer.Address, p.state.GitServer.PushUsername, p.state.GitServer.PushPassword, p.cfg.DeployOpts.ForcePushRepos)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ type ZarfDeployOptions struct {
Timeout time.Duration
// [Library Only] A map of component names to chart names containing Helm Chart values to override values on deploy
ValuesOverridesMap map[string]map[string]map[string]interface{}
// Force push all repositories to gitea during deployment
ForcePushRepos bool
}

// ZarfMirrorOptions tracks the user-defined preferences during a package mirror.
Expand Down

0 comments on commit dcae8e4

Please sign in to comment.