diff --git a/README.md b/README.md index 63148d3..2a06fb9 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ jobs: replicas: 3 registry: 'my-registry' owner: 'my-owner' + directoryPath: k8s + imagePullSecretsName: regcred minReplicas: 1 maxReplicas: 5 targetCPUUtilizationPercentage: 75 diff --git a/action.yml b/action.yml index 6777dde..de9b835 100644 --- a/action.yml +++ b/action.yml @@ -47,6 +47,13 @@ inputs: description: 'Directory path for package.json, build-info.json, and .env files' required: false default: '.' + imagePullSecretsName: + description: 'Custom secret for image and private repository' + required: false + directoryPath: + description: 'Output Directory path' + required: false + default: '.' runs: - using: 'node12' + using: 'node20' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index 1a306fa..a9ea067 100644 --- a/dist/index.js +++ b/dist/index.js @@ -31108,7 +31108,10 @@ function log(msg) { } const contextPath = core.getInput("path") || '.'; +const directoryPath = core.getInput("directoryPath") || path.join('.', "k8s"); +const imagePullSecretsName = core.getInput("imagePullSecretsName"); +// Funzione per uscire con un messaggio di errore const exit = (msg) => { console.error(msg); process.exit(1); @@ -31123,9 +31126,18 @@ if (fs.existsSync(envPath)) { exit(`File .env non trovato nel percorso ${envPath}`); } +// Imposta i valori predefiniti per PORT e HOST se non sono definiti +const envConfig = dotenv.parse(fs.readFileSync(envPath)); +const port = parseInt(process.env.PORT, 10) || 3000; +const host = process.env.HOST || '0.0.0.0'; + +// Aggiungi PORT e HOST nel envConfig se non presenti +envConfig.PORT = envConfig.PORT || '3000'; +envConfig.HOST = envConfig.HOST || '0.0.0.0'; + // Carica il file package.json usando readFileSync e JSON.parse const packagePath = path.join(contextPath, "package.json"); -if (!fs.existsSync(packagePath)) { +if (!fs.exists(packagePath)) { exit(`File package.json non trovato nel percorso ${packagePath}`); } const packageContent = fs.readFileSync(packagePath, "utf8"); @@ -31139,8 +31151,6 @@ if (fs.existsSync(buildInfoPath)) { } log(`build-info.json content: ${JSON.stringify(buildInfo)}`); -const port = parseInt(process.env.PORT, 10); - const version = `${packageJson.version}-${buildInfo.buildNumber}`; const autor = packageJson.author.replace(" ", "_"); @@ -31193,7 +31203,7 @@ const configMap = { apiVersion: "v1", kind: "ConfigMap", metadata: { ...baseMetadata, name: `${packageJson.name}-config` }, - data: dotenv.parse(fs.readFileSync(envPath)) + data: envConfig }; // Service @@ -31227,13 +31237,17 @@ const deployment = { envFrom: [{ configMapRef: { name: `${packageJson.name}-config` } }], imagePullPolicy: "Always" } - ], - imagePullSecrets: [{ name: "regcred" }] + ] } } } }; +// Aggiungi imagePullSecrets se imagePullSecretsName è specificato +if (imagePullSecretsName) { + deployment.spec.template.spec.imagePullSecrets = [{ name: imagePullSecretsName }]; +} + // HorizontalPodAutoscaler const autoscaler = { apiVersion: "autoscaling/v1", @@ -31265,8 +31279,6 @@ yamlContents.push(yaml.dump(autoscaler, yamlOptions)); const allYaml = yamlContents.join("\n---\n"); -const directoryPath = path.join('.', "k8s"); // Imposta il percorso della directory - // Verifica se la directory esiste if (!fs.existsSync(directoryPath)) { // Se non esiste, creala diff --git a/index.js b/index.js index 2308ab8..2dca6fe 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,10 @@ function log(msg) { } const contextPath = core.getInput("path") || '.'; +const directoryPath = core.getInput("directoryPath") || path.join('.', "k8s"); +const imagePullSecretsName = core.getInput("imagePullSecretsName"); +// Funzione per uscire con un messaggio di errore const exit = (msg) => { console.error(msg); process.exit(1); @@ -28,6 +31,15 @@ if (fs.existsSync(envPath)) { exit(`File .env non trovato nel percorso ${envPath}`); } +// Imposta i valori predefiniti per PORT e HOST se non sono definiti +const envConfig = dotenv.parse(fs.readFileSync(envPath)); +const port = parseInt(process.env.PORT, 10) || 3000; +const host = process.env.HOST || '0.0.0.0'; + +// Aggiungi PORT e HOST nel envConfig se non presenti +envConfig.PORT = envConfig.PORT || '3000'; +envConfig.HOST = envConfig.HOST || '0.0.0.0'; + // Carica il file package.json usando readFileSync e JSON.parse const packagePath = path.join(contextPath, "package.json"); if (!fs.existsSync(packagePath)) { @@ -44,8 +56,6 @@ if (fs.existsSync(buildInfoPath)) { } log(`build-info.json content: ${JSON.stringify(buildInfo)}`); -const port = parseInt(process.env.PORT, 10); - const version = `${packageJson.version}-${buildInfo.buildNumber}`; const autor = packageJson.author.replace(" ", "_"); @@ -98,7 +108,7 @@ const configMap = { apiVersion: "v1", kind: "ConfigMap", metadata: { ...baseMetadata, name: `${packageJson.name}-config` }, - data: dotenv.parse(fs.readFileSync(envPath)) + data: envConfig }; // Service @@ -132,13 +142,17 @@ const deployment = { envFrom: [{ configMapRef: { name: `${packageJson.name}-config` } }], imagePullPolicy: "Always" } - ], - imagePullSecrets: [{ name: "regcred" }] + ] } } } }; +// Aggiungi imagePullSecrets se imagePullSecretsName è specificato +if (imagePullSecretsName) { + deployment.spec.template.spec.imagePullSecrets = [{ name: imagePullSecretsName }]; +} + // HorizontalPodAutoscaler const autoscaler = { apiVersion: "autoscaling/v1", @@ -170,8 +184,6 @@ yamlContents.push(yaml.dump(autoscaler, yamlOptions)); const allYaml = yamlContents.join("\n---\n"); -const directoryPath = path.join('.', "k8s"); // Imposta il percorso della directory - // Verifica se la directory esiste if (!fs.existsSync(directoryPath)) { // Se non esiste, creala