Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add flag to force push repositories to gitea during deployment #3023

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 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
2 changes: 2 additions & 0 deletions src/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,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 @@ -551,6 +552,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)

err := deployFlags.MarkHidden("sget")
if err != nil {
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
5 changes: 2 additions & 3 deletions src/internal/git/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,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 {
l := logger.From(ctx)
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 @@ -213,7 +212,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
11 changes: 6 additions & 5 deletions src/internal/packager2/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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 @@ -48,7 +49,8 @@ func Mirror(ctx context.Context, opt MirrorOptions) error {
if err != nil {
return err
}
err = pushReposToRepository(ctx, opt.Cluster, opt.PkgLayout, opt.Filter, opt.GitInfo, opt.Retries)

err = pushReposToRepository(ctx, opt.Cluster, opt.PkgLayout, opt.Filter, opt.GitInfo, opt.Retries, opt.ForcePushRepos)
if err != nil {
return err
}
Expand Down Expand Up @@ -167,8 +169,7 @@ func pushImagesToRegistry(ctx context.Context, c *cluster.Cluster, pkgLayout *la
return nil
}

func pushReposToRepository(ctx context.Context, c *cluster.Cluster, pkgLayout *layout.PackageLayout, filter filters.ComponentFilterStrategy, gitInfo types.GitServerInfo, retries int) error {
l := logger.From(ctx)
func pushReposToRepository(ctx context.Context, c *cluster.Cluster, pkgLayout *layout.PackageLayout, filter filters.ComponentFilterStrategy, gitInfo types.GitServerInfo, retries int, forcePushRepos bool) error {
components, err := filter.Apply(pkgLayout.Pkg)
if err != nil {
return err
Expand All @@ -192,7 +193,7 @@ func pushReposToRepository(ctx context.Context, c *cluster.Cluster, pkgLayout *l
if !dns.IsServiceURL(gitInfo.Address) {
message.Infof("Pushing repository %s to server %s", repoURL, gitInfo.Address)
l.Info("pushing repository to server", "repo", repoURL, "server", 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 @@ -222,7 +223,7 @@ func pushReposToRepository(ctx context.Context, c *cluster.Cluster, pkgLayout *l
return tunnel.Wrap(func() error {
message.Infof("Pushing repository %s to server %s", repoURL, tunnel.HTTPEndpoint())
l.Info("pushing repository to server", "repo", repoURL, "server", 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 @@ -621,7 +621,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 @@ -638,7 +638,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 @@ -78,6 +78,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
// [Dev Deploy Only] Manual override for ###ZARF_REGISTRY###
RegistryURL string
}
Expand Down