customize envName

This commit is contained in:
LucaZanni committed 2024-07-11 08:55:19 +02:00
1 parent b2bc55d3e4
commit bb5f4d9734
2 files changed
+16 -10

No files matched your search

+4
View File
@@ -9,6 +9,10 @@ inputs:
description: 'Namespace for Kubernetes'
required: false
default: 'default'
envName:
description: 'Name of env file'
required: false
default: '.env'
serviceType:
description: 'Type of Kubernetes Service'
required: false
+12 -10
View File
@@ -28,21 +28,21 @@ const exit = (msg) => {
process.exit(1);
};
const envName = core.getInput("envName") || ".env";
// Load environment variables from the .env file
const envPath = path.join(contextPath, ".env");
const envPath = path.join(contextPath, envName);
log(`envPath: ${envPath}`);
if (fs.existsSync(envPath)) {
let envConfig = {};
const envExist = fs.existsSync(envPath);
if (envExist) {
dotenv.config({ path: envPath });
log("Loaded environment variables from the .env file");
} else {
exit(`.env file not found at path ${envPath}`);
// Set default values for PORT and HOST if not defined
envConfig = dotenv.parse(fs.readFileSync(envPath));
log(`envConfig: ${JSON.stringify(envConfig)}`);
}
// Set default values for PORT and HOST if not defined
const envConfig = dotenv.parse(fs.readFileSync(envPath));
log(`envConfig: ${JSON.stringify(envConfig)}`);
// Add PORT and HOST to envConfig if not present
envConfig.PORT = parseInt(envConfig.PORT || '3000', 10);
log(`envConfig.PORT: ${envConfig.PORT}`);
@@ -136,7 +136,8 @@ const configMap = {
metadata: { ...baseMetadata, name: `${packageJson.name}-config` },
data: envConfig
};
log(`configMap: ${JSON.stringify(configMap)}`);
if (envExist)
log(`configMap: ${JSON.stringify(configMap)}`);
// Service
const service = {
@@ -209,7 +210,8 @@ const yamlOptions = {
log(`yamlOptions: ${JSON.stringify(yamlOptions)}`);
const yamlContents = [];
yamlContents.push(yaml.dump(configMap, yamlOptions));
if (envExist)
yamlContents.push(yaml.dump(configMap, yamlOptions));
yamlContents.push(yaml.dump(service, yamlOptions));
yamlContents.push(yaml.dump(deployment, yamlOptions));
yamlContents.push(yaml.dump(autoscaler, yamlOptions));