This commit is contained in:
LucaZanni committed 2024-07-05 20:34:35 +02:00
1 parent 26aefe665e
commit 4e1d0d8810
4 files changed
+49 -16

No files matched your search

+2
View File
@@ -27,6 +27,8 @@ jobs:
replicas: 3
registry: 'my-registry'
owner: 'my-owner'
directoryPath: k8s
imagePullSecretsName: regcred
minReplicas: 1
maxReplicas: 5
targetCPUUtilizationPercentage: 75
+8 -1
View File
@@ -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'
+20 -8
View File
@@ -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
+19 -7
View File
@@ -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