From 8698fce8f866f9334f60be30d094b94dad6ebf2f Mon Sep 17 00:00:00 2001 From: Gavin Staniforth Date: Wed, 9 Feb 2022 10:23:17 +0000 Subject: [PATCH 1/2] build: use specific version of alpine --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 66bbd38..850483f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3 +FROM alpine:3.15 ENV SLACK_SIGNING_SECRET="" ENV PORT=8080 @@ -7,4 +7,4 @@ ENV SSH_KNOWN_HOSTS="/etc/ssh/ssh_known_hosts" RUN apk add --no-cache openssh-client && ssh-keyscan -H github.com >> /etc/ssh/ssh_known_hosts ENTRYPOINT ["/gitops-commit"] -COPY gitops-commit / \ No newline at end of file +COPY gitops-commit / From 60bfe5ce12979ede5dffb1410255156094dc5181 Mon Sep 17 00:00:00 2001 From: Gavin Staniforth Date: Wed, 9 Feb 2022 20:21:18 +0000 Subject: [PATCH 2/2] feat: improve the error handling to bubble up --- internal/app/gitops-commit/cmd/run.go | 4 +--- internal/pkg/gitops/git.go | 14 ++++++++------ internal/pkg/gitops/handler.go | 4 +--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/internal/app/gitops-commit/cmd/run.go b/internal/app/gitops-commit/cmd/run.go index 3c5b13f..3464d04 100644 --- a/internal/app/gitops-commit/cmd/run.go +++ b/internal/app/gitops-commit/cmd/run.go @@ -37,15 +37,13 @@ func newRunCommand() *cobra.Command { defer c() - err = gitops.DeployVersionHandler(gitops.DeployVersionCommand{ + return gitops.DeployVersionHandler(gitops.DeployVersionCommand{ GitOptions: *options, Repository: repo, Notation: notation, File: file, Version: newVersion, }) - - return err }, } diff --git a/internal/pkg/gitops/git.go b/internal/pkg/gitops/git.go index c09aa00..4f3ce3f 100644 --- a/internal/pkg/gitops/git.go +++ b/internal/pkg/gitops/git.go @@ -38,16 +38,16 @@ func NewGitOptions(keys *ssh.PublicKeys) (*GitOptions, func(), error) { }, nil } -func PushVersion(r *git.Repository, options *GitOptions, file string, message string) { +func PushVersion(r *git.Repository, options *GitOptions, file string, message string) error { tree, err := r.Worktree() if err != nil { - panic(err) + return err } _, err = tree.Add(file) if err != nil { - panic(err) + return fmt.Errorf("failed to stage file for comit:%w", err) } commit, err := tree.Commit(message, &git.CommitOptions{ @@ -59,13 +59,13 @@ func PushVersion(r *git.Repository, options *GitOptions, file string, message st }) if err != nil { - panic(err) + return fmt.Errorf("failed to commit: %w", err) } _, err = r.CommitObject(commit) if err != nil { - panic(err) + return fmt.Errorf("failed to commit: %w", err) } err = r.Push(&git.PushOptions{ @@ -73,8 +73,10 @@ func PushVersion(r *git.Repository, options *GitOptions, file string, message st }) if err != nil { - panic(err) + return fmt.Errorf("failed to push change to the repo: %w", err) } + + return nil } func GetPasswordlessKey(key string) (*ssh.PublicKeys, error) { diff --git a/internal/pkg/gitops/handler.go b/internal/pkg/gitops/handler.go index cfece50..5080695 100644 --- a/internal/pkg/gitops/handler.go +++ b/internal/pkg/gitops/handler.go @@ -38,7 +38,5 @@ func DeployVersionHandler(c DeployVersionCommand) error { return fmt.Errorf("cannot write new version: %w", err) } - PushVersion(r, &c.GitOptions, c.File, fmt.Sprintf("ci: update tag to %s", c.Version)) - - return nil + return PushVersion(r, &c.GitOptions, c.File, fmt.Sprintf("ci: update tag to %s", c.Version)) }