Skip to content

Commit b30e27c

Browse files
committed
fix: various fixes
1 parent fddf323 commit b30e27c

File tree

6 files changed

+108
-9
lines changed

6 files changed

+108
-9
lines changed

.github/workflows/release.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: goreleaser
2+
3+
on:
4+
push:
5+
tags:
6+
- "*" # triggers only if push new tag version, like `0.8.4` or else
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
goreleaser:
13+
runs-on: ubuntu-latest
14+
steps:
15+
-
16+
name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
-
21+
name: Set up Go
22+
uses: actions/setup-go@v5
23+
-
24+
name: Run GoReleaser
25+
uses: goreleaser/goreleaser-action@v6
26+
with:
27+
distribution: goreleaser
28+
version: '~> v2'
29+
args: release --clean
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: 2
2+
3+
archives:
4+
- format: binary
5+
6+
before:
7+
hooks:
8+
# You may remove this if you don't use go modules.
9+
- go mod tidy
10+
# you may remove this if you don't need go generate
11+
- go generate ./...
12+
13+
builds:
14+
- main: ./cmd/operator-docker
15+
env:
16+
- CGO_ENABLED=0
17+
goos:
18+
- linux
19+
- windows
20+
- darwin
21+
22+
checksum:
23+
split: true
24+
25+
changelog:
26+
sort: asc
27+
filters:
28+
exclude:
29+
- "^docs:"
30+
- "^test:"
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
package main
2+
3+
var hardcodedConfig = `
14
repos:
25
operators:
36
docker:
47
binary:
58
linux_amd64:
6-
url: https://github.com/octocompose/operator-docker/releases/download/v0.0.2/operator-docker_0.0.2_linux_amd64
7-
sha256Url: https://github.com/octocompose/operator-docker/releases/download/v0.0.2/operator-docker_0.0.2_linux_amd64.sha256
9+
url: https://github.com/octocompose/operator-docker/releases/download/v0.0.3/operator-docker_0.0.3_linux_amd64
10+
sha256Url: https://github.com/octocompose/operator-docker/releases/download/v0.0.3/operator-docker_0.0.3_linux_amd64.sha256
811
linux_arm64:
9-
url: https://github.com/octocompose/operator-docker/releases/download/v0.0.2/operator-docker_0.0.2_linux_arm64
10-
sha256Url: https://github.com/octocompose/operator-docker/releases/download/v0.0.2/operator-docker_0.0.2_linux_arm64.sha256
12+
url: https://github.com/octocompose/operator-docker/releases/download/v0.0.3/operator-docker_0.0.3_linux_arm64
13+
sha256Url: https://github.com/octocompose/operator-docker/releases/download/v0.0.3/operator-docker_0.0.3_linux_arm64.sha256
1114
source:
1215
# If path is set and existing, repo and ref are ignored.
1316
path: ../operator-docker
1417
repo: https://github.com/octocompose/operator-docker.git
1518
ref: refs/heads/main
1619
buildCmds:
1720
- GOOS={{.OS}} GOARCH={{.ARCH}} make build
18-
binary: dist/{{.OS}}/{{.ARCH}}/operator-docker
21+
binary: dist/{{.OS}}/{{.ARCH}}/operator-docker
22+
`

cmd/octoctl/main.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,19 @@ func createConfig(ctx context.Context, cmd *cli.Command) (context.Context, error
4747

4848
logger.Debug("Creating configuration", "config", cmd.StringSlice("config"))
4949

50-
cfg, err := octoconfig.New(logger, cmd.StringSlice("config"))
50+
codec, err := codecs.GetMime(codecs.MimeYAML)
51+
if err != nil {
52+
logger.Error("Error while getting codec", "error", err)
53+
return ctx, err
54+
}
55+
56+
hardCodedData := map[string]any{}
57+
if err := codec.Unmarshal([]byte(hardcodedConfig), &hardCodedData); err != nil {
58+
logger.Error("Error while marshaling configuration", "error", err)
59+
return ctx, err
60+
}
61+
62+
cfg, err := octoconfig.New(logger, cmd.StringSlice("config"), hardCodedData)
5163
if err != nil {
5264
logger.Error("Error while creating configuration", "error", err)
5365
return ctx, err
@@ -119,6 +131,11 @@ func runOperator(ctx context.Context, cmd *cli.Command, args []string) error {
119131
return fmt.Errorf("while getting cached URL: %w", err)
120132
}
121133

134+
if err := os.Chmod(url.Path, 0o700); err != nil {
135+
logger.Error("Error while chmoding cached operator", "error", err)
136+
return fmt.Errorf("while chmoding cached operator: %w", err)
137+
}
138+
122139
logger.Debug("Using cached operator", "url", binary.URL, "cached", url.Path)
123140
execPath = url.Path
124141
}
@@ -149,6 +166,8 @@ func runOperator(ctx context.Context, cmd *cli.Command, args []string) error {
149166
return err
150167
}
151168

169+
logger.Debug("Running operator", "path", execPath, "args", args)
170+
152171
execCmd := exec.CommandContext(ctx, execPath, args...) //nolint:gosec
153172
execCmd.Stdin = bytes.NewReader(b)
154173
execCmd.Stdout = os.Stdout

pkg/octocache/octocache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func checkSha256Sum(filePath, checksumPath string) error {
8888
fileHashStr := hex.EncodeToString(fileHash[:])
8989

9090
// Compare the hashes
91-
if strings.EqualFold(fileHashStr, checksumStr) {
91+
if !strings.EqualFold(fileHashStr, checksumStr) {
9292
return fmt.Errorf("checksum mismatch: expected %s, got %s", checksumStr, fileHashStr)
9393
}
9494

pkg/octoconfig/octoconfig.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,18 @@ type Config struct {
350350

351351
KnownURLs map[string]struct{}
352352

353+
// Hardcoded config
354+
HardcodedData map[string]any
355+
353356
// Merged data.
354357
Data map[string]any
355358

356359
ProjectID string
357360
}
358361

359362
// New creates a new configuration from the given paths.
360-
func New(logger log.Logger, paths []string) (*Config, error) {
361-
cfg := &Config{logger: logger, Paths: []*urlConfig{}, KnownURLs: map[string]struct{}{}, Repo: &Repo{}}
363+
func New(logger log.Logger, paths []string, hardcodedData map[string]any) (*Config, error) {
364+
cfg := &Config{logger: logger, Paths: []*urlConfig{}, KnownURLs: map[string]struct{}{}, Repo: &Repo{}, HardcodedData: hardcodedData}
362365

363366
for _, path := range paths {
364367
myURL, err := config.NewURL(path)
@@ -390,6 +393,8 @@ func New(logger log.Logger, paths []string) (*Config, error) {
390393
cfg.KnownURLs[myURL.String()] = struct{}{}
391394
}
392395

396+
cfg.HardcodedData = hardcodedData
397+
393398
return cfg, nil
394399
}
395400

@@ -481,6 +486,11 @@ func (c *Config) mergeRepos(ctx context.Context) error {
481486
repoFiles = append(repoFiles, slices.Collect(path.FlattenRepo())...)
482487
}
483488

489+
repoFile := &Repo{}
490+
if err := config.Parse(nil, "repos", c.Data, repoFile); err == nil {
491+
mergo.Merge(c.Repo, repoFile)
492+
}
493+
484494
slices.Reverse(repoFiles)
485495

486496
for _, repoFile := range repoFiles {
@@ -530,6 +540,11 @@ func (c *Config) merge(_ context.Context) error {
530540

531541
var mErr *multierror.Error
532542

543+
// Merge hardcoded data first.
544+
if err := config.Merge(&c.Data, c.HardcodedData); err != nil {
545+
mErr = multierror.Append(mErr, err)
546+
}
547+
533548
for _, cfg := range configs {
534549
// Log that we're merging this config.
535550
c.logger.Trace("Merging config", "url", cfg.URL.String())

0 commit comments

Comments
 (0)