diff --git a/Dockerfile b/Dockerfile index 85bc76a6..cabae467 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,7 +35,7 @@ ENV NODE_ENV="production" # ENV NEXT_TELEMETRY_DISABLED="1" COPY --from=builder /app/public ./public - +COPY --from=builder /app/scripts ./scripts # Ensure no write permissions for executable directories COPY --from=builder --chown=1001:1001 /app/.next/standalone ./ @@ -64,4 +64,4 @@ LABEL org.opencontainers.image.description="${APP_DESCRIPTION}" LABEL io.k8s.display-name="${APP_TITLE}" LABEL io.k8s.description="${APP_DESCRIPTION}" -CMD ["node", "server.js"] +CMD ["node", "scripts/start.js"] diff --git a/scripts/generate-env.js b/scripts/generate-env.js new file mode 100644 index 00000000..676a66e3 --- /dev/null +++ b/scripts/generate-env.js @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2024 PNED G.I.E. +// +// SPDX-License-Identifier: Apache-2.0 +const fs = require("fs"); +const path = require("path"); + +function loadProperties() { + const propertiesPath = path.join(process.cwd(), "public", "properties.json"); + try { + const properties = JSON.parse(fs.readFileSync(propertiesPath, "utf8")); + + Object.entries(properties).forEach(([key, value]) => { + process.env[key] = value; + }); + + console.log( + "Environment variables loaded successfully from properties.json" + ); + } catch (error) { + console.error("Error loading properties:", error); + process.exit(1); + } +} + +module.exports = loadProperties; + +if (require.main === module) { + loadProperties(); +} diff --git a/scripts/start.js b/scripts/start.js new file mode 100644 index 00000000..345fac5f --- /dev/null +++ b/scripts/start.js @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: 2024 PNED G.I.E. +// +// SPDX-License-Identifier: Apache-2.0 +const loadProperties = require("./generate-env"); +const { spawn } = require("child_process"); + +loadProperties(); + +const server = spawn("node", ["server.js"], { + stdio: "inherit", + env: process.env, +}); + +server.on("error", (err) => { + console.error("Failed to start server:", err); + process.exit(1); +}); + +["SIGINT", "SIGTERM"].forEach((signal) => { + process.on(signal, () => { + server.kill(signal); + }); +}); + +server.on("exit", (code) => { + process.exit(code); +}); diff --git a/sonar-project.properties b/sonar-project.properties index 9e43ba91..52c582c1 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -5,5 +5,5 @@ sonar.projectKey=GenomicDataInfrastructure_gdi-userportal-frontend sonar.organization=genomicdatainfrastructure sonar.qualitygate.wait=true sonar.javascript.lcov.reportPaths=./coverage/lcov.info -sonar.exclusions= **/*.test.ts, e2e/*,**/*.tsx,**/*Repository.ts,src/config/*,src/app/about/renderer.ts,**/*.json,**/instrumentation*,src/app/api/**/schemas.ts +sonar.exclusions= **/*.test.ts, e2e/*,**/*.tsx,**/*Repository.ts,src/config/*,src/app/about/renderer.ts,**/*.json,**/instrumentation*,src/app/api/**/schemas.ts,scripts/**/* sonar.test.inclusions= **/*.test.ts diff --git a/src/config/contentConfig.ts b/src/config/contentConfig.ts index 5edcce5b..c2573ba3 100644 --- a/src/config/contentConfig.ts +++ b/src/config/contentConfig.ts @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2024 PNED G.I.E. // // SPDX-License-Identifier: Apache-2.0 -import config from "../../public/properties.json"; +import { env } from "next-runtime-env"; interface ContentConfig { linkedInUrl?: string; @@ -21,27 +21,28 @@ interface ContentConfig { } const contentConfig: ContentConfig = { - linkedInUrl: config.NEXT_PUBLIC_LINKEDIN_URL, - twitterUrl: config.NEXT_PUBLIC_TWITTER_URL, - githubUrl: config.NEXT_PUBLIC_GITHUB_URL, - websiteUrl: config.NEXT_PUBLIC_WEBSITE_URL, - email: config.NEXT_PUBLIC_EMAIL, + linkedInUrl: env("NEXT_PUBLIC_LINKEDIN_URL"), + twitterUrl: env("NEXT_PUBLIC_TWITTER_URL"), + githubUrl: env("NEXT_PUBLIC_GITHUB_URL"), + gitlabUrl: env("NEXT_PUBLIC_GITLAB_URL"), + websiteUrl: env("NEXT_PUBLIC_WEBSITE_URL"), + email: env("NEXT_PUBLIC_EMAIL"), footerText: - config.NEXT_PUBLIC_FOOTER_TEXT || + env("NEXT_PUBLIC_FOOTER_TEXT") || "GDI project receives funding from the European Union's Digital Europe \n Programme under grant agreement number 101081813.", - homepageTitle: config.NEXT_PUBLIC_HOMEPAGE_TITLE || "WELCOME TO GDI", + homepageTitle: env("NEXT_PUBLIC_HOMEPAGE_TITLE") || "WELCOME TO GDI", homepageSubtitle: - config.NEXT_PUBLIC_HOMEPAGE_SUBTITLE || + env("NEXT_PUBLIC_HOMEPAGE_SUBTITLE") || "The Genomic Data Infrastructure (GDI) project is enabling access to genomic and related phenotypic and clinical data across Europe.", aboutContent: - config.NEXT_PUBLIC_HOMEPAGE_ABOUT_CONTENT || + env("NEXT_PUBLIC_HOMEPAGE_ABOUT_CONTENT") || "The Genomic Data Infrastructure (GDI) homepage is your gateway to an extensive network of genomic data designed to revolutionize research, policymaking, and healthcare in Europe. The GDI project aims to provide seamless access to over one million genome sequences, facilitating groundbreaking advancements in personalized medicine for various diseases, including cancer and rare conditions. By integrating genomic, phenotypic, and clinical data, GDI supports precise diagnostics, treatments, and clinical decision-making. Explore our user-friendly platform to connect with crucial datasets, and join our mission to enhance healthcare outcomes and foster innovation across Europe. Visit the GDI website for more information.", - bannerLink: config.NEXT_PUBLIC_BANNER_LINK || "/howto", - siteTitle: config.NEXT_PUBLIC_SITE_TITLE || "GDI - User Portal", + bannerLink: env("NEXT_PUBLIC_BANNER_LINK") || "/howto", + siteTitle: env("NEXT_PUBLIC_SITE_TITLE") || "GDI - User Portal", siteDescription: - config.NEXT_PUBLIC_SITE_DESCRIPTION || + env("NEXT_PUBLIC_SITE_DESCRIPTION") || "Genomic Data Infrastructure User Portal", - showBasketAndLogin: config.NEXT_PUBLIC_SHOW_BASKET_AND_LOGIN !== "false", + showBasketAndLogin: env("NEXT_PUBLIC_SHOW_BASKET_AND_LOGIN") !== "false", }; export default contentConfig;