.
This commit is contained in:
1 parent
221a4f2097
commit
b152a5b0fa
5 files changed
+91
-6
No files matched your search
@@ -16,5 +16,3 @@ coverage
|
||||
.DS_Store
|
||||
.vscode
|
||||
.idea
|
||||
|
||||
apps/project.env
|
||||
+3
-1
@@ -42,7 +42,9 @@ COPY --from=prod-deps --chown=nonroot:nonroot /app/node_modules ./node_modules
|
||||
COPY --from=prod-deps --chown=nonroot:nonroot /app/apps/api/package.json ./apps/api/package.json
|
||||
COPY --from=prod-deps --chown=nonroot:nonroot /app/apps/api/node_modules ./apps/api/node_modules
|
||||
COPY --from=build --chown=nonroot:nonroot /app/apps/api/dist ./apps/api/dist
|
||||
COPY --chown=nonroot:nonroot apps/project.env ./project.env
|
||||
COPY --chown=nonroot:nonroot apps/api/docker-entrypoint.js ./apps/api/docker-entrypoint.js
|
||||
|
||||
EXPOSE 10712
|
||||
|
||||
CMD ["apps/api/dist/main.js"]
|
||||
CMD ["apps/api/docker-entrypoint.js"]
|
||||
@@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const MACHINE_ENV_PATHS = [
|
||||
process.env.MachineEnvFile,
|
||||
process.env.MACHINE_ENV_FILE,
|
||||
'/source/global-env-vars.txt',
|
||||
process.env.HOME
|
||||
? path.join(process.env.HOME, 'source/global-env-vars.txt')
|
||||
: '',
|
||||
].filter(Boolean);
|
||||
|
||||
const PROJECT_ENV_PATHS = [
|
||||
'project.env',
|
||||
'/app/project.env',
|
||||
'apps/project.env',
|
||||
];
|
||||
|
||||
function stripQuotes(value) {
|
||||
const trimmed = value.trim();
|
||||
if (
|
||||
(trimmed.startsWith('"') && trimmed.endsWith('"')) ||
|
||||
(trimmed.startsWith("'") && trimmed.endsWith("'"))
|
||||
) {
|
||||
return trimmed.slice(1, -1);
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
function loadEnvFile(filePath, options = {}) {
|
||||
const { override = false } = options;
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
for (const line of content.split(/\r?\n/u)) {
|
||||
if (!line.trim() || /^\s*#/u.test(line)) continue;
|
||||
|
||||
const match = line.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/u);
|
||||
if (!match) continue;
|
||||
|
||||
if (!override && process.env[match[1]] !== undefined) continue;
|
||||
process.env[match[1]] = stripQuotes(match[2]);
|
||||
}
|
||||
}
|
||||
|
||||
const machineEnvFile = MACHINE_ENV_PATHS.find((candidate) =>
|
||||
fs.existsSync(candidate),
|
||||
);
|
||||
if (machineEnvFile) {
|
||||
loadEnvFile(machineEnvFile, { override: true });
|
||||
}
|
||||
|
||||
for (const projectEnvFile of PROJECT_ENV_PATHS) {
|
||||
if (fs.existsSync(projectEnvFile)) {
|
||||
loadEnvFile(projectEnvFile);
|
||||
}
|
||||
}
|
||||
|
||||
const missing = [
|
||||
'INFISICAL_CLIENT_ID',
|
||||
'INFISICAL_CLIENT_SECRET',
|
||||
'INFISICAL_PROJECT_ID',
|
||||
].filter((key) => !process.env[key]);
|
||||
|
||||
if (missing.length > 0) {
|
||||
console.error(
|
||||
`Missing required environment variables: ${missing.join(', ')}`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
require('./dist/main.js');
|
||||
@@ -47,8 +47,16 @@ export class SecretService {
|
||||
this.projectId = this.config.get<string>('INFISICAL_PROJECT_ID') as string;
|
||||
// console.log(this.siteUrl, this.clientSecret, this.clientId, this.projectId)
|
||||
|
||||
if (!this.siteUrl || !this.clientSecret || !this.clientId) {
|
||||
throw new Error('Missing required Infisical configuration');
|
||||
const missing = [
|
||||
!this.siteUrl && 'INFISICAL_SITE_URL',
|
||||
!this.clientId && 'INFISICAL_CLIENT_ID',
|
||||
!this.clientSecret && 'INFISICAL_CLIENT_SECRET',
|
||||
!this.projectId && 'INFISICAL_PROJECT_ID',
|
||||
].filter(Boolean);
|
||||
if (missing.length > 0) {
|
||||
throw new Error(
|
||||
`Missing required Infisical configuration: ${missing.join(', ')}`,
|
||||
);
|
||||
}
|
||||
|
||||
this.infisicalClient = new InfisicalSDK({ siteUrl: this.siteUrl });
|
||||
|
||||
+6
-1
@@ -56,8 +56,13 @@ if (-not $env:INFISICAL_CLIENT_SECRET) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
if (-not $env:INFISICAL_PROJECT_ID) {
|
||||
Write-Error "INFISICAL_PROJECT_ID is not set."
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($UsePm2) {
|
||||
pm2 start $MainScript --name $Pm2Name --update-env
|
||||
} else {
|
||||
node $MainScript
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user