Skip to content

Commit 4d3d235

Browse files
committed
[#709] New rake
1 parent d369306 commit 4d3d235

File tree

8 files changed

+1681
-1209
lines changed

8 files changed

+1681
-1209
lines changed

Rakefile

Lines changed: 1 addition & 1209 deletions
Large diffs are not rendered by default.

rakelib/1_init.rake

Lines changed: 460 additions & 0 deletions
Large diffs are not rendered by default.

rakelib/2_codebase.rake

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# coding: utf-8
2+
3+
###############
4+
### Swagger ###
5+
###############
6+
7+
swagger_file = 'api/swagger.yaml'
8+
swagger_api_files = FileList['api/*.yaml'].exclude(swagger_file)
9+
file swagger_file => swagger_api_files + [YAMLINC] do
10+
sh YAMLINC, "-o", swagger_file, "api/swagger.in.yaml"
11+
end
12+
13+
###############
14+
### Backend ###
15+
###############
16+
17+
swagger_server_dir = "backend/server/gen"
18+
file swagger_server_dir => [swagger_file, GOSWAGGER] do
19+
swagger_abs = File.expand_path(swagger_file)
20+
Dir.chdir("backend") do
21+
sh GOSWAGGER, "generate", "server",
22+
"-m", "server/gen/models",
23+
"-s", "server/gen/restapi",
24+
"--exclude-main",
25+
"--name", "Stork",
26+
"--regenerate-configureapi",
27+
"--spec", swagger_abs,
28+
"--template", "stratoscale"
29+
end
30+
sh "touch", swagger_server_dir
31+
end
32+
33+
agent_proto_file = "backend/api/agent.proto"
34+
agent_pb_go_file = "backend/api/agent.pb.go"
35+
agent_grpc_pb_go_file = "backend/api/agent_grpc.pb.go"
36+
file agent_pb_go_file => [agent_proto_file, PROTOC, PROTOC_GEN_GO, PROTOC_GEN_GO_GRPC] do
37+
Dir.chdir("backend/api") do
38+
sh PROTOC, "--proto_path=.", "--go_out=.", "--go-grpc_out=.", "agent.proto"
39+
end
40+
end
41+
file agent_grpc_pb_go_file => [agent_pb_go_file]
42+
43+
go_dependencies_dir = File.join(ENV["GOPATH"], "pkg")
44+
file go_dependencies_dir => [GO, "backend/go.mod", "backend/go.sum"] do
45+
Dir.chdir("backend") do
46+
sh GO, "mod", "download"
47+
end
48+
sh "touch", go_dependencies_dir
49+
end
50+
51+
go_server_codebase = FileList[
52+
"backend/server",
53+
"backend/server/**/*",
54+
"backend/cmd/stork-server",
55+
"backend/cmd/stork-server/*",
56+
swagger_server_dir
57+
]
58+
59+
60+
go_agent_codebase = FileList[
61+
"backend/agent",
62+
"backend/agent/**/*",
63+
"backend/cmd/stork-agent",
64+
"backend/cmd/stork-agent/*",
65+
"backend/server/certs/**/*",
66+
"backend/server/database/**/*"
67+
]
68+
go_tool_codebase = FileList[
69+
"backend/cmd/stork-tool",
70+
"backend/cmd/stork-tool/*"
71+
]
72+
73+
go_common_codebase = FileList["backend/**/*"]
74+
.exclude("backend/coverage.out")
75+
.exclude(go_server_codebase)
76+
.exclude(go_agent_codebase)
77+
.exclude(go_tool_codebase)
78+
.include(go_dependencies_dir)
79+
.include(agent_pb_go_file)
80+
.include(agent_grpc_pb_go_file)
81+
82+
GO_SERVER_API_MOCK = "backend/server/agentcomm/api_mock.go"
83+
84+
GO_SERVER_CODEBASE = go_server_codebase
85+
.include(go_common_codebase)
86+
.exclude("backend/cmd/stork-server/stork-server")
87+
.exclude(GO_SERVER_API_MOCK)
88+
89+
GO_AGENT_CODEBASE = go_agent_codebase
90+
.include(go_common_codebase)
91+
.exclude("backend/cmd/stork-agent/stork-agent")
92+
93+
GO_TOOL_CODEBASE = go_tool_codebase
94+
.include(go_common_codebase)
95+
.exclude("backend/cmd/stork-tool/stork-tool")
96+
97+
file GO_SERVER_API_MOCK => [GO, MOCKERY, MOCKGEN] + GO_SERVER_CODEBASE do
98+
99+
Dir.chdir("backend") do
100+
sh GO, "generate", "-v", "./..."
101+
end
102+
sh "touch", GO_SERVER_API_MOCK
103+
end
104+
105+
#####################
106+
### Documentation ###
107+
#####################
108+
109+
DOC_CODEBASE = FileList["doc", "doc/**/*"]
110+
.include("backend/version.go")
111+
.exclude("doc/_build")
112+
.exclude("doc/_build/**/*")
113+
.exclude("doc/doctrees/**/*")
114+
.exclude("doc/man/*.8")
115+
116+
################
117+
### Frontend ###
118+
################
119+
120+
open_api_generator_webui_dir = "webui/src/app/backend"
121+
file open_api_generator_webui_dir => [swagger_file, OPENAPI_GENERATOR] do
122+
sh "java", "-jar", OPENAPI_GENERATOR, "generate",
123+
"-i", swagger_file,
124+
"-g", "typescript-angular",
125+
"-o", open_api_generator_webui_dir,
126+
"--additional-properties", "snapshot=true,ngVersion=10.1.5,modelPropertyNaming=camelCase"
127+
sh "touch", open_api_generator_webui_dir
128+
end
129+
130+
node_module_dir = "webui/node_modules"
131+
file node_module_dir => [NPM, "webui/package.json", "webui/package-lock.json"] do
132+
Dir.chdir("webui") do
133+
ENV["NG_CLI_ANALYTICS"] = "false"
134+
sh NPM, "ci",
135+
"--prefer-offline",
136+
"--no-audit",
137+
"--no-progress"
138+
end
139+
sh "touch", node_module_dir
140+
end
141+
142+
WEBUI_CODEBASE = FileList["webui", "webui/**/*"]
143+
.exclude("webui/.angular")
144+
.exclude("webui/.angular/**/*")
145+
.exclude("webui/node_modules/**/*")
146+
.exclude(File.join(open_api_generator_webui_dir, "**/*"))
147+
.exclude("webui/dist")
148+
.exclude("webui/dist/**/*")
149+
.exclude("webui/src/assets/arm")
150+
.exclude("webui/src/assets/arm/**/*")
151+
.include(open_api_generator_webui_dir)
152+
.include(node_module_dir)

rakelib/3_build.rake

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# coding: utf-8
2+
3+
############
4+
### Date ###
5+
############
6+
7+
require 'date'
8+
9+
now = Time.now
10+
build_date = now.strftime("%Y-%m-%d %H:%M")
11+
12+
if ENV['STORK_BUILD_TIMESTAMP']
13+
TIMESTAMP = ENV['STORK_BUILD_TIMESTAMP']
14+
else
15+
TIMESTAMP = now.strftime("%y%m%d%H%M%S")
16+
end
17+
18+
#####################
19+
### Documentation ###
20+
#####################
21+
22+
ARM_DIRECTORY = "doc/_build/html"
23+
file ARM_DIRECTORY => DOC_CODEBASE + [SPHINX_BUILD] do
24+
sh SPHINX_BUILD, "-M", "html", "doc/", "doc/_build", "-v", "-E", "-a", "-W", "-j", "2"
25+
sh "touch", ARM_DIRECTORY
26+
end
27+
28+
TOOL_MAN_FILE = "doc/man/stork-tool.8"
29+
file TOOL_MAN_FILE => DOC_CODEBASE + [SPHINX_BUILD] do
30+
sh SPHINX_BUILD, "-M", "man", "doc/", "doc/", "-v", "-E", "-a", "-W", "-j", "2"
31+
sh "touch", TOOL_MAN_FILE, AGENT_MAN_FILE, SERVER_MAN_FILE
32+
end
33+
34+
AGENT_MAN_FILE = "doc/man/stork-agent.8"
35+
file AGENT_MAN_FILE => [TOOL_MAN_FILE]
36+
37+
SERVER_MAN_FILE = "doc/man/stork-server.8"
38+
file SERVER_MAN_FILE => [TOOL_MAN_FILE]
39+
40+
man_files = FileList[SERVER_MAN_FILE, AGENT_MAN_FILE, TOOL_MAN_FILE]
41+
42+
################
43+
### Frontend ###
44+
################
45+
46+
file WEBUI_DIST_DIRECTORY = "webui/dist/stork"
47+
file WEBUI_DIST_DIRECTORY => WEBUI_CODEBASE + [NPX] do
48+
Dir.chdir("webui") do
49+
sh NPX, "ng", "build", "--configuration", "production"
50+
end
51+
end
52+
53+
file WEBUI_DIST_ARM_DIRECTORY = "webui/dist/stork/assets/arm"
54+
file WEBUI_DIST_ARM_DIRECTORY => [ARM_DIRECTORY] do
55+
sh "cp", "-a", ARM_DIRECTORY, WEBUI_DIST_ARM_DIRECTORY
56+
sh "touch", WEBUI_DIST_ARM_DIRECTORY
57+
end
58+
59+
file WEBUI_DEBUG_DIRECTORY = "webui/dist/stork-debug"
60+
file WEBUI_DEBUG_DIRECTORY => WEBUI_CODEBASE + [NPX] do
61+
Dir.chdir("webui") do
62+
sh NPX, "ng", "build"
63+
end
64+
end
65+
66+
###############
67+
### Backend ###
68+
###############
69+
70+
AGENT_BINARY_FILE = "backend/cmd/stork-agent/stork-agent"
71+
file AGENT_BINARY_FILE => GO_AGENT_CODEBASE + [GO] do
72+
Dir.chdir("backend/cmd/stork-agent") do
73+
sh GO, "build", "-ldflags=\"-X 'isc.org/stork.BuildDate=#{build_date}'\""
74+
end
75+
puts "Stork Agent build date: #{build_date} (timestamp: #{TIMESTAMP})"
76+
end
77+
78+
SERVER_BINARY_FILE = "backend/cmd/stork-server/stork-server"
79+
file SERVER_BINARY_FILE => GO_SERVER_CODEBASE + [GO] do
80+
sh "rm", "-f", GO_SERVER_API_MOCK
81+
Dir.chdir("backend/cmd/stork-server") do
82+
sh GO, "build", "-ldflags=\"-X 'isc.org/stork.BuildDate=#{build_date}'\""
83+
end
84+
puts "Stork Server build date: #{build_date} (timestamp: #{TIMESTAMP})"
85+
end
86+
87+
TOOL_BINARY_FILE = "backend/cmd/stork-tool/stork-tool"
88+
file TOOL_BINARY_FILE => GO_TOOL_CODEBASE + [GO] do
89+
Dir.chdir("backend/cmd/stork-tool") do
90+
sh GO, "build", "-ldflags=\"-X 'isc.org/stork.BuildDate=#{build_date}'\""
91+
end
92+
puts "Stork Tool build date: #{build_date} (timestamp: #{TIMESTAMP})"
93+
end
94+
95+
#############
96+
### Tasks ###
97+
#############
98+
99+
## Documentation
100+
101+
task :build_doc => man_files + [ARM_DIRECTORY]
102+
103+
task :rebuild_doc do
104+
sh "touch", "doc"
105+
Rake::Task["build_doc"].invoke()
106+
end
107+
108+
## Stork Server
109+
110+
desc "Build Stork Server from sources"
111+
task :build_server => [SERVER_BINARY_FILE]
112+
113+
desc "Rebuild Stork Server from sources"
114+
task :rebuild_server do
115+
sh "touch", "backend/cmd/stork-server"
116+
Rake::Task["build_server"].invoke()
117+
end
118+
119+
# Internal task that configure environment variables for server
120+
task :pre_run_server, [:dbtrace, :ui_mode] do |t, args|
121+
if args.dbtrace == "true"
122+
ENV["STORK_DATABASE_TRACE_QUERIES"] = "run"
123+
end
124+
125+
use_testing_ui = false
126+
# If the UI mode is not provided then detect it
127+
if args.ui_mode == nil
128+
# Enable testing mode if live build UI is active
129+
use_testing_ui = system "pgrep", "-f", "ng build --watch"
130+
# Enable testing mode if testing dir is newer then production dir
131+
if use_testing_ui == true
132+
puts "Using testing UI - live UI build is active"
133+
else
134+
production_time = File.mtime(WEBUI_DIST_DIRECTORY)
135+
testing_time = File.mtime(WEBUI_DEBUG_DIRECTORY)
136+
use_testing_ui = testing_time > production_time
137+
puts "Using testing UI - testing UI is newer than production"
138+
end
139+
elsif args.ui_mode == "testing"
140+
# Check if user manually forces the UI mode
141+
use_testing_ui = true
142+
puts "Using testing UI - user choice"
143+
elsif args.ui_mode != "production"
144+
puts "Invalid UI mode - choose 'production' or 'testing'"
145+
fail
146+
end
147+
if use_testing_ui
148+
ENV["STORK_REST_STATIC_FILES_DIR"] = "./webui/dist/stork-debug"
149+
end
150+
151+
ENV["STORK_SERVER_ENABLE_METRICS"] = "true"
152+
end
153+
154+
desc "Run Stork Server (release mode)"
155+
task :run_server, [:dbtrace, :ui_mode] => [SERVER_BINARY_FILE, :pre_run_server] do
156+
sh SERVER_BINARY_FILE
157+
end
158+
159+
## Stork Agent
160+
161+
desc "Build Stork Agent from sources"
162+
task :build_agent => [AGENT_BINARY_FILE]
163+
164+
desc "Rebuild Stork Agent from sources"
165+
task :rebuild_agent do
166+
sh "touch", "backend/cmd/stork-agent"
167+
Rake::Task["build_agent"].invoke()
168+
end
169+
170+
desc "Run Stork Agent (release mode)"
171+
task :run_agent, [:port] => [AGENT_BINARY_FILE] do |t, args|
172+
args.with_defaults(:port => "8888")
173+
sh AGENT_BINARY_FILE, "--port", args.port
174+
end
175+
176+
## Stork Tool
177+
178+
desc "Build Stork Tool from sources"
179+
task :build_tool => [TOOL_BINARY_FILE]
180+
181+
desc "Rebuild Stork Tool from sources"
182+
task :rebuild_tool do
183+
sh "touch", "backend/cmd/stork-tool"
184+
Rake::Task["build_tool"].invoke()
185+
end
186+
187+
## Stork UI
188+
189+
desc "Build Web UI (production mode)"
190+
task :build_ui => [WEBUI_DIST_DIRECTORY, WEBUI_DIST_ARM_DIRECTORY]
191+
192+
desc "Rebuild Web UI (production mode)"
193+
task :rebuild_ui do
194+
sh "touch", "webui"
195+
Rake::Task["build_ui"].invoke()
196+
end
197+
198+
## Shorthands
199+
200+
desc "Build Stork Backend (Server, Agent, Tool)"
201+
task :build_backend => [:build_server, :build_agent, :build_tool]
202+
203+
desc "Build all Stork components (Server, Agent, Tool, UI, doc)"
204+
task :build_all => [:build_backend, :build_doc, :build_ui]

0 commit comments

Comments
 (0)