Skip to content

Commit

Permalink
Avoid argocd login (#36)
Browse files Browse the repository at this point in the history
* got rid of interfacer
* added codegen to ci-cd flow
* added login to argocd after repo bootstrap
* increased test coverage
  • Loading branch information
roi-codefresh authored May 4, 2021
1 parent e91be0c commit a0e9542
Show file tree
Hide file tree
Showing 24 changed files with 936 additions and 142 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ test:
./hack/test.sh

.PHONY: codegen
codegen: $(GOBIN)/mockery $(GOBIN)/interfacer
codegen: $(GOBIN)/mockery
go generate ./...

.PHONY: pre-commit
pre-commit: lint

.PHONY: pre-push
pre-push: codegen test check-worktree
pre-push: lint test codegen check-worktree

.PHONY: build-docs
build-docs:
Expand Down
35 changes: 13 additions & 22 deletions build/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ steps:
on:
- success

codegen:
<<: *deps
stage: Test
title: check codegen
commands:
- make codegen
- make check-worktree
when:
steps:
- name: prepare_env_vars
on:
- success

test:
<<: *deps
stage: Test
Expand Down Expand Up @@ -102,19 +115,6 @@ steps:
- name: main_clone
on:
- success

# codegen:
# <<: *deps
# stage: Test
# title: compile and check codegen
# commands:
# - make codegen
# - make check-worktree
# when:
# steps:
# - name: test
# on:
# - success

push_dev:
stage: Push Dev
Expand All @@ -128,15 +128,6 @@ steps:
- name: build
on:
- success
- name: test
on:
- success
- name: lint
on:
- success
# - name: codegen
# on:
# - success
branch:
ignore: [ "main" ]
scale:
Expand Down
30 changes: 17 additions & 13 deletions build/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ steps:
- name: download_modules
on:
- success

codegen:
<<: *deps
stage: Release
title: check codegen
commands:
- make codegen
- make check-worktree
when:
steps:
- name: download_modules
on:
- success

test:
<<: *deps
Expand All @@ -91,6 +104,7 @@ steps:
on:
- success


codecov-report:
stage: Test
type: codecov-reporter
Expand Down Expand Up @@ -154,6 +168,9 @@ steps:
- name: test
on:
- success
- name: codegen
on:
- success
- name: lint
on:
- success
Expand All @@ -175,19 +192,6 @@ steps:
on:
- success

# codegen:
# <<: *deps
# stage: Release
# title: check codegen
# commands:
# - make codegen
# - make check-worktree
# when:
# steps:
# - name: build_binaries
# on:
# - success

push_prod:
stage: Release
title: promote images
Expand Down
2 changes: 1 addition & 1 deletion cmd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewAppCommand() *cobra.Command {
Short: "Manage applications",
Run: func(cmd *cobra.Command, args []string) {
cmd.HelpFunc()(cmd, args)
os.Exit(1)
exit(1)
},
}
opts, err := addFlags(cmd)
Expand Down
95 changes: 50 additions & 45 deletions cmd/commands/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"context"
"fmt"
"os"

"github.com/argoproj/argocd-autopilot/pkg/fs"
"github.com/argoproj/argocd-autopilot/pkg/git"
Expand All @@ -22,6 +23,55 @@ type (
}
)

// used for mocking
var (
die = util.Die
exit = os.Exit

clone = func(ctx context.Context, cloneOpts *git.CloneOptions, filesystem fs.FS) (git.Repository, fs.FS, error) {
return cloneOpts.Clone(ctx, filesystem)
}

prepareRepo = func(ctx context.Context, o *BaseOptions) (git.Repository, fs.FS, error) {
var (
r git.Repository
err error
)
log.G().WithFields(log.Fields{
"repoURL": o.CloneOptions.URL,
"revision": o.CloneOptions.Revision,
}).Debug("starting with options: ")

// clone repo
log.G().Infof("cloning git repository: %s", o.CloneOptions.URL)
r, repofs, err := clone(ctx, o.CloneOptions, o.FS)
if err != nil {
return nil, nil, fmt.Errorf("Failed cloning the repository: %w", err)
}

root := repofs.Root()
log.G().Infof("using revision: \"%s\", installation path: \"%s\"", o.CloneOptions.Revision, root)
if !repofs.ExistsOrDie(store.Default.BootsrtrapDir) {
cmd := "repo bootstrap"
if root != "/" {
cmd += " --installation-path " + root
}

return nil, nil, fmt.Errorf("Bootstrap directory not found, please execute `%s` command", cmd)
}

if o.ProjectName != "" {
projExists := repofs.ExistsOrDie(repofs.Join(store.Default.ProjectsDir, o.ProjectName+".yaml"))
if !projExists {
return nil, nil, fmt.Errorf(util.Doc(fmt.Sprintf("project '%[1]s' not found, please execute `<BIN> project create %[1]s`", o.ProjectName)))
}
}

log.G().Debug("repository is ok")
return r, repofs, nil
}
)

func addFlags(cmd *cobra.Command) (*BaseOptions, error) {
cloneOptions, err := git.AddFlags(cmd)
if err != nil {
Expand All @@ -35,48 +85,3 @@ func addFlags(cmd *cobra.Command) (*BaseOptions, error) {
cmd.PersistentFlags().StringVarP(&o.ProjectName, "project", "p", "", "Project name")
return o, nil
}

var prepareRepo = func(ctx context.Context, o *BaseOptions) (git.Repository, fs.FS, error) {
var (
r git.Repository
err error
)
log.G().WithFields(log.Fields{
"repoURL": o.CloneOptions.URL,
"revision": o.CloneOptions.Revision,
}).Debug("starting with options: ")

// clone repo
log.G().Infof("cloning git repository: %s", o.CloneOptions.URL)
r, repofs, err := clone(ctx, o.CloneOptions, o.FS)
if err != nil {
return nil, nil, fmt.Errorf("Failed cloning the repository: %w", err)
}

root := repofs.Root()
log.G().Infof("using revision: \"%s\", installation path: \"%s\"", o.CloneOptions.Revision, root)
if !repofs.ExistsOrDie(store.Default.BootsrtrapDir) {
cmd := "repo bootstrap"
if root != "/" {
cmd += " --installation-path " + root
}

return nil, nil, fmt.Errorf("Bootstrap directory not found, please execute `%s` command", cmd)
}

if o.ProjectName != "" {
projExists := repofs.ExistsOrDie(repofs.Join(store.Default.ProjectsDir, o.ProjectName+".yaml"))
if !projExists {
return nil, nil, fmt.Errorf(util.Doc(fmt.Sprintf("project '%[1]s' not found, please execute `<BIN> project create %[1]s`", o.ProjectName)))
}
}

log.G().Debug("repository is ok")
return r, repofs, nil
}

var clone = func(ctx context.Context, cloneOpts *git.CloneOptions, filesystem fs.FS) (git.Repository, fs.FS, error) {
return cloneOpts.Clone(ctx, filesystem)
}

var die = util.Die
5 changes: 2 additions & 3 deletions cmd/commands/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/argoproj/argocd-autopilot/pkg/argocd"
Expand Down Expand Up @@ -43,7 +42,7 @@ func NewProjectCommand() *cobra.Command {
Short: "Manage projects",
Run: func(cmd *cobra.Command, args []string) {
cmd.HelpFunc()(cmd, args)
os.Exit(1)
exit(1)
},
}

Expand Down Expand Up @@ -81,7 +80,7 @@ func NewProjectCreateCommand() *cobra.Command {
# Create a new project in a specific path inside the GitOps repo
<BIN> project create <PROJECT_NAME> --installation-path path/to/bootstrap/root
<BIN> project create <PROJECT_NAME> --installation-path path/to/installation_root
`),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
Expand Down
Loading

0 comments on commit a0e9542

Please sign in to comment.