Skip to content

Commit

Permalink
fix-ref/sha/tag (#107)
Browse files Browse the repository at this point in the history
* revert #98 
* checkout after clone

Co-authored-by: roi.kramer <[email protected]>
  • Loading branch information
ATGardner and roi-codefresh authored Jun 17, 2021
1 parent 3f70d9e commit c79e942
Show file tree
Hide file tree
Showing 14 changed files with 732 additions and 402 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ CLI_NAME?=argocd-autopilot
IMAGE_REPOSITORY?=quay.io
IMAGE_NAMESPACE?=argoprojlabs

INSTALLATION_MANIFESTS_URL="github.com/argoproj-labs/argocd-autopilot/manifests?tag=$(VERSION)"
INSTALLATION_MANIFESTS_NAMESPACED_URL="github.com/argoproj-labs/argocd-autopilot/manifests/namespace-install?tag=$(VERSION)"
INSTALLATION_MANIFESTS_URL="github.com/argoproj-labs/argocd-autopilot/manifests?ref=$(VERSION)"
INSTALLATION_MANIFESTS_NAMESPACED_URL="github.com/argoproj-labs/argocd-autopilot/manifests/namespace-install?ref=$(VERSION)"

DEV_INSTALLATION_MANIFESTS_URL="manifests/"
DEV_INSTALLATION_MANIFESTS_NAMESPACED_URL="manifests/namespace-install"
Expand Down
4 changes: 3 additions & 1 deletion cmd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ var setAppOptsDefaults = func(ctx context.Context, repofs fs.FS, opts *AppCreate
// local directory
fsys = fs.Create(osfs.New(opts.AppOpts.AppSpecifier))
} else {
log.G().Infof("trying to infer application type from '%s'", opts.AppOpts.AppSpecifier)
host, orgRepo, p, _, _, suffix, _ := util.ParseGitUrl(opts.AppOpts.AppSpecifier)
url := host + orgRepo + suffix
log.G().Infof("cloning repo: '%s', to infer app type from path '%s'", url, p)
cloneOpts := &git.CloneOptions{
Repo: opts.AppOpts.AppSpecifier,
Auth: opts.CloneOpts.Auth,
Expand Down
5 changes: 2 additions & 3 deletions cmd/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func NewRepoBootstrapCommand() *cobra.Command {
},
}

cmd.Flags().StringVar(&appSpecifier, "app", "", "The application specifier (e.g. argocd@v1.0.2)")
cmd.Flags().StringVar(&appSpecifier, "app", "", "The application specifier (e.g. github.com/argoproj-labs/argocd-autopilot/manifests?ref=v0.2.5), overrides the default installation argo-cd manifests")
cmd.Flags().BoolVar(&namespaced, "namespaced", false, "If true, install a namespaced version of argo-cd (no need for cluster-role)")
cmd.Flags().BoolVar(&dryRun, "dry-run", false, "If true, print manifests instead of applying them to the cluster (nothing will be commited to git)")
cmd.Flags().BoolVar(&hidePassword, "hide-password", false, "If true, will not print initial argo cd password")
Expand Down Expand Up @@ -264,7 +264,6 @@ func RunRepoCreate(ctx context.Context, opts *RepoCreateOptions) (*git.CloneOpti
Password: opts.Token,
},
}

co.Parse()
return co, nil
}
Expand Down Expand Up @@ -664,7 +663,7 @@ func createBootstrapKustomization(namespace, repoURL, appSpecifier string) (*kus
}

func createCreds(repoUrl string) ([]byte, error) {
host, _, _, _, _ := git.ParseGitUrl(repoUrl)
host, _, _, _, _, _, _ := util.ParseGitUrl(repoUrl)
creds := []argocdsettings.RepositoryCredentials{
{
URL: host,
Expand Down
1 change: 1 addition & 0 deletions cmd/commands/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ func Test_buildBootstrapManifests(t *testing.T) {
for tname, tt := range tests {
t.Run(tname, func(t *testing.T) {
tt.args.cloneOpts.Parse()

b, ret := buildBootstrapManifests(
tt.args.namespace,
tt.args.appSpecifier,
Expand Down
41 changes: 41 additions & 0 deletions docs/App-Specifier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# The Application Specifier

The application specifier is a string denoting the entrypoint to the application that you want to create. You specify it when using the `--app`
flag in the `app create` and `repo bootstrap` commands.

## Structure
Lets look at the following example of adding argo workflows v3.0.7 to project `prod` to better understand the structure of the application specifier:
```bash
argocd-autopilot app create workflows --app "github.com/argoproj/argo-workflows/manifests/cluster-install?ref=v3.0.7" --project prod
```
In this example the app specifier is: `github.com/argoproj/argo-workflows/manifests/cluster-install?ref=v3.0.7`, which is composed of three parts:

1. `github.com/argoproj/argo-workflows`: The repository
2. `manifests/cluster-install`: The path inside the repository to the directory containing the base `kustomization.yaml`
3. `?ref=v3.0.7`: The git ref to use, in this case, the tag `v3.0.7`

!!! note
The `ref` that will be used to get the application manifests is calculated using the following logic:

1. If not specified - uses the HEAD of the main branch of the repository
2. If there is a commit with the same SHA use this commit
3. Looks for a tag with the same name
4. Looks for a branch with the same name

## Application Type Inference
By default, `argocd-autopilot` will try to automatically infer the correct application type from the supported [application types](https://argoproj.github.io/argo-cd/user-guide/application_sources/#tools) (currently only kustomize and directory types are supported). To do that it would try to clone the repository, checkout the correct ref, and look at the specified path for the following:

1. If there is a `kustomization.yaml` - the infered application type is `kustomize`
2. Else - the infered application type is `directory`

!!! tip
If you don't want `argocd-autopilot` to infer the type automatically, you can specify the application type yourself using the `--type` flag.

## Local Application Path
If the application specifier is a path to a local directory on your machine, `argocd autopilot` will automatically detect that and use `flat` installation mode, meaning it would build all of the manifests and write them into one `install.yaml` file, which would be required by a base `kustomization.yaml`.

For example:
```
argocd-autopilot app create someapp --app ./path/to/kustomization/dir --project dev
```
Assuming the file `./path/to/kustomization/dir/kustomization.yaml` exists, `argocd-autopilot` will run `kustomize build`, then commit the resulting manifests to the gitops repository under: `apps/someapp/base/install.yaml`, with the base kustomization, located at `apps/someapp/base/kustomization.yaml`, requiring it.
2 changes: 1 addition & 1 deletion docs/commands/argocd-autopilot_repo_bootstrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ argocd-autopilot repo bootstrap [flags]
### Options

```
--app string The application specifier (e.g. argocd@v1.0.2)
--app string The application specifier (e.g. github.com/argoproj-labs/argocd-autopilot/manifests?ref=v0.2.5), overrides the default installation argo-cd manifests
--as string Username to impersonate for the operation
--as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
--cache-dir string Default cache directory (default "/home/user/.kube/cache")
Expand Down
2 changes: 1 addition & 1 deletion manifests/namespace-install/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- https://raw.githubusercontent.com/argoproj/argo-cd/v2.0.0/manifests/namespace-install.yaml
- https://raw.githubusercontent.com/argoproj-labs/applicationset/v0.1.0/manifests/install.yaml
- https://raw.githubusercontent.com/argoproj-labs/applicationset/master/manifests/install.yaml # TODO: switch to the next release when available
5 changes: 4 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ markdown_extensions:
permalink: true
nav:
- Introduction: index.md
- Getting Started: Getting-Started.md
- Installation: Installation-Guide.md
- User Guide:
- Getting Started: Getting-Started.md
- Application Specifier: App-Specifier.md
- Command Reference: commands/argocd-autopilot.md
- Development: Development.md
- Roadmap: Roadmap.md
- Blogs: Blogs.md
Expand Down
15 changes: 7 additions & 8 deletions pkg/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"reflect"

"github.com/argoproj-labs/argocd-autopilot/pkg/fs"
"github.com/argoproj-labs/argocd-autopilot/pkg/git"
"github.com/argoproj-labs/argocd-autopilot/pkg/kube"
"github.com/argoproj-labs/argocd-autopilot/pkg/log"
"github.com/argoproj-labs/argocd-autopilot/pkg/store"
"github.com/argoproj-labs/argocd-autopilot/pkg/util"

"github.com/ghodss/yaml"
billyUtils "github.com/go-git/go-billy/v5/util"
Expand Down Expand Up @@ -399,18 +399,17 @@ func newDirApp(opts *CreateOptions) *dirApp {
app := &dirApp{
baseApp: baseApp{opts},
}
cloneOpts := &git.CloneOptions{
Repo: opts.AppSpecifier,
}
cloneOpts.Parse()

host, orgRepo, path, gitRef, _, suffix, _ := util.ParseGitUrl(opts.AppSpecifier)
url := host + orgRepo + suffix
app.config = &Config{
AppName: opts.AppName,
UserGivenName: opts.AppName,
DestNamespace: opts.DestNamespace,
DestServer: opts.DestServer,
SrcRepoURL: cloneOpts.URL(),
SrcPath: cloneOpts.Path(),
SrcTargetRevision: cloneOpts.Revision(),
SrcRepoURL: url,
SrcPath: path,
SrcTargetRevision: gitRef,
}

return app
Expand Down
Loading

0 comments on commit c79e942

Please sign in to comment.