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

feat: improve local UX with up --create-cluster and --watch by default #20

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 6 additions & 4 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Create k8s Kind Cluster
uses: helm/kind-action@v1.10.0
with:
install_only: true
# we will also be testing installing kind, so we don't want to do
# this as part of the github action workflow
#- name: Create k8s Kind Cluster
# uses: helm/kind-action@v1.10.0
# with:
# install_only: true

- name: Setup
run: ./tests/bin/travis/setup.sh
Expand Down
6 changes: 4 additions & 2 deletions cmd/subcommands/init/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import (
)

func NewInitLocalCmd() *cobra.Command {
var buildFlag bool
var verboseFlag bool

var cmd = &cobra.Command{
Use: "local",
Short: "Initialize a local control plane",
Long: "Initialize a local control plane",
RunE: func(cmd *cobra.Command, args []string) error {
return initialize.Local(initialize.InitLocalOptions{Verbose: verboseFlag})
return initialize.Local(initialize.InitLocalOptions{BuildImages: buildFlag, Verbose: verboseFlag})
},
}

cmd.Flags().BoolVarP(&verboseFlag, "verbose", "v", verboseFlag, "Verbose output")
cmd.Flags().BoolVarP(&buildFlag, "build-images", "b", false, "Also build Lunchpail support images")
cmd.Flags().BoolVarP(&verboseFlag, "verbose", "v", false, "Verbose output")
return cmd
}
24 changes: 21 additions & 3 deletions cmd/subcommands/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"lunchpail.io/pkg/be"
"lunchpail.io/pkg/boot"
"lunchpail.io/pkg/fe/linker"
initialize "lunchpail.io/pkg/lunchpail/init"
"lunchpail.io/pkg/util"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -36,7 +38,8 @@ func addAssemblyOptions(cmd *cobra.Command) *assembly.Options {
func newUpCmd() *cobra.Command {
var verboseFlag bool
var dryrunFlag bool
var watchFlag bool
watchFlag := false
var createCluster bool
var createNamespace bool

var cmd = &cobra.Command{
Expand All @@ -45,14 +48,29 @@ func newUpCmd() *cobra.Command {
Long: "Deploy the application",
}

if util.StdoutIsTty() {
// default to watch if we are connected to a TTY
watchFlag = true
}

cmd.Flags().SortFlags = false
appOpts := addAssemblyOptions(cmd)
cmd.Flags().BoolVarP(&dryrunFlag, "dry-run", "", false, "Emit application yaml to stdout")
cmd.Flags().BoolVarP(&verboseFlag, "verbose", "v", false, "Verbose output")
cmd.Flags().BoolVarP(&watchFlag, "watch", "w", false, "After deployment, watch for status updates")
cmd.Flags().BoolVarP(&createNamespace, "create-namespace", "N", false, "Create a new Kubernetes namespace")
cmd.Flags().BoolVarP(&watchFlag, "watch", "w", watchFlag, "After deployment, watch for status updates")
cmd.Flags().BoolVarP(&createCluster, "create-cluster", "I", false, "Create a new (local) Kubernetes cluster, if needed")
cmd.Flags().BoolVarP(&createNamespace, "create-namespace", "N", false, "Create a new Kubernetes namespace, if needed")

cmd.RunE = func(cmd *cobra.Command, args []string) error {
if appOpts.TargetPlatform == be.Kubernetes && createCluster {
if err := initialize.Local(initialize.InitLocalOptions{BuildImages: false, Verbose: verboseFlag}); err != nil {
return err
}

// if we were asked to create a cluster, then certainly we will want to create a namespace
createNamespace = true
}

overrideValues, err := cmd.Flags().GetStringSlice("set")
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion hack/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ if [ ! -f /tmp/lunchpail ]
then "$TOP"/hack/setup/cli.sh /tmp/lunchpail
fi

/tmp/lunchpail init local
/tmp/lunchpail init local --build-images
2 changes: 1 addition & 1 deletion pkg/lunchpail/init/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func createKindCluster() error {
args = append(args, "/tmp/kindhack.yaml")
}

fmt.Printf("Creating kind cluster " + lunchpail.LocalClusterName)
fmt.Printf("Creating kind cluster %s\n", lunchpail.LocalClusterName)

cmd := exec.Command("kind", args...)
cmd.Stdout = os.Stdout
Expand Down
15 changes: 11 additions & 4 deletions pkg/lunchpail/init/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

type InitLocalOptions struct {
Verbose bool
BuildImages bool
Verbose bool
}

func Local(opts InitLocalOptions) error {
Expand Down Expand Up @@ -37,7 +38,13 @@ func Local(opts InitLocalOptions) error {
return err
}

bopts := build.BuildOptions{}
bopts.Verbose = opts.Verbose
return images.Build(bopts)
if opts.BuildImages {
bopts := build.BuildOptions{}
bopts.Verbose = opts.Verbose
if err := images.Build(bopts); err != nil {
return err
}
}

return nil
}
11 changes: 11 additions & 0 deletions pkg/util/term.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package util

import "os"

func StdoutIsTty() bool {
if fileInfo, _ := os.Stdout.Stat(); (fileInfo.Mode() & os.ModeCharDevice) != 0 {
return true
} else {
return false
}
}
1 change: 0 additions & 1 deletion tests/bin/deploy-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ repo_secret="" # e.g. user:pat@https://github.mycompany.com
$repo_secret \
$2

echo "!!!!!!!!!!!!!!!XXXXXXXXXXXXXXXXXXXXXXX $2"
if [[ -d "$2" ]] && [[ -f "$2"/version ]]
then
# Check that app version passes through
Expand Down
7 changes: 2 additions & 5 deletions tests/bin/travis/setup.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/usr/bin/env bash

set -e
set -o pipefail
set -eo pipefail

# ibm travis currently runs ubuntu 20, for which there are no podman
# v4 builds. We rely on v4 for the `podman machine init --rootful`
# option
# Keeping this here, in case we want to test podman in CI.
# if ! which podman >& /dev/null
# then
# echo "Installing podman"
Expand Down