dokploy icon indicating copy to clipboard operation
dokploy copied to clipboard

feat: server support custom name

Open hehehai opened this issue 1 year ago • 14 comments

done: #39

https://github.com/Dokploy/dokploy/assets/12692552/48320416-6f81-466e-98ac-42f4f07d4153

hehehai avatar May 15 '24 11:05 hehehai

First of all thank you!

Here I see that we can have different cases of problems that may have given that the appName refers to the name of the docker container.

Example:

We create a project called: dokploy

  1. We create an application called backend, the appName would be dokploy-backend (ALL GOOD)
  2. We create a database called backend, the appName would be dokploy-backend (At the moment of deploy there will be an error since the application has the same name so it would enter in conflict)
  3. the appName should be validated in a regular expression, example when you try to deploy a docker container with the following name : dokploy-backend-2- -> this will be an error because is not a DNS name valid, instead it should be something like dokploy-backend so in short the name should cover the docker name validation and it should be a dns name valid.

I would propose 2 ways

Give multiple options to choose in the appName:

  1. To be able to randomly generate the appName as it is currently working which should be the default.
  2. To be able to generate the name as you implemented it in your PR, but you would have to verify in the tables of mysql, postgres, mongo, redis and mariadb to verify that the appName does not exist, and if it does exist to throw an error because this would make that there could not be duplicate appName in all the docker system.

Siumauricio avatar May 16 '24 04:05 Siumauricio

I think the second option is much more relevant; however, you could combine both solutions.

Using random names makes app setup and debugging more challenging because you can't identify what each service does.

But if we use names like 'myproject-myservice-', it could be sufficient. This approach requires more thought.

TheoCouss avatar May 16 '24 18:05 TheoCouss

I think the second option is much more relevant; however, you could combine both solutions.

Using random names makes app setup and debugging more challenging because you can't identify what each service does.

But if we use names like 'myproject-myservice-', it could be sufficient. This approach requires more thought.

It is a good idea, and currently is very difficult to debug an application with a random name.

I think that doing it this way would make it more specific

myproject-[app|pg|mongo|redis|mariadb|mysql]-myservice-hash

examples:

  1. myproject-app-service-hash
  2. myproject-pg-service-hash
  3. myproject-mongo-service-hash ......

Siumauricio avatar May 17 '24 04:05 Siumauricio

I don't think it's necessary to specify the type of service in its name. In a project, you shouldn't give the same name to two different services

TheoCouss avatar May 17 '24 05:05 TheoCouss

Yes but we are back to the same problem you assume that it wouldn't happen because you surely wouldn't do it, but someone is very sure that they can do it, but let's do it that way.

Also currently when creating a project we don't apply any validation, so the user can write any project name, also that make kinda dificult to implement this feature, because we need to validate from the creation of the project and apply some regex validation to not include certain values like #$%^**() and also need to slug the value, so this is not simple as you can think, need to cover multiple cases, also for existing projects this could be a issue

But yeah the validation could be like this

project-serviceName-hash

the hash would be ideal around 7 characters

myproject-serviceName-abc12345

and for regular expression could be something like ^[a-z0-9]+-[a-z0-9]+$

Siumauricio avatar May 17 '24 06:05 Siumauricio

@Siumauricio @TheoCouss Is this okay?

  • [x] Can only contain letters (upper and lower case), numbers, -
  • [x] - cannot be at the beginning or end
  • [x] Numbers cannot start

/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/i

✅ demo
✅ d1
✅ d-1-d
✅ d-000
✅ ok-ok-ok

🔴 1
🔴 -ok
🔴 ok-1-
🔴 1ok
🔴 ok-ok-
🔴 -ok-

hehehai avatar May 18 '24 03:05 hehehai

Looks good @hehehai , can you try this input? TEST-hi looks like that regex is accepting uppercase which shouldn't

Siumauricio avatar May 18 '24 05:05 Siumauricio

Looks good @hehehai , can you try this input? TEST-hi looks like that regex is accepting uppercase which shouldn't

@Siumauricio Yes, case is currently supported. You mean capitalized cases should not be supported?

  • Can only contain letters (lower case), numbers, -

/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/

✅ demo
✅ d1
✅ d-1-d
✅ d-000
✅ ok-ok-ok

🔴 1
🔴 -ok
🔴 ok-1-
🔴 1ok
🔴 ok-ok-
🔴 -ok-
🔴 oK
🔴 OK
🔴 OK-1

hehehai avatar May 20 '24 00:05 hehehai

@hehehai Also this case is working test-tes-1 and is not a DNS valid name

Siumauricio avatar May 20 '24 04:05 Siumauricio

@hehehai Also this case is working test-tes-1 and is not a DNS valid name

why? Is it the number at the end?

hehehai avatar May 21 '24 04:05 hehehai

@hehehai Also this case is working test-tes-1 and is not a DNS valid name

why? Is it the number at the end?

Correct

Siumauricio avatar May 21 '24 05:05 Siumauricio

^[a-z](?!.*--)([a-z0-9-]*[a-z])?$

  • Match letters, numbers and "-"
  • Only letters can start
  • Only letters can end
  • The minimum length is 1 (that is, one letter)
  • “-”cannot appear continuously
  • No capital letters

image

hehehai avatar May 23 '24 07:05 hehehai

yeah that looks good

Siumauricio avatar May 23 '24 08:05 Siumauricio

https://github.com/Dokploy/dokploy/assets/12692552/b2233d35-d024-45c7-b9c4-3d38f12374e4

hehehai avatar May 23 '24 08:05 hehehai

Thanks to everyone!

Siumauricio avatar Jun 08 '24 22:06 Siumauricio