From d0a03f50ab2fbca8d2579da2dcbb27b1d572bb61 Mon Sep 17 00:00:00 2001 From: Gavin Staniforth Date: Wed, 9 Feb 2022 20:24:34 +0000 Subject: [PATCH 1/3] feat: add entrypoint to container for pulling github known hosts --- Dockerfile | 4 +++- entrypoint.sh | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 850483f..e080e95 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,5 +6,7 @@ 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 entrypoint.sh . + +ENTRYPOINT ["/entrypoint.sh"] COPY gitops-commit / diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..3f415c8 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,6 @@ +#/bin/sh +set -e + +ssh-keyscan -H github.com >> /etc/ssh/ssh_known_hosts + +exec "$@" \ No newline at end of file From 0ba3653e5a67242998a9a9a721368860c1fbc60d Mon Sep 17 00:00:00 2001 From: Gavin Staniforth Date: Fri, 2 Sep 2022 10:28:12 +0100 Subject: [PATCH 2/3] feat: add the abilty to set a conventional commit scope --- internal/app/gitops-commit/cmd/run.go | 13 ++++++++----- internal/pkg/gitops/handler.go | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/internal/app/gitops-commit/cmd/run.go b/internal/app/gitops-commit/cmd/run.go index 3464d04..d04f965 100644 --- a/internal/app/gitops-commit/cmd/run.go +++ b/internal/app/gitops-commit/cmd/run.go @@ -12,6 +12,7 @@ func newRunCommand() *cobra.Command { c := cobra.Command{ Use: "run", RunE: func(cmd *cobra.Command, args []string) error { + commitScope := cmd.Flag("commit-scope").Value.String() key := cmd.Flag("key").Value.String() email := cmd.Flag("email").Value.String() newVersion := cmd.Flag("version").Value.String() @@ -38,15 +39,17 @@ func newRunCommand() *cobra.Command { defer c() return gitops.DeployVersionHandler(gitops.DeployVersionCommand{ - GitOptions: *options, - Repository: repo, - Notation: notation, - File: file, - Version: newVersion, + GitOptions: *options, + Repository: repo, + Notation: notation, + File: file, + Version: newVersion, + CommitScope: commitScope, }) }, } + c.Flags().String("commit-scope", "", "If you want to add a commit scope inline with conventional commits") c.Flags().String("notation", "", "The yaml path in dot notation i.e. image.tag") c.Flags().String("email", "", "The email address of the commit") c.Flags().String("version", "", "The semver version you want to deploy i.e. v1.1.2") diff --git a/internal/pkg/gitops/handler.go b/internal/pkg/gitops/handler.go index 5080695..7d3215a 100644 --- a/internal/pkg/gitops/handler.go +++ b/internal/pkg/gitops/handler.go @@ -6,11 +6,12 @@ import ( ) type DeployVersionCommand struct { - GitOptions GitOptions - Repository string - Notation string - File string - Version string + GitOptions GitOptions + Repository string + Notation string + File string + Version string + CommitScope string } func DeployVersionHandler(c DeployVersionCommand) error { @@ -38,5 +39,11 @@ func DeployVersionHandler(c DeployVersionCommand) error { return fmt.Errorf("cannot write new version: %w", err) } - return PushVersion(r, &c.GitOptions, c.File, fmt.Sprintf("ci: update tag to %s", c.Version)) + message := fmt.Sprintf("ci: update tag to %s", c.Version) + + if len(c.CommitScope) > 0 { + message = fmt.Sprintf("ci(%s): update tag to %s", c.CommitScope, c.Version) + } + + return PushVersion(r, &c.GitOptions, c.File, message) } From 59ea72e316a5b0a822330969c21d6cd175e1f399 Mon Sep 17 00:00:00 2001 From: Gavin Staniforth Date: Fri, 2 Sep 2022 10:35:37 +0100 Subject: [PATCH 3/3] refactor: remove deprecated usages of ioutil (dep 1.16) for replacements --- internal/app/gitops-commit/slackhttp/manifest.go | 4 ++-- internal/app/gitops-commit/slackhttp/middleware.go | 3 +-- internal/pkg/gitops/git.go | 3 +-- internal/pkg/gitops/handler.go | 4 ++-- internal/pkg/gitops/version.go | 4 ++-- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/internal/app/gitops-commit/slackhttp/manifest.go b/internal/app/gitops-commit/slackhttp/manifest.go index 9ee5926..7aca18e 100644 --- a/internal/app/gitops-commit/slackhttp/manifest.go +++ b/internal/app/gitops-commit/slackhttp/manifest.go @@ -3,7 +3,7 @@ package slackhttp import ( "fmt" "gopkg.in/yaml.v3" - "io/ioutil" + "os" ) type Manifest struct { @@ -29,7 +29,7 @@ func LoadManifest(f string) (*Manifest, error) { registry: NewNamedRepositoryRegistry(), } - d, err := ioutil.ReadFile(f) + d, err := os.ReadFile(f) if err != nil { return nil, fmt.Errorf("cannot read yaml file: %w", err) diff --git a/internal/app/gitops-commit/slackhttp/middleware.go b/internal/app/gitops-commit/slackhttp/middleware.go index a372794..cc4729f 100644 --- a/internal/app/gitops-commit/slackhttp/middleware.go +++ b/internal/app/gitops-commit/slackhttp/middleware.go @@ -4,7 +4,6 @@ import ( "github.com/google/martian/log" "github.com/slack-go/slack" "io" - "io/ioutil" "net/http" ) @@ -17,7 +16,7 @@ func (s *server) SlackCommandMiddleware(next func(w http.ResponseWriter, s slack return } - r.Body = ioutil.NopCloser(io.TeeReader(r.Body, &verifier)) + r.Body = io.NopCloser(io.TeeReader(r.Body, &verifier)) s, err := slack.SlashCommandParse(r) if err != nil { w.WriteHeader(http.StatusInternalServerError) diff --git a/internal/pkg/gitops/git.go b/internal/pkg/gitops/git.go index 4f3ce3f..99274f8 100644 --- a/internal/pkg/gitops/git.go +++ b/internal/pkg/gitops/git.go @@ -5,7 +5,6 @@ import ( "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing/object" "github.com/go-git/go-git/v5/plumbing/transport/ssh" - "io/ioutil" "os" "time" ) @@ -19,7 +18,7 @@ type GitOptions struct { } func NewGitOptions(keys *ssh.PublicKeys) (*GitOptions, func(), error) { - dir, err := ioutil.TempDir("/tmp", "prefix") + dir, err := os.MkdirTemp("/tmp", "prefix") if err != nil { return nil, nil, err } diff --git a/internal/pkg/gitops/handler.go b/internal/pkg/gitops/handler.go index 7d3215a..e17bc1e 100644 --- a/internal/pkg/gitops/handler.go +++ b/internal/pkg/gitops/handler.go @@ -2,7 +2,7 @@ package gitops import ( "fmt" - "io/ioutil" + "os" ) type DeployVersionCommand struct { @@ -23,7 +23,7 @@ func DeployVersionHandler(c DeployVersionCommand) error { filename := fmt.Sprintf("%s/%s", c.GitOptions.WorkingDirectory, c.File) - f, err := ioutil.ReadFile(filename) + f, err := os.ReadFile(filename) if err != nil { return fmt.Errorf("cannot read file: %w", err) diff --git a/internal/pkg/gitops/version.go b/internal/pkg/gitops/version.go index 9e38b48..4a831e6 100644 --- a/internal/pkg/gitops/version.go +++ b/internal/pkg/gitops/version.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" "gopkg.in/yaml.v3" - "io/ioutil" + "os" "regexp" "strconv" "strings" @@ -32,7 +32,7 @@ func ReadCurrentVersion(f []byte, notation string) (string, error) { func WriteVersion(f []byte, version string, newVersion string, filename string) error { output := bytes.Replace(f, []byte(version), []byte(newVersion), -1) - err := ioutil.WriteFile(filename, output, 0666) + err := os.WriteFile(filename, output, 0666) if err != nil { return fmt.Errorf("cannot replace version: %w", err)