Added `launch` command and release pipeline

This commit is contained in:
Serge Smertin 2022-05-13 17:43:54 +02:00
parent 02e62a7176
commit 2dab552829
9 changed files with 159 additions and 22 deletions

31
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,31 @@
name: release
on:
push:
tags:
- "v*"
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
# - name: Import GPG key
# id: import_gpg
# uses: hashicorp/ghaction-import-gpg@v2.1.0
# env:
# GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
# PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
# GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ bricks
# Dependency directories (remove the comment below to include it)
vendor/
dist/

47
.goreleaser Normal file
View File

@ -0,0 +1,47 @@
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- '-s -w'
goos:
- windows
- linux
- darwin
goarch:
- amd64
- '386'
- arm
- arm64
ignore:
- goos: darwin
goarch: '386'
binary: '{{ .ProjectName }}_v{{ .Version }}'
archives:
- format: zip
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
algorithm: sha256
snapshot:
name_template: '{{ incpatch .Version }}-devel'
# signs:
# - artifacts: checksum
# args:
# - "--local-user"
# - "{{ .Env.GPG_FINGERPRINT }}"
# - "--output"
# - "${signature}"
# - "--detach-sign"
# - "${artifact}"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

View File

@ -1,7 +1,26 @@
# Bricks!
`make build`
This is an early PoC at this stage!
`./bricks test`
`make build` (or download artifacts)
the rest will follow someday.
Reuses authentication from Databricks CLI. And terraform provider. See details here: https://registry.terraform.io/providers/databrickslabs/databricks/latest/docs#environment-variables
Supports:
* Databricks CLI
* Databricks CLI Profiles
* Azure CLI Auth
* Azure MSI Auth
* Azure SPN Auth
* Google OIDC Auth
* Direct `DATABRICKS_HOST`, `DATABRICKS_TOKEN` or `DATABRICKS_USERNAME` + `DATABRICKS_PASSWORD` variables.
What works:
* `./bricks fs ls /`
* `./bricks test`
* `./bricks run test.py`
What doesn't work:
* Everything else.

33
cmd/launch.go Normal file
View File

@ -0,0 +1,33 @@
package cmd
import (
"fmt"
"log"
"os"
"github.com/databricks/bricks/project"
"github.com/spf13/cobra"
)
// launchCmd represents the launch command
var launchCmd = &cobra.Command{
Use: "launch",
Short: "Launches a notebook on development cluster",
Long: `Reads a file and executes it on dev cluster`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
contents, err := os.ReadFile(args[0])
if err != nil {
log.Fatal(err)
}
results := project.RunPythonOnDev(cmd.Context(), string(contents))
if results.Failed() {
log.Fatal(results.Error())
}
fmt.Println(results.Text())
},
}
func init() {
rootCmd.AddCommand(launchCmd)
}

View File

@ -2,14 +2,12 @@ package cmd
import (
"context"
"log"
"os"
"time"
"strings"
"github.com/databricks/bricks/project"
"github.com/spf13/cobra"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
// rootCmd represents the base command when called without any subcommands
@ -19,12 +17,30 @@ var rootCmd = &cobra.Command{
Long: `Where's "data"? Secured by the unity catalog. Projects build lifecycle is secured by bricks`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}
// TODO: replace with zerolog
type levelWriter []string
var logLevel = levelWriter{"[INFO]", "[ERROR]", "[WARN]"}
var verbose bool
func (lw *levelWriter) Write(p []byte) (n int, err error) {
a := string(p)
for _, l := range *lw {
if strings.Contains(a, l) {
return os.Stdout.Write(p)
}
}
return
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if verbose {
logLevel = append(logLevel, "[DEBUG]")
}
ctx := project.Authenticate(context.Background())
err := rootCmd.ExecuteContext(ctx)
if err != nil {
@ -33,16 +49,6 @@ func Execute() {
}
func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.bricks.yaml)")
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
zerolog.DurationFieldUnit = time.Second
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "print debug logs")
log.SetOutput(&logLevel)
}

View File

@ -13,7 +13,7 @@ var testCmd = &cobra.Command{
Short: "run tests for the project",
Long: `This is longer description of the command`,
Run: func(cmd *cobra.Command, args []string) {
results := project.RunPythonOnDev(cmd.Context(), `print("hello, world!")`)
results := project.RunPythonOnDev(cmd.Context(), `return 1`)
if results.Failed() {
log.Fatal(results.Error())
}

1
go.mod
View File

@ -4,6 +4,5 @@ go 1.16
require (
github.com/databrickslabs/terraform-provider-databricks v0.5.7
github.com/rs/zerolog v1.26.1
github.com/spf13/cobra v1.4.0
)

1
test.py Normal file
View File

@ -0,0 +1 @@
spark.sql('show tables').show()