-
Notifications
You must be signed in to change notification settings - Fork 0
/
values.yml
303 lines (283 loc) · 16.4 KB
/
values.yml
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
replicaCount: 1
image:
repository: 9mine/9minegrid-marketplace
tag: "main"
pullPolicy: Always
initContainerImage:
repository: 9mine/execfuse-jinja2
tag: "master"
pullPolicy: Always
serviceAccount:
create: false
securityContext:
privileged: true
capabilities:
add:
- SYS_ADMIN
service:
type: ClusterIP
port: 2500
ClusterIPRange:
from: 2501
to: 2530
description: "9minegrid-marketplace"
fs: |
{% include './common.j2' %}
fs:
# root
"/":
readdir:
sh: ls /accounts
getattr:
sh: *dir
# /<id>
"/[0-9]+":
name: id
readdir:
list:
- 9minegrid
getattr:
sh: *dir
# /<id/.init.lua
"/.init.lua":
getattr:
sh: *file
read_file:
sh: |
cat <<EOF
-- function used to check if requested service already available
-- or it is in process of creation. If check fails, than next check
-- will be made in 5 seconds. If service is present HUD in right bottom
-- corner will show information and than in 20 seconds will be removed
function check_service_availability(conn, player_name, name, helm_hud_id, repo_branch)
local result = np_prot.file_read(conn.conn, "index")
if result:find(name:gsub("^[0-9]+", "n") .. "-svc", 1, true) then
local res = name:gsub("^[0-9]+", "n") .. "-svc"
res = res:gsub("%-", "%%%-")
res = result:match("tcp%!" .. res .. "%![0-9]+")
minetest.chat_send_player(player_name, "Resource " .. minetest.formspec_escape(res) .. " found in registry")
local player = minetest.get_player_by_name(player_name)
player:hud_change(helm_hud_id, "text", name .. " installed")
local http = require("ssl.https")
local body = http.request("https://raw.githubusercontent.com/9mine/" .. name .. "/" .. repo_branch .. "/formspec.lua")
if not body then
return
end
local external_form = loadstring(body)
if not external_form then return end
local context = {
player_name = player_name,
res = res
}
setmetatable(context, {
__index = _G
})
setfenv(external_form, context)
minetest.after(2, function()
external_form()
end)
minetest.after(1, function()
player:hud_remove(helm_hud_id)
end)
return
end
minetest.chat_send_player(player_name, "Resource " .. name .. " not found in registry")
minetest.after(5, check_service_availability, conn, player_name, name, helm_hud_id, repo_branch)
end
-- function for handling player interaction with forms
-- shown after punching 'search' entity
local marketplace = function(player, formname, fields)
if formname == "core:marketplace" then
-- if esc key pressed then close form
if fields.quit == "true" then
return
end
local player_name = player:get_player_name()
local repo_url = fields.url
local repo_branch = fields.repo_branch
-- if pressed button 'install'
if fields.install then
minetest.show_formspec(player_name, "core:marketplace", "")
local player_graph = graphs:get_player_graph(player_name)
-- path to file in which data will be written after 'install' press
-- by default, file 'install' if the same directory
local install_path = fields.platform_path == "/" and fields.platform.path .. "install" or
fields.platform_path .. "/install"
local conn = player_graph:get_platform(common.get_platform_string(player)):get_conn()
local result, response = pcall(np_prot.file_write, conn, install_path, repo_url)
-- notify player about writing to file outcome
minetest.chat_send_player(player_name,
result and "File successfully saved" or "Editing file failed: " .. response)
local registry_addr = common.get_env(grid_conf, "REGISTRY_ADDR")
conn = connections:get_connection(player_name, registry_addr, true)
local helm_hud_id = player:hud_add({
hud_elem_type = "text",
position = {
x = 1,
y = 0.97
},
offset = {
x = -(string.len("Installing some long string there") * 10) - 5
},
text = "Installing " .. fields.repo_name,
number = 0xFF0000,
size = {
x = 2
},
scale = {
x = 100,
y = 100
}
})
minetest.after(1, check_service_availability, conn, player_name, fields.repo_name, helm_hud_id, repo_branch)
return
end
local repo = ""
local repo_idx = ""
local repo_branch = ""
local repo_name = fields.repo_name
-- get events of user interaction with table in formspec
local event = core.explode_table_event(fields["repos"])
-- if some row in the form was selected
-- set values if new formspec to those
if event.row ~= 0 then
local repos_for_k8s = minetest.deserialize(fields.repos_for_k8s)
-- lua table with contains selected repository information
repo = repos_for_k8s[event.row]
-- ID of the row selected
repo_idx = event.row
repo_url = repo.url
repo_name = repo.name
repo_branch = repo.defaultBranchRef.name
end
-- send new formspec to player with updated values
minetest.show_formspec(player_name, "core:marketplace",
table.concat({"formspec_version[4]", "size[15.5,9,false]",
"field[0,0;0,0;repo_name;;" .. minetest.formspec_escape(repo_name) .. "]",
"field[0,0;0,0;platform_path;;" .. minetest.formspec_escape(fields.platform_path) .. "]",
"field[0,0;0,0;repos_list;;" .. minetest.formspec_escape(fields.repos_list) .. "]",
"field[0,0;0,0;url;;" .. minetest.formspec_escape(repo_url) .. "]",
"field[0,0;0,0;repo_branch;;" .. minetest.formspec_escape(repo_branch) .. "]",
"field[0,0;0,0;repos_for_k8s;;" .. minetest.formspec_escape(fields.repos_for_k8s) .. "]",
"hypertext[0, 0.2; 15.5, 1;;<bigger><center>9mine marketplace</center></bigger>]",
"table[0.5, 1.2; 7, 7.3;repos;" .. fields.repos_list .. ";" .. repo_idx .. "]",
"image[8, 1.2; 7, 3.8;" .. repo.name .. ".png]",
"hypertext[8, 5.2; 7, 2.5;;<big><justify>" .. minetest.formspec_escape(repo.description) ..
"</center></justify>]",
"hypertext[8, 7.8; 3.5, 1;;<big>Rating: " .. repo.stargazerCount .. " stars</big>]",
"button[12, 7.8; 3, 0.7;install;install]"}, ""))
end
end
register.add_form_handler("core:marketplace", marketplace)
local function set_texture(entry, entity)
local prefix = init_path:match("/$") and init_path:sub(1, -2) or init_path
if not prefix then
return
end
if entry.entry_string == prefix .. "/9minegrid/search" then
entity:set_properties({
visual = "sprite",
textures = {"core_marketplace.png"}
})
entity:get_luaentity().on_punch = function(self, player)
local player_name = player:get_player_name()
local player_graph = graphs:get_player_graph(player_name)
local entry = player_graph:get_entry(self.entry_string)
local conn = player_graph:get_platform(common.get_platform_string(player)):get_conn()
-- file read will return json array of objects
-- objects represents reposities, which nave '9minegrid-marketplace' tag
-- with following fields:
-- "openGraphImageUrl", "description", "stargazerCount", "name", "url"
local response, content = pcall(np_prot.file_read, conn, entry.path)
if not response then
minetest.chat_send_player(player_name, content)
return
else
local json = require("cjson")
-- convert json object to lua tables
local repos_for_k8s = json.decode(content)
local repos = ""
-- generate string with repos names separated with commas
-- each value represents row in a table
-- download icons for repos
for _, repo in pairs(repos_for_k8s) do
repos = repos == "" and repo.name or repos .. "," .. repo.name
texture.download(repo.openGraphImageUrl, true, repo.name .. ".png", "marketplace")
end
minetest.show_formspec(player_name, "core:marketplace",
table.concat({"formspec_version[4]", "size[15.5,9,false]",
"field[0,0;0,0;platform_path;;" ..
minetest.formspec_escape(entry.platform_path) .. "]",
"field[0,0;0,0;repos_list;;" .. minetest.formspec_escape(repos) .. "]",
"field[0,0;0,0;repos_for_k8s;;" ..
minetest.formspec_escape(minetest.serialize(repos_for_k8s)) .. "]",
"hypertext[0, 0.2; 15.5, 1;;<bigger><center>9mine marketplace</center></bigger>]",
"table[0.5, 1.2; 7, 7.3;repos;" .. repos .. ";]",
"image[8, 1.2; 7, 3.8;core_marketplace.png]",
"hypertext[8, 5.2; 7, 3.3;;Welcome to 9mine marketplace. Please, choose one of available filesystems and press 'install'. This will deploy filesystem on a k8s cluster. New filesystem address will appear in the 9mine registry (use tool 'registry' to access 9mine registry). \n ! Please, note, that filesystem deployment could take up to 2 minutes. Until deployment is finished, fileystem will not appear in registry.]"},
""))
return
end
end
end
end
register.add_texture_handler(init_path .. "marketplace", set_texture)
EOF
# /<id>/9minegrid
"/9minegrid":
getattr:
sh: *dir
readdir:
list:
- install
- search
# /<id>/9minegrid/install
"/install":
getattr:
sh: *file
read_file:
sh: |
cat /accounts/$id/out
write_file:
sh: |
REPO_URL="$(cat $CACHE_FILE_NAME)"
REPO_NAME="$(basename $REPO_URL .git)"
rm -rf "$REPO_NAME"
git clone "$REPO_URL" "$REPO_NAME"
helm upgrade --install "$(echo $REPO_NAME | sed 's/[0-9]\+/n/')"-svc 9mine/9p-execfuse-jinja2 -f "${REPO_NAME}/values.yml" --kubeconfig=/accounts/$id/config > /accounts/$id/out 2>&1
#/<id>/9minegrid/search
"/search":
cache: 9600
getattr:
sh: *file
read_file:
sh: |
curl -H "Authorization: token $GITHUB_ACCESS_TOKEN" -H "Content-Type:application/json" -d '{ "query": "{ organization(login: \"9mine\") { repositories(last: 37) { nodes { refs(refPrefix:\"refs/tags/\", last: 1, query: \"9minegrid-marketplace\") { nodes { repository { defaultBranchRef { name } openGraphImageUrl description stargazerCount name url } } } } } } } " }' https://api.github.com/graphql | jq '[.data.organization.repositories.nodes[].refs.nodes[].repository]'
profile: |
echo --- start of profile loading ---
load file2chan
load std
ndb/cs
for host_var in `{ os env } { '{'$host_var'}' }
test -d /tmp || mkdir -p /tmp
test -d /mnt/registry || mkdir -p /mnt/registry
mount -A tcp!registry!registry /mnt/registry
dir = $EXPORT_PATH
port = $NINEP_PUBLIC_PORT
echo $NINEP_PUBLIC_HOST > /dev/sysname
load mpexpr
fs_port = ${expr $NINEP_PUBLIC_PORT 1 +}
file2chan /tmp/kubectl {
} {
load mpexpr
var=${expr 10 rand}
echo new id is $var
config =`{echo ${rget data}}]
`{os /bin/bash -c 'mkdir -p /accounts/'^$var}
`{os /bin/bash -c 'echo '^$config^' | base64 -d > /accounts/'^$var^'/config'}
grid/reglisten -A -r description 'user id is '^$var tcp!*!^$fs_port { export $dir^/^$var & } &
fs_port=${expr $fs_port 1 +}
}
grid/reglisten -A -r description ${quote $NINEP_DESCRIPTION} 'tcp!*!'^$port { export /tmp & }
test -n $status && os pkill -9 emu-g
echo --- end of profile loading ---