Skip to content

Commit

Permalink
Add init command for creating new configuration (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
baksetercx authored Jan 3, 2025
1 parent 77693be commit 2e9d1b6
Show file tree
Hide file tree
Showing 17 changed files with 438 additions and 147 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ issues:
- linters:
- varnamelen
text: "parameter name 'c' is too short for the scope of its usage"
- linters:
- gochecknoglobals
text: "Command is a global variable"
- linters:
- gochecknoglobals
text: "Dotnet.* is a global variable"
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# cli

Command Line Interface tool for developing, building and securing Elvia applications ⚡
Command Line Interface tool for creating, building and securing Elvia applications ⚡

## 🚀 Features

- **Build** Docker images for .NET and Go projects without needing a Dockerfile.
- **Scan** Docker images for vulnerabilities using Trivy.
- **Build** a container for .NET, Go or Python projects without needing a Dockerfile.
- **Scan** a container for vulnerabilities using Trivy.
- **Deploy** to Azure Kubernetes Service, Google Kubernetes Engine and ISS.
- **Create** new projects with all batteries included.
- **Generate** GitHub Actions workflows for building and deploying to Elvia's clusters on Azure, Google Cloud and ISS.
- **Create** new projects from Elvia templates, with all batteries included.
- **Generate** a GitHub Actions workflow for building and deploying to Elvia's clusters on Azure, Google Cloud and ISS.

The GitHub composite actions at [core-github-actions-templates](https://github.com/3lvia/core-github-actions-templates) are wrappers around many of the CLI commands.
The GitHub Actions composite actions at [core-github-actions-templates](https://github.com/3lvia/core-github-actions-templates) are wrappers around many of the CLI commands.
Therefore it's useful to use the CLI when debugging or testing Elvias actions, since you can very easily reproduce the same commands locally.

## 📚 Documentation
Expand Down
55 changes: 44 additions & 11 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,56 @@

The CLI assumes that you are in the git repository of the project you are working on.

### Init

<details>

<summary>Expand</summary>

#### Create a new 3lv configuration file

```bash
# you will be prompted for input
3lv init
```

This will create a `3lv.yml` file in the root of your repository.
The advantage of having a configuration file is that you can avoid typing the same options every time you run a command.

### Build

<details>

<summary>Expand</summary>

#### Build a Docker image for a .NET project
#### Build a container for a .NET project

```bash
3lv build --project-file src/MyProject.csproj --system-name core my-cool-application
# or use shorthand
3lv build -f src/MyProject.csproj -s core my-cool-application
# or with 3lv.yml
3lv build my-cool-application
```

#### Build a Docker image for a .NET project and push it to Elvias registry
#### Build a container for a .NET project and push it to Elvia's registry

```bash
3lv build --project-file src/MyProject.csproj --system-name core --push my-cool-application
# or use shorthand
3lv build -f src/MyProject.csproj -s core -p my-cool-application
# or with 3lv.yml
3lv build -p my-cool-application
```

#### Build a Docker image for a Go project and push it to GitHub Container Registry
#### Build a container for a Go project and push it to GitHub Container Registry

```bash
3lv build --project-file src/MyProject.csproj --system-name core --push --registry ghcr my-cool-application
# or use shorthand
3lv build -f src/MyProject.csproj -s core -p -r ghcr my-cool-application
# or with 3lv.yml
3lv build -p -r ghcr my-cool-application
```

#### Generate a Dockerfile for a .NET project
Expand All @@ -38,6 +60,8 @@ The CLI assumes that you are in the git repository of the project you are workin
3lv build --project-file src/MyProject.csproj --system-name core --generate-only my-cool-application
# or use shorthand
3lv build -f src/MyProject.csproj -s core -G my-cool-application
# or with 3lv.yml
3lv build -G my-cool-application
```

</details>
Expand All @@ -48,21 +72,21 @@ The CLI assumes that you are in the git repository of the project you are workin

<summary>Expand</summary>

#### Scan a Docker image for vulnerabilities
#### Scan a container for vulnerabilities

```bash
3lv scan my-cool-image
```

#### Scan a Docker image for critical vulnerabilities only
#### Scan a container for critical vulnerabilities only

```bash
3lv scan --severity CRITICAL my-cool-image
# or use shorthand
3lv scan -S CRITICAL my-cool-image
```

#### Scan a Docker image for vulnerabilities and output the results to JSON and Markdown
#### Scan a container for vulnerabilities and output the results to JSON and Markdown

```bash
3lv scan --formats json,markdown my-cool-image
Expand All @@ -78,7 +102,7 @@ The CLI assumes that you are in the git repository of the project you are workin

<summary>Expand</summary>

### Generate GitHub Actions workflow for Kubernetes deploy
### Generate a GitHub Actions workflow for deploying to Kubernetes

```bash
3lv github-actions --system-name core --application-name my-cool-application --project-file src/MyProject.csproj
Expand All @@ -89,7 +113,7 @@ The CLI assumes that you are in the git repository of the project you are workin
Remember to also add your repository to [github-repositories-terraform](https://github.com/3lvia/github-repositories-terraform)
to enable access from GitHub Actions to Kubernetes.

### Generate GitHub Actions workflow for Kubernetes deploy with existing Helm values file on ISS
### Generate a GitHub Actions workflow for deploying to ISS, using an existing Helm values file

```bash
3lv github-actions --system-name core --application-name my-cool-application --runtime-cloud-provider iss --helm-values-file CI/values.yml --project-file src/MyProject.csproj
Expand Down Expand Up @@ -119,11 +143,20 @@ in [iss-terraform](https://github.com/3lvia/iss-terraform) to enable access from
#### Create a new Python API in the current directory

```bash
3lv create --system-name core --application-name my-cool-application --template python-api .
3lv create --system-name core --application-name my-cool-application --template python-webapi .
# or use shorthand
3lv create -s core -a my-cool-application -t dotnet8-webapi .
3lv create -s core -a my-cool-application -t python-webapi .
```

#### Create a new Go API in the current directory

```bash
3lv create --system-name core --application-name my-cool-application --template go-webapi .
# or use shorthand
3lv create -s core -a my-cool-application -t go-webapi .
```

#### Create a new .NET 8 API in the applications directory of a monorepo, putting the GitHub Actions workflows in the the root of the repository
#### Create a new .NET 8 API in the `applications` directory of a monorepo, putting the GitHub Actions workflows in the the root of the repository

```bash
3lv create --system-name core --application-name my-cool-application --template dotnet8-webapi --github-actions-directory . applications
Expand Down
14 changes: 7 additions & 7 deletions docs/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

To use every part of the 3lv CLI, you need to have these dependencies installed:

- [git](https://git-scm.com/downloads): used for several subcommands.
- [Docker](https://docs.docker.com/engine/install): used for building.
- [Helm](https://helm.sh/docs/intro/install): used for deploying.
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl): used for deploying.
- [Trivy](https://aquasecurity.github.io/trivy): used for scanning Docker images.
- [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli): used for pushing to Azure Container Registry and deploying to Azure Kubernetes Service.
- [Google Cloud SDK](https://cloud.google.com/sdk/docs/install): used for deploying to Google Kubernetes Engine.
- [git](https://git-scm.com/downloads): used for several commands.
- [Docker](https://docs.docker.com/engine/install): used for building containers.
- [Helm](https://helm.sh/docs/intro/install): used for deploying containers.
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl): used for deploying containers.
- [Trivy](https://aquasecurity.github.io/trivy): used for scanning containers.
- [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli): used for pushing containers to Azure Container Registry and deploying containers to Azure Kubernetes Service.
- [Google Cloud SDK](https://cloud.google.com/sdk/docs/install): used for deploying containers to Google Kubernetes Engine.
- [cookiecutter](https://cookiecutter.readthedocs.io/en/stable/installation.html): used for creating new projects; if [pipx](https://pipx.pypa.io/stable) is installed, the CLI will prompt you to install cookiecutter for you.

**Any of these dependencies can be skipped if you dont't use the subcommands that require them.**
Expand Down
16 changes: 15 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,27 @@ require (
)

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/catppuccin/go v0.2.0 // indirect
github.com/charmbracelet/bubbles v0.20.0 // indirect
github.com/charmbracelet/bubbletea v1.1.0 // indirect
github.com/charmbracelet/huh v0.6.0 // indirect
github.com/charmbracelet/x/ansi v0.6.0 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
)
31 changes: 31 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA=
github.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
github.com/charmbracelet/bubbletea v1.1.0 h1:FjAl9eAL3HBCHenhz/ZPjkKdScmaS5SK69JAK2YJK9c=
github.com/charmbracelet/bubbletea v1.1.0/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4=
github.com/charmbracelet/huh v0.6.0 h1:mZM8VvZGuE0hoDXq6XLxRtgfWyTI3b2jZNKh0xWmax8=
github.com/charmbracelet/huh v0.6.0/go.mod h1:GGNKeWCeNzKpEOh/OJD8WBwTQjV3prFAtQPpLv+AVwU=
github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo=
github.com/charmbracelet/x/ansi v0.6.0 h1:qOznutrb93gx9oMiGf7caF7bqqubh6YIM0SWKyA08pA=
github.com/charmbracelet/x/ansi v0.6.0/go.mod h1:KBUFw1la39nl0dLl10l5ORDAqGXaeurTQmwyyVKse/Q=
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 h1:qko3AQ4gK1MTS/de7F5hPGx6/k1u0w4TeYmBFwzYVP4=
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ=
github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
Expand All @@ -19,10 +37,20 @@ github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ=
github.com/matryer/is v1.4.1/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a h1:2MaM6YC3mGu54x+RKAA6JiFFHlHDY1UbkxqppT7wYOg=
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a/go.mod h1:hxSnBBYLK21Vtq/PHd0S2FYCxBXzBua8ov5s1RobyRQ=
github.com/orsinium-labs/enum v1.4.0 h1:3NInlfV76kuAg0kq2FFUondmg3WO7gMEgrPPrlzLDUM=
github.com/orsinium-labs/enum v1.4.0/go.mod h1:Qj5IK2pnElZtkZbGDxZMjpt7SUsn4tqE5vRelmWaBbc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -38,6 +66,9 @@ github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjc
github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Expand Down
21 changes: 9 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/3lvia/cli/pkg/create"
"github.com/3lvia/cli/pkg/deploy"
"github.com/3lvia/cli/pkg/githubactions"
"github.com/3lvia/cli/pkg/initialize"
"github.com/3lvia/cli/pkg/run"
"github.com/3lvia/cli/pkg/scan"
"github.com/3lvia/cli/pkg/shared"
Expand All @@ -33,28 +34,24 @@ func main() {

version := strings.TrimSpace(string(versionFile))

config, err := shared.ReadConfig()
if err != nil {
style.PrintInfo("No configuration file (3lv.yml) found.")
}

// Check for a new version of the CLI after all these commands.
// Any new commands should be added here.
commands := shared.WithCheckVersionAfterCommands(
[]*cli.Command{
build.Command(config),
deploy.Command(config),
run.Command(config),
scan.Command,
githubactions.Command,
create.Command,
build.Command(),
deploy.Command(),
run.Command(),
scan.Command(),
githubactions.Command(),
create.Command(),
initialize.Command(),
},
version,
)

app := &cli.Command{
Name: "3lv",
Usage: "Command Line Interface tool for developing, building and securing Elvia applications ⚡",
Usage: "Command Line Interface tool for creating, building and securing Elvia applications ⚡",
Version: version,
EnableShellCompletion: true,
Flags: []cli.Flag{
Expand Down
10 changes: 5 additions & 5 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const commandName = "build"

func Command(config *shared.Config) *cli.Command {
func Command() *cli.Command {
return &cli.Command{
Name: commandName,
Aliases: []string{"b"},
Expand Down Expand Up @@ -107,13 +107,13 @@ func Command(config *shared.Config) *cli.Command {
Sources: cli.EnvVars("3LV_SKIP_AUTHENTICATION"),
},
},
Action: func(ctx context.Context, c *cli.Command) error {
return Build(ctx, c, config)
},
Action: Build,
}
}

func Build(_ context.Context, c *cli.Command, config *shared.Config) error {
func Build(_ context.Context, c *cli.Command) error {
config := shared.GetConfig()

if c.NArg() <= 0 {
cli.ShowSubcommandHelpAndExit(c, 1)
}
Expand Down
Loading

0 comments on commit 2e9d1b6

Please sign in to comment.