Skip to content

Commit

Permalink
Switch to RunE
Browse files Browse the repository at this point in the history
  • Loading branch information
schnie committed Feb 14, 2018
1 parent 27110a0 commit 45dd02a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 31 deletions.
7 changes: 5 additions & 2 deletions airflow/airflow.go
Expand Up @@ -57,7 +57,7 @@ func initFiles(root string, files map[string]string) bool {
}

// Init will scaffold out a new airflow project
func Init(path string) {
func Init(path string) error {
// List of directories to create
dirs := []string{"dags", "plugins", "include"}

Expand All @@ -74,8 +74,11 @@ func Init(path string) {

// Initialize files
initFiles(path, files)

return nil
}

// Create new airflow deployment
func Create() {
func Create() error {
return nil
}
8 changes: 7 additions & 1 deletion airflow/docker.go
Expand Up @@ -136,11 +136,17 @@ func Stop(path string) error {
// Deploy pushes a new docker image
// TODO: Check for uncommitted git changes
// TODO: Command to bump version or create version automatically
func Deploy(path, name, tag string) {
func Deploy(path, name, tag string) error {
imageName := imageName(name, tag)
imageBuild(path, imageName)
fmt.Printf("Pushing %s...\n", imageName)
remoteImage := fmt.Sprintf("%s/%s", docker.CloudRegistry, imageName)
docker.Exec("tag", imageName, remoteImage)
docker.Exec("push", remoteImage)
return nil
}

// PS prints the running airflow containers
func PS() error {
return nil
}
10 changes: 10 additions & 0 deletions airflow/files.go
Expand Up @@ -17,13 +17,19 @@ var dockerignore = strings.TrimSpace(`
var composeyml = strings.TrimSpace(`
version: '2'
networks:
airflow:
driver: bridge
volumes:
postgres_data: {}
services:
postgres:
image: postgres:10.1-alpine
restart: unless-stopped
networks:
- airflow
labels:
io.astronomer.docker: "true"
io.astronomer.docker.cli: "true"
Expand All @@ -39,6 +45,8 @@ services:
image: {{ .AirflowImage }}
command: ["airflow", "scheduler"]
restart: unless-stopped
networks:
- airflow
user: {{ .AirflowUser }}
labels:
io.astronomer.docker: "true"
Expand All @@ -58,6 +66,8 @@ services:
image: {{ .AirflowImage }}
command: ["airflow", "webserver"]
restart: unless-stopped
networks:
- airflow
user: {{ .AirflowUser }}
labels:
io.astronomer.docker: "true"
Expand Down
64 changes: 36 additions & 28 deletions cmd/airflow.go
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand All @@ -27,43 +28,50 @@ var (
Use: "init",
Short: "Scaffold a new airflow project",
Long: "Scaffold a new airflow project",
Run: airflowInit,
RunE: airflowInit,
}

airflowCreateCmd = &cobra.Command{
Use: "create",
Short: "Create a new airflow deployment",
Long: "Create a new airflow deployment",
Run: airflowCreate,
RunE: airflowCreate,
}

airflowDeployCmd = &cobra.Command{
Use: "deploy",
Short: "Deploy an airflow project",
Long: "Deploy an airflow project to a given deployment",
Args: cobra.ExactArgs(2),
Run: airflowDeploy,
RunE: airflowDeploy,
}

airflowStatusCmd = &cobra.Command{
Use: "status",
Short: "Print the status of an airflow deployment",
Long: "Print the status of an airflow deployment",
Run: airflowStatus,
RunE: airflowStatus,
}

airflowStartCmd = &cobra.Command{
Use: "start",
Short: "Start a development airflow cluster",
Long: "Start a development airflow cluster",
Run: airflowStart,
RunE: airflowStart,
}

airflowStopCmd = &cobra.Command{
Use: "stop",
Short: "Stop a development airflow cluster",
Long: "Stop a development airflow cluster",
Run: airflowStop,
RunE: airflowStop,
}

airflowPSCmd = &cobra.Command{
Use: "ps",
Short: "List airflow containers",
Long: "List airflow containers",
RunE: airflowPS,
}
)

Expand All @@ -89,6 +97,9 @@ func init() {

// Airflow stop
airflowRootCmd.AddCommand(airflowStopCmd)

// Airflow PS
airflowRootCmd.AddCommand(airflowPSCmd)
}

// projectRoot returns the project root
Expand All @@ -103,7 +114,7 @@ func projectRoot() string {

// TODO: allow specify directory and/or project name (store in .astro/config)
// Use project name for image name
func airflowInit(cmd *cobra.Command, args []string) {
func airflowInit(cmd *cobra.Command, args []string) error {
// Grab working directory
path := utils.GetWorkingDir()

Expand All @@ -114,8 +125,7 @@ func airflowInit(cmd *cobra.Command, args []string) {
MatchString

if !projectNameValid(projectName) {
fmt.Println("Project name is invalid")
return
return errors.New("Project name is invalid")
}
} else {
projectDirectory := filepath.Base(path)
Expand All @@ -134,36 +144,34 @@ func airflowInit(cmd *cobra.Command, args []string) {
} else {
fmt.Printf("Initialized empty astronomer project in %s\n", path)
}
}

func airflowCreate(cmd *cobra.Command, args []string) {
fmt.Println(config.GetString(config.CFGProjectName))
airflow.Create()
return nil
}

func airflowDeploy(cmd *cobra.Command, args []string) {
deploymentName := args[0]
deploymentTag := args[1]
func airflowCreate(cmd *cobra.Command, args []string) error {
return airflow.Create()
}

airflow.Deploy(projectRoot(), deploymentName, deploymentTag)
func airflowDeploy(cmd *cobra.Command, args []string) error {
return airflow.Deploy(projectRoot(), args[0], args[1])
}

// Get airflow status
func airflowStatus(cmd *cobra.Command, args []string) {
func airflowStatus(cmd *cobra.Command, args []string) error {
return nil
}

// Start airflow
func airflowStart(cmd *cobra.Command, args []string) {
err := airflow.Start(projectRoot())
if err != nil {
fmt.Println(err)
}
func airflowStart(cmd *cobra.Command, args []string) error {
return airflow.Start(projectRoot())
}

// Stop airflow
func airflowStop(cmd *cobra.Command, args []string) {
err := airflow.Stop(projectRoot())
if err != nil {
fmt.Println(err)
}
func airflowStop(cmd *cobra.Command, args []string) error {
return airflow.Stop(projectRoot())
}

// Airflow PS
func airflowPS(cmd *cobra.Command, args []string) error {
return airflow.PS()
}

0 comments on commit 45dd02a

Please sign in to comment.