Skip to content

Commit 5dd946e

Browse files
authored
feat: add argocd binary support and fix packer environment setup (#87)
This pull request adds support for managing the `argocd` binary within the project. The main changes include introducing a new package for `argocd`, updating the application to recognize and handle this binary, and documenting its addition. There are also minor adjustments to environment variable handling for consistency. **New binary support:** * Added a new package `pkg/binaries/argocd` with an implementation for managing the `argocd` binary, including logic for version detection and GitHub release fetching. * Registered the new `argocd` binary in the main application by importing the package and including it in the binaries list in `cmd/b/main.go`. [[1]](diffhunk://#diff-9220de3f3af10d1a2eb38298eefa2c9cc92852596770de03bc85dbbb6d136f9fR8) [[2]](diffhunk://#diff-9220de3f3af10d1a2eb38298eefa2c9cc92852596770de03bc85dbbb6d136f9fR52) * Updated the VSCode launch configuration to use `argocd` as an argument for debugging. **Documentation:** * Added `argocd` to the list of supported binaries in `README.md` with a brief description and link to the upstream repository. **Code consistency:** * Updated environment variable assignment in the `packer` binary implementation for consistency with the new `argocd` approach.
1 parent bbe1fb8 commit 5dd946e

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"request": "launch",
1111
"mode": "debug",
1212
"program": "${workspaceRoot}/cmd/b/main.go",
13-
"args": ["v", "envsubst"]
13+
"args": ["v", "argocd"]
1414
}
1515
]
1616
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ Have a look at [pkg/binary](./pkg/binary/) for more details.
168168

169169
Have a look at [pkg/binaries](./pkg/binaries/) for prepackaged binaries.
170170

171+
- [argocd](https://github.com/argoproj/argo-cd) - Declarative Continuous Deployment for Kubernetes
171172
- [argsh](https://github.com/arg-sh/argsh) - Utilities for Bash script quality
172173
- `b` - (Selfupdate) Manage and execute binary files
173174
- [cilium](https://github.com/cilium/cilium-cli) - Providing, securing, and observing network connectivity between workloads

cmd/b/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66

77
"github.com/fentas/b/pkg/binaries"
8+
"github.com/fentas/b/pkg/binaries/argocd"
89
"github.com/fentas/b/pkg/binaries/argsh"
910
"github.com/fentas/b/pkg/binaries/b"
1011
"github.com/fentas/b/pkg/binaries/cilium"
@@ -48,6 +49,7 @@ func main() {
4849
}
4950

5051
binaries := []*binary.Binary{
52+
argocd.Binary(o),
5153
argsh.Binary(o),
5254
b.Binary(o),
5355
cilium.Binary(o),

pkg/binaries/argocd/argocd.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Package argocd implements the argocd binary.
2+
package argocd
3+
4+
import (
5+
"context"
6+
"fmt"
7+
"regexp"
8+
"runtime"
9+
10+
"github.com/fentas/b/pkg/binaries"
11+
"github.com/fentas/b/pkg/binary"
12+
)
13+
14+
var argocdVersionRegex = regexp.MustCompile(`argocd: (v[\.\d]+)`)
15+
16+
func Binary(options *binaries.BinaryOptions) *binary.Binary {
17+
if options == nil {
18+
options = &binaries.BinaryOptions{
19+
Context: context.Background(),
20+
}
21+
}
22+
return &binary.Binary{
23+
Context: options.Context,
24+
Envs: options.Envs,
25+
Tracker: options.Tracker,
26+
Version: options.Version,
27+
Name: "argocd",
28+
GitHubRepo: "argoproj/argo-cd",
29+
GitHubFile: fmt.Sprintf("argocd-%s-%s", runtime.GOOS, runtime.GOARCH),
30+
VersionF: binary.GithubLatest,
31+
IsTarGz: false,
32+
VersionLocalF: func(b *binary.Binary) (string, error) {
33+
b.Envs = map[string]string{"HOME": "/tmp"}
34+
s, err := b.Exec("version", "--client", "--short")
35+
if err != nil {
36+
return "", err
37+
}
38+
v := argocdVersionRegex.FindStringSubmatch(s)
39+
if len(v) != 2 {
40+
return "", fmt.Errorf("argocd version regex did not match")
41+
}
42+
return v[1], nil
43+
},
44+
}
45+
}

pkg/binaries/packer/packer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func Binary(options *binaries.BinaryOptions) *binary.Binary {
3636
VersionF: binary.GithubLatest,
3737
IsZip: true,
3838
VersionLocalF: func(b *binary.Binary) (string, error) {
39-
b.Envs["HOME"] = "/tmp"
39+
b.Envs = map[string]string{"HOME": "/tmp"}
4040
s, err := b.Exec("version")
4141
if err != nil {
4242
return "", err

0 commit comments

Comments
 (0)