Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Use the new libgitops GitDirectory implementation #615

Merged
merged 2 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
63 changes: 56 additions & 7 deletions cmd/ignited/cmd/gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,43 @@ package cmd

import (
"io"
"io/ioutil"
"time"

"github.com/lithammer/dedent"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/weaveworks/ignite/pkg/gitops"
"github.com/weaveworks/ignite/pkg/util"
"github.com/weaveworks/libgitops/pkg/gitdir"
)

type gitOpsFlags struct {
branch string
paths []string
branch string
interval time.Duration
timeout time.Duration

identityFile string
username string
password string

paths []string
hostsFile string
}

// NewCmdGitOps runs the GitOps functionality of Ignite
func NewCmdGitOps(out io.Writer) *cobra.Command {
f := &gitOpsFlags{
branch: "master",
paths: []string{},
branch: "master",
interval: 30 * time.Second,
timeout: 1 * time.Minute,

identityFile: "",
username: "",
password: "",

//paths: []string{},
//hostsFile: "~/.ssh/known_hosts",
}
cmd := &cobra.Command{
Use: "gitops <repo-url>",
Expand All @@ -35,7 +54,24 @@ func NewCmdGitOps(out io.Writer) *cobra.Command {
`),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
util.GenericCheckErr(gitops.RunGitOps(args[0], f.branch, f.paths))
opts := gitdir.GitDirectoryOptions{
Branch: f.branch,
Interval: f.interval,
Timeout: f.timeout,
}
if f.identityFile != "" {
var err error
opts.IdentityFileContent, err = ioutil.ReadFile(f.identityFile)
util.GenericCheckErr(err)
}
if f.username != "" {
opts.Username = &f.username
}
if f.password != "" {
opts.Password = &f.password
}

util.GenericCheckErr(gitops.RunGitOps(args[0], opts))
},
}

Expand All @@ -45,6 +81,19 @@ func NewCmdGitOps(out io.Writer) *cobra.Command {

func addGitOpsFlags(fs *pflag.FlagSet, f *gitOpsFlags) {
fs.StringVarP(&f.branch, "branch", "b", f.branch, "What branch to sync")
fs.StringSliceVarP(&f.paths, "paths", "p", f.paths, "What subdirectories to care about. Default the whole repository")
// TODO: Add ssh key opts etc.
fs.DurationVar(&f.interval, "interval", f.interval, "Sync interval for pushing to and pulling from the remote")
fs.DurationVar(&f.timeout, "timeout", f.timeout, "Git operation (clone, push, pull) timeout")

fs.StringVar(&f.identityFile, "identity-file", f.identityFile, "What SSH identity file to use for pushing")
fs.StringVar(&f.username, "https-username", f.username, "What username to use when authenticating with Git over HTTPS")
fs.StringVar(&f.password, "https-password", f.password, "What password/access token to use when authenticating with Git over HTTPS")

// TODO: We need to add path prefix support to the WatchStorage to support this
// fs.StringSliceVarP(&f.paths, "paths", "p", f.paths, "What subdirectories to care about. Default the whole repository")

// TODO: When https://github.com/fluxcd/toolkit/issues/2 is fixed and the
// https://github.com/fluxcd/source-controller/tree/master/internal/crypto/ssh/knownhosts package
// can be vendored, we'll add support for reading a hosts file. In the meantime, the
// SSH_KNOWN_HOSTS variable can be used.
// fs.StringVar(&f.hostsFile, "hosts-file", f.hostsFile, "What hosts file to use")
}
10 changes: 7 additions & 3 deletions docs/cli/ignited/ignited_gitops.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ ignited gitops <repo-url> [flags]
### Options

```
-b, --branch string What branch to sync (default "master")
-h, --help help for gitops
-p, --paths strings What subdirectories to care about. Default the whole repository
-b, --branch string What branch to sync (default "master")
-h, --help help for gitops
--https-password string What password/access token to use when authenticating with Git over HTTPS
--https-username string What username to use when authenticating with Git over HTTPS
--identity-file string What SSH identity file to use for pushing
--interval duration Sync interval for pushing to and pulling from the remote (default 30s)
--timeout duration Git operation (clone, push, pull) timeout (default 1m0s)
```

### Options inherited from parent commands
Expand Down
14 changes: 9 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ replace (

require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Microsoft/hcsshim v0.8.7 // indirect
github.com/alessio/shellescape v1.2.2
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 // indirect
github.com/c2h5oh/datasize v0.0.0-20200112174442-28bbd4740fee
github.com/containerd/cgroups v0.0.0-20200407151229-7fc7a507c04c // indirect
github.com/containerd/console v1.0.0
Expand All @@ -23,22 +25,23 @@ require (
github.com/containernetworking/plugins v0.8.5
github.com/containers/image v3.0.2+incompatible
github.com/coreos/go-iptables v0.4.5
github.com/docker/distribution v0.0.0-00010101000000-000000000000 // indirect
github.com/docker/docker v0.0.0-00010101000000-000000000000
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v1.4.2-0.20200203170920-46ec8731fbce
github.com/docker/go-connections v0.4.0
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
github.com/firecracker-microvm/firecracker-go-sdk v0.21.1-0.20200312220944-e6eaff81c885
github.com/freddierice/go-losetup v0.0.0-20170407175016-fc9adea44124
github.com/go-openapi/spec v0.19.7
github.com/gogo/googleapis v1.3.2 // indirect
github.com/googleapis/gnostic v0.3.1 // indirect
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e
github.com/gorilla/mux v1.7.4 // indirect
github.com/imdario/mergo v0.3.9 // indirect
github.com/krolaw/dhcp4 v0.0.0-20190909130307-a50d88189771
github.com/lithammer/dedent v1.1.0
github.com/miekg/dns v1.1.29
github.com/morikuni/aec v1.0.0 // indirect
github.com/nightlyone/lockfile v1.0.0
github.com/onsi/gomega v1.8.1 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1
github.com/opencontainers/image-spec v1.0.1
github.com/opencontainers/runc v0.1.1 // indirect
Expand All @@ -53,10 +56,11 @@ require (
github.com/stretchr/testify v1.5.1
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2 // indirect
github.com/vishvananda/netlink v1.1.0
github.com/weaveworks/libgitops v0.0.0-20200605124804-6f749e677cc0
github.com/weaveworks/libgitops v0.0.0-20200609112803-ee6851c3359a
go.etcd.io/bbolt v1.3.3 // indirect
golang.org/x/crypto v0.0.0-20200406173513-056763e48d71
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect
golang.org/x/sys v0.0.0-20200409092240-59c9f1ba88fa
google.golang.org/grpc v1.27.0 // indirect
gotest.tools v2.2.0+incompatible
k8s.io/apimachinery v0.18.1
k8s.io/kube-openapi v0.0.0-20200427153329-656914f816f9
Expand Down
Loading