diff --git a/fe/app/service/page.tsx b/fe/app/service/page.tsx index af90e5e..55fa3ac 100644 --- a/fe/app/service/page.tsx +++ b/fe/app/service/page.tsx @@ -80,12 +80,12 @@ export default function ServicePage() {
  • {activeService === service.id ? ( scrollToService(service.name)} /> ) : ( scrollToService(service.name)} /> )} diff --git a/fe/components/ServiceForm.tsx b/fe/components/ServiceForm.tsx index 3295acb..4852ac8 100644 --- a/fe/components/ServiceForm.tsx +++ b/fe/components/ServiceForm.tsx @@ -5,13 +5,22 @@ import Image from 'next/image'; import exclamationImg from '@/public/exclamation.png' import { Env } from '@/types'; import { time } from 'console'; +import { uniqueNamesGenerator, Config, adjectives, animals } from 'unique-names-generator'; + const ServiceForm = () => { + + const customConfig: Config = { + dictionaries: [adjectives, animals], + separator: '_', + length: 2, + }; const env: Env = { 'any':'any' } const [imageName, setImageName] = useState(''); const [port, setPort] = useState(0); + const [deploymentName, setDeploymentName] = useState(uniqueNamesGenerator(customConfig)); // const [env, setEnv] = useState(Env); // const [region, setRegion] = useState('US East (Ohio)'); @@ -29,6 +38,7 @@ const ServiceForm = () => { 'image': imageName.trim(), 'port': Number(port), 'env': env, + 'deploymentName': deploymentName, }), }); console.log(resp.text()); @@ -38,7 +48,17 @@ const ServiceForm = () => { return (
    - + + {setDeploymentName(e.target.value) + console.log(deploymentName) + }} + placeholder="e.g., docker.io/library/nginx:latest" + className="text-4xl font-bold w-full bg-transparent text-white px-3 py-2 focus:border-r-2 rounded hover:shadow-[inset_-32px_0_32px_-15px_rgba(255,255,255,0.2)] transition-shadow duration-150 focus:outline-none focus:shadow-[inset_-32px_0_20px_-15px_rgba(255,255,255,0.2)] transition-shadow duration-300"/> +
    diff --git a/fe/components/Services.tsx b/fe/components/Services.tsx index 35e2d93..9e234cf 100644 --- a/fe/components/Services.tsx +++ b/fe/components/Services.tsx @@ -6,7 +6,7 @@ export default function Services({ services }: { services: Service[] }) { {services.map((service) => (
    -

    {service.name}

    +

    {service.deploymentName}

    hi {/* Add the content for each service section here */} diff --git a/fe/package-lock.json b/fe/package-lock.json index a26ee98..ad16efd 100644 --- a/fe/package-lock.json +++ b/fe/package-lock.json @@ -12,8 +12,10 @@ "@splinetool/runtime": "^1.7.6", "next": "14.2.4", "next-auth": "^4.24.7", + "random-words": "^2.0.1", "react": "^18", - "react-dom": "^18" + "react-dom": "^18", + "unique-names-generator": "^4.7.1" }, "devDependencies": { "@types/node": "^20", @@ -3955,6 +3957,14 @@ } ] }, + "node_modules/random-words": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/random-words/-/random-words-2.0.1.tgz", + "integrity": "sha512-nZNJAmgcFmtJMTDDIUCm/iK4R6RydC6NvALvWhYItXQrgYGk1F7Gww416LpVROFQtfVd5TaLEf4WuSsko03N7w==", + "dependencies": { + "seedrandom": "^3.0.5" + } + }, "node_modules/react": { "version": "18.3.1", "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", @@ -4206,6 +4216,11 @@ "loose-envify": "^1.1.0" } }, + "node_modules/seedrandom": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz", + "integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==" + }, "node_modules/semver": { "version": "7.6.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", @@ -4863,6 +4878,14 @@ "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", "dev": true }, + "node_modules/unique-names-generator": { + "version": "4.7.1", + "resolved": "https://registry.npmjs.org/unique-names-generator/-/unique-names-generator-4.7.1.tgz", + "integrity": "sha512-lMx9dX+KRmG8sq6gulYYpKWZc9RlGsgBR6aoO8Qsm3qvkSJ+3rAymr+TnV8EDMrIrwuFJ4kruzMWM/OpYzPoow==", + "engines": { + "node": ">=8" + } + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/fe/package.json b/fe/package.json index 3e4fa45..fb0de09 100644 --- a/fe/package.json +++ b/fe/package.json @@ -13,8 +13,10 @@ "@splinetool/runtime": "^1.7.6", "next": "14.2.4", "next-auth": "^4.24.7", + "random-words": "^2.0.1", "react": "^18", - "react-dom": "^18" + "react-dom": "^18", + "unique-names-generator": "^4.7.1" }, "devDependencies": { "@types/node": "^20", diff --git a/fe/types.ts b/fe/types.ts index 6779187..7f0e4e9 100644 --- a/fe/types.ts +++ b/fe/types.ts @@ -40,6 +40,7 @@ export interface Service{ user: string; userName: string; logs: string; + deploymentName: string; } export interface Env { [variableName: string]: string; diff --git a/pkg/controllers/deploy-container.go b/pkg/controllers/deploy-container.go index c19a37c..b3b1b5f 100644 --- a/pkg/controllers/deploy-container.go +++ b/pkg/controllers/deploy-container.go @@ -16,12 +16,12 @@ import ( ) // Deploy the container -func Deploy_container(UserName string, Image string, Port int32, Environment map[string]string) (*byocTypes.Service, error) { +func Deploy_container(newDeployment *byocTypes.DeployContainerPayload) (*byocTypes.Service, error) { // KeyValuePair Environment2 := func() []types.KeyValuePair { var Environment2 []types.KeyValuePair - for key, value := range Environment { + for key, value := range newDeployment.Environment { Environment2 = append(Environment2, types.KeyValuePair{ Name: &key, Value: &value, @@ -41,17 +41,17 @@ func Deploy_container(UserName string, Image string, Port int32, Environment map svc := ecs.NewFromConfig(cfg) sess := session.Must(session.NewSession()) elbSvc := elbv2.New(sess) - err = core.CreateCluster(svc, UserName) + err = core.CreateCluster(svc, newDeployment.UserName) if err != nil { return nil, err } - err = core.CreateTaskDefinition(svc, UserName, Image, Port, Environment2) + err = core.CreateTaskDefinition(svc, newDeployment.UserName, newDeployment.Image, int32(newDeployment.Port), Environment2) if err != nil { return nil, err } - service, err := core.CreateService(svc, elbSvc, UserName, Image, Port, Environment2) + service, err := core.CreateService(svc, elbSvc, newDeployment.UserName, newDeployment.Image, int32(newDeployment.Port), Environment2, newDeployment.DeplomentName) if err != nil { return nil, err } @@ -62,7 +62,7 @@ func Deploy_container(UserName string, Image string, Port int32, Environment map return nil, nil } - service.Slug, err = GenerateSlug(UserName) + service.Slug, err = GenerateSlug(newDeployment.UserName) if err != nil { return nil, err } diff --git a/pkg/core/service-ops.go b/pkg/core/service-ops.go index 4d15c47..f17ad37 100644 --- a/pkg/core/service-ops.go +++ b/pkg/core/service-ops.go @@ -13,7 +13,7 @@ import ( byocTypes "github.com/g4ze/byoc/pkg/types" ) -func CreateService(svc *ecs.Client, elbSvc *elbv2.ELBV2, UserName string, Image string, Port int32, Environment []types.KeyValuePair) (*byocTypes.Service, error) { +func CreateService(svc *ecs.Client, elbSvc *elbv2.ELBV2, UserName string, Image string, Port int32, Environment []types.KeyValuePair, DeploymentName string) (*byocTypes.Service, error) { var desiredCount int32 = 2 containerName := generateName(UserName, Image, "container") serviceName := generateNameFromImage(Image) @@ -125,6 +125,7 @@ func CreateService(svc *ecs.Client, elbSvc *elbv2.ELBV2, UserName string, Image Cluster: UserName, Image: Image, EventListenerARN: EventListenerARN, + DeploymentName: DeploymentName, }, nil } diff --git a/pkg/database/Service.go b/pkg/database/Service.go index 6568266..0a9e56b 100644 --- a/pkg/database/Service.go +++ b/pkg/database/Service.go @@ -38,6 +38,7 @@ func InsertService(Service *types.Service, userName string) error { db.Service.User.Link( db.User.UserName.Equals(userName), ), + db.Service.DeploymentName.Set(Service.DeploymentName), ).Exec(ctx) if err != nil { return err diff --git a/pkg/database/schema.prisma b/pkg/database/schema.prisma index 77e1eab..e7ed43d 100644 --- a/pkg/database/schema.prisma +++ b/pkg/database/schema.prisma @@ -38,4 +38,5 @@ model Service { userName String // logging functionality still in development logs String? + deploymentName String @default("default") } diff --git a/pkg/handlers/deploy-container.go b/pkg/handlers/deploy-container.go index 57d499b..a16f457 100644 --- a/pkg/handlers/deploy-container.go +++ b/pkg/handlers/deploy-container.go @@ -7,6 +7,7 @@ import ( "github.com/g4ze/byoc/pkg/controllers" "github.com/g4ze/byoc/pkg/database" + "github.com/g4ze/byoc/pkg/types" "github.com/gin-gonic/gin" ) @@ -16,7 +17,7 @@ func Deploy_Container(c *gin.Context) { // return response to client // check if request payload matches the required payload - var reqPayload DeployContainerPayload + var reqPayload types.DeployContainerPayload err := json.NewDecoder(c.Request.Body).Decode(&reqPayload) if err != nil { @@ -26,14 +27,13 @@ func Deploy_Container(c *gin.Context) { // extracting user name from the auth add on param reqPayload.UserName = c.Params.ByName("user") log.Printf("Received request to deploy container: %v", reqPayload) - + log.Printf("Deployment Name: %v", reqPayload.DeploymentName) // validate the request payload if reqPayload.Image == "" || reqPayload.UserName == "" || (reqPayload.Port) == 0 { http.Error(c.Writer, "Invalid request payload", http.StatusBadRequest) return } - Int32Port := int32(reqPayload.Port) - resp, err := controllers.Deploy_container(reqPayload.UserName, reqPayload.Image, Int32Port, reqPayload.Environment) + resp, err := controllers.Deploy_container(&reqPayload) if err != nil { http.Error(c.Writer, err.Error(), http.StatusInternalServerError) return diff --git a/pkg/types/database-types.go b/pkg/types/database-types.go index 2442641..6f00d4d 100644 --- a/pkg/types/database-types.go +++ b/pkg/types/database-types.go @@ -22,4 +22,5 @@ type Service struct { Image string `json:"image"` Slug string `json:"slug"` EventListenerARN string `json:"eventListenerARN"` + DeploymentName string `json:"deploymentName"` } diff --git a/pkg/types/requests-types.go b/pkg/types/requests-types.go index 5b356ae..d37345c 100644 --- a/pkg/types/requests-types.go +++ b/pkg/types/requests-types.go @@ -5,8 +5,9 @@ type DeleteContainer struct { UserName string `json:"userName"` } type DeployContainerPayload struct { - Image string `json:"image"` - UserName string `json:"userName"` - Port int `json:"port"` - Environment map[string]string `json:"environment"` + DeploymentName string `json:"deploymentName"` + Image string `json:"image"` + UserName string `json:"userName"` + Port int `json:"port"` + Environment map[string]string `json:"environment"` }