Skip to content

Commit

Permalink
Merge pull request #10 from iIIusi0n/dev
Browse files Browse the repository at this point in the history
done!
  • Loading branch information
iIIusi0n authored Jan 13, 2025
2 parents 2ebe54b + 84ceda1 commit 3ba9e04
Show file tree
Hide file tree
Showing 39 changed files with 1,905 additions and 1,140 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CHATBOT_LISTEN_HOST=
CHATBOT_LISTEN_PORT=

DOCKER_HOST=
DOCKER_HOST_MOUNT_PATH=
INSTANCE_LISTEN_HOST=
INSTANCE_LISTEN_PORT=
INSTANCE_STREAMING_SERVICE_LISTEN_HOST=
Expand Down
33 changes: 33 additions & 0 deletions api/instance.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ option go_package = "easypwn/internal/api";

service Instance {
rpc CreateInstance(CreateInstanceRequest) returns (CreateInstanceResponse) {}

rpc GetInstance(GetInstanceRequest) returns (GetInstanceResponse) {}
rpc GetInstances(GetInstancesRequest) returns (GetInstancesResponse) {}

rpc DeleteInstance(DeleteInstanceRequest) returns (DeleteInstanceResponse) {}

rpc GetInstanceLogs(GetInstanceLogsRequest) returns (GetInstanceLogsResponse) {}

rpc StopInstance(StopInstanceRequest) returns (StopInstanceResponse) {}
rpc StartInstance(StartInstanceRequest) returns (StartInstanceResponse) {}
}

message CreateInstanceRequest {
Expand All @@ -27,6 +34,16 @@ message GetInstanceResponse {
string instance_id = 1;
string project_id = 2;
string container_id = 3;
string status = 4;
int32 memory = 5;
}

message GetInstancesRequest {
string project_id = 1;
}

message GetInstancesResponse {
repeated GetInstanceResponse instances = 1;
}

message DeleteInstanceRequest {
Expand All @@ -44,4 +61,20 @@ message GetInstanceLogsRequest {

message GetInstanceLogsResponse {
string logs = 1;
}

message StopInstanceRequest {
string instance_id = 1;
}

message StopInstanceResponse {
string instance_id = 1;
}

message StartInstanceRequest {
string instance_id = 1;
}

message StartInstanceResponse {
string instance_id = 1;
}
4 changes: 2 additions & 2 deletions assets/mysql/initdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ CREATE TABLE IF NOT EXISTS project (

CREATE TABLE IF NOT EXISTS instance (
id BINARY(16) PRIMARY KEY NOT NULL UNIQUE,
project_id BINARY(16) NOT NULL REFERENCES project(id),
project_id BINARY(16) NOT NULL REFERENCES project(id) ON DELETE CASCADE,
container_id VARCHAR(64) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS instance_log (
id BINARY(16) PRIMARY KEY NOT NULL UNIQUE,
instance_id BINARY(16) NOT NULL REFERENCES instance(id),
instance_id BINARY(16) NOT NULL REFERENCES instance(id) ON DELETE CASCADE,
log TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
Expand Down
6 changes: 6 additions & 0 deletions cmd/api-gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var (

chatbotListenHost = os.Getenv("CHATBOT_LISTEN_HOST")
chatbotListenPort = os.Getenv("CHATBOT_LISTEN_PORT")

dockerHostMountPath = os.Getenv("DOCKER_HOST_MOUNT_PATH")
)

func init() {
Expand All @@ -54,6 +56,10 @@ func init() {
if chatbotListenHost == "" || chatbotListenPort == "" {
log.Fatalf("CHATBOT_LISTEN_HOST and CHATBOT_LISTEN_PORT must be set")
}

if dockerHostMountPath == "" {
log.Fatalf("DOCKER_HOST_MOUNT_PATH must be set")
}
}

func main() {
Expand Down
3 changes: 3 additions & 0 deletions cmd/instance-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"

pb "easypwn/internal/api"
"easypwn/internal/pkg/instance"
"easypwn/internal/service"

"google.golang.org/grpc"
Expand All @@ -24,6 +25,8 @@ func init() {
}

func main() {
instance.InitImages()

lis, err := net.Listen("tcp", fmt.Sprintf(":%s", listenPort))
if err != nil {
log.Fatalf("failed to listen: %v", err)
Expand Down
14 changes: 9 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ services:
- CHATBOT_LISTEN_PORT=${CHATBOT_LISTEN_PORT}
- AUTH_JWT_SECRET=${AUTH_JWT_SECRET}
- DATABASE_URL=${DATABASE_URL}
- DOCKER_HOST_MOUNT_PATH=${DOCKER_HOST_MOUNT_PATH}
volumes:
- easypwn_data:/var/lib/easypwn
- /tmp/easypwn-data:/var/lib/easypwn
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- chatbot
- mailer
Expand Down Expand Up @@ -93,9 +95,10 @@ services:
- PROJECT_LISTEN_PORT=${PROJECT_LISTEN_PORT}
- DATABASE_URL=${DATABASE_URL}
- DOCKER_HOST=${DOCKER_HOST}
- DOCKER_HOST_MOUNT_PATH=${DOCKER_HOST_MOUNT_PATH}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- easypwn_data:/var/lib/easypwn
- /tmp/easypwn-data:/var/lib/easypwn
depends_on:
mysqldb:
condition: service_healthy
Expand All @@ -109,9 +112,10 @@ services:
- INSTANCE_LISTEN_PORT=${INSTANCE_LISTEN_PORT}
- DATABASE_URL=${DATABASE_URL}
- DOCKER_HOST=${DOCKER_HOST}
- DOCKER_HOST_MOUNT_PATH=${DOCKER_HOST_MOUNT_PATH}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- easypwn_data:/var/lib/easypwn
- /tmp/easypwn-data:/var/lib/easypwn
depends_on:
mysqldb:
condition: service_healthy
Expand All @@ -130,9 +134,10 @@ services:
- AUTH_JWT_SECRET=${AUTH_JWT_SECRET}
- DATABASE_URL=${DATABASE_URL}
- DOCKER_HOST=${DOCKER_HOST}
- DOCKER_HOST_MOUNT_PATH=${DOCKER_HOST_MOUNT_PATH}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- easypwn_data:/var/lib/easypwn
- /tmp/easypwn-data:/var/lib/easypwn
depends_on:
- project-service
- instance-service
Expand Down Expand Up @@ -171,4 +176,3 @@ services:

volumes:
mysql_data:
easypwn_data:
68 changes: 18 additions & 50 deletions internal/api/chatbot.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/api/chatbot_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3ba9e04

Please sign in to comment.