Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft info command #159

Merged
merged 35 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
04d5f11
add info cobra command
davidgamero Nov 1, 2022
6af9850
add info command with languages and deploytypes
davidgamero Nov 3, 2022
eda81dd
add integration test for draft info
davidgamero Nov 4, 2022
871eec3
run info integration test on pr
davidgamero Nov 4, 2022
ec1d20e
missing pipe
davidgamero Nov 4, 2022
a05f472
tab
davidgamero Nov 4, 2022
67643e9
relative pathing
davidgamero Nov 4, 2022
2ed2f25
wrong schema path
davidgamero Nov 7, 2022
5b19a7c
update json validation
davidgamero Nov 7, 2022
5460b5c
update inputs
davidgamero Nov 7, 2022
7f8ade8
whyy
davidgamero Nov 7, 2022
11286c0
pwd for debug
davidgamero Nov 7, 2022
9f83a5a
src dir"
davidgamero Nov 7, 2022
1624b57
yaml with fix
davidgamero Nov 7, 2022
4225473
cd to src;
davidgamero Nov 8, 2022
dd659f4
yet another fix
davidgamero Nov 8, 2022
329f9ab
use ghworkspace env
davidgamero Nov 8, 2022
a78d827
try absolute paths
davidgamero Nov 8, 2022
f97aff7
clone to github workspace
davidgamero Nov 8, 2022
e4aa7b9
im done with premade github actions. cli ftw
davidgamero Nov 8, 2022
dca44cf
missing make
davidgamero Nov 8, 2022
bd47192
fix info schema naming
davidgamero Nov 8, 2022
80a47b8
ls the integration dir
davidgamero Nov 8, 2022
a7d8ee0
it was missing the pkg dir
davidgamero Nov 8, 2022
ab91d88
missing slash
davidgamero Nov 8, 2022
1d0c475
ls
davidgamero Nov 8, 2022
7320a12
another ls
davidgamero Nov 8, 2022
fbd2572
again
davidgamero Nov 8, 2022
4a610b7
no dots
davidgamero Nov 8, 2022
ff711b4
add cat
davidgamero Nov 8, 2022
09c0a15
rename again
davidgamero Nov 8, 2022
3eedb12
ahhh make deletes the integration folder
davidgamero Nov 8, 2022
6ae7f0d
cat jsons
davidgamero Nov 8, 2022
479ff7d
use system fmt print to get rid of log prefix
davidgamero Nov 8, 2022
4b8cf30
add example and update readme for info
davidgamero Nov 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/integration-info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Draft Info Integration Test
on:
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18.2
- name: make
run: make
- run: |
./draft info > ./info.json
echo "Draft Info JSON schema:"
cat test/info_schema.json
echo "Draft Info JSON:"
cat info.json
- name: Validate JSON
run: |
npm install -g ajv-cli
ajv validate -s test/info_schema.json -d info.json
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ If you don’t plan on using the GitHub Action, you can directly apply your depl

If you plan on deploying your application through your GitHub Action, commit all the files to your repository and watch your application get deployed!

### `draft info`
The `draft info` command prints information about supported languages and deployment types.
Example output:
```
{
"supported_languages": [
"php",
"python",
"rust",
"swift",
"csharp",
"go",
"gradle",
"javascript",
"ruby",
"clojure",
"erlang",
"gomodule",
"java"
],
"supported_deployment_types": [
"helm",
"kustomize",
"manifests"
]
}
```
<!-- ABOUT THE PROJECT -->

## About The Project
Expand All @@ -61,6 +88,7 @@ Draft makes it easier for developers to get started building apps that run on Ku
- `draft setup-gh` automates the GitHub OIDC setup process for your project.
- `draft generate-workflow` generates a GitHub Actions workflow for automatic build and deploy to a Kubernetes cluster.
- `draft update` automatically make your application to be internet accessible.
- `draft info` print supported language and field information in json format.

Use `draft [command] --help` for more information about a command.

Expand Down
70 changes: 70 additions & 0 deletions cmd/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package cmd

import (
"encoding/json"
"fmt"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/Azure/draft/pkg/deployments"
"github.com/Azure/draft/pkg/languages"
"github.com/Azure/draft/template"
)

type Format string

const (
JSON Format = "json"
)

type infoCmd struct {
format string
info *draftInfo
}

type draftInfo struct {
SupportedLanguages []string `json:"supported_languages"`
SupportedDeploymentTypes []string `json:"supported_deployment_types"`
}

func newInfoCmd() *cobra.Command {
ic := &infoCmd{}
var cmd = &cobra.Command{
Use: "info",
Short: "Prints draft supported values in machine-readable format",
Long: `This command prints information about the current draft environment and supported values such as supported dockerfile languages and deployment manifest types.`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := ic.run(); err != nil {
return err
}
return nil
},
}
f := cmd.Flags()
f.StringVarP(&ic.format, "format", "f", ".", "specify the format to print draft information in (json, yaml, etc)")

return cmd
}

func (ic *infoCmd) run() error {
log.Debugf("getting supported languages")
l := languages.CreateLanguagesFromEmbedFS(template.Dockerfiles, "")
d := deployments.CreateDeploymentsFromEmbedFS(template.Deployments, "")

ic.info = &draftInfo{
SupportedLanguages: l.Names(),
SupportedDeploymentTypes: d.DeployTypes(),
}

infoText, err := json.MarshalIndent(ic.info, "", " ")
if err != nil {
return fmt.Errorf("could not marshal draft info into json: %w", err)
}
fmt.Println(string(infoText))
return nil
}

func init() {
rootCmd.AddCommand(newInfoCmd())
}
7 changes: 7 additions & 0 deletions pkg/deployments/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/fs"

log "github.com/sirupsen/logrus"
"golang.org/x/exp/maps"
"gopkg.in/yaml.v3"

"github.com/Azure/draft/pkg/config"
Expand All @@ -26,6 +27,12 @@ type Deployments struct {
deploymentTemplates fs.FS
}

// DeployTypes returns a slice of the supported deployment types
func (d *Deployments) DeployTypes() []string {
names := maps.Keys(d.deploys)
return names
}

func (d *Deployments) CopyDeploymentFiles(deployType string, customInputs map[string]string, templateWriter templatewriter.TemplateWriter) error {
val, ok := d.deploys[deployType]
if !ok {
Expand Down
7 changes: 7 additions & 0 deletions pkg/languages/languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/fs"

log "github.com/sirupsen/logrus"
"golang.org/x/exp/maps"
"gopkg.in/yaml.v3"

"github.com/Azure/draft/pkg/config"
Expand All @@ -25,6 +26,12 @@ type Languages struct {
dockerfileTemplates fs.FS
}

// Names returns a slice of the names of the supported languages
func (l *Languages) Names() []string {
names := maps.Keys(l.langs)
return names
}

func (l *Languages) ContainsLanguage(lang string) bool {
_, ok := l.langs[lang]
return ok
Expand Down
38 changes: 38 additions & 0 deletions test/info_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Root",
"type": "object",
"required": [
"supported_languages",
"supported_deployment_types"
],
"properties": {
"supported_languages": {
"$id": "#root/supported_languages",
"title": "Supported_languages",
"type": "array",
"default": [],
"items":{
"$id": "#root/supported_languages/items",
"title": "Items",
"type": "string",
"default": "",
"pattern": "^.*$"
}
},
"supported_deployment_types": {
"$id": "#root/supported_deployment_types",
"title": "Supported_deployment_types",
"type": "array",
"default": [],
"items":{
"$id": "#root/supported_deployment_types/items",
"title": "Items",
"type": "string",
"default": "",
"pattern": "^.*$"
}
}
}
}