diff --git a/.dockerignore b/.dockerignore index b99e7de96..72cdca100 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,14 @@ node_modules .git .gitignore +.angular +dist +app +release +backup +*.log +.idea +.vscode +coverage +e2e-results +tmp diff --git a/Dockerfile b/Dockerfile index 8e58bf5cb..3c6673d60 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,8 @@ RUN npm run prepare # Copy source and build COPY . . -RUN npm run env && npm run lint && npm run buildFrontend:prodWeb +# Pass build args as environment variables for the build commands +RUN UNSPLASH_KEY=$UNSPLASH_KEY UNSPLASH_CLIENT_ID=$UNSPLASH_CLIENT_ID npm run env && npm run lint && npm run buildFrontend:prodWeb # Production stage FROM nginx:1-alpine diff --git a/tools/load-env.js b/tools/load-env.js index 2f5de3b1c..5054e6ffb 100755 --- a/tools/load-env.js +++ b/tools/load-env.js @@ -4,39 +4,55 @@ const fs = require('fs'); const path = require('path'); const dotenv = require('dotenv'); -// Load .env file +const REQUIRED_ENV_KEYS = [ + 'UNSPLASH_KEY', + 'UNSPLASH_CLIENT_ID', + // 'GOOGLE_DRIVE_TOKEN', + // 'DROPBOX_API_KEY', + // 'WEBDAV_URL', + // 'WEBDAV_USERNAME', + // 'WEBDAV_PASSWORD', +]; + +// Start with system environment variables for required keys +const env = {}; +REQUIRED_ENV_KEYS.forEach((key) => { + if (process.env[key]) { + env[key] = process.env[key]; + } +}); + +// Load and override with .env file values if they exist const envPath = path.join(process.cwd(), '.env'); const envConfig = dotenv.config({ path: envPath }); - -let env = envConfig.parsed || {}; - -// In CI environment, also read from process.env for specific keys -if (process.env.CI === 'true' || !envConfig.parsed) { - console.log('🔍 CI environment detected, checking for environment variables...'); - - // List of environment variables to check for in CI - const ciEnvKeys = [ - 'UNSPLASH_KEY', - 'UNSPLASH_CLIENT_ID', - 'GOOGLE_DRIVE_TOKEN', - 'DROPBOX_API_KEY', - 'WEBDAV_URL', - 'WEBDAV_USERNAME', - 'WEBDAV_PASSWORD', - ]; - - ciEnvKeys.forEach((key) => { - if (process.env[key]) { - env[key] = process.env[key]; - console.log(` ✓ Found ${key} in environment`); - } - }); +if (envConfig.parsed) { + Object.assign(env, envConfig.parsed); } -if (Object.keys(env).length === 0) { - console.warn('⚠️ No environment variables found, generating empty env.generated.ts'); +// Log what we found +const foundKeys = Object.keys(env).filter((key) => REQUIRED_ENV_KEYS.includes(key)); +if (foundKeys.length > 0) { + console.log( + `✅ Found ${foundKeys.length} environment variable(s): ${foundKeys.join(', ')}`, + ); +} else { + console.warn( + '⚠️ No environment variables found, generating env.generated.ts with undefined values', + ); } +// Create ENV object with all expected keys (undefined if not set) +const envEntries = REQUIRED_ENV_KEYS.map((key) => { + const value = env[key]; + if (value !== undefined) { + // Escape quotes in values + const escapedValue = value.replace(/'/g, "\\'"); + return ` ${key}: '${escapedValue}',`; + } else { + return ` ${key}: undefined,`; + } +}); + // Generate TypeScript content const tsContent = `// This file is auto-generated by tools/load-env.js // Do not modify directly - edit .env file instead @@ -47,13 +63,7 @@ const tsContent = `// This file is auto-generated by tools/load-env.js * Access these constants instead of process.env in your Angular app */ export const ENV = { -${Object.entries(env) - .map(([key, value]) => { - // Escape quotes in values - const escapedValue = value.replace(/'/g, "\\'"); - return ` ${key}: '${escapedValue}',`; - }) - .join('\n')} +${envEntries.join('\n')} } as const; // Type-safe helper to ensure all expected env vars are defined @@ -70,9 +80,7 @@ if (!fs.existsSync(configDir)) { const outputPath = path.join(configDir, 'env.generated.ts'); fs.writeFileSync(outputPath, tsContent); -console.log( - `✅ Generated ${outputPath} with ${Object.keys(env).length} environment variables`, -); +console.log(`✅ Generated ${outputPath}`); // Pass through to the next command if (process.argv.length > 2) {