Skip to content

Commit

Permalink
change default outputs directories (#119)
Browse files Browse the repository at this point in the history
We use default directories two times.
One for downloading the existing release assets
from github. We were downloading it inside `tmp`
directory. This commit changes it to use `.tmp`
directory.

Another instance we need a default output directory
is to write the release assets created by csctl.
We were writing to `releases` folder and this commit
updates the same to use `.release` folder.

This commit also updates the `.gitignore` file
accordingly.

Signed-off-by: Aniruddha Basak <aniruddha.basak@syself.com>
  • Loading branch information
aniruddha2000 committed May 10, 2024
1 parent 7496484 commit 8549aad
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var createCmd = &cobra.Command{

func init() {
createCmd.Flags().StringVarP(&mode, "mode", "m", "stable", "It defines the mode of the cluster stack manager")
createCmd.Flags().StringVarP(&outputDirectory, "output", "o", "./releases", "It defines the output directory in which the release artifacts will be generated")
createCmd.Flags().StringVarP(&outputDirectory, "output", "o", "./.release", "It defines the output directory in which the release artifacts will be generated")
createCmd.Flags().StringVarP(&nodeImageRegistry, "node-image-registry", "r", "", "It defines the node image registry. For example oci://ghcr.io/foo/bar/node-images/staging/")
}

Expand Down Expand Up @@ -133,11 +133,11 @@ func GetCreateOptions(ctx context.Context, clusterStackPath string) (*CreateOpti
createOption.Metadata.Versions.ClusterStack = "v1"
createOption.Metadata.Versions.Components.ClusterAddon = "v1"
} else {
if err := github.DownloadReleaseAssets(ctx, latestRepoRelease, "./tmp/releases/", gc); err != nil {
if err := github.DownloadReleaseAssets(ctx, latestRepoRelease, "./.tmp/release/", gc); err != nil {
return nil, fmt.Errorf("failed to download release asset: %w", err)
}

createOption.Metadata, err = clusterstack.HandleStableMode("./tmp/releases/", createOption.CurrentReleaseHash, createOption.LatestReleaseHash)
createOption.Metadata, err = clusterstack.HandleStableMode("./.tmp/release/", createOption.CurrentReleaseHash, createOption.LatestReleaseHash)
if err != nil {
return nil, fmt.Errorf("failed to handle stable mode: %w", err)
}
Expand All @@ -157,6 +157,8 @@ func GetCreateOptions(ctx context.Context, clusterStackPath string) (*CreateOpti
}

func createAction(cmd *cobra.Command, args []string) error {
defer cleanTmpDirectory()

if len(args) != 1 {
return fmt.Errorf("please provide a valid command, create only accept one argument to path to the cluster stacks")
}
Expand Down Expand Up @@ -324,3 +326,11 @@ func overwriteVersionInFile(chartYaml, newVersion string) error {
}
return nil
}

func cleanTmpDirectory() error {
if err := os.RemoveAll("./.tmp/"); err != nil {
return fmt.Errorf("failed to remove tmp directory: %w", err)
}

return nil
}

0 comments on commit 8549aad

Please sign in to comment.