Skip to content

Commit 2dab552

Browse files
committed
Added launch command and release pipeline
1 parent 02e62a7 commit 2dab552

File tree

9 files changed

+159
-22
lines changed

9 files changed

+159
-22
lines changed

.github/workflows/release.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: release
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
jobs:
7+
goreleaser:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
- name: Unshallow
13+
run: git fetch --prune --unshallow
14+
- name: Set up Go
15+
uses: actions/setup-go@v2
16+
with:
17+
go-version: 1.16
18+
# - name: Import GPG key
19+
# id: import_gpg
20+
# uses: hashicorp/ghaction-import-gpg@v2.1.0
21+
# env:
22+
# GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
23+
# PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
24+
- name: Run GoReleaser
25+
uses: goreleaser/goreleaser-action@v2
26+
with:
27+
version: latest
28+
args: release --rm-dist
29+
env:
30+
# GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ bricks
1414

1515
# Dependency directories (remove the comment below to include it)
1616
vendor/
17+
dist/

.goreleaser

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
hooks:
3+
- go mod tidy
4+
builds:
5+
- env:
6+
- CGO_ENABLED=0
7+
mod_timestamp: '{{ .CommitTimestamp }}'
8+
flags:
9+
- -trimpath
10+
ldflags:
11+
- '-s -w'
12+
goos:
13+
- windows
14+
- linux
15+
- darwin
16+
goarch:
17+
- amd64
18+
- '386'
19+
- arm
20+
- arm64
21+
ignore:
22+
- goos: darwin
23+
goarch: '386'
24+
binary: '{{ .ProjectName }}_v{{ .Version }}'
25+
archives:
26+
- format: zip
27+
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
28+
checksum:
29+
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
30+
algorithm: sha256
31+
snapshot:
32+
name_template: '{{ incpatch .Version }}-devel'
33+
# signs:
34+
# - artifacts: checksum
35+
# args:
36+
# - "--local-user"
37+
# - "{{ .Env.GPG_FINGERPRINT }}"
38+
# - "--output"
39+
# - "${signature}"
40+
# - "--detach-sign"
41+
# - "${artifact}"
42+
changelog:
43+
sort: asc
44+
filters:
45+
exclude:
46+
- '^docs:'
47+
- '^test:'

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
# Bricks!
22

3-
`make build`
3+
This is an early PoC at this stage!
44

5-
`./bricks test`
5+
`make build` (or download artifacts)
66

7-
the rest will follow someday.
7+
Reuses authentication from Databricks CLI. And terraform provider. See details here: https://registry.terraform.io/providers/databrickslabs/databricks/latest/docs#environment-variables
8+
9+
Supports:
10+
* Databricks CLI
11+
* Databricks CLI Profiles
12+
* Azure CLI Auth
13+
* Azure MSI Auth
14+
* Azure SPN Auth
15+
* Google OIDC Auth
16+
* Direct `DATABRICKS_HOST`, `DATABRICKS_TOKEN` or `DATABRICKS_USERNAME` + `DATABRICKS_PASSWORD` variables.
17+
18+
What works:
19+
20+
* `./bricks fs ls /`
21+
* `./bricks test`
22+
* `./bricks run test.py`
23+
24+
What doesn't work:
25+
26+
* Everything else.

cmd/launch.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os"
7+
8+
"github.com/databricks/bricks/project"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
// launchCmd represents the launch command
13+
var launchCmd = &cobra.Command{
14+
Use: "launch",
15+
Short: "Launches a notebook on development cluster",
16+
Long: `Reads a file and executes it on dev cluster`,
17+
Args: cobra.ExactArgs(1),
18+
Run: func(cmd *cobra.Command, args []string) {
19+
contents, err := os.ReadFile(args[0])
20+
if err != nil {
21+
log.Fatal(err)
22+
}
23+
results := project.RunPythonOnDev(cmd.Context(), string(contents))
24+
if results.Failed() {
25+
log.Fatal(results.Error())
26+
}
27+
fmt.Println(results.Text())
28+
},
29+
}
30+
31+
func init() {
32+
rootCmd.AddCommand(launchCmd)
33+
}

cmd/root.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ package cmd
22

33
import (
44
"context"
5+
"log"
56
"os"
6-
"time"
7+
"strings"
78

89
"github.com/databricks/bricks/project"
910
"github.com/spf13/cobra"
10-
11-
"github.com/rs/zerolog"
12-
"github.com/rs/zerolog/log"
1311
)
1412

1513
// rootCmd represents the base command when called without any subcommands
@@ -19,12 +17,30 @@ var rootCmd = &cobra.Command{
1917
Long: `Where's "data"? Secured by the unity catalog. Projects build lifecycle is secured by bricks`,
2018
// Uncomment the following line if your bare application
2119
// has an action associated with it:
22-
// Run: func(cmd *cobra.Command, args []string) { },
20+
}
21+
22+
// TODO: replace with zerolog
23+
type levelWriter []string
24+
25+
var logLevel = levelWriter{"[INFO]", "[ERROR]", "[WARN]"}
26+
var verbose bool
27+
28+
func (lw *levelWriter) Write(p []byte) (n int, err error) {
29+
a := string(p)
30+
for _, l := range *lw {
31+
if strings.Contains(a, l) {
32+
return os.Stdout.Write(p)
33+
}
34+
}
35+
return
2336
}
2437

2538
// Execute adds all child commands to the root command and sets flags appropriately.
2639
// This is called by main.main(). It only needs to happen once to the rootCmd.
2740
func Execute() {
41+
if verbose {
42+
logLevel = append(logLevel, "[DEBUG]")
43+
}
2844
ctx := project.Authenticate(context.Background())
2945
err := rootCmd.ExecuteContext(ctx)
3046
if err != nil {
@@ -33,16 +49,6 @@ func Execute() {
3349
}
3450

3551
func init() {
36-
// Here you will define your flags and configuration settings.
37-
// Cobra supports persistent flags, which, if defined here,
38-
// will be global for your application.
39-
40-
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.bricks.yaml)")
41-
42-
// Cobra also supports local flags, which will only run
43-
// when this action is called directly.
44-
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
45-
46-
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
47-
zerolog.DurationFieldUnit = time.Second
52+
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "print debug logs")
53+
log.SetOutput(&logLevel)
4854
}

cmd/test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var testCmd = &cobra.Command{
1313
Short: "run tests for the project",
1414
Long: `This is longer description of the command`,
1515
Run: func(cmd *cobra.Command, args []string) {
16-
results := project.RunPythonOnDev(cmd.Context(), `print("hello, world!")`)
16+
results := project.RunPythonOnDev(cmd.Context(), `return 1`)
1717
if results.Failed() {
1818
log.Fatal(results.Error())
1919
}

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ go 1.16
44

55
require (
66
github.com/databrickslabs/terraform-provider-databricks v0.5.7
7-
github.com/rs/zerolog v1.26.1
87
github.com/spf13/cobra v1.4.0
98
)

test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spark.sql('show tables').show()

0 commit comments

Comments
 (0)