@@ -4,16 +4,12 @@ require 'dotenv'
4
4
5
5
Dir . glob ( 'lib/tasks/*.rake' ) . each { |r | load r }
6
6
7
- environment = ENV . fetch ( 'ENV' , 'development' )
8
-
9
7
MANIFESTS = {
10
8
container : '.Dockerfile' ,
11
9
build : '.Makefile'
12
10
} . freeze
13
11
14
- default_environment = File . join ( '.env' , 'default' )
15
- custom_environment = File . join ( '.env' , environment )
16
- Dotenv . load ( custom_environment , default_environment )
12
+ Dotenv . load
17
13
18
14
class ::Hash
19
15
def recursive_merge ( h )
@@ -29,27 +25,20 @@ def default_provider
29
25
end
30
26
end
31
27
32
- def commands_for ( language , framework , ** options )
28
+ def commands_for ( language , framework , provider )
33
29
config = YAML . safe_load ( File . read ( 'config.yaml' ) )
34
30
35
- directory = File . dirname ( options [ :path ] )
36
- main_config = YAML . safe_load ( File . open ( File . join ( directory , '..' , '..' , ' config.yaml') ) )
37
- language_config = YAML . safe_load ( File . open ( File . join ( directory , '..' , 'config.yaml' ) ) )
38
- framework_config = YAML . safe_load ( File . open ( File . join ( directory , 'config.yaml' ) ) )
31
+ directory = Dir . pwd
32
+ main_config = YAML . safe_load ( File . open ( File . join ( directory , 'config.yaml' ) ) )
33
+ language_config = YAML . safe_load ( File . open ( File . join ( directory , language , 'config.yaml' ) ) )
34
+ framework_config = YAML . safe_load ( File . open ( File . join ( directory , language , framework , 'config.yaml' ) ) )
39
35
app_config = main_config . recursive_merge ( language_config ) . recursive_merge ( framework_config )
40
-
41
- options [ :framework ] = framework
42
- options [ :language ] = language
43
-
44
- ENV . each do |key , value |
45
- options [ key ] = value unless options . key? ( key )
46
- end
47
-
36
+ options = { language : language , framework : framework }
48
37
commands = { build : [ ] , collect : [ ] , clean : [ ] }
49
38
50
39
# Compile first, only for non containers
51
40
52
- if app_config . key? ( 'binaries' ) && !( options [ : provider] . start_with? ( 'docker' ) || options [ : provider] . start_with? ( 'podman' ) )
41
+ if app_config . key? ( 'binaries' ) && !( provider . start_with? ( 'docker' ) || provider . start_with? ( 'podman' ) )
53
42
commands << "docker build -f #{ MANIFESTS [ :container ] } -t #{ language } .#{ framework } ."
54
43
commands << "docker run -td #{ language } .#{ framework } > cid.txt"
55
44
app_config [ 'binaries' ] . each do |out |
@@ -62,36 +51,32 @@ def commands_for(language, framework, **options)
62
51
end
63
52
end
64
53
65
- config [ 'providers' ] [ options [ : provider] ] [ 'build' ] . each do |cmd |
54
+ config [ 'providers' ] [ provider ] [ 'build' ] . each do |cmd |
66
55
commands [ :build ] << Mustache . render ( cmd , options . merge! ( manifest : MANIFESTS [ :container ] ) ) . to_s
67
56
end
68
57
69
- config [ 'providers' ] [ options [ : provider] ] [ 'metadata' ] . each do |cmd |
58
+ config [ 'providers' ] [ provider ] [ 'metadata' ] . each do |cmd |
70
59
commands [ :build ] << Mustache . render ( cmd , options ) . to_s
71
60
end
72
61
73
- if app_config . key? ( 'bootstrap' ) && config [ 'providers' ] [ options [ : provider] ] . key? ( 'exec' )
74
- remote_command = config [ 'providers' ] [ options [ : provider] ] [ 'exec' ]
62
+ if app_config . key? ( 'bootstrap' ) && config [ 'providers' ] [ provider ] . key? ( 'exec' )
63
+ remote_command = config [ 'providers' ] [ [ provider ] ] [ 'exec' ]
75
64
app_config [ 'bootstrap' ] . each do |cmd |
76
65
commands [ :build ] << Mustache . render ( remote_command , options . merge! ( command : cmd ) ) . to_s
77
66
end
78
67
end
79
68
80
- if config [ 'providers' ] [ options [ : provider] ] . key? ( 'reboot' )
81
- commands [ :build ] << config [ 'providers' ] [ options [ : provider] ] . fetch ( 'reboot' )
69
+ if config . dig ( 'providers' , provider ) . key? ( 'reboot' )
70
+ commands [ :build ] << config . dig ( 'providers' , provider , 'reboot' )
82
71
commands [ :build ] << 'sleep 30'
83
72
end
84
73
85
74
commands [ :build ] << 'curl --retry 5 --retry-delay 5 --retry-max-time 180 --retry-connrefused http://`cat ip.txt`:3000 -v'
86
75
87
- unless options [ :collect ] == 'off'
88
- commands [ :collect ] << "DATABASE_URL=#{ ENV [ 'DATABASE_URL' ] } ../../bin/client --language #{ language } --framework #{ framework } #{ options [ :sieger_options ] } -h `cat ip.txt`"
89
- end
76
+ commands [ :collect ] << "LANGUAGE=#{ language } FRAMEWORK=#{ framework } DATABASE_URL=#{ ENV [ 'DATABASE_URL' ] } bundle exec rake collect"
90
77
91
- unless options [ :clean ] == 'off'
92
- config [ 'providers' ] [ options [ :provider ] ] [ 'clean' ] . each do |cmd |
93
- commands [ :clean ] << Mustache . render ( cmd , options ) . to_s
94
- end
78
+ config . dig ( 'providers' , provider , 'clean' ) . each do |cmd |
79
+ commands [ :clean ] << Mustache . render ( cmd , options ) . to_s
95
80
end
96
81
97
82
commands
@@ -170,7 +155,7 @@ task :config do
170
155
171
156
makefile = File . open ( File . join ( language , framework , MANIFESTS [ :build ] ) , 'w' )
172
157
173
- commands_for ( language , framework , provider : provider , clean : clean , sieger_options : sieger_options , path : path , collect : collect ) . each do |target , commands |
158
+ commands_for ( language , framework , provider ) . each do |target , commands |
174
159
makefile . write ( "#{ target } :\n " )
175
160
commands . each do |command |
176
161
makefile . write ( "\t #{ command } \n " )
0 commit comments