8000 Fix chart issues by mahendraintelops · Pull Request #171 · intelops/compage · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix chart issues #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ openapitools.json
/ui/.env.kind.cluster
/app/compage-app.sqlite3
/deploy/build/
/app/secure-connect-compage.zip
/charts/compage/secure-connect-compage.zip
24 changes: 10 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ To contribute code.
GO111MODULE=on
GOFLAGS=-mod=vendor
```
3. Ensure you have Node.js(LTS >= 18.12.0) installed for Core and UI part of the compage.
4. Ensure you have access to any Kubernetes (tested on KinD) cluster to store the compage projects and users related data on it.
3. Ensure you have Node.js(LTS >= v18.18.0) installed for app and ui part of the compage.
#### KinD
- Install KinD from https://kind.sigs.k8s.io/docs/user/quick-start/#installing-from-release-binaries
- Create KinD cluster using below command
Expand All @@ -29,19 +28,16 @@ To contribute code.
./create-kind-cluster.sh
```
- Check if you can access the cluster created in previous step, and you are able to list down the pods.
5. Fork the project.
6. Clone the project: `git clone https://github.com/[YOUR_USERNAME]/compage && cd compage`
7. kindly refer compage.md file to know the structure of the project.
8. The Compage has three servers (subprojects) which need to be started to run the compage on local
4. Fork the project.
5. Clone the project: `git clone https://github.com/[YOUR_USERNAME]/compage && cd compage`
6. kindly refer compage.md file to know the structure of the project.
7. The Compage has three servers (subprojects) which need to be started to run the compage on local
- core (Golang), navigate to core directory and follow its [core README](./core/README.md)
- app (Node.js), navigate to app directory and follow its [app README](./app/README.md)
- ui (ReactJs), navigate to ui directory and follow its [ui README](./ui/README.md)
9. Commit changes *([Please refer the commit message conventions](https://www.conventionalcommits.org/en/v1.0.0/))*
10. Push commits.
11. Open pull request.

## Improving the Documentation
The documentation is contained within `./docs` and made with Docusaurus. See the [Docs README](./docs/README.md) for infos about developing the docs.
8. Commit changes *([Please refer the commit message conventions](https://www.conventionalcommits.org/en/v1.0.0/))*
9. Push commits.
10. Open pull request.

## Regenerate the gRPC code from .proto files
- Install below packages in order to regenerate the gRPC code.
Expand All @@ -57,5 +53,5 @@ The documentation is contained within `./docs` and made with Docusaurus. See the
```shell
buf generate
```
## How are K8s and GitHub interacted with above three components?
![architecture-med.png](images/architecture-med.png)
## How are DB(sqlite/cassandra) and GitHub interacted with above three components?
![architecture.png](images/architecture-med.png)
16 changes: 14 additions & 2 deletions app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,23 @@ RUN apk update && apk add git
COPY --from=builder /app/dist /server/dist
COPY --from=builder /app/node_modules /server/node_modules
COPY --from=builder /app/protobufs /server/protobufs

ARG USER_NAME=compageuser
ARG GROUP_NAME=compagegroup
### Add new user
RUN adduser -D -g '' compageuser
RUN addgroup -g 1001 $GROUP_NAME && adduser -D -u 1001 -G $GROUP_NAME $USER_NAME
USER $USER_NAME

### create workdir directory
RUN mkdir -p $HOME/.compage/workdir
RUN chmod -R 777 $HOME/.compage/workdir
USER compageuser
RUN chown -R $USER_NAME:$GROUP_NAME $HOME/.compage/workdir

### create logs directory
RUN mkdir -p $HOME/.compage/logs
RUN chmod -R 777 $HOME/.compage/logs
RUN chown -R $USER_NAME:$GROUP_NAME $HOME/.compage/logs

ENV NODE_ENV=production
EXPOSE 5000
CMD [ "node", "dist/src/app.js" ]
39 changes: 28 additions & 11 deletions app/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
# app
- This is a component that connects to different git-platforms and push-pull repositories.
- This also uses Cassandra or SQLite (based on configuration) databases to persist projects, git platforms, and users related details.

- This is a component that connects to different git-platforms and push-pull repositories.
- This also uses Cassandra or SQLite (based on configuration) databases to persist projects, git platforms, and users
related details.
- It's an Express.js based REST server and gRPC client to a core component.
- The sqlite is used as a database for development. To use cassandra, you need to set the following environment variables in your terminal along with a `environment DB_TYPE='cassandra'`.
- The sqlite is used as a database for development. To use cassandra, you need to set the following environment
variables in your terminal along with a `environment DB_TYPE='cassandra'`.

#### Use cassandra as a database

```bash
export CASSANDRA_CONTACT_POINTS = 'localhost';
export CASSANDRA_LOCAL_DATA_CENTER = 'datacenter1';
export CASSANDRA_KEYSPACE = 'compage';
export CASSANDRA_USERNAME = 'cassandra';
export CASSANDRA_PASSWORD = 'cassandra';
export DB_TYPE='cassandra';
export CASSANDRA_CONTACT_POINTS = 'localhost';
export CASSANDRA_LOCAL_DATA_CENTER = 'datacenter1';
export CASSANDRA_KEYSPACE = 'compage';
export CASSANDRA_USERNAME = 'cassandra';
export CASSANDRA_PASSWORD = 'cassandra';
```

- To start the cassandra server on local, you can fire command `docker-compose up -d` from the setup directory of
compage/app.

#### Use SQLite as a database

```shell
export DB_TYPE='sqlite'
```
- To start the cassandra server on local, you can fire command `docker-compose up -d` from the setup directory of compage/app.

#### How to run this component?

- Navigate to app directory [`cd app`] from root directory of compage
- Fire `npm install` to install the dependencies
- Run `npm run dev` command to start the express-server. This command will auto-reload the changes you make to app directory.
- Run `npm run dev` command to start the express-server. This command will auto-reload the changes you make to app
directory.
- If something goes wrong, you want to kill the proce 2E87 ss on port 5000, run the following command
```sudo kill -9 `sudo lsof -t -i:5000```
```sudo kill -9 `sudo lsof -t -i:5000```
24 changes: 11 additions & 13 deletions app/src/integrations/simple-git/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,17 @@ export const gitOperations = async (git: SimpleGit, repositoryBranch?: string, p
branchName = repositoryBranch + '-' + projectVersion;
}

if (repositoryBranch && projectVersion) {
// checkoutLocalBranch checks out local branch with name supplied
await git.checkoutLocalBranch(branchName)
.then(
(success: any) => {
Logger.debug(`git checkoutLocalBranch succeeded: ${JSON.stringify(success)}`);
}, (failure: any) => {
Logger.debug(`git checkoutLocalBranch failed: ${JSON.stringify(failure)}`);
error = `git checkoutLocalBranch failed: ${JSON.stringify(failure)}`;
});
if (error.length > 0) {
return error;
}
// checkoutLocalBranch checks out local branch with name supplied
await git.checkoutLocalBranch(branchName)
.then(
(success: any) => {
Logger.debug(`git checkoutLocalBranch succeeded: ${JSON.stringify(success)}`);
}, (failure: any) => {
Logger.debug(`git checkoutLocalBranch failed: ${JSON.stringify(failure)}`);
error = `git checkoutLocalBranch failed: ${JSON.stringify(failure)}`;
});
if (error.length > 0) {
return error;
}

// Finally, push to online repository
Expand Down
1 change: 0 additions & 1 deletion app/src/integrations/simple-git/newProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Logger from '../../utils/logger';
import {NewProjectGitServerRequest} from './models';

export const pushNewProjectToGitServer = async (newProjectGitServerRequest: NewProjectGitServerRequest): Promise<string> => {
console.log('pushNewProjectToGitServer' + newProjectGitServerRequest.generatedProjectPath);
const options: Partial<SimpleGitOptions> = {
baseDir: newProjectGitServerRequest.generatedProjectPath,
binary: 'git',
Expand Down
10 changes: 6 additions & 4 deletions app/src/routes/codeOperations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {getProjectGrpcClient} from '../grpc/project';
import {Router} from 'express';
import * as fs from 'fs';
import * as os from 'os';
import {
cloneExistingProjectFromGitServer,
pushToExistingProjectOnGitServer,
Expand Down Expand Up @@ -40,9 +39,12 @@ codeOperationsRouter.post('/generate', requireEmailMiddleware, async (request, r

const cleanup = (downloadedPrjPath: string) => {
// remove directory created, delete directory recursively
rimraf(downloadedPrjPath).then((result: any) => {
Logger.debug(`Result: ${result}`);
Logger.debug(`${downloadedPrjPath} is cleaned up`);
rimraf(downloadedPrjPath).then((result: boolean) => {
if (result) {
Logger.debug(`${downloadedPrjPath} is cleaned up`);
} else {
Logger.debug(`${downloadedPrjPath} is not cleaned up`);
}
});
};

Expand Down
13 changes: 9 additions & 4 deletions app/src/services/gitPlatformService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ import {GitPlatformEntity} from '../models/gitPlatform';
import {GitPlatformDao} from '../store/gitPlatformDao';
import {SqliteGitPlatformDaoImpl} from '../store/sqliteGitPlatformDaoImpl';
import {CassandraGitPlatformDaoImpl} from '../store/cassandraGitPlatformDaoImpl';
import config from '../utils/constants';

export class GitPlatformService {
private gitPlatformDao: GitPlatformDao;

constructor() {
// create the appropriate gitPlatformDao based on the environment
this.gitPlatformDao = process.env.NODE_ENV === 'production'
? new CassandraGitPlatformDaoImpl()
: new SqliteGitPlatformDaoImpl();
// create the appropriate gitPlatformDao based on the DB_TYPE
if (config.db?.type === 'cassandra') {
this.gitPlatformDao = new CassandraGitPlatformDaoImpl();
} else if (config.db?.type === 'sqlite') {
this.gitPlatformDao = new SqliteGitPlatformDaoImpl();
} else {
throw new Error('Invalid process.env.DB_TYPE');
}
}

async createGitPlatform(gitPlatform: GitPlatformEntity): Promise<GitPlatformEntity> {
Expand Down
13 changes: 9 additions & 4 deletions app/src/services/projectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ import {ProjectEntity} from '../models/project';
import {ProjectDao} from '../store/projectDao';
import {SqliteProjectDaoImpl} from '../store/sqliteProjectDaoImpl';
import {CassandraProjectDaoImpl} from '../store/cassandraProjectDaoImpl';
import config from '../utils/constants';

export class ProjectService {
private projectDao: ProjectDao;

constructor() {
// create the appropriate projectDao based on the environment
this.projectDao = process.env.NODE_ENV === 'production'
? new CassandraProjectDaoImpl()
: new SqliteProjectDaoImpl();
// create the appropriate projectDao based on the DB_TYPE
if (config.db?.type === 'cassandra') {
this.projectDao = new CassandraProjectDaoImpl();
} else if (config.db?.type === 'sqlite') {
this.projectDao = new SqliteProjectDaoImpl();
} else {
throw new Error('Invalid process.env.DB_TYPE');
}
}

async createProject(project: ProjectEntity): Promise<ProjectEntity> {
Expand Down
13 changes: 9 additions & 4 deletions app/src/services/userService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ import {UserEntity} from '../models/user';
import {UserDao} from '../store/userDao';
import {SqliteUserDaoImpl} from '../store/sqliteUserDaoImpl';
import {CassandraUserDaoImpl} from '../store/cassandraUserDaoImpl';
import config from '../utils/constants';

export class UserService {
private userDao: UserDao;

constructor() {
// create the appropriate userDao based on the environment
this.userDao = process.env.NODE_ENV === 'production'
? new CassandraUserDaoImpl()
: new SqliteUserDaoImpl();
// create the appropriate userDao based on the DB_TYPE
if (config.db?.type === 'cassandra') {
this.userDao = new CassandraUserDaoImpl();
} else if (config.db?.type === 'sqlite') {
this.userDao = new SqliteUserDaoImpl();
} else {
throw new Error('Invalid process.env.DB_TYPE');
}
}

async createUser(user: UserEntity): Promise<UserEntity> {
Expand Down
88 changes: 77 additions & 11 deletions app/src/store/cassandra/cassandraClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,80 @@
import cassandra from 'cassandra-driver';
import config from '../../utils/constants';
import Logger from '../../utils/logger';

const contactPoints = config.db?.cassandra?.contactPoints as string[] || ['localhost'];
const localDataCenter = config.db?.cassandra?.localDataCenter as string || 'datacenter1';
const keyspace = config.db?.cassandra?.keyspace as string || 'compage';
const authProvider = new cassandra.auth.PlainTextAuthProvider(config.db?.cassandra?.credentials?.username as string, config.db?.cassandra?.credentials?.password as string);

export const cassandraClient = new cassandra.Client({
contactPoints,
authProvider,
localDataCenter,
keyspace
});
let cassandraClient: cassandra.Client = {} as cassandra.Client;

const initDB = async () => {
// git_platforms table
const gitPlatformsTable = `CREATE TABLE IF NOT EXISTS compage.git_platforms
(
name TEXT,
url TEXT,
user_name TEXT,
personal_access_token TEXT,
owner_email TEXT,
created_at TIMESTAMP,
updated_at TIMESTAMP,
PRIMARY KEY (name, owner_email)
);`;
await cassandraClient.execute(gitPlatformsTable);
const usersTable = `CREATE TABLE IF NOT EXISTS compage.users
(
email TEXT PRIMARY KEY,
first_name TEXT,
last_name TEXT,
role TEXT,
status TEXT,
created_at TIMESTAMP,
updated_at TIMESTAMP
);
`;
await cassandraClient.execute(usersTable);
const projectsTable = `CREATE TABLE IF NOT EXISTS compage.projects
(
id TEXT,
display_name TEXT,
version TEXT,
owner_email TEXT,
json TEXT,
metadata TEXT,
old_versions TEXT,
git_platform_user_name TEXT,
git_platform_name TEXT,
repository_name TEXT,
repository_branch TEXT,
is_repository_public BOOLEAN,
repository_url TEXT,
created_at TIMESTAMP,
updated_at TIMESTAMP,
PRIMARY KEY (id)
);`;
await cassandraClient.execute(projectsTable);
};

if (config.db?.type === 'cassandra') {
const contactPoints = config.db?.cassandra?.contactPoints as string[] || ['localhost'];
const localDataCenter = config.db?.cassandra?.localDataCenter as string || 'datacenter1';
const keyspace = config.db?.cassandra?.keyspace as string || 'compage';
const authProvider = new cassandra.auth.PlainTextAuthProvider(config.db?.cassandra?.credentials?.username as string, config.db?.cassandra?.credentials?.password as string);
cassandraClient = new cassandra.Client({
contactPoints,
authProvider,
localDataCenter,
keyspace
});
}

// below check is required because cassandraClient is an empty object when DB_TYPE is sqlite
if (Object.keys(cassandraClient).length > 0) {
cassandraClient.connect()
.then(async () => {
Logger.debug('connected to Cassandra');
await initDB();
})
.catch((err: any) => {
Logger.debug('error while connecting to Cassandra: ' + JSON.stringify(err));
});
}

export default cassandraClient;
2 changes: 1 addition & 1 deletion app/src/store/cassandraGitPlatformDaoImpl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {GitPlatformEntity} from '../models/gitPlatform';

import {GitPlatformDao} from './gitPlatformDao';
import {cassandraClient} from './cassandra/cassandraClient';
import cassandraClient from './cassandra/cassandraClient';

export class CassandraGitPlatformDaoImpl implements GitPlatformDao {
async createGitPlatform(gitPlatformEntity: GitPlatformEntity): Promise<GitPlatformEntity> {
Expand Down
4 changes: 2 additions & 2 deletions app/src/store/cassandraProjectDaoImpl.ts
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {generateProjectId} from '../utils/utils';
import {OldVersion, ProjectEntity} from '../models/project';
import {cassandraClient} from './cassandra/cassandraClient';
import {ProjectEntity} from '../models/project';
import cassandraClient from './cassandra/cassandraClient';

import {ProjectDao} from './projectDao';

Expand Down
2 changes: 1 addition & 1 deletion app/src/store/cassandraUserDaoImpl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {UserEntity} from '../models/user';
import {UserDao} from './userDao';
import {cassandraClient} from './cassandra/cassandraClient';
import cassandraClient from './cassandra/cassandraClient';

export class CassandraUserDaoImpl implements UserDao {

Expand Down
Loading
0