Skip to content

Commit

Permalink
"merge"
Browse files Browse the repository at this point in the history
Merge branch 'dev' into John/clean_up_frontend
  • Loading branch information
jayoo0621 committed Jul 19, 2023
2 parents 1cec7cd + 1c7abb4 commit 91dfba9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
2 changes: 1 addition & 1 deletion dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN curl -fsSLO https://download.docker.com/linux/static/stable/x86_64/docker-${
COPY package*.json ./

# Run npm install to install app dependencies
RUN npm install
RUN npm install --yes

# Copy the current directory contents into the container at /app
COPY . .
Expand Down
35 changes: 26 additions & 9 deletions server/controllers/commandController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
composeStacksDockerObject,
} from '../../types';
import { exec } from 'child_process';
import { getNetworkContainers } from '../../src/reducers/composeReducer';

/**
* Parse all the stdout output into array to manipulate data properly.
Expand Down Expand Up @@ -409,6 +408,10 @@ const commandController: CommandController = {
);
},

/**
* @description runs terminal commands to return a list of user-defined networks and bridge, filtering out host and none networks.
*/

networkContainers: (
req: Request,
res: Response,
Expand Down Expand Up @@ -449,6 +452,10 @@ const commandController: CommandController = {
);
},

/**
* @description runs terminal commands to return an array of network objects with a complete list of containers attached to it.
*/

networkListContainers: async (
req: Request,
res: Response,
Expand Down Expand Up @@ -533,11 +540,13 @@ const commandController: CommandController = {
return next();
},

/**
* @description runs terminal command to create a new network.
*/

networkCreate: (req: Request, res: Response, next: NextFunction): void => {
const { networkName } = req.body;

// added below line

exec(
`docker network create ${networkName}`,
(error: Error | null, stdout: string, stderr: string) => {
Expand All @@ -559,6 +568,10 @@ const commandController: CommandController = {
);
},

/**
* @description runs terminal commands to remove a network.
*/

networkRemove: (req: Request, res: Response, next: NextFunction): void => {
const { networkName } = req.body;

Expand All @@ -576,13 +589,17 @@ const commandController: CommandController = {
console.log(`networkRemove controller error: ${error.message}`);
return next();
}

res.locals.result = { hash: stdout };
return next();
}
);
},

/**
* @description runs terminal commands to connect a container with a network.
*/

networkConnect: (req: Request, res: Response, next: NextFunction): void => {
const { networkName, containerName } = req.body;

Expand All @@ -607,6 +624,10 @@ const commandController: CommandController = {
);
},

/**
* @description runs terminal commands to disconnect a container with a network.
*/

networkDisconnect: (
req: Request,
res: Response,
Expand All @@ -626,7 +647,6 @@ const commandController: CommandController = {

if (error) {
console.log(`networkDisconnect controller error: ${error.message}`);
// res.locals.result = { error: stderr };
return next();
}

Expand Down Expand Up @@ -807,12 +827,9 @@ const commandController: CommandController = {
res.locals.volumeRemoved = { volume: stdout };
return next();
}
)
);
},




getLogs: (req: Request, res: Response, next: NextFunction) => {
const containerLogs: { [k: string]: LogObject[] } = {
stdout: [],
Expand Down
11 changes: 6 additions & 5 deletions server/routes/commandRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ router.get(
},
);

// Route to get network container list
// Route to get a list of networks
router.get(
'/networkContainers',
commandController.networkContainers,
Expand All @@ -123,7 +123,7 @@ router.get(
},
);

// Route to get network container list
// Route to get a list of networks with the containers they are attached to
router.get(
'/networkListContainers',
commandController.networkContainers,
Expand All @@ -133,7 +133,7 @@ router.get(
},
);

//
// Route to create a new network
router.post(
'/networkCreate',
commandController.networkCreate,
Expand All @@ -142,7 +142,7 @@ router.post(
}
);

//
// Route to remove a network
router.post(
'/networkRemove',
commandController.networkRemove,
Expand All @@ -151,7 +151,7 @@ router.post(
}
);

//
// Route to connect a container with a network
router.post(
'/networkConnect',
commandController.networkConnect,
Expand All @@ -160,6 +160,7 @@ router.post(
}
);

// Route to disconnect a container from a network
router.post(
'/networkDisconnect',
commandController.networkDisconnect,
Expand Down
16 changes: 6 additions & 10 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export interface StoppedContainerObj extends ContainerType {
Labels: string;
LocalVolumes: string;
Mounts: string;
Networks: string;
Ports: string;
Size: string;
State: string;
Expand Down Expand Up @@ -434,6 +433,12 @@ export interface CommandController {
*/
networkContainers: MiddleWareFunction;

/**
* @description List containers attached to each of the networks
*/

networkListContainers: MiddleWareFunction;

/**
* @description Display all networks based on docker-compose in a json object; when the user creates a new network
*/
Expand All @@ -458,12 +463,6 @@ export interface CommandController {

networkDisconnect: MiddleWareFunction;

/**
* @description List containers attached to each of the networks
*/

networkListContainers: MiddleWareFunction;

/**
* @description inspects docker containers
* @note is not implemented right now
Expand Down Expand Up @@ -511,9 +510,6 @@ export interface CommandController {
* @description runs docker to remove selected volume
*/
volumeRemove: MiddleWareFunction;



}

export interface ConfigController {
Expand Down

0 comments on commit 91dfba9

Please sign in to comment.