Use environment variables from DB in published record data (#70)
* Publish environment variables of deployment * Handle review changes * Use dummy gray image for projects --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
parent
c4ba59d97e
commit
d29b29f161
@ -34,7 +34,7 @@
|
|||||||
yarn db:load:fixtures
|
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
|
- 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
|
- https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app
|
||||||
- In "Homepage URL", type `http://localhost:3000`
|
- In "Homepage URL", type `http://localhost:3000`
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"format:check": "prettier --check .",
|
"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:load:fixtures": "DEBUG=snowball:* ts-node ./test/initialize-db.ts",
|
||||||
"db:delete": "DEBUG=snowball:* ts-node ./test/delete-db.ts"
|
"db:delete": "DEBUG=snowball:* ts-node ./test/delete-db.ts"
|
||||||
},
|
},
|
||||||
|
@ -196,14 +196,15 @@ export class Database {
|
|||||||
return projectMembers;
|
return projectMembers;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getEnvironmentVariablesByProjectId (projectId: string): Promise<EnvironmentVariable[]> {
|
async getEnvironmentVariablesByProjectId (projectId: string, filter?: FindOptionsWhere<EnvironmentVariable>): Promise<EnvironmentVariable[]> {
|
||||||
const environmentVariableRepository = this.dataSource.getRepository(EnvironmentVariable);
|
const environmentVariableRepository = this.dataSource.getRepository(EnvironmentVariable);
|
||||||
|
|
||||||
const environmentVariables = await environmentVariableRepository.find({
|
const environmentVariables = await environmentVariableRepository.find({
|
||||||
where: {
|
where: {
|
||||||
project: {
|
project: {
|
||||||
id: projectId
|
id: projectId
|
||||||
}
|
},
|
||||||
|
...filter
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -92,7 +92,8 @@ export class Registry {
|
|||||||
async createApplicationDeploymentRequest (data: {
|
async createApplicationDeploymentRequest (data: {
|
||||||
appName: string,
|
appName: string,
|
||||||
commitHash: string,
|
commitHash: string,
|
||||||
repository: string
|
repository: string,
|
||||||
|
environmentVariables: { [key: string]: string }
|
||||||
}): Promise<{
|
}): Promise<{
|
||||||
registryRecordId: string,
|
registryRecordId: string,
|
||||||
registryRecordData: ApplicationDeploymentRequest
|
registryRecordData: ApplicationDeploymentRequest
|
||||||
@ -118,9 +119,7 @@ export class Registry {
|
|||||||
|
|
||||||
// https://git.vdb.to/cerc-io/laconic-registry-cli/commit/129019105dfb93bebcea02fde0ed64d0f8e5983b
|
// https://git.vdb.to/cerc-io/laconic-registry-cli/commit/129019105dfb93bebcea02fde0ed64d0f8e5983b
|
||||||
config: JSON.stringify({
|
config: JSON.stringify({
|
||||||
env: {
|
env: data.environmentVariables
|
||||||
CERC_WEBAPP_DEBUG: `${applicationRecord.attributes.app_version}`
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
meta: JSON.stringify({
|
meta: JSON.stringify({
|
||||||
note: `Added by Snowball @ ${DateTime.utc().toFormat('EEE LLL dd HH:mm:ss \'UTC\' yyyy')}`,
|
note: `Added by Snowball @ ${DateTime.utc().toFormat('EEE LLL dd HH:mm:ss \'UTC\' yyyy')}`,
|
||||||
|
@ -231,6 +231,7 @@ export class Service {
|
|||||||
recordData.repoUrl = repoDetails.html_url;
|
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({
|
const { registryRecordId, registryRecordData } = await this.registry.createApplicationRecord({
|
||||||
packageJSON,
|
packageJSON,
|
||||||
appType: data.project!.template!,
|
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(
|
const { registryRecordId, registryRecordData } = await this.registry.createApplicationDeploymentRequest(
|
||||||
{
|
{
|
||||||
appName: newDeployment.registryRecordData.name!,
|
appName: newDeployment.registryRecordData.name!,
|
||||||
commitHash: latestCommit.sha,
|
commitHash: latestCommit.sha,
|
||||||
repository: repoDetails.html_url
|
repository: repoDetails.html_url,
|
||||||
|
environmentVariables: environmentVariablesObj
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.db.updateProjectById(project.id, {
|
await this.db.updateProjectById(project.id, {
|
||||||
registryRecordId,
|
registryRecordId,
|
||||||
registryRecordData
|
registryRecordData
|
||||||
@ -351,7 +362,8 @@ export class Service {
|
|||||||
if (
|
if (
|
||||||
!(err instanceof RequestError &&
|
!(err instanceof RequestError &&
|
||||||
err.status === 422 &&
|
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;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
packages/frontend/public/gray.png
Normal file
BIN
packages/frontend/public/gray.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 126 B |
@ -21,7 +21,7 @@ const ProjectCard: React.FC<ProjectCardProps> = ({ project }) => {
|
|||||||
return (
|
return (
|
||||||
<div className="bg-white border border-gray-200 rounded-lg shadow">
|
<div className="bg-white border border-gray-200 rounded-lg shadow">
|
||||||
<div className="flex gap-2 p-2 items-center">
|
<div className="flex gap-2 p-2 items-center">
|
||||||
<Avatar variant="square" src={project.icon} />
|
<Avatar variant="rounded" src={project.icon || '/gray.png'} />
|
||||||
<div className="grow">
|
<div className="grow">
|
||||||
<Link to={`projects/${project.id}`}>
|
<Link to={`projects/${project.id}`}>
|
||||||
<Typography>{project.name}</Typography>
|
<Typography>{project.name}</Typography>
|
||||||
|
@ -87,7 +87,7 @@ const ProjectSearchBar = ({ onChange }: ProjectsSearchProps) => {
|
|||||||
{...getItemProps({ item, index })}
|
{...getItemProps({ item, index })}
|
||||||
>
|
>
|
||||||
<ListItemPrefix>
|
<ListItemPrefix>
|
||||||
<Avatar src={item.icon} variant="square" />
|
<Avatar src={item.icon || '/gray.png'} variant="rounded" />
|
||||||
</ListItemPrefix>
|
</ListItemPrefix>
|
||||||
<div>
|
<div>
|
||||||
<Typography variant="h6" color="blue-gray">
|
<Typography variant="h6" color="blue-gray">
|
||||||
|
@ -46,7 +46,7 @@ const CreateWithTemplate = () => {
|
|||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center">
|
<div className="flex flex-col items-center">
|
||||||
<div className="flex justify-between w-5/6 my-4 bg-gray-200 rounded-xl p-6 items-center">
|
<div className="flex justify-between w-5/6 my-4 bg-gray-200 rounded-xl p-6 items-center">
|
||||||
<Avatar variant="square" />
|
<Avatar variant="rounded" src="/gray.png" />
|
||||||
<div className="grow px-2">{template?.name}</div>
|
<div className="grow px-2">{template?.name}</div>
|
||||||
<div>
|
<div>
|
||||||
<a href={GIT_TEMPLATE_LINK} target="_blank" rel="noreferrer">
|
<a href={GIT_TEMPLATE_LINK} target="_blank" rel="noreferrer">
|
||||||
|
@ -107,7 +107,7 @@ const OverviewTabPanel = () => {
|
|||||||
<div className="grid grid-cols-5">
|
<div className="grid grid-cols-5">
|
||||||
<div className="col-span-3 p-2">
|
<div className="col-span-3 p-2">
|
||||||
<div className="flex items-center gap-2 p-2 ">
|
<div className="flex items-center gap-2 p-2 ">
|
||||||
<Avatar src={project.icon} variant="square" />
|
<Avatar src={project.icon || '/gray.png'} variant="rounded" />
|
||||||
<div className="grow">
|
<div className="grow">
|
||||||
<Typography>{project.name}</Typography>
|
<Typography>{project.name}</Typography>
|
||||||
<Typography variant="small" color="gray">
|
<Typography variant="small" color="gray">
|
||||||
|
Loading…
Reference in New Issue
Block a user