Skip to content

Commit

Permalink
updated to use component hash instead of commit
Browse files Browse the repository at this point in the history
  • Loading branch information
xadhatter committed Mar 12, 2024
1 parent 7d1ad98 commit 037391b
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 38 deletions.
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func init() {
func addCommonDeployFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&cfg.Flags.Namespace, "namespace", "n", "", "namespace of KubeFox Platform")
cmd.Flags().StringVarP(&cfg.Flags.Platform, "platform", "p", "", "name of KubeFox Platform to utilize")
cmd.Flags().DurationVarP(&cfg.Flags.WaitTime, "wait", "", 0, "wait up the specified time for components to be ready")
cmd.Flags().DurationVarP(&cfg.Flags.WaitTime, "wait", "", 0, "wait up to the specified time for components to be ready")
cmd.Flags().BoolVarP(&cfg.Flags.DryRun, "dry-run", "", false, "submit server-side request without persisting the resource")
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fox proxy 8080 --wait 5m
fox proxy 8080 --virtual-env my-env --app-deployment my-dep
http://127.0.0.1:8080/hello # uses my-env and my-deployment
http://127.0.0.1:8080/hello?kf-env=your-env # uses your-env and my-dep
http://127.0.0.1:8080/hello?kf-ve=your-env # uses your-env and my-dep
http://127.0.0.1:8080/hello?kf-dep=your-dep # uses my-env and your-dep
`),
}
Expand Down
2 changes: 1 addition & 1 deletion docs/fox_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fox deploy [flags]
-n, --namespace string namespace of KubeFox Platform
-p, --platform string name of KubeFox Platform to utilize
-s, --version string version to assign to the AppDeployment, making it immutable
--wait duration wait up the specified time for components to be ready
--wait duration wait up to the specified time for components to be ready
```

### Options inherited from parent commands
Expand Down
4 changes: 2 additions & 2 deletions docs/fox_proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fox proxy 8080 --wait 5m
fox proxy 8080 --virtual-env my-env --app-deployment my-dep
http://127.0.0.1:8080/hello # uses my-env and my-deployment
http://127.0.0.1:8080/hello?kf-env=your-env # uses your-env and my-dep
http://127.0.0.1:8080/hello?kf-ve=your-env # uses your-env and my-dep
http://127.0.0.1:8080/hello?kf-dep=your-dep # uses my-env and your-dep
```

Expand All @@ -41,7 +41,7 @@ fox proxy 8080 --virtual-env my-env --app-deployment my-dep
-n, --namespace string namespace of KubeFox Platform
-p, --platform string name of KubeFox Platform to utilize
-e, --virtual-env string environment to add to proxied requests
--wait duration wait up the specified time for components to be ready
--wait duration wait up to the specified time for components to be ready
```

### Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion docs/fox_publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fox publish [flags]
--skip-deploy do not perform deployment after build
--skip-push do not push image after build
-s, --version string version to assign to the AppDeployment, making it immutable
--wait duration wait up the specified time for components to be ready
--wait duration wait up to the specified time for components to be ready
```

### Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion docs/fox_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fox release v1.2.3 --virtual-env prod
-n, --namespace string namespace of KubeFox Platform
-p, --platform string name of KubeFox Platform to utilize
-e, --virtual-env string name of VirtualEnvironment to use for Release
--wait duration wait up the specified time for components to be ready
--wait duration wait up to the specified time for components to be ready
```

### Options inherited from parent commands
Expand Down
4 changes: 2 additions & 2 deletions efs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ARG APP_YAML
ARG BUILD_DATE
ARG COMPONENT_DIR
ARG COMPONENT
ARG COMPONENT_COMMIT
ARG COMPONENT_HASH
ARG ROOT_COMMIT
ARG HEAD_REF
ARG TAG_REF
Expand All @@ -31,7 +31,7 @@ RUN CGO_ENABLED=0 go build \
-ldflags " \
-X github.com/xigxog/kubefox/build.date=${BUILD_DATE}\
-X github.com/xigxog/kubefox/build.component=${COMPONENT} \
-X github.com/xigxog/kubefox/build.commit=${COMPONENT_COMMIT} \
-X github.com/xigxog/kubefox/build.hash=${COMPONENT_HASH} \
-X github.com/xigxog/kubefox/build.rootCommit=${ROOT_COMMIT} \
-X github.com/xigxog/kubefox/build.headRef=${HEAD_REF} \
-X github.com/xigxog/kubefox/build.tagRef=${TAG_REF}"
Expand Down
2 changes: 1 addition & 1 deletion hack/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ go build \
-w -s
-X github.com/xigxog/kubefox/build.date=${BUILD_DATE}\
-X github.com/xigxog/kubefox/build.component=${COMPONENT} \
-X github.com/xigxog/kubefox/build.commit=${COMPONENT_COMMIT} \
-X github.com/xigxog/kubefox/build.hash=${COMPONENT_COMMIT} \
-X github.com/xigxog/kubefox/build.rootCommit=${ROOT_COMMIT} \
-X github.com/xigxog/kubefox/build.headRef=${HEAD_REF} \
-X github.com/xigxog/kubefox/build.tagRef=${TAG_REF}" \
Expand Down
12 changes: 6 additions & 6 deletions internal/kubernetes/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ func (c *Client) WaitPlatformReady(waitTime time.Duration, p *v1alpha1.Platform,
}
}

func (c *Client) WaitPodReady(ctx context.Context, p *v1alpha1.Platform, comp, commit string) error {
log.Verbose("Waiting for component '%s' with commit '%s' to be ready...", comp, commit)
func (c *Client) WaitPodReady(ctx context.Context, p *v1alpha1.Platform, comp, hash string) error {
log.Verbose("Waiting for component '%s' with hash '%s' to be ready...", comp, hash)

hasLabels := client.MatchingLabels{
api.LabelK8sComponent: comp,
api.LabelK8sPlatform: p.Name,
}
if commit != "" {
hasLabels[api.LabelK8sComponentCommit] = commit
if hash != "" {
hasLabels[api.LabelK8sComponentHash] = hash

Check failure on line 282 in internal/kubernetes/client.go

View workflow job for this annotation

GitHub Actions / Build binary

undefined: api.LabelK8sComponentHash
}

l := &corev1.PodList{}
Expand All @@ -301,9 +301,9 @@ func (c *Client) WaitPodReady(ctx context.Context, p *v1alpha1.Platform, comp, c
return ctx.Err()
}
time.Sleep(time.Second * 3)
return c.WaitPodReady(ctx, p, comp, commit)
return c.WaitPodReady(ctx, p, comp, hash)
}
log.Verbose("Component '%s' with commit '%s' is ready.", comp, commit)
log.Verbose("Component '%s' with commit '%s' is ready.", comp, hash)

return nil
}
Expand Down
20 changes: 10 additions & 10 deletions internal/repo/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ func (r *repo) Build(compDirName string) string {
appYaml := r.AppYAMLBuildSubpath()
compName := utils.CleanName(compDirName)
compDir := r.ComponentBuildSubpath(compDirName)
compCommit := r.GetCompHash(compDirName)
compHash := r.GetCompHash(compDirName)
rootCommit := r.GetCommit().Hash.String()
headRef := r.GetHeadRef()
tagRef := r.GetTagRef()
now := time.Now().Format(time.RFC3339)

buildArgs := map[string]*string{
"APP_YAML": &appYaml,
"BUILD_DATE": &now,
"COMPONENT": &compName,
"COMPONENT_DIR": &compDir,
"COMPONENT_COMMIT": &compCommit,
"ROOT_COMMIT": &rootCommit,
"HEAD_REF": &headRef,
"TAG_REF": &tagRef,
"APP_YAML": &appYaml,
"BUILD_DATE": &now,
"COMPONENT": &compName,
"COMPONENT_DIR": &compDir,
"COMPONENT_HASH": &compHash,
"ROOT_COMMIT": &rootCommit,
"HEAD_REF": &headRef,
"TAG_REF": &tagRef,
}
log.VerboseMarshal(buildArgs, "Docker build args:")

Expand Down Expand Up @@ -98,7 +98,7 @@ func (r *repo) Build(compDirName string) string {
labels := map[string]string{
api.LabelOCIComponent: compName,
api.LabelOCICreated: now,
api.LabelOCIRevision: compCommit,
api.LabelOCIRevision: compHash,
api.LabelOCISource: r.GetRepoURL(),
}

Expand Down
4 changes: 2 additions & 2 deletions internal/repo/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (r *repo) buildAppDep() *v1alpha1.AppDeployment {
}

func (r *repo) extractCompDef(compName string, comp *api.ComponentDefinition) error {
commit := comp.Hash
hash := comp.Hash
img := r.GetCompImage(compName, comp.Hash)

resp, err := r.docker.ContainerCreate(r.ctx, &container.Config{
Expand Down Expand Up @@ -268,7 +268,7 @@ func (r *repo) extractCompDef(compName string, comp *api.ComponentDefinition) er
if err := json.Unmarshal(b, comp); err != nil {
return err
}
comp.Hash = commit
comp.Hash = hash

return nil
}
Expand Down
10 changes: 5 additions & 5 deletions internal/repo/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func initApp(cfg *config.Config) {

if cfg.Flags.Quickstart {
initDir(efs.HelloWorldPath, cfg.AppPath)
initGit(cfg.RepoPath, &App{}, cfg)
initGit(cfg.RepoPath, cfg)
return
}

Expand All @@ -72,7 +72,7 @@ func initApp(cfg *config.Config) {
} else if !errors.Is(err, fs.ErrNotExist) {
log.VerboseMarshal(app, "App definition:")
log.Info("A valid KubeFox App definition already exists.")
initGit(cfg.RepoPath, app, cfg)
initGit(cfg.RepoPath, cfg)
return
}

Expand All @@ -83,7 +83,7 @@ func initApp(cfg *config.Config) {
log.Info("includes two components and example environments for testing.")
if foxutils.YesNoPrompt("Would you like to initialize the 'hello-world' KubeFox App?", false) {
initDir(efs.HelloWorldPath, cfg.AppPath)
initGit(cfg.RepoPath, app, cfg)
initGit(cfg.RepoPath, cfg)
return
}
log.InfoNewline()
Expand All @@ -97,10 +97,10 @@ func initApp(cfg *config.Config) {
app.Description = foxutils.InputPrompt("Enter the KubeFox App's description", "", false)

WriteApp(cfg.AppPath, app)
initGit(cfg.RepoPath, app, cfg)
initGit(cfg.RepoPath, cfg)
}

func initGit(repoPath string, app *App, cfg *config.Config) {
func initGit(repoPath string, cfg *config.Config) {
wt := osfs.New(repoPath)
dot, _ := wt.Chroot(git.GitDirName)
s := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())
Expand Down
11 changes: 6 additions & 5 deletions internal/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ func (r *repo) CreateTag(tag string) *plumbing.Reference {

func (r *repo) GetCompImageFromDir(compDirName string) string {
name := utils.CleanName(compDirName)
commit := r.GetCompHash(compDirName)
return r.GetCompImage(name, commit)
hash := r.GetCompHash(compDirName)
return r.GetCompImage(name, hash)
}

func (r *repo) GetCompImage(name, commit string) string {
return fmt.Sprintf("%s/%s/%s:%s", r.cfg.GetContainerRegistry().Address, r.app.Name, name, commit)
func (r *repo) GetCompImage(name, hash string) string {
return fmt.Sprintf("%s/%s/%s:%s", r.cfg.GetContainerRegistry().Address, r.app.Name, name, hash)
}

func (r *repo) GetRepoURL() string {
Expand Down Expand Up @@ -202,13 +202,14 @@ func (r *repo) GetTagRef() string {
func (r *repo) GetCompHash(compDirName string) string {
h := md5.New()

err := filepath.Walk(r.ComponentRepoSubpath(compDirName),
err := filepath.Walk(r.ComponentDir(compDirName),
func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if !info.IsDir() {
// compPath := foxutils.Subpath(path, r.cfg.RepoPath)
f, err := os.Open(path)
if err != nil {
return err
Expand Down

0 comments on commit 037391b

Please sign in to comment.