File tree Expand file tree Collapse file tree
apps/dokploy/server/api/routers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import {
1111 findProjectById ,
1212 getAccessibleServerIds ,
1313 getContainerLogs ,
14- getServiceContainerCommand ,
14+ getServiceContainer ,
1515 getWebServerSettings ,
1616 IS_CLOUD ,
1717 rebuildDatabase ,
@@ -410,17 +410,17 @@ export const mariadbRouter = createTRPCRouter({
410410 const maria = await findMariadbById ( mariadbId ) ;
411411 const { appName, serverId, databaseUser, databaseRootPassword } = maria ;
412412
413- const containerCmd = getServiceContainerCommand ( appName ) ;
413+ const container = await getServiceContainer ( appName , serverId ) ;
414+ if ( ! container ) {
415+ throw new TRPCError ( {
416+ code : "BAD_REQUEST" ,
417+ message : `No running container found for ${ appName } ` ,
418+ } ) ;
419+ }
420+
414421 const targetUser = type === "root" ? "root" : databaseUser ;
415422
416- const command = `
417- CONTAINER_ID=$(${ containerCmd } )
418- if [ -z "$CONTAINER_ID" ]; then
419- echo "No running container found for ${ appName } " >&2
420- exit 1
421- fi
422- docker exec "$CONTAINER_ID" mariadb -u root -p'${ databaseRootPassword } ' -e "ALTER USER '${ targetUser } '@'%' IDENTIFIED BY '${ password } '; FLUSH PRIVILEGES;"
423- ` ;
423+ const command = `docker exec ${ container . Id } mariadb -u root -p'${ databaseRootPassword } ' -e "ALTER USER '${ targetUser } '@'%' IDENTIFIED BY '${ password } '; FLUSH PRIVILEGES;"` ;
424424
425425 await db . transaction ( async ( tx ) => {
426426 const setData =
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import {
1111 findProjectById ,
1212 getAccessibleServerIds ,
1313 getContainerLogs ,
14- getServiceContainerCommand ,
14+ getServiceContainer ,
1515 getWebServerSettings ,
1616 IS_CLOUD ,
1717 rebuildDatabase ,
@@ -431,15 +431,15 @@ export const mongoRouter = createTRPCRouter({
431431 const mongo = await findMongoById ( mongoId ) ;
432432 const { appName, serverId, databaseUser, databasePassword } = mongo ;
433433
434- const containerCmd = getServiceContainerCommand ( appName ) ;
435- const command = `
436- CONTAINER_ID=$( ${ containerCmd } )
437- if [ -z "$CONTAINER_ID" ]; then
438- echo " No running container found for ${ appName } " >&2
439- exit 1
440- fi
441- docker exec "$CONTAINER_ID" mongosh -u ' ${ databaseUser } ' -p ' ${ databasePassword } ' --authenticationDatabase admin --eval "db.getSiblingDB('admin').changeUserPassword(' ${ databaseUser } ', ' ${ password } ')"
442- ` ;
434+ const container = await getServiceContainer ( appName , serverId ) ;
435+ if ( ! container ) {
436+ throw new TRPCError ( {
437+ code : "BAD_REQUEST" ,
438+ message : ` No running container found for ${ appName } ` ,
439+ } ) ;
440+ }
441+
442+ const command = `docker exec ${ container . Id } mongosh -u ' ${ databaseUser } ' -p ' ${ databasePassword } ' --authenticationDatabase admin --eval "db.getSiblingDB('admin').changeUserPassword(' ${ databaseUser } ', ' ${ password } ')" `;
443443
444444 await db . transaction ( async ( tx ) => {
445445 await tx
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import {
1111 findProjectById ,
1212 getAccessibleServerIds ,
1313 getContainerLogs ,
14- getServiceContainerCommand ,
14+ getServiceContainer ,
1515 getWebServerSettings ,
1616 IS_CLOUD ,
1717 rebuildDatabase ,
@@ -428,17 +428,17 @@ export const mysqlRouter = createTRPCRouter({
428428 const my = await findMySqlById ( mysqlId ) ;
429429 const { appName, serverId, databaseUser, databaseRootPassword } = my ;
430430
431- const containerCmd = getServiceContainerCommand ( appName ) ;
431+ const container = await getServiceContainer ( appName , serverId ) ;
432+ if ( ! container ) {
433+ throw new TRPCError ( {
434+ code : "BAD_REQUEST" ,
435+ message : `No running container found for ${ appName } ` ,
436+ } ) ;
437+ }
438+
432439 const targetUser = type === "root" ? "root" : databaseUser ;
433440
434- const command = `
435- CONTAINER_ID=$(${ containerCmd } )
436- if [ -z "$CONTAINER_ID" ]; then
437- echo "No running container found for ${ appName } " >&2
438- exit 1
439- fi
440- docker exec "$CONTAINER_ID" mysql -u root -p'${ databaseRootPassword } ' -e "ALTER USER '${ targetUser } '@'%' IDENTIFIED BY '${ password } '; FLUSH PRIVILEGES;"
441- ` ;
441+ const command = `docker exec ${ container . Id } mysql -u root -p'${ databaseRootPassword } ' -e "ALTER USER '${ targetUser } '@'%' IDENTIFIED BY '${ password } '; FLUSH PRIVILEGES;"` ;
442442
443443 await db . transaction ( async ( tx ) => {
444444 const setData =
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import {
1212 getAccessibleServerIds ,
1313 getContainerLogs ,
1414 getMountPath ,
15- getServiceContainerCommand ,
15+ getServiceContainer ,
1616 getWebServerSettings ,
1717 IS_CLOUD ,
1818 rebuildDatabase ,
@@ -437,15 +437,15 @@ export const postgresRouter = createTRPCRouter({
437437 const pg = await findPostgresById ( postgresId ) ;
438438 const { appName, serverId, databaseUser } = pg ;
439439
440- const containerCmd = getServiceContainerCommand ( appName ) ;
441- const command = `
442- CONTAINER_ID=$( ${ containerCmd } )
443- if [ -z "$CONTAINER_ID" ]; then
444- echo " No running container found for ${ appName } " >&2
445- exit 1
446- fi
447- docker exec "$CONTAINER_ID" psql -U ${ databaseUser } -c "ALTER USER \\" ${ databaseUser } \\" WITH PASSWORD ' ${ password } ';"
448- ` ;
440+ const container = await getServiceContainer ( appName , serverId ) ;
441+ if ( ! container ) {
442+ throw new TRPCError ( {
443+ code : "BAD_REQUEST" ,
444+ message : ` No running container found for ${ appName } ` ,
445+ } ) ;
446+ }
447+
448+ const command = `docker exec ${ container . Id } psql -U ${ databaseUser } -d postgres -c "ALTER USER \\" ${ databaseUser } \\" WITH PASSWORD ' ${ password } ';" `;
449449
450450 await db . transaction ( async ( tx ) => {
451451 await tx
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import {
1010 findRedisById ,
1111 getAccessibleServerIds ,
1212 getContainerLogs ,
13- getServiceContainerCommand ,
13+ getServiceContainer ,
1414 getWebServerSettings ,
1515 IS_CLOUD ,
1616 rebuildDatabase ,
@@ -418,15 +418,15 @@ export const redisRouter = createTRPCRouter({
418418 const rd = await findRedisById ( redisId ) ;
419419 const { appName, serverId, databasePassword } = rd ;
420420
421- const containerCmd = getServiceContainerCommand ( appName ) ;
422- const command = `
423- CONTAINER_ID=$( ${ containerCmd } )
424- if [ -z "$CONTAINER_ID" ]; then
425- echo " No running container found for ${ appName } " >&2
426- exit 1
427- fi
428- docker exec "$CONTAINER_ID" redis-cli -a ' ${ databasePassword } ' CONFIG SET requirepass ' ${ password } '
429- ` ;
421+ const container = await getServiceContainer ( appName , serverId ) ;
422+ if ( ! container ) {
423+ throw new TRPCError ( {
424+ code : "BAD_REQUEST" ,
425+ message : ` No running container found for ${ appName } ` ,
426+ } ) ;
427+ }
428+
429+ const command = `docker exec ${ container . Id } redis-cli -a ' ${ databasePassword } ' CONFIG SET requirepass ' ${ password } ' `;
430430
431431 await db . transaction ( async ( tx ) => {
432432 await tx
You can’t perform that action at this time.
0 commit comments