diff --git a/README.md b/README.md index dcf6307c..3accec13 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ yarn db:load:fixtures ``` -- Set `githubOauth.clientId` and `githubOauth.clientSecret` in backend [config file](packages/backend/environments/local.toml) +- Set `gitHub.oAuth.clientId` and `gitHub.oAuth.clientSecret` in backend [config file](packages/backend/environments/local.toml) - Client ID and secret will be available after creating Github OAuth app - https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app - In "Homepage URL", type `http://localhost:3000` diff --git a/packages/backend/package.json b/packages/backend/package.json index 9e36f5b4..75ba8d67 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -36,7 +36,7 @@ "lint": "eslint .", "format": "prettier --write .", "format:check": "prettier --check .", - "registry:init": "DEBUG=snowball:* ts-node scripts/initialize-registry.ts", + "registry:init": "DEBUG=snowball:* ts-node ./test/initialize-registry.ts", "db:load:fixtures": "DEBUG=snowball:* ts-node ./test/initialize-db.ts", "db:delete": "DEBUG=snowball:* ts-node ./test/delete-db.ts" }, diff --git a/packages/backend/src/database.ts b/packages/backend/src/database.ts index 2fc2c88c..81c9fbd3 100644 --- a/packages/backend/src/database.ts +++ b/packages/backend/src/database.ts @@ -196,14 +196,15 @@ export class Database { return projectMembers; } - async getEnvironmentVariablesByProjectId (projectId: string): Promise { + async getEnvironmentVariablesByProjectId (projectId: string, filter?: FindOptionsWhere): Promise { const environmentVariableRepository = this.dataSource.getRepository(EnvironmentVariable); const environmentVariables = await environmentVariableRepository.find({ where: { project: { id: projectId - } + }, + ...filter } }); diff --git a/packages/backend/src/registry.ts b/packages/backend/src/registry.ts index 1dfbb463..5c17871a 100644 --- a/packages/backend/src/registry.ts +++ b/packages/backend/src/registry.ts @@ -92,7 +92,8 @@ export class Registry { async createApplicationDeploymentRequest (data: { appName: string, commitHash: string, - repository: string + repository: string, + environmentVariables: { [key: string]: string } }): Promise<{ registryRecordId: string, registryRecordData: ApplicationDeploymentRequest @@ -118,9 +119,7 @@ export class Registry { // https://git.vdb.to/cerc-io/laconic-registry-cli/commit/129019105dfb93bebcea02fde0ed64d0f8e5983b config: JSON.stringify({ - env: { - CERC_WEBAPP_DEBUG: `${applicationRecord.attributes.app_version}` - } + env: data.environmentVariables }), meta: JSON.stringify({ note: `Added by Snowball @ ${DateTime.utc().toFormat('EEE LLL dd HH:mm:ss \'UTC\' yyyy')}`, diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 6d51df92..8edb63a0 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -231,6 +231,7 @@ export class Service { recordData.repoUrl = repoDetails.html_url; } + // TODO: Set environment variables for each deployment (environment variables can`t be set in application record) const { registryRecordId, registryRecordData } = await this.registry.createApplicationRecord({ packageJSON, appType: data.project!.template!, @@ -318,12 +319,22 @@ export class Service { } ); + const environmentVariables = await this.db.getEnvironmentVariablesByProjectId(project.id, { environment: Environment.Production }); + + const environmentVariablesObj = environmentVariables.reduce((acc, env) => { + acc[env.key] = env.value; + + return acc; + }, {} as { [key: string]: string }); + const { registryRecordId, registryRecordData } = await this.registry.createApplicationDeploymentRequest( { appName: newDeployment.registryRecordData.name!, commitHash: latestCommit.sha, - repository: repoDetails.html_url + repository: repoDetails.html_url, + environmentVariables: environmentVariablesObj }); + await this.db.updateProjectById(project.id, { registryRecordId, registryRecordData @@ -351,7 +362,8 @@ export class Service { if ( !(err instanceof RequestError && err.status === 422 && - (err.response?.data as any).errors.some((err: any) => err.message === GITHUB_UNIQUE_WEBHOOK_ERROR))) { + (err.response?.data as any).errors.some((err: any) => err.message === GITHUB_UNIQUE_WEBHOOK_ERROR)) + ) { throw err; } diff --git a/packages/backend/scripts/initialize-registry.ts b/packages/backend/test/initialize-registry.ts similarity index 100% rename from packages/backend/scripts/initialize-registry.ts rename to packages/backend/test/initialize-registry.ts diff --git a/packages/frontend/public/gray.png b/packages/frontend/public/gray.png new file mode 100644 index 00000000..77205594 Binary files /dev/null and b/packages/frontend/public/gray.png differ diff --git a/packages/frontend/src/components/projects/ProjectCard.tsx b/packages/frontend/src/components/projects/ProjectCard.tsx index c5c4916d..0d94a777 100644 --- a/packages/frontend/src/components/projects/ProjectCard.tsx +++ b/packages/frontend/src/components/projects/ProjectCard.tsx @@ -21,7 +21,7 @@ const ProjectCard: React.FC = ({ project }) => { return (
- +
{project.name} diff --git a/packages/frontend/src/components/projects/ProjectSearchBar.tsx b/packages/frontend/src/components/projects/ProjectSearchBar.tsx index c6653bbb..6d695b66 100644 --- a/packages/frontend/src/components/projects/ProjectSearchBar.tsx +++ b/packages/frontend/src/components/projects/ProjectSearchBar.tsx @@ -87,7 +87,7 @@ const ProjectSearchBar = ({ onChange }: ProjectsSearchProps) => { {...getItemProps({ item, index })} > - +
diff --git a/packages/frontend/src/pages/org-slug/projects/create/Template.tsx b/packages/frontend/src/pages/org-slug/projects/create/Template.tsx index 47e75c62..cae84f67 100644 --- a/packages/frontend/src/pages/org-slug/projects/create/Template.tsx +++ b/packages/frontend/src/pages/org-slug/projects/create/Template.tsx @@ -46,7 +46,7 @@ const CreateWithTemplate = () => { return (