.
This commit is contained in:
parent
7510c2a7b3
commit
73b2f7f3b5
10 changed files with 67 additions and 35 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -3,8 +3,9 @@
|
||||||
/starter/alpine-make-rootfs/
|
/starter/alpine-make-rootfs/
|
||||||
/run
|
/run
|
||||||
/starter/shared
|
/starter/shared
|
||||||
/starter/starter
|
/starter/starter.so
|
||||||
/starter/minrootfs
|
/starter/minrootfs
|
||||||
|
/transport/transport
|
||||||
/pkg/go/gen
|
/pkg/go/gen
|
||||||
/gen
|
/gen
|
||||||
/runs
|
/runs
|
||||||
|
|
22
Makefile
22
Makefile
|
@ -1,13 +1,11 @@
|
||||||
.PHONY: all clean install uninstall test
|
.PHONY: all clean install uninstall test
|
||||||
|
|
||||||
PROTOBUF=/usr/include/
|
PROTOBUF=/usr/include/
|
||||||
STARTER=starter
|
|
||||||
GEN=gen
|
GEN=gen
|
||||||
SRCS=$(STARTER)/cgroup_prepare.c $(STARTER)/ns_exec.c $(STARTER)/util.c $(STARTER)/starter.c
|
|
||||||
RUNS=runs
|
RUNS=runs
|
||||||
PROTO_OUT=$(GEN)/google/protobuf/empty.pb-c.c $(GEN)/google/protobuf/empty.pb-c.h $(GEN)/google/protobuf/timestamp.pb-c.c $(GEN)/google/protobuf/timestamp.pb-c.h $(GEN)/google/protobuf/duration.pb-c.c $(GEN)/google/protobuf/duration.pb-c.h gen/runner/v1/runner.pb-c.c gen/runner/v1/runner.pb-c.c
|
PROTO_OUT=$(GEN)/google/protobuf/empty.pb-c.c $(GEN)/google/protobuf/empty.pb-c.h $(GEN)/google/protobuf/timestamp.pb-c.c $(GEN)/google/protobuf/timestamp.pb-c.h $(GEN)/google/protobuf/duration.pb-c.c $(GEN)/google/protobuf/duration.pb-c.h gen/runner/v1/runner.pb-c.c gen/runner/v1/runner.pb-c.c
|
||||||
|
|
||||||
all: $(STARTER)/alpine-make-rootfs $(STARTER)/minrootfs $(STARTER)/starter transport/transport $(RUNS)
|
all: starter/alpine-make-rootfs starter/minrootfs starter/starter.so transport/transport $(RUNS) $(GEN)/google/protobuf/empty.pb-c.c $(GEN)/google/protobuf/empty.pb-c.h $(GEN)/google/protobuf/timestamp.pb-c.c $(GEN)/google/protobuf/timestamp.pb-c.h $(GEN)/google/protobuf/duration.pb-c.c $(GEN)/google/protobuf/duration.pb-c.h $(GEN)/runner/v1/runner.pb-c.c $(GEN)/runner/v1/runner.pb-c.h
|
||||||
|
|
||||||
$(GEN):
|
$(GEN):
|
||||||
mkdir -p $(GEN)
|
mkdir -p $(GEN)
|
||||||
|
@ -21,23 +19,21 @@ $(GEN)/google/protobuf/timestamp.pb-c.c $(GEN)/google/protobuf/timestamp.pb-c.h:
|
||||||
$(GEN)/google/protobuf/duration.pb-c.c $(GEN)/google/protobuf/duration.pb-c.h: $(PROTOBUF)/google/protobuf/duration.proto $(GEN)
|
$(GEN)/google/protobuf/duration.pb-c.c $(GEN)/google/protobuf/duration.pb-c.h: $(PROTOBUF)/google/protobuf/duration.proto $(GEN)
|
||||||
protoc --c_out=$(GEN) google/protobuf/duration.proto -I $(PROTOBUF)
|
protoc --c_out=$(GEN) google/protobuf/duration.proto -I $(PROTOBUF)
|
||||||
|
|
||||||
gen/runner/v1/runner.pb-c.c gen/runner/v1/runner.pb-c.h: proto/runner/v1/runner.proto $(GEN)
|
$(GEN)/runner/v1/runner.pb-c.c $(GEN)/runner/v1/runner.pb-c.h: proto/runner/v1/runner.proto $(GEN)
|
||||||
protoc --c_out=$(GEN) runner/v1/runner.proto -I proto
|
protoc --c_out=$(GEN) runner/v1/runner.proto -I proto
|
||||||
|
|
||||||
|
|
||||||
$(STARTER)/alpine-make-rootfs:
|
starter/alpine-make-rootfs:
|
||||||
git clone https://github.com/alpinelinux/alpine-make-rootfs starter/alpine-make-rootfs
|
git clone https://github.com/alpinelinux/alpine-make-rootfs starter/alpine-make-rootfs
|
||||||
|
|
||||||
$(STARTER)/minrootfs: $(STARTER)/create_rootfs.sh
|
starter/minrootfs: starter/create_rootfs.sh
|
||||||
$(STARTER)/create_rootfs.sh
|
starter/create_rootfs.sh
|
||||||
|
|
||||||
$(STARTER)/starter: $(PROTO) $(STARTER)/starter.c $(STARTER)/cgroup_prepare.c $(STARTER)/ns_exec.c Makefile
|
starter/starter.so: $(PROTO) starter/starter.c starter/cgroup_prepare.c starter/ns_exec.c starter/util.c
|
||||||
#$(CC) -shared -o $(STARTER)/starter $(SRCS) -g -fsanitize=address -fsanitize=leak -fno-omit-frame-pointer -lrabbitmq -lprotobuf-c -I gen
|
$(CC) -fPIC -shared -o starter/starter.so $^ -lrabbitmq -lprotobuf-c -I gen
|
||||||
$(CC) -fPIC -shared -o $(STARTER)/starter $(SRCS) -lrabbitmq -lprotobuf-c -I gen
|
|
||||||
#$(CC) $(STARTER)/starter.c -o $(STARTER)/starter
|
|
||||||
|
|
||||||
transport/transport: $(PROTO) transport/utils.c transport/transport.c transport/transport.h
|
transport/transport: $(PROTO) transport/utils.c transport/transport.c transport/transport.h starter/starter.so
|
||||||
$(CC) -o $@ gen/runner/v1/runner.pb-c.c transport/utils.c transport/transport.c -I . -I gen -lrabbitmq -lprotobuf-c -g -fsanitize=address -fsanitize=leak -fno-omit-frame-pointer
|
$(CC) -o $@ gen/runner/v1/runner.pb-c.c transport/utils.c transport/transport.c starter/starter.so -I . -I starter -I gen -lrabbitmq -lprotobuf-c -lcurl -fsanitize=address -g
|
||||||
|
|
||||||
$(RUNS):
|
$(RUNS):
|
||||||
mkdir $(RUNS)
|
mkdir $(RUNS)
|
||||||
|
|
2
proto
2
proto
|
@ -1 +1 @@
|
||||||
Subproject commit 360832a5ab10821a76b7df5e23950e217f2c5221
|
Subproject commit 1138a5406c554ec29059da2da2a16eb001cc7b36
|
|
@ -9,14 +9,12 @@ void procfs_prepare()
|
||||||
#define hostname "runner"
|
#define hostname "runner"
|
||||||
|
|
||||||
#define put_old "oldfs"
|
#define put_old "oldfs"
|
||||||
void mnt_prepare(char* rootfs, char* shared_mountpoint) {
|
void mnt_prepare(char* rootfs, char* shared_folder) {
|
||||||
char* shared_folder = NULL;
|
|
||||||
asprintf(&shared_folder, "../%s", shared_mountpoint);
|
|
||||||
if (mount(rootfs, rootfs, "ext4", MS_BIND,"")) die("failed to mount %s: %m", rootfs);
|
if (mount(rootfs, rootfs, "ext4", MS_BIND,"")) die("failed to mount %s: %m", rootfs);
|
||||||
if (chdir(rootfs)) die("falied to cd:%m");
|
if (chdir(rootfs)) die("falied to cd:%m");
|
||||||
//if (mount("/sys","sys","sysfs",0,"")) die("failed to mount sysfs: %m");
|
//if (mount("/sys","sys","sysfs",0,"")) die("failed to mount sysfs: %m");
|
||||||
//if (mount("/dev","dev","udev",0,"")) die("failed to mount: %m");
|
//if (mount("/dev","dev","udev",0,"")) die("failed to mount: %m");
|
||||||
if (mkdir("shared", 0777) && errno != EEXIST) die("Failed to mkdir %s: %m\n", shared_mountpoint);
|
if (mkdir("shared", 0777) && errno != EEXIST) die("Failed to mkdir: %m\n");
|
||||||
if (mount(shared_folder, "shared", "ext4", MS_BIND, "")) die("failed to mount shared folder: %m");
|
if (mount(shared_folder, "shared", "ext4", MS_BIND, "")) die("failed to mount shared folder: %m");
|
||||||
if (mkdir(put_old, 0000) && errno != EEXIST) die("Failed to mkdir %s: %m\n", put_old);
|
if (mkdir(put_old, 0000) && errno != EEXIST) die("Failed to mkdir %s: %m\n", put_old);
|
||||||
if (syscall(SYS_pivot_root, ".", put_old)) die("Failed to pivot_root from %s to %s: %m\n", rootfs, put_old);
|
if (syscall(SYS_pivot_root, ".", put_old)) die("Failed to pivot_root from %s to %s: %m\n", rootfs, put_old);
|
||||||
|
@ -24,7 +22,6 @@ void mnt_prepare(char* rootfs, char* shared_mountpoint) {
|
||||||
procfs_prepare();
|
procfs_prepare();
|
||||||
if (umount2(put_old, MNT_DETACH)) die("Failed to umount put_old %s: %m\n", put_old);
|
if (umount2(put_old, MNT_DETACH)) die("Failed to umount put_old %s: %m\n", put_old);
|
||||||
if (rmdir(put_old)) die("Failed to rmdir: %m");
|
if (rmdir(put_old)) die("Failed to rmdir: %m");
|
||||||
free(shared_folder);
|
|
||||||
}
|
}
|
||||||
void ro_fs(char* shared_mountpoint) {
|
void ro_fs(char* shared_mountpoint) {
|
||||||
char* shared_folder = malloc(strlen(shared_mountpoint)+4);
|
char* shared_folder = malloc(strlen(shared_mountpoint)+4);
|
||||||
|
@ -69,7 +66,7 @@ int nsrun(void* arg) {
|
||||||
char* env[]={
|
char* env[]={
|
||||||
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||||
"PWD=/",
|
"PWD=/",
|
||||||
NULL,
|
(char*)0,
|
||||||
};
|
};
|
||||||
if (execve(cmd, argv, env) == -1) die("failed to exec,%m");
|
if (execve(cmd, argv, env) == -1) die("failed to exec,%m");
|
||||||
return 1;// removes warning
|
return 1;// removes warning
|
||||||
|
|
|
@ -48,13 +48,12 @@ static void prepare_userns(int pid) {
|
||||||
write_file(path, line);
|
write_file(path, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
int starter(char* working_path, struct limits limits, struct params params) {
|
int starter(char* shared_folder, char* minrootfs_path, struct limits limits, struct params params) {
|
||||||
|
puts("starter started");
|
||||||
if(setuid(0)) die("must be run as root");
|
if(setuid(0)) die("must be run as root");
|
||||||
if(setgid(0)) die("must be run as root");
|
if(setgid(0)) die("must be run as root");
|
||||||
// get binary path
|
// get binary path
|
||||||
char* real_path=working_path;
|
if(chdir(minrootfs_path)) die("unable to chdir: %m");
|
||||||
//get_real_path(real_path, argv[0]);
|
|
||||||
if(chdir(real_path)) die("unable to chdir to binary path: %m");
|
|
||||||
// set random seed
|
// set random seed
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
// setup parameters
|
// setup parameters
|
||||||
|
|
|
@ -51,3 +51,4 @@ extern void await_setup(int pipe);
|
||||||
extern int nsrun(void* arg);
|
extern int nsrun(void* arg);
|
||||||
extern void die_func(const char *fmt, ...);
|
extern void die_func(const char *fmt, ...);
|
||||||
extern void write_file(char* path, char* line);
|
extern void write_file(char* path, char* line);
|
||||||
|
extern int starter(char* shared_folder, char* minrootfs_path, struct limits limits, struct params params);
|
||||||
|
|
Binary file not shown.
|
@ -51,12 +51,13 @@ void send_to_rbmq(struct connection_data condata, char const* msg)
|
||||||
amqp_basic_publish(condata.conn, 1, amqp_cstring_bytes(condata.exchange), amqp_cstring_bytes(condata.routingkey), 0, 0, &props, amqp_cstring_bytes(msg)), "Publishing";
|
amqp_basic_publish(condata.conn, 1, amqp_cstring_bytes(condata.exchange), amqp_cstring_bytes(condata.routingkey), 0, 0, &props, amqp_cstring_bytes(msg)), "Publishing";
|
||||||
}
|
}
|
||||||
|
|
||||||
void build_serialize(int32_t solution_id, char* binding_key, int32_t language, char* solution, void** buf) {
|
void build_serialize(int32_t solution_id, char* binding_key, int32_t language, char* solution_uri, char* executable_uri, void** buf) {
|
||||||
struct Runner__V1__Build build = RUNNER__V1__BUILD__INIT;
|
struct Runner__V1__Build build = RUNNER__V1__BUILD__INIT;
|
||||||
build.solution_id = solution_id;
|
build.solution_id = solution_id;
|
||||||
build.binding_key = binding_key;
|
build.binding_key = binding_key;
|
||||||
build.language = language;
|
build.language = language;
|
||||||
build.solution = solution;
|
build.solution_uri = solution_uri;
|
||||||
|
build.executable_uri = executable_uri;
|
||||||
|
|
||||||
struct Runner__V1__Instruction inst = RUNNER__V1__INSTRUCTION__INIT;
|
struct Runner__V1__Instruction inst = RUNNER__V1__INSTRUCTION__INIT;
|
||||||
inst.instruction_case = RUNNER__V1__INSTRUCTION__INSTRUCTION_BUILD;
|
inst.instruction_case = RUNNER__V1__INSTRUCTION__INSTRUCTION_BUILD;
|
||||||
|
@ -91,11 +92,14 @@ int main(int argc, char const *const *argv) {
|
||||||
void *messagebody;
|
void *messagebody;
|
||||||
char* binding_key;
|
char* binding_key;
|
||||||
asprintf(&binding_key,"bktest");
|
asprintf(&binding_key,"bktest");
|
||||||
char* solution;
|
char* solution_uri;
|
||||||
asprintf(&solution,"soltest");
|
asprintf(&solution_uri,"http://localhost/code.cpp");
|
||||||
build_serialize(0,binding_key,1,solution,&messagebody);
|
char* executable_uri;
|
||||||
|
asprintf(&executable_uri,"http://localhost/executable");
|
||||||
|
build_serialize(0,binding_key,1,solution_uri, executable_uri, &messagebody);
|
||||||
free(binding_key);
|
free(binding_key);
|
||||||
free(solution);
|
free(solution_uri);
|
||||||
|
free(executable_uri);
|
||||||
send_to_rbmq(condata,messagebody);
|
send_to_rbmq(condata,messagebody);
|
||||||
free(messagebody);
|
free(messagebody);
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -1,5 +1,6 @@
|
||||||
#include "transport/transport.h"
|
#include "transport/transport.h"
|
||||||
#include "starter/starter.h"
|
#include "starter/starter.h"
|
||||||
|
#include "curl/curl.h"
|
||||||
|
|
||||||
void prepare_amqp_connection(int argc, char const *const *argv,struct connection_data *condata) {
|
void prepare_amqp_connection(int argc, char const *const *argv,struct connection_data *condata) {
|
||||||
int status;
|
int status;
|
||||||
|
@ -45,7 +46,27 @@ void prepare_amqp_connection(int argc, char const *const *argv,struct connection
|
||||||
amqp_assert(amqp_get_rpc_reply(condata->conn));
|
amqp_assert(amqp_get_rpc_reply(condata->conn));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void download_file(char* uri, char* path) {
|
||||||
|
FILE* f = fopen(path, "w");
|
||||||
|
//fwrite("test", 4,1,f);
|
||||||
|
CURL *handle;
|
||||||
|
handle = curl_easy_init();
|
||||||
|
curl_easy_setopt(handle, CURLOPT_URL, uri);
|
||||||
|
curl_easy_setopt(handle, CURLOPT_WRITEDATA, f);
|
||||||
|
CURLcode code = curl_easy_perform(handle);
|
||||||
|
if(code==CURLE_OK) {
|
||||||
|
int response_code;
|
||||||
|
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &response_code);
|
||||||
|
printf("response code:%d", response_code);
|
||||||
|
} else {puts("not success");}
|
||||||
|
sleep(1);
|
||||||
|
//puts(res);
|
||||||
|
curl_easy_cleanup(handle);
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char const *const *argv) {
|
int main(int argc, char const *const *argv) {
|
||||||
|
curl_global_init (CURL_GLOBAL_ALL);
|
||||||
struct connection_data condata;
|
struct connection_data condata;
|
||||||
prepare_amqp_connection(argc,argv,&condata);
|
prepare_amqp_connection(argc,argv,&condata);
|
||||||
|
|
||||||
|
@ -70,7 +91,20 @@ int main(int argc, char const *const *argv) {
|
||||||
switch(inst->instruction_case) {
|
switch(inst->instruction_case) {
|
||||||
case RUNNER__V1__INSTRUCTION__INSTRUCTION_BUILD:
|
case RUNNER__V1__INSTRUCTION__INSTRUCTION_BUILD:
|
||||||
puts("build request recieved");
|
puts("build request recieved");
|
||||||
printf("solution_id: %d\nbinding_key:%s\nlanguage:%d\nsolution:%s\n\n",inst->build->solution_id,inst->build->binding_key,inst->build->language,inst->build->solution);
|
printf("solution_id: %d\nbinding_key:%s\nlanguage:%d\nsolution uri:%s\nexecutable uri: %s\n\n",inst->build->solution_id,inst->build->binding_key,inst->build->language,inst->build->solution_uri, inst->build->executable_uri);
|
||||||
|
download_file(inst->build->solution_uri, "/home/dragonmuffin/ms-runner/runs/solution");
|
||||||
|
//struct limits limits;
|
||||||
|
//limits.memory = 10000000;
|
||||||
|
//limits.core = 2;
|
||||||
|
//limits.time = 3000;
|
||||||
|
//limits.processes = 1;
|
||||||
|
|
||||||
|
//struct params params;
|
||||||
|
//params.shared_folder = "/home/dragonmuffin/ms-runner/runs/";
|
||||||
|
//params.argv = (char*[]){"/bin/ls", "/", NULL};
|
||||||
|
|
||||||
|
//starter("/home/dragonmuffin/ms-runner/runs", "/home/dragonmuffin/ms-runner/starter", limits, params); // fix this
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case RUNNER__V1__INSTRUCTION__INSTRUCTION_RUN:
|
case RUNNER__V1__INSTRUCTION__INSTRUCTION_RUN:
|
||||||
puts("run request recieved");
|
puts("run request recieved");
|
||||||
|
|
Loading…
Add table
Reference in a new issue