/
airflow.go
84 lines (66 loc) · 1.47 KB
/
airflow.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package airflow
import (
"fmt"
"os"
"path/filepath"
"github.com/astronomerio/astro-cli/utils"
)
func initDirs(root string, dirs []string) bool {
// Any inputs exist
exists := false
// Create the dirs
for _, dir := range dirs {
// Create full path to directory
fullpath := filepath.Join(root, dir)
// Move on if already exists
if utils.Exists(fullpath) {
exists = true
continue
}
// Create directory
if err := os.MkdirAll(dir, 0777); err != nil {
fmt.Println(err)
}
}
return exists
}
func initFiles(root string, files map[string]string) bool {
// Any inputs exist
exists := false
// Create the files
for file, content := range files {
// Create full path to file
fullpath := filepath.Join(root, file)
// Move on if already exiss
if utils.Exists(fullpath) {
exists = true
continue
}
// Write files out
if err := utils.WriteStringToFile(fullpath, content); err != nil {
fmt.Println(err)
}
}
return exists
}
// Init will scaffold out a new airflow project
func Init(path string) error {
// List of directories to create
dirs := []string{"dags", "plugins", "include"}
// Map of files to create
files := map[string]string{
".dockerignore": dockerignore,
"Dockerfile": dockerfile,
"packages.txt": "",
"requirements.txt": "",
}
// Initailize directories
initDirs(path, dirs)
// Initialize files
initFiles(path, files)
return nil
}
// Create new airflow deployment
func Create() error {
return nil
}