Skip to content

Commit 707d89b

Browse files
authored
Merge pull request #132 from microservices-suite/repo-engineering/universal-cli
Repo engineering/universal cli
2 parents 627071b + c765188 commit 707d89b

File tree

8 files changed

+50
-53
lines changed

8 files changed

+50
-53
lines changed
Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = ({ services }) => {
1+
module.exports = ({ services, webserver }) => {
22
const servicesConfig = services.map(service => `
33
${service.name.toLowerCase().replace(/\s+/g, '-')}:
44
build:
@@ -10,37 +10,21 @@ module.exports = ({ services }) => {
1010
- /app/node_modules
1111
- ../../../microservices/${service.name}:/app`).join('');
1212

13-
return `version: '3.8'
14-
services:${servicesConfig}`;
15-
};
13+
// Collect all service names for the 'depends_on' section of the web server
14+
const serviceNames = services.map(service => service.name.toLowerCase().replace(/\s+/g, '-'));
1615

17-
18-
// module.exports = ({ services }) => `
19-
// version: '3.8'
20-
// services:
21-
// mongodb:
22-
// image: mongo:latest
23-
// container_name: mongodb
24-
// ports:
25-
// - '27017:27017'
26-
// rabbitmq:
27-
// image: rabbitmq:3.8
28-
// container_name: rabbitmq
29-
// ports:
30-
// - '5672:5672'
31-
// - '15672:15672'
32-
// ${services.map(({ service, ports, prerequisites }) => `
33-
// ${service}:
34-
// depends_on:
35-
// ${prerequisites.map((prerequisite) => ` - ${prerequisite}`).join('\n')}
36-
// container_name: ${service}
37-
// restart: always
38-
// build:
39-
// context: ../../../microservices/${service}
40-
// dockerfile: DockerFile.dev
41-
// ports:
42-
// ${ports.map((p) => ` - '${p}:${p}'`).join('\n')}
43-
// volumes:
44-
// - /app/node_modules
45-
// - ../../../microservices/${service}:/app`).join('\n')}
46-
// `.trim();
16+
return `
17+
version: '3.8'
18+
services:
19+
${servicesConfig}
20+
${webserver.toLowerCase().replace(/\s+/g, '-') || 'webserver'}:
21+
depends_on:
22+
${serviceNames.map(service => ` - ${service}`).join('\n')}
23+
restart: always
24+
build:
25+
context: ./${webserver}
26+
dockerfile: Dockerfile.dev
27+
ports:
28+
- '4000:80'
29+
`;
30+
};

.suite-cli/cli/scripts/assets/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ module.exports.suiteRC = require('./suiteRC.asset')
4848
module.exports.nginxContent = require('./nginxContent.asset')
4949
module.exports.dockerComposeContent = require('./dockerComposeContent.asset')
5050
module.exports.dockerfileContent = require('./dockerfileContent.asset')
51+
module.exports.nginxDockerfileContent = require('./nginxDockerfileContent.asset')
5152

5253

.suite-cli/cli/scripts/assets/nginxDockerfile.asset.js

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = () =>`
2+
FROM nginx
3+
COPY ./nginx.conf /etc/nginx/conf.d/nginx.conf`

.suite-cli/cli/scripts/scripts.module.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ const getComponentDirecotories = async ({ components, component_type }) => {
578578

579579
const { workspace_name } = retrieveWorkSpaceName({ package_json_path })
580580

581-
const component_root_dir = join(project_root, `${component_type === 'app' ? `gateway/apps` : 'microservices'}`)
581+
const component_root_dir = join(project_root, `${component_type === 'app' ? `gateways/apps` : 'microservices'}`)
582582

583583
// Simulate delay before checking if the component directory exists
584584
await delay(1);
@@ -1363,17 +1363,18 @@ const test = async ({ package }) => {
13631363

13641364
const scaffoldApp = ({ answers }) => {
13651365

1366-
const project_root = generatRootPath({ currentDir: cwd() })
1367-
const app_directory = join(project_root, 'gateway/apps', answers.app_name)
13681366
const { webserver } = readFileContent({ currentDir: cwd() })
1367+
const project_root = generatRootPath({ currentDir: cwd() })
1368+
const app_directory = join(project_root, 'gateways/apps', answers.app_name)
1369+
const webserver_dir = join(app_directory, webserver)
13691370

1370-
mkdirSync(app_directory, { recursive: true })
1371-
writeFileSync(join(app_directory, 'docker-compose.dev.yml'), assets.dockerComposeContent({ services: answers.services, app_name: answers.app_name }));
1372-
writeFileSync(join(app_directory, 'docker-compose.yml'), assets.dockerComposeContent({ services: answers.services, app_name: answers.app_name }));
1371+
mkdirSync(webserver_dir, { recursive: true })
1372+
writeFileSync(join(app_directory, 'docker-compose.dev.yml'), assets.dockerComposeContent({ services: answers.services, app_name: answers.app_name, webserver }));
1373+
writeFileSync(join(app_directory, 'docker-compose.yml'), assets.dockerComposeContent({ services: answers.services, app_name: answers.app_name, webserver }));
13731374
ora().succeed(`Generated docker-compose configs at: ${app_directory}`)
13741375
switch (webserver) {
13751376
case 'nginx':
1376-
generateNginxConfiguration({ services: answers.services, app_directory });
1377+
generateNginxConfiguration({ services: answers.services, webserver_dir });
13771378
break
13781379
default:
13791380

@@ -1388,9 +1389,11 @@ const readFileContent = ({ currentDir }) => {
13881389
return project_config
13891390
}
13901391

1391-
const generateNginxConfiguration = ({ services, app_directory }) => {
1392-
writeFileSync(join(app_directory, 'nginx.conf'), assets.nginxContent({ services }));
1393-
ora().succeed(`Generated nginx.conf at: ${app_directory}`)
1392+
const generateNginxConfiguration = ({ services, webserver_dir }) => {
1393+
writeFileSync(join(webserver_dir, 'nginx.conf'), assets.nginxContent({ services }));
1394+
writeFile(join(webserver_dir, 'Dockerfile'), assets.nginxDockerfileContent());
1395+
writeFile(join(webserver_dir, 'Dockerfile.dev'), assets.nginxDockerfileContent());
1396+
ora().succeed(`Generated webserver configs at: ${webserver_dir}`)
13941397
}
13951398
const installDependencies = async ({ project_base, workspace, spinner, deps, flags }) => {
13961399

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

33

4+
## v1.6.6
5+
6+
[compare changes](https://github.com/microservices-suite/node-microservices-suite/compare/v2.0.10...v1.6.6)
7+
48
## v1.6.5
59

610
[compare changes](https://github.com/microservices-suite/node-microservices-suite/compare/v1.6.4...v1.6.5)

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ To easily work with a `@microservices-suite monorepo` you need to install [Suite
1414
| │ │ ├─ cli.js
1515
| │ │ ├─ package.json
1616
| │ │ ├─ README.md
17-
│ ├─ api-gateways/
18-
| │ ├─ app-1/
19-
| │ │ ├─ nginx
20-
| │ │ ├─ apache
21-
| │ │ ├─ README.md
17+
│ ├─ gateways/
18+
| │ ├─ apps/
19+
| │ | ├─app-1/
20+
| │ │ | ├─ webserver/
21+
| │ │ | | ├─Dockerfile
22+
| │ │ | | ├─Dockerfile.dev
23+
| │ │ | | ├─webserver.conf
24+
| │ │ | ├─ docker-compose.yml
25+
| │ │ | ├─ docker-compose.dev.yml
26+
| │ │ | ├─ README.md
2227
│ ├─ graphql/
2328
| │ ├─ app-1/
2429
| │ │ ├─ apollo-server

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@microservices-suite/microservices",
3-
"version": "1.6.5",
3+
"version": "1.6.6",
44
"description": "This is the central orchestration point for our microservices-based platform, encompassing user management, email communications, file upload handling, and role-based access control services. It serves as the backbone of our application's backend, facilitating seamless interaction, development, and scaling of individual microservices. The workspace is designed to streamline the development process, ensuring dependency consistency, and simplifying the build and deployment workflows across all services.\nThis root workspace enables our development teams to:\n- Manage dependencies for all services in a unified manner, reducing conflicts and easing updates.\n- Utilize shared configurations, such as ESLint rules, TypeScript configurations, and shared utility libraries, to maintain coding standards and reduce redundancy across services.\n- Implement global scripts for tasks like testing, linting, and deployment that can run across all services, ensuring consistency and efficiency in our development pipeline.\n- Leverage the workspace's structure for local development, allowing for easy testing of interactions between services without the need for deploying or configuring external environments.",
55
"keywords": [],
66
"author": "Gilbert Andanje",

0 commit comments

Comments
 (0)