From b1ab83700d5954463d2f5e0006403179802c731e Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Tue, 12 Nov 2024 16:50:58 +1100 Subject: [PATCH 01/12] feat: working three domains --- docker-compose.yaml | 37 ++++- next/components/atoms/DomainComponent.js | 11 ++ next/components/molecules/Menu.js | 179 +++++++++++++++++------ next/next-i18next.config.js | 20 ++- next/next.config.js | 23 ++- next/package.json | 13 +- 6 files changed, 221 insertions(+), 62 deletions(-) create mode 100644 next/components/atoms/DomainComponent.js diff --git a/docker-compose.yaml b/docker-compose.yaml index 7203b4202..f137ea379 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,14 +1,47 @@ version: '3' services: - next: - container_name: nextjs + next-basedosdados: + container_name: nextjs-basedosdados build: context: next dockerfile: Dockerfile args: - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} + - NEXT_PUBLIC_DOMAIN=basedosdados.org env_file: - .env + environment: + - NEXT_PUBLIC_DOMAIN=basedosdados.org ports: - ${NEXT_PORT}:3000 + + next-databasis: + container_name: nextjs-databasis + build: + context: next + dockerfile: Dockerfile + args: + - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} + - NEXT_PUBLIC_DOMAIN=data-basis.org + env_file: + - .env + environment: + - NEXT_PUBLIC_DOMAIN=data-basis.org + ports: + - "3001:3000" + + next-basedelosdatos: + container_name: nextjs-basedelosdatos + build: + context: next + dockerfile: Dockerfile + args: + - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} + - NEXT_PUBLIC_DOMAIN=basedelosdatos.org + env_file: + - .env + environment: + - NEXT_PUBLIC_DOMAIN=basedelosdatos.org + ports: + - "3002:3000" diff --git a/next/components/atoms/DomainComponent.js b/next/components/atoms/DomainComponent.js new file mode 100644 index 000000000..04b53e16a --- /dev/null +++ b/next/components/atoms/DomainComponent.js @@ -0,0 +1,11 @@ +import { useRouter } from 'next/router'; + +export default function DomainComponent({ domains = [], children }) { + const router = useRouter(); + const hostname = typeof window !== 'undefined' ? window.location.hostname : ''; + + // Check if current hostname matches any of the allowed domains + const shouldRender = domains.includes(hostname); + + return shouldRender ? children : null; +} \ No newline at end of file diff --git a/next/components/molecules/Menu.js b/next/components/molecules/Menu.js index 8fe8371b1..704a23f5c 100644 --- a/next/components/molecules/Menu.js +++ b/next/components/molecules/Menu.js @@ -24,7 +24,6 @@ import { import { useEffect, useRef, useState, useMemo } from "react"; import { useRouter } from "next/router" import { useTranslation } from 'next-i18next'; -import LanguageSelector from "../atoms/LanguageSelector"; import cookies from "js-cookie"; import MenuDropdown from "./MenuDropdown"; import { useCheckMobile } from "../../hooks/useCheckMobile.hook" @@ -33,6 +32,7 @@ import Link from "../atoms/Link"; import RoundedButton from "../atoms/RoundedButton"; import HelpWidget from "../atoms/HelpWidget"; import { triggerGAEvent } from "../../utils"; +import DomainComponent from "../atoms/DomainComponent"; import BDLogoImage from "../../public/img/logos/bd_logo"; import BDLogoProImage from "../../public/img/logos/bd_logo_pro"; @@ -993,49 +993,140 @@ export default function MenuNav({ simpleTemplate = false, userTemplate = false } } }, [userBD, isLoading]) - const links = { - [t('data')]: `/search`, - [t('solutions')]: [ - { - icon: locale === 'en' ? : , - name: [t('exclusive_data')], - href: locale === 'en' ? "https://info.basedosdados.org/en/bd-pro" : - locale === 'es' ? "https://info.basedosdados.org/es/bd-pro" : - "https://info.basedosdados.org/bd-pro" - }, - { - icon: locale === 'en' ? : , - name: [t('data_courses')], - href: "https://info.basedosdados.org/bd-edu-sql" - }, - { - icon: locale === 'en' ? : , - name: [t('services')], - href: "/services" - }, - ], - [t('prices')]: "/prices", - [t('tutorials')]: [ - {name: [t('documentation')], href: - locale === "en" ? "https://basedosdados.github.io/mais/en" : - locale === "es" ? "https://basedosdados.github.io/mais/es" : - "https://basedosdados.github.io/mais" - }, - {name: [t('youtube_videos')], href: "https://www.youtube.com/c/BasedosDados/featured"}, - {name: [t('blog')], href: "https://medium.com/basedosdados"} - ], - Blog: "/blog", - [t('institutional')]: [ - {name: [t('about_us')], href: "/about-us"}, - {name: [t('transparency')], href: "/transparency"}, - {name: [t('newsletter')], href: locale === 'en' ? "https://info.basedosdados.org/en/newsletter" : - locale === 'es' ? "https://info.basedosdados.org/es/newsletter" : - "https://info.basedosdados.org/newsletter"}, - {name: [t('jobs')], href: "https://info.basedosdados.org/carreiras"}, - {name: [t('faq')], href: "/faq"}, - ], - [t('contact')]: "/contact", - Button: [] + let links; + + if (typeof window === 'undefined') { + // Server-side rendering - use default (Portuguese) version + links = { + [t('data')]: `/search`, + [t('solutions')]: [ + { + icon: , + name: [t('exclusive_data')], + href: "https://info.basedosdados.org/bd-pro" + }, + { + icon: , + name: [t('data_courses')], + href: "https://info.basedosdados.org/bd-edu-sql" + }, + { + icon: , + name: [t('services')], + href: "/services" + }, + ], + [t('prices')]: "/prices", + [t('tutorials')]: [ + {name: [t('documentation')], href: "https://basedosdados.github.io/mais"}, + {name: [t('youtube_videos')], href: "https://www.youtube.com/c/BasedosDados/featured"}, + {name: [t('blog')], href: "https://medium.com/basedosdados"} + ], + Blog: "/blog", + [t('institutional')]: [ + {name: [t('about_us')], href: "/about-us"}, + {name: [t('transparency')], href: "/transparency"}, + {name: [t('newsletter')], href: "https://info.basedosdados.org/newsletter"}, + {name: [t('jobs')], href: "https://info.basedosdados.org/carreiras"}, + {name: [t('faq')], href: "/faq"}, + ], + [t('contact')]: "/contact", + Button: [] + } + } else if (window.location.hostname === '127.0.0.1') { + // Portuguese version + links = { + [t('data')]: `/search`, + [t('solutions')]: [ + { + icon: , + name: [t('exclusive_data')], + href: "https://info.basedosdados.org/bd-pro" + }, + { + icon: , + name: [t('data_courses')], + href: "https://info.basedosdados.org/bd-edu-sql" + }, + { + icon: , + name: [t('services')], + href: "/services" + }, + ], + [t('prices')]: "/prices", + [t('tutorials')]: [ + {name: [t('documentation')], href: "https://basedosdados.github.io/mais"}, + {name: [t('youtube_videos')], href: "https://www.youtube.com/c/BasedosDados/featured"}, + {name: [t('blog')], href: "https://medium.com/basedosdados"} + ], + Blog: "/blog", + [t('institutional')]: [ + {name: [t('about_us')], href: "/about-us"}, + {name: [t('transparency')], href: "/transparency"}, + {name: [t('newsletter')], href: "https://info.basedosdados.org/newsletter"}, + {name: [t('jobs')], href: "https://info.basedosdados.org/carreiras"}, + {name: [t('faq')], href: "/faq"}, + ], + [t('contact')]: "/contact", + Button: [] + } + } else if (window.location.hostname === '127.0.0.2') { + // English version + links = { + [t('data')]: `/search`, + [t('solutions')]: [ + { + icon: , + name: [t('exclusive_data')], + href: "https://info.basedosdados.org/en/bd-pro" + } + ], + [t('prices')]: "/prices", + [t('tutorials')]: [ + {name: [t('documentation')], href: "https://basedosdados.github.io/mais/en"}, + {name: [t('youtube_videos')], href: "https://www.youtube.com/c/BasedosDados/featured"}, + {name: [t('blog')], href: "https://medium.com/basedosdados"} + ], + Blog: "/blog", + [t('institutional')]: [ + {name: [t('about_us')], href: "/about-us"}, + {name: [t('transparency')], href: "/transparency"}, + {name: [t('newsletter')], href: "https://info.basedosdados.org/en/newsletter"}, + {name: [t('jobs')], href: "https://info.basedosdados.org/carreiras"}, + {name: [t('faq')], href: "/faq"}, + ], + [t('contact')]: "/contact", + Button: [] + } + } else { + // Spanish version (127.0.0.3) + links = { + [t('data')]: `/search`, + [t('solutions')]: [ + { + icon: , + name: [t('exclusive_data')], + href: "https://info.basedosdados.org/es/bd-pro" + } + ], + [t('prices')]: "/prices", + [t('tutorials')]: [ + {name: [t('documentation')], href: "https://basedosdados.github.io/mais/es"}, + {name: [t('youtube_videos')], href: "https://www.youtube.com/c/BasedosDados/featured"}, + {name: [t('blog')], href: "https://medium.com/basedosdados"} + ], + Blog: "/blog", + [t('institutional')]: [ + {name: [t('about_us')], href: "/about-us"}, + {name: [t('transparency')], href: "/transparency"}, + {name: [t('newsletter')], href: "https://info.basedosdados.org/es/newsletter"}, + {name: [t('jobs')], href: "https://info.basedosdados.org/carreiras"}, + {name: [t('faq')], href: "/faq"}, + ], + [t('contact')]: "/contact", + Button: [] + } } useEffect(() => { diff --git a/next/next-i18next.config.js b/next/next-i18next.config.js index be76eaa91..d39cbfdbc 100644 --- a/next/next-i18next.config.js +++ b/next/next-i18next.config.js @@ -1,9 +1,21 @@ -const path = require('path'); - module.exports = { i18n: { defaultLocale: 'pt', locales: ['pt', 'en', 'es'], - localeDetection: false - }, + localeDetection: false, + domains: [ + { + domain: '127.0.0.1', + defaultLocale: 'pt', + }, + { + domain: '127.0.0.2', + defaultLocale: 'en', + }, + { + domain: '127.0.0.3', + defaultLocale: 'es', + } + ] + } }; diff --git a/next/next.config.js b/next/next.config.js index 8adf47b5b..650be6b1b 100644 --- a/next/next.config.js +++ b/next/next.config.js @@ -7,21 +7,28 @@ module.exports = { disableStaticImages: true, domains: [ "basedosdados.org", - "storage.googleapis.com/basedosdados-website", + "data-basis.org", + "basedelosdatos.org", + "storage.googleapis.com", ] }, output: "standalone", reactStrictMode: true, swcMinify: true, - - async redirects() { + serverRuntimeConfig: { + port: parseInt(process.env.PORT, 10) || 3000 + }, + async headers() { return [ { - source: '/dataset', - destination: '/search', - permanent: true, - } + source: '/:path*', + headers: [ + { + key: 'Access-Control-Allow-Origin', + value: 'https://basedosdados.org, https://data-basis.org, https://basedelosdatos.org, http://0.0.0.0:3000, http://0.0.0.0:3001, http://0.0.0.0:3002', + }, + ], + }, ] } - }; diff --git a/next/package.json b/next/package.json index b9759e397..6c100b2c4 100644 --- a/next/package.json +++ b/next/package.json @@ -1,13 +1,17 @@ { - "name": "bdd-next", + "name": "next", "version": "0.1.0", "private": true, "cacheDirectories": [ ".next/cache" ], "scripts": { - "dev": "next dev", - "build": "next build", + "dev-basedosdados": "env-cmd -f .env.basedosdados next dev -p 3000 -H 127.0.0.1", + "dev-databasis": "env-cmd -f .env.databasis next dev -p 3000 -H 127.0.0.2", + "dev-basedelosdatos": "env-cmd -f .env.basedelosdatos next dev -p 3000 -H 127.0.0.3", + "build-basedosdados": "env-cmd -f .env.basedosdados next build", + "build-databasis": "env-cmd -f .env.databasis next build", + "build-basedelosdatos": "env-cmd -f .env.basedelosdatos next build", "start": "NODE_OPTIONS='-r next-logger' next start" }, "dependencies": { @@ -54,6 +58,7 @@ "remark-parse": "^11.0.0", "remark-stringify": "^11.0.0", "unified": "^11.0.5", - "unist-util-visit": "^5.0.0" + "unist-util-visit": "^5.0.0", + "env-cmd": "^10.1.0" } } From 972e57343178d0240a820cdbe8090efdb2f70114 Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Sun, 17 Nov 2024 11:28:52 +1100 Subject: [PATCH 02/12] feat: GitHub actions --- .github/workflows/cd-basedelosdatos-dev.yaml | 95 +++++++++++++++++++ .github/workflows/cd-databasis-dev.yaml | 95 +++++++++++++++++++ .github/workflows/cd-dev.yaml | 6 +- .../workflows/release-basedelosdatos-dev.yaml | 64 +++++++++++++ .github/workflows/release-databasis-dev.yaml | 64 +++++++++++++ next/Dockerfile | 4 + next/components/molecules/Menu.js | 8 +- next/next-i18next.config.js | 6 +- 8 files changed, 332 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/cd-basedelosdatos-dev.yaml create mode 100644 .github/workflows/cd-databasis-dev.yaml create mode 100644 .github/workflows/release-basedelosdatos-dev.yaml create mode 100644 .github/workflows/release-databasis-dev.yaml diff --git a/.github/workflows/cd-basedelosdatos-dev.yaml b/.github/workflows/cd-basedelosdatos-dev.yaml new file mode 100644 index 000000000..d38c2282f --- /dev/null +++ b/.github/workflows/cd-basedelosdatos-dev.yaml @@ -0,0 +1,95 @@ +name: Deploy (Base de los Datos Development) + +on: + workflow_run: + workflows: ["Release Docker Image (Data Basis Development)"] + types: + - completed + workflow_dispatch: + +env: + IMAGE_NAME: ghcr.io/basedosdados/website:basedelosdatos-development + +jobs: + deploy-development: + if: ${{ github.event.workflow_run.conclusion == 'success' }} || ${{ github.event_name == 'workflow_dispatch' }} + name: Deploy (Base de los Datos Development) + runs-on: ubuntu-latest + environment: + name: development + url: https://development.basedelosdatos.org + + steps: + - name: Checkout + uses: actions/checkout@v3.3.0 + with: + ref: development + + - name: Import Secrets + id: import_secrets + uses: hashicorp/vault-action@v2.4.1 + with: + url: https://vault.basedosdados.org + token: ${{ secrets.VAULT_TOKEN }} + secrets: | + secret/data/gcp_credentials/basedosdados-dev GCP_SA_KEY_BASE64 | GCP_SA_KEY_BASE64 ; + secret/data/gcp_credentials/basedosdados-dev GCP_PROJECT_ID | GCP_PROJECT_ID ; + secret/data/gcp_credentials/basedosdados-dev GKE_CLUSTER_NAME | GKE_CLUSTER_NAME ; + secret/data/gcp_credentials/basedosdados-dev GKE_CLUSTER_ZONE | GKE_CLUSTER_ZONE ; + + - name: Setup Google Cloud CLI + uses: google-github-actions/setup-gcloud@v0.2.1 + with: + service_account_key: ${{ steps.import_secrets.outputs.GCP_SA_KEY_BASE64 }} + project_id: ${{ steps.import_secrets.outputs.GCP_PROJECT_ID }} + export_default_credentials: true + + - name: Get GKE credentials + uses: google-github-actions/get-gke-credentials@v0.2.1 + with: + cluster_name: ${{ steps.import_secrets.outputs.GKE_CLUSTER_NAME }} + location: ${{ steps.import_secrets.outputs.GKE_CLUSTER_ZONE }} + credentials: ${{ steps.import_secrets.outputs.GCP_SA_KEY_BASE64 }} + + - name: Write values.yaml file + run: | + cat << EOF > values.yaml + website: + name: "basedelosdatos-website-development" + image: + name: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}" + tag: "basedelosdatos-development" + pullPolicy: "Always" + replicas: 1 + resources: + requests: + cpu: 100m + memory: 500Mi + limits: + cpu: 500m + memory: 1Gi + env: + - name: "NEXT_PUBLIC_DOMAIN" + value: "basedelosdatos.org" + - name: "NEXT_PUBLIC_SITE_NAME" + value: "Base de los Datos" + envFrom: + - secretRef: + name: basedelosdatos-website-development + ingress: + enabled: true + host: "development.basedelosdatos.org" + annotations: + cert-manager.io/issuer: "letsencrypt-production" + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/rewrite-target: / + nginx.ingress.kubernetes.io/ssl-redirect: "true" + tls: + - hosts: + - "development.basedelosdatos.org" + secretName: "development-basedelosdatos-org-tls" + EOF + + - name: Deploy using Helm + run: | + helm upgrade --install basedelosdatos-website-development charts/basedosdados-website/. -n website -f values.yaml --wait diff --git a/.github/workflows/cd-databasis-dev.yaml b/.github/workflows/cd-databasis-dev.yaml new file mode 100644 index 000000000..b136803aa --- /dev/null +++ b/.github/workflows/cd-databasis-dev.yaml @@ -0,0 +1,95 @@ +name: Deploy (Data Basis Development) + +on: + workflow_run: + workflows: ["Release Docker Image (Data Basis Development)"] + types: + - completed + workflow_dispatch: + +env: + IMAGE_NAME: ghcr.io/basedosdados/website:databasis-development + +jobs: + deploy-development: + if: ${{ github.event.workflow_run.conclusion == 'success' }} || ${{ github.event_name == 'workflow_dispatch' }} + name: Deploy (Data Basis Development) + runs-on: ubuntu-latest + environment: + name: development + url: https://development.data-basis.org + + steps: + - name: Checkout + uses: actions/checkout@v3.3.0 + with: + ref: development + + - name: Import Secrets + id: import_secrets + uses: hashicorp/vault-action@v2.4.1 + with: + url: https://vault.basedosdados.org + token: ${{ secrets.VAULT_TOKEN }} + secrets: | + secret/data/gcp_credentials/basedosdados-dev GCP_SA_KEY_BASE64 | GCP_SA_KEY_BASE64 ; + secret/data/gcp_credentials/basedosdados-dev GCP_PROJECT_ID | GCP_PROJECT_ID ; + secret/data/gcp_credentials/basedosdados-dev GKE_CLUSTER_NAME | GKE_CLUSTER_NAME ; + secret/data/gcp_credentials/basedosdados-dev GKE_CLUSTER_ZONE | GKE_CLUSTER_ZONE ; + + - name: Setup Google Cloud CLI + uses: google-github-actions/setup-gcloud@v0.2.1 + with: + service_account_key: ${{ steps.import_secrets.outputs.GCP_SA_KEY_BASE64 }} + project_id: ${{ steps.import_secrets.outputs.GCP_PROJECT_ID }} + export_default_credentials: true + + - name: Get GKE credentials + uses: google-github-actions/get-gke-credentials@v0.2.1 + with: + cluster_name: ${{ steps.import_secrets.outputs.GKE_CLUSTER_NAME }} + location: ${{ steps.import_secrets.outputs.GKE_CLUSTER_ZONE }} + credentials: ${{ steps.import_secrets.outputs.GCP_SA_KEY_BASE64 }} + + - name: Write values.yaml file + run: | + cat << EOF > values.yaml + website: + name: "databasis-website-development" + image: + name: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}" + tag: "databasis-development" + pullPolicy: "Always" + replicas: 1 + resources: + requests: + cpu: 100m + memory: 500Mi + limits: + cpu: 500m + memory: 1Gi + env: + - name: "NEXT_PUBLIC_DOMAIN" + value: "data-basis.org" + - name: "NEXT_PUBLIC_SITE_NAME" + value: "Data Basis" + envFrom: + - secretRef: + name: databasis-website-development + ingress: + enabled: true + host: "development.data-basis.org" + annotations: + cert-manager.io/issuer: "letsencrypt-production" + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/rewrite-target: / + nginx.ingress.kubernetes.io/ssl-redirect: "true" + tls: + - hosts: + - "development.data-basis.org" + secretName: "development-data-basis-org-tls" + EOF + + - name: Deploy using Helm + run: | + helm upgrade --install databasis-website-development charts/basedosdados-website/. -n website -f values.yaml --wait \ No newline at end of file diff --git a/.github/workflows/cd-dev.yaml b/.github/workflows/cd-dev.yaml index d30c34e4a..ff85be08a 100644 --- a/.github/workflows/cd-dev.yaml +++ b/.github/workflows/cd-dev.yaml @@ -1,8 +1,8 @@ -name: Deploy (Development) +name: Deploy (Base dos Dados Development) on: workflow_run: - workflows: ["Release Docker Image (Development)"] + workflows: ["Release Docker Image (Base dos Dados Development)"] types: - completed workflow_dispatch: @@ -13,7 +13,7 @@ env: jobs: deploy-development: if: ${{ github.event.workflow_run.conclusion == 'success' }} || ${{ github.event_name == 'workflow_dispatch' }} - name: Deploy (Development) + name: Deploy (Base dos Dados Development) runs-on: ubuntu-latest environment: name: development diff --git a/.github/workflows/release-basedelosdatos-dev.yaml b/.github/workflows/release-basedelosdatos-dev.yaml new file mode 100644 index 000000000..764226d4b --- /dev/null +++ b/.github/workflows/release-basedelosdatos-dev.yaml @@ -0,0 +1,64 @@ +name: Release Docker Image (Base de los Datos Development) + +on: + push: + branches: + - development + paths: + - ".github/workflows/release-basedelosdatos-dev.yaml" + - "next/**/*" + workflow_dispatch: + +jobs: + release: + name: Release Docker Image (Base de los Datos Development) + runs-on: ubuntu-latest + environment: + name: development + env: + NEXT_PUBLIC_API_URL: ${{ vars.NEXT_PUBLIC_API_URL }} + NEXT_PUBLIC_SITE_NAME: "Base de los Datos" + NEXT_PUBLIC_DOMAIN: "basedelosdatos.org" + NEXT_PUBLIC_KEY_STRIPE: ${{ secrets.NEXT_PUBLIC_KEY_STRIPE }} + NEXT_PUBLIC_BASE_URL_FRONTEND: ${{ vars.NEXT_PUBLIC_BASE_URL_FRONTEND }} + NODE_ENV: ${{ vars.NODE_ENV }} + IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:basedelosdatos-development + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: development + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Import Secrets + id: import_secrets + uses: hashicorp/vault-action@v2.4.1 + with: + url: https://vault.basedosdados.org + token: ${{ secrets.VAULT_TOKEN }} + secrets: | + secret/data/url_download_data URL_DOWNLOAD_CLOSED | URL_DOWNLOAD_CLOSED ; + secret/data/url_download_data URL_DOWNLOAD_OPEN | URL_DOWNLOAD_OPEN ; + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: next + file: next/Dockerfile + push: true + tags: ${{ env.IMAGE_NAME }} + build-args: | + NEXT_PUBLIC_API_URL=${{ env.NEXT_PUBLIC_API_URL }} + NEXT_PUBLIC_SITE_NAME=${{ env.NEXT_PUBLIC_SITE_NAME }} + NEXT_PUBLIC_DOMAIN=${{ env.NEXT_PUBLIC_DOMAIN }} + NEXT_PUBLIC_KEY_STRIPE=${{ env.NEXT_PUBLIC_KEY_STRIPE }} + NEXT_PUBLIC_BASE_URL_FRONTEND=${{ env.NEXT_PUBLIC_BASE_URL_FRONTEND }} + URL_DOWNLOAD_CLOSED=${{ steps.import_secrets.outputs.URL_DOWNLOAD_CLOSED }} + URL_DOWNLOAD_OPEN=${{ steps.import_secrets.outputs.URL_DOWNLOAD_OPEN }} \ No newline at end of file diff --git a/.github/workflows/release-databasis-dev.yaml b/.github/workflows/release-databasis-dev.yaml new file mode 100644 index 000000000..0569c1952 --- /dev/null +++ b/.github/workflows/release-databasis-dev.yaml @@ -0,0 +1,64 @@ +name: Release Docker Image (Data Basis Development) + +on: + push: + branches: + - development + paths: + - ".github/workflows/release-databasis-dev.yaml" + - "next/**/*" + workflow_dispatch: + +jobs: + release: + name: Release Docker Image (Data Basis Development) + runs-on: ubuntu-latest + environment: + name: development + env: + NEXT_PUBLIC_API_URL: ${{ vars.NEXT_PUBLIC_API_URL }} + NEXT_PUBLIC_SITE_NAME: "Data Basis" + NEXT_PUBLIC_DOMAIN: "data-basis.org" + NEXT_PUBLIC_KEY_STRIPE: ${{ secrets.NEXT_PUBLIC_KEY_STRIPE }} + NEXT_PUBLIC_BASE_URL_FRONTEND: ${{ vars.NEXT_PUBLIC_BASE_URL_FRONTEND }} + NODE_ENV: ${{ vars.NODE_ENV }} + IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:databasis-development + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: development + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Import Secrets + id: import_secrets + uses: hashicorp/vault-action@v2.4.1 + with: + url: https://vault.basedosdados.org + token: ${{ secrets.VAULT_TOKEN }} + secrets: | + secret/data/url_download_data URL_DOWNLOAD_CLOSED | URL_DOWNLOAD_CLOSED ; + secret/data/url_download_data URL_DOWNLOAD_OPEN | URL_DOWNLOAD_OPEN ; + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: next + file: next/Dockerfile + push: true + tags: ${{ env.IMAGE_NAME }} + build-args: | + NEXT_PUBLIC_API_URL=${{ env.NEXT_PUBLIC_API_URL }} + NEXT_PUBLIC_SITE_NAME=${{ env.NEXT_PUBLIC_SITE_NAME }} + NEXT_PUBLIC_DOMAIN=${{ env.NEXT_PUBLIC_DOMAIN }} + NEXT_PUBLIC_KEY_STRIPE=${{ env.NEXT_PUBLIC_KEY_STRIPE }} + NEXT_PUBLIC_BASE_URL_FRONTEND=${{ env.NEXT_PUBLIC_BASE_URL_FRONTEND }} + URL_DOWNLOAD_CLOSED=${{ steps.import_secrets.outputs.URL_DOWNLOAD_CLOSED }} + URL_DOWNLOAD_OPEN=${{ steps.import_secrets.outputs.URL_DOWNLOAD_OPEN }} \ No newline at end of file diff --git a/next/Dockerfile b/next/Dockerfile index 21a34e24c..9185944cb 100644 --- a/next/Dockerfile +++ b/next/Dockerfile @@ -18,12 +18,16 @@ ARG URL_DOWNLOAD_OPEN # Rebuild the source code only when needed FROM node:18.17.0-alpine AS builder +ARG NEXT_PUBLIC_DOMAIN +ARG NEXT_PUBLIC_SITE_NAME ARG NEXT_PUBLIC_API_URL ARG NEXT_PUBLIC_KEY_STRIPE ARG NEXT_PUBLIC_BASE_URL_FRONTEND ARG URL_DOWNLOAD_CLOSED ARG URL_DOWNLOAD_OPEN +ENV NEXT_PUBLIC_DOMAIN=$NEXT_PUBLIC_DOMAIN +ENV NEXT_PUBLIC_SITE_NAME=$NEXT_PUBLIC_SITE_NAME ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL ENV NEXT_PUBLIC_KEY_STRIPE=$NEXT_PUBLIC_KEY_STRIPE ENV NEXT_PUBLIC_BASE_URL_FRONTEND=$NEXT_PUBLIC_BASE_URL_FRONTEND diff --git a/next/components/molecules/Menu.js b/next/components/molecules/Menu.js index 704a23f5c..4ea2c89e6 100644 --- a/next/components/molecules/Menu.js +++ b/next/components/molecules/Menu.js @@ -1033,7 +1033,7 @@ export default function MenuNav({ simpleTemplate = false, userTemplate = false } [t('contact')]: "/contact", Button: [] } - } else if (window.location.hostname === '127.0.0.1') { + } else if (window.location.hostname === 'basedosdados.org' || window.location.hostname === '127.0.0.1') { // Portuguese version links = { [t('data')]: `/search`, @@ -1071,7 +1071,7 @@ export default function MenuNav({ simpleTemplate = false, userTemplate = false } [t('contact')]: "/contact", Button: [] } - } else if (window.location.hostname === '127.0.0.2') { + } else if (window.location.hostname === 'data-basis.org' || window.location.hostname === '127.0.0.2') { // English version links = { [t('data')]: `/search`, @@ -1099,8 +1099,8 @@ export default function MenuNav({ simpleTemplate = false, userTemplate = false } [t('contact')]: "/contact", Button: [] } - } else { - // Spanish version (127.0.0.3) + } else if (window.location.hostname === 'basedelosdatos.org' || window.location.hostname === '127.0.0.3') { + // Spanish version links = { [t('data')]: `/search`, [t('solutions')]: [ diff --git a/next/next-i18next.config.js b/next/next-i18next.config.js index d39cbfdbc..417afeef9 100644 --- a/next/next-i18next.config.js +++ b/next/next-i18next.config.js @@ -5,15 +5,15 @@ module.exports = { localeDetection: false, domains: [ { - domain: '127.0.0.1', + domain: 'basedosdados.org', defaultLocale: 'pt', }, { - domain: '127.0.0.2', + domain: 'data-basis.org', defaultLocale: 'en', }, { - domain: '127.0.0.3', + domain: 'basedelosdatos.org', defaultLocale: 'es', } ] From 574e1cbcbb7c1613e0041f09ab3f653030c3898c Mon Sep 17 00:00:00 2001 From: Gabriel Gazola Milan Date: Fri, 29 Nov 2024 17:11:59 -0300 Subject: [PATCH 03/12] feat: add international domains ingress resources --- .github/workflows/cd-dev.yaml | 21 +++++ .github/workflows/cd-prod.yaml | 21 +++++ .github/workflows/cd-staging.yaml | 21 +++++ .../templates/ingress.yaml | 83 ++++++++++++++++++- charts/basedosdados-website/values.yaml | 6 ++ 5 files changed, 149 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd-dev.yaml b/.github/workflows/cd-dev.yaml index ff85be08a..7597226b0 100644 --- a/.github/workflows/cd-dev.yaml +++ b/.github/workflows/cd-dev.yaml @@ -86,6 +86,27 @@ jobs: - hosts: - "development.basedosdados.org" secretName: "development-basedosdados-org-tls" + internationalDomains: + - language: "es" + host: "development.basedelosdatos.org" + annotations: + cert-manager.io/issuer: "letsencrypt-production" + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/ssl-redirect: "true" + tls: + - hosts: + - "development.basedelosdatos.org" + secretName: "development-basedelosdatos-org-tls" + - language: "en" + host: "development.data-basis.org" + annotations: + cert-manager.io/issuer: "letsencrypt-production" + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/ssl-redirect: "true" + tls: + - hosts: + - "development.data-basis.org" + secretName: "development-data-basis-org-tls" EOF - name: Deploy using Helm diff --git a/.github/workflows/cd-prod.yaml b/.github/workflows/cd-prod.yaml index 2d2ee2715..a05d29cc6 100644 --- a/.github/workflows/cd-prod.yaml +++ b/.github/workflows/cd-prod.yaml @@ -84,6 +84,27 @@ jobs: - hosts: - "basedosdados.org" secretName: "basedosdados-org-tls" + internationalDomains: + - language: "es" + host: "basedelosdatos.org" + annotations: + cert-manager.io/issuer: "letsencrypt-production" + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/ssl-redirect: "true" + tls: + - hosts: + - "basedelosdatos.org" + secretName: "basedelosdatos-org-tls" + - language: "en" + host: "data-basis.org" + annotations: + cert-manager.io/issuer: "letsencrypt-production" + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/ssl-redirect: "true" + tls: + - hosts: + - "data-basis.org" + secretName: "data-basis-org-tls" EOF - name: Deploy using Helm diff --git a/.github/workflows/cd-staging.yaml b/.github/workflows/cd-staging.yaml index 367e69898..c09224447 100644 --- a/.github/workflows/cd-staging.yaml +++ b/.github/workflows/cd-staging.yaml @@ -84,6 +84,27 @@ jobs: - hosts: - "staging.basedosdados.org" secretName: "staging-basedosdados-org-tls" + internationalDomains: + - language: "es" + host: "staging.basedelosdatos.org" + annotations: + cert-manager.io/issuer: "letsencrypt-production" + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/ssl-redirect: "true" + tls: + - hosts: + - "staging.basedelosdatos.org" + secretName: "staging-basedelosdatos-org-tls" + - language: "en" + host: "staging.data-basis.org" + annotations: + cert-manager.io/issuer: "letsencrypt-production" + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/ssl-redirect: "true" + tls: + - hosts: + - "staging.data-basis.org" + secretName: "staging-data-basis-org-tls" EOF - name: Deploy using Helm diff --git a/charts/basedosdados-website/templates/ingress.yaml b/charts/basedosdados-website/templates/ingress.yaml index 0ef11d7fc..8b6ff6504 100644 --- a/charts/basedosdados-website/templates/ingress.yaml +++ b/charts/basedosdados-website/templates/ingress.yaml @@ -1,11 +1,14 @@ {{- if .Values.website.ingress.enabled }} +{{- $name := .Values.website.name }} + +# Default Ingress apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: {{ .Values.website.name }}-ingress + name: {{ $name }}-ingress labels: app.kubernetes.io/component: basedosdados-website - app.kubernetes.io/name: {{ .Values.website.name }} + app.kubernetes.io/name: {{ $name }} annotations: {{- toYaml .Values.website.ingress.annotations | nindent 4 }} spec: @@ -17,11 +20,85 @@ spec: pathType: Prefix backend: service: - name: "{{ .Values.website.name }}-service" + name: "{{ $name }}-service" port: number: 80 {{- with .Values.website.ingress.tls }} tls: {{- toYaml . | nindent 4 }} {{- end }} + +# International domain Ingresses +{{- range $domain := .Values.website.ingress.internationalDomains }} +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ $name }}-{{ $domain.language }}-direct-ingress + labels: + app.kubernetes.io/component: basedosdados-website + app.kubernetes.io/name: {{ $name }} + annotations: + {{- toYaml $domain.annotations | nindent 4 }} +spec: + {{- with $domain.tls }} + tls: + {{- toYaml . | nindent 4 }} + {{- end }} + rules: + - host: {{ $domain.host | quote }} + http: + paths: + - path: /_next + pathType: Prefix + backend: + service: + name: "{{ $name }}-service" + port: + number: 80 + - path: /favicon_default.ico + pathType: Exact + backend: + service: + name: "{{ $name }}-service" + port: + number: 80 + - path: /{{ $domain.language }}/* + pathType: Prefix + backend: + service: + name: "{{ $name }}-service" + port: + number: 80 + +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ $name }}-{{ $domain.language }}-rewrite-ingress + labels: + app.kubernetes.io/component: basedosdados-website + app.kubernetes.io/name: {{ $name }} + annotations: + nginx.ingress.kubernetes.io/rewrite-target: /es/$1 + nginx.ingress.kubernetes.io/use-regex: "true" + {{- toYaml $domain.annotations | nindent 4 }} +spec: + {{- with $domain.tls }} + tls: + {{- toYaml . | nindent 4 }} + {{- end }} + rules: + - host: {{ $domain.host | quote }} + http: + paths: + - path: /(.*) + pathType: Prefix + backend: + service: + name: "{{ $name }}-service" + port: + number: 80 + +{{- end }} {{- end }} \ No newline at end of file diff --git a/charts/basedosdados-website/values.yaml b/charts/basedosdados-website/values.yaml index fb1228acd..5ccf701d3 100644 --- a/charts/basedosdados-website/values.yaml +++ b/charts/basedosdados-website/values.yaml @@ -47,3 +47,9 @@ website: # - secretName: basedosdados-website-tls # hosts: # - basedosdados-website.example.com + + internationalDomains: + - language: "es" + host: "basedelosdatos-website.example.com" + annotations: {} + tls: [] From 1fb8f24244a03c506007c4e31443e46f9ff7dbe1 Mon Sep 17 00:00:00 2001 From: Gabriel Gazola Milan Date: Fri, 29 Nov 2024 17:12:59 -0300 Subject: [PATCH 04/12] chore: remove unnecessary files --- .github/workflows/cd-basedelosdatos-dev.yaml | 95 ------------------- .github/workflows/cd-databasis-dev.yaml | 95 ------------------- .../workflows/release-basedelosdatos-dev.yaml | 64 ------------- .github/workflows/release-databasis-dev.yaml | 64 ------------- 4 files changed, 318 deletions(-) delete mode 100644 .github/workflows/cd-basedelosdatos-dev.yaml delete mode 100644 .github/workflows/cd-databasis-dev.yaml delete mode 100644 .github/workflows/release-basedelosdatos-dev.yaml delete mode 100644 .github/workflows/release-databasis-dev.yaml diff --git a/.github/workflows/cd-basedelosdatos-dev.yaml b/.github/workflows/cd-basedelosdatos-dev.yaml deleted file mode 100644 index d38c2282f..000000000 --- a/.github/workflows/cd-basedelosdatos-dev.yaml +++ /dev/null @@ -1,95 +0,0 @@ -name: Deploy (Base de los Datos Development) - -on: - workflow_run: - workflows: ["Release Docker Image (Data Basis Development)"] - types: - - completed - workflow_dispatch: - -env: - IMAGE_NAME: ghcr.io/basedosdados/website:basedelosdatos-development - -jobs: - deploy-development: - if: ${{ github.event.workflow_run.conclusion == 'success' }} || ${{ github.event_name == 'workflow_dispatch' }} - name: Deploy (Base de los Datos Development) - runs-on: ubuntu-latest - environment: - name: development - url: https://development.basedelosdatos.org - - steps: - - name: Checkout - uses: actions/checkout@v3.3.0 - with: - ref: development - - - name: Import Secrets - id: import_secrets - uses: hashicorp/vault-action@v2.4.1 - with: - url: https://vault.basedosdados.org - token: ${{ secrets.VAULT_TOKEN }} - secrets: | - secret/data/gcp_credentials/basedosdados-dev GCP_SA_KEY_BASE64 | GCP_SA_KEY_BASE64 ; - secret/data/gcp_credentials/basedosdados-dev GCP_PROJECT_ID | GCP_PROJECT_ID ; - secret/data/gcp_credentials/basedosdados-dev GKE_CLUSTER_NAME | GKE_CLUSTER_NAME ; - secret/data/gcp_credentials/basedosdados-dev GKE_CLUSTER_ZONE | GKE_CLUSTER_ZONE ; - - - name: Setup Google Cloud CLI - uses: google-github-actions/setup-gcloud@v0.2.1 - with: - service_account_key: ${{ steps.import_secrets.outputs.GCP_SA_KEY_BASE64 }} - project_id: ${{ steps.import_secrets.outputs.GCP_PROJECT_ID }} - export_default_credentials: true - - - name: Get GKE credentials - uses: google-github-actions/get-gke-credentials@v0.2.1 - with: - cluster_name: ${{ steps.import_secrets.outputs.GKE_CLUSTER_NAME }} - location: ${{ steps.import_secrets.outputs.GKE_CLUSTER_ZONE }} - credentials: ${{ steps.import_secrets.outputs.GCP_SA_KEY_BASE64 }} - - - name: Write values.yaml file - run: | - cat << EOF > values.yaml - website: - name: "basedelosdatos-website-development" - image: - name: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}" - tag: "basedelosdatos-development" - pullPolicy: "Always" - replicas: 1 - resources: - requests: - cpu: 100m - memory: 500Mi - limits: - cpu: 500m - memory: 1Gi - env: - - name: "NEXT_PUBLIC_DOMAIN" - value: "basedelosdatos.org" - - name: "NEXT_PUBLIC_SITE_NAME" - value: "Base de los Datos" - envFrom: - - secretRef: - name: basedelosdatos-website-development - ingress: - enabled: true - host: "development.basedelosdatos.org" - annotations: - cert-manager.io/issuer: "letsencrypt-production" - kubernetes.io/ingress.class: nginx - nginx.ingress.kubernetes.io/rewrite-target: / - nginx.ingress.kubernetes.io/ssl-redirect: "true" - tls: - - hosts: - - "development.basedelosdatos.org" - secretName: "development-basedelosdatos-org-tls" - EOF - - - name: Deploy using Helm - run: | - helm upgrade --install basedelosdatos-website-development charts/basedosdados-website/. -n website -f values.yaml --wait diff --git a/.github/workflows/cd-databasis-dev.yaml b/.github/workflows/cd-databasis-dev.yaml deleted file mode 100644 index b136803aa..000000000 --- a/.github/workflows/cd-databasis-dev.yaml +++ /dev/null @@ -1,95 +0,0 @@ -name: Deploy (Data Basis Development) - -on: - workflow_run: - workflows: ["Release Docker Image (Data Basis Development)"] - types: - - completed - workflow_dispatch: - -env: - IMAGE_NAME: ghcr.io/basedosdados/website:databasis-development - -jobs: - deploy-development: - if: ${{ github.event.workflow_run.conclusion == 'success' }} || ${{ github.event_name == 'workflow_dispatch' }} - name: Deploy (Data Basis Development) - runs-on: ubuntu-latest - environment: - name: development - url: https://development.data-basis.org - - steps: - - name: Checkout - uses: actions/checkout@v3.3.0 - with: - ref: development - - - name: Import Secrets - id: import_secrets - uses: hashicorp/vault-action@v2.4.1 - with: - url: https://vault.basedosdados.org - token: ${{ secrets.VAULT_TOKEN }} - secrets: | - secret/data/gcp_credentials/basedosdados-dev GCP_SA_KEY_BASE64 | GCP_SA_KEY_BASE64 ; - secret/data/gcp_credentials/basedosdados-dev GCP_PROJECT_ID | GCP_PROJECT_ID ; - secret/data/gcp_credentials/basedosdados-dev GKE_CLUSTER_NAME | GKE_CLUSTER_NAME ; - secret/data/gcp_credentials/basedosdados-dev GKE_CLUSTER_ZONE | GKE_CLUSTER_ZONE ; - - - name: Setup Google Cloud CLI - uses: google-github-actions/setup-gcloud@v0.2.1 - with: - service_account_key: ${{ steps.import_secrets.outputs.GCP_SA_KEY_BASE64 }} - project_id: ${{ steps.import_secrets.outputs.GCP_PROJECT_ID }} - export_default_credentials: true - - - name: Get GKE credentials - uses: google-github-actions/get-gke-credentials@v0.2.1 - with: - cluster_name: ${{ steps.import_secrets.outputs.GKE_CLUSTER_NAME }} - location: ${{ steps.import_secrets.outputs.GKE_CLUSTER_ZONE }} - credentials: ${{ steps.import_secrets.outputs.GCP_SA_KEY_BASE64 }} - - - name: Write values.yaml file - run: | - cat << EOF > values.yaml - website: - name: "databasis-website-development" - image: - name: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}" - tag: "databasis-development" - pullPolicy: "Always" - replicas: 1 - resources: - requests: - cpu: 100m - memory: 500Mi - limits: - cpu: 500m - memory: 1Gi - env: - - name: "NEXT_PUBLIC_DOMAIN" - value: "data-basis.org" - - name: "NEXT_PUBLIC_SITE_NAME" - value: "Data Basis" - envFrom: - - secretRef: - name: databasis-website-development - ingress: - enabled: true - host: "development.data-basis.org" - annotations: - cert-manager.io/issuer: "letsencrypt-production" - kubernetes.io/ingress.class: nginx - nginx.ingress.kubernetes.io/rewrite-target: / - nginx.ingress.kubernetes.io/ssl-redirect: "true" - tls: - - hosts: - - "development.data-basis.org" - secretName: "development-data-basis-org-tls" - EOF - - - name: Deploy using Helm - run: | - helm upgrade --install databasis-website-development charts/basedosdados-website/. -n website -f values.yaml --wait \ No newline at end of file diff --git a/.github/workflows/release-basedelosdatos-dev.yaml b/.github/workflows/release-basedelosdatos-dev.yaml deleted file mode 100644 index 764226d4b..000000000 --- a/.github/workflows/release-basedelosdatos-dev.yaml +++ /dev/null @@ -1,64 +0,0 @@ -name: Release Docker Image (Base de los Datos Development) - -on: - push: - branches: - - development - paths: - - ".github/workflows/release-basedelosdatos-dev.yaml" - - "next/**/*" - workflow_dispatch: - -jobs: - release: - name: Release Docker Image (Base de los Datos Development) - runs-on: ubuntu-latest - environment: - name: development - env: - NEXT_PUBLIC_API_URL: ${{ vars.NEXT_PUBLIC_API_URL }} - NEXT_PUBLIC_SITE_NAME: "Base de los Datos" - NEXT_PUBLIC_DOMAIN: "basedelosdatos.org" - NEXT_PUBLIC_KEY_STRIPE: ${{ secrets.NEXT_PUBLIC_KEY_STRIPE }} - NEXT_PUBLIC_BASE_URL_FRONTEND: ${{ vars.NEXT_PUBLIC_BASE_URL_FRONTEND }} - NODE_ENV: ${{ vars.NODE_ENV }} - IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:basedelosdatos-development - - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - ref: development - - - name: Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Import Secrets - id: import_secrets - uses: hashicorp/vault-action@v2.4.1 - with: - url: https://vault.basedosdados.org - token: ${{ secrets.VAULT_TOKEN }} - secrets: | - secret/data/url_download_data URL_DOWNLOAD_CLOSED | URL_DOWNLOAD_CLOSED ; - secret/data/url_download_data URL_DOWNLOAD_OPEN | URL_DOWNLOAD_OPEN ; - - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: next - file: next/Dockerfile - push: true - tags: ${{ env.IMAGE_NAME }} - build-args: | - NEXT_PUBLIC_API_URL=${{ env.NEXT_PUBLIC_API_URL }} - NEXT_PUBLIC_SITE_NAME=${{ env.NEXT_PUBLIC_SITE_NAME }} - NEXT_PUBLIC_DOMAIN=${{ env.NEXT_PUBLIC_DOMAIN }} - NEXT_PUBLIC_KEY_STRIPE=${{ env.NEXT_PUBLIC_KEY_STRIPE }} - NEXT_PUBLIC_BASE_URL_FRONTEND=${{ env.NEXT_PUBLIC_BASE_URL_FRONTEND }} - URL_DOWNLOAD_CLOSED=${{ steps.import_secrets.outputs.URL_DOWNLOAD_CLOSED }} - URL_DOWNLOAD_OPEN=${{ steps.import_secrets.outputs.URL_DOWNLOAD_OPEN }} \ No newline at end of file diff --git a/.github/workflows/release-databasis-dev.yaml b/.github/workflows/release-databasis-dev.yaml deleted file mode 100644 index 0569c1952..000000000 --- a/.github/workflows/release-databasis-dev.yaml +++ /dev/null @@ -1,64 +0,0 @@ -name: Release Docker Image (Data Basis Development) - -on: - push: - branches: - - development - paths: - - ".github/workflows/release-databasis-dev.yaml" - - "next/**/*" - workflow_dispatch: - -jobs: - release: - name: Release Docker Image (Data Basis Development) - runs-on: ubuntu-latest - environment: - name: development - env: - NEXT_PUBLIC_API_URL: ${{ vars.NEXT_PUBLIC_API_URL }} - NEXT_PUBLIC_SITE_NAME: "Data Basis" - NEXT_PUBLIC_DOMAIN: "data-basis.org" - NEXT_PUBLIC_KEY_STRIPE: ${{ secrets.NEXT_PUBLIC_KEY_STRIPE }} - NEXT_PUBLIC_BASE_URL_FRONTEND: ${{ vars.NEXT_PUBLIC_BASE_URL_FRONTEND }} - NODE_ENV: ${{ vars.NODE_ENV }} - IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:databasis-development - - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - ref: development - - - name: Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Import Secrets - id: import_secrets - uses: hashicorp/vault-action@v2.4.1 - with: - url: https://vault.basedosdados.org - token: ${{ secrets.VAULT_TOKEN }} - secrets: | - secret/data/url_download_data URL_DOWNLOAD_CLOSED | URL_DOWNLOAD_CLOSED ; - secret/data/url_download_data URL_DOWNLOAD_OPEN | URL_DOWNLOAD_OPEN ; - - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: next - file: next/Dockerfile - push: true - tags: ${{ env.IMAGE_NAME }} - build-args: | - NEXT_PUBLIC_API_URL=${{ env.NEXT_PUBLIC_API_URL }} - NEXT_PUBLIC_SITE_NAME=${{ env.NEXT_PUBLIC_SITE_NAME }} - NEXT_PUBLIC_DOMAIN=${{ env.NEXT_PUBLIC_DOMAIN }} - NEXT_PUBLIC_KEY_STRIPE=${{ env.NEXT_PUBLIC_KEY_STRIPE }} - NEXT_PUBLIC_BASE_URL_FRONTEND=${{ env.NEXT_PUBLIC_BASE_URL_FRONTEND }} - URL_DOWNLOAD_CLOSED=${{ steps.import_secrets.outputs.URL_DOWNLOAD_CLOSED }} - URL_DOWNLOAD_OPEN=${{ steps.import_secrets.outputs.URL_DOWNLOAD_OPEN }} \ No newline at end of file From 19db64da52b2604c02af50d744002a9a3343ebde Mon Sep 17 00:00:00 2001 From: Gabriel Gazola Milan Date: Fri, 29 Nov 2024 17:14:04 -0300 Subject: [PATCH 05/12] chore: undo renamings on actions --- .github/workflows/cd-dev.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd-dev.yaml b/.github/workflows/cd-dev.yaml index 7597226b0..fbe09d6be 100644 --- a/.github/workflows/cd-dev.yaml +++ b/.github/workflows/cd-dev.yaml @@ -1,8 +1,8 @@ -name: Deploy (Base dos Dados Development) +name: Deploy (Development) on: workflow_run: - workflows: ["Release Docker Image (Base dos Dados Development)"] + workflows: ["Release Docker Image (Development)"] types: - completed workflow_dispatch: @@ -13,7 +13,7 @@ env: jobs: deploy-development: if: ${{ github.event.workflow_run.conclusion == 'success' }} || ${{ github.event_name == 'workflow_dispatch' }} - name: Deploy (Base dos Dados Development) + name: Deploy (Development) runs-on: ubuntu-latest environment: name: development From 68ddd9f6926441d7936aade72bf641a5c7e05d39 Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Wed, 4 Dec 2024 17:05:51 +1100 Subject: [PATCH 06/12] adjustments: next config, menu in en and es --- next/components/molecules/Menu.js | 13 +++---------- next/next.config.js | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/next/components/molecules/Menu.js b/next/components/molecules/Menu.js index 8c922f606..61f0b4232 100644 --- a/next/components/molecules/Menu.js +++ b/next/components/molecules/Menu.js @@ -1068,7 +1068,6 @@ export default function MenuNav({ simpleTemplate = false, userTemplate = false } [t('tutorials')]: [ {name: [t('documentation')], href: "https://basedosdados.github.io/sdk"}, {name: [t('youtube_videos')], href: "https://www.youtube.com/c/BasedosDados/featured"}, - {name: [t('blog')], href: "https://medium.com/basedosdados"} ], Blog: "/blog", [t('institutional')]: [ @@ -1094,16 +1093,13 @@ export default function MenuNav({ simpleTemplate = false, userTemplate = false } ], [t('prices')]: "/prices", [t('tutorials')]: [ - {name: [t('documentation')], href: "https://basedosdados.github.io/mais/en"}, + {name: [t('documentation')], href: "https://basedosdados.github.io/sdk/en"}, {name: [t('youtube_videos')], href: "https://www.youtube.com/c/BasedosDados/featured"}, - {name: [t('blog')], href: "https://medium.com/basedosdados"} ], Blog: "/blog", [t('institutional')]: [ {name: [t('about_us')], href: "/about-us"}, {name: [t('transparency')], href: "/transparency"}, - {name: [t('newsletter')], href: "https://info.basedosdados.org/en/newsletter"}, - {name: [t('jobs')], href: "https://info.basedosdados.org/carreiras"}, {name: [t('faq')], href: "/faq"}, ], [t('contact')]: "/contact", @@ -1115,23 +1111,20 @@ export default function MenuNav({ simpleTemplate = false, userTemplate = false } [t('data')]: `/search`, [t('solutions')]: [ { - icon: , + icon: , name: [t('exclusive_data')], href: "https://info.basedosdados.org/es/bd-pro" } ], [t('prices')]: "/prices", [t('tutorials')]: [ - {name: [t('documentation')], href: "https://basedosdados.github.io/mais/es"}, + {name: [t('documentation')], href: "https://basedosdados.github.io/sdk/es"}, {name: [t('youtube_videos')], href: "https://www.youtube.com/c/BasedosDados/featured"}, - {name: [t('blog')], href: "https://medium.com/basedosdados"} ], Blog: "/blog", [t('institutional')]: [ {name: [t('about_us')], href: "/about-us"}, {name: [t('transparency')], href: "/transparency"}, - {name: [t('newsletter')], href: "https://info.basedosdados.org/es/newsletter"}, - {name: [t('jobs')], href: "https://info.basedosdados.org/carreiras"}, {name: [t('faq')], href: "/faq"}, ], [t('contact')]: "/contact", diff --git a/next/next.config.js b/next/next.config.js index 650be6b1b..313841104 100644 --- a/next/next.config.js +++ b/next/next.config.js @@ -25,7 +25,7 @@ module.exports = { headers: [ { key: 'Access-Control-Allow-Origin', - value: 'https://basedosdados.org, https://data-basis.org, https://basedelosdatos.org, http://0.0.0.0:3000, http://0.0.0.0:3001, http://0.0.0.0:3002', + value: 'https://basedosdados.org, https://data-basis.org, https://basedelosdatos.org, http://127.0.0.1, http://127.0.0.2, http://127.0.0.3', }, ], }, From ebca00551e0fa2d602b699ed3a4a81ebad1d6ec8 Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Fri, 6 Dec 2024 16:14:48 +1100 Subject: [PATCH 07/12] fix: package-lock, language from es, next build --- charts/basedosdados-website/templates/ingress.yaml | 2 +- next/next.config.js | 2 +- next/package-lock.json | 4 ++-- next/package.json | 11 +++-------- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/charts/basedosdados-website/templates/ingress.yaml b/charts/basedosdados-website/templates/ingress.yaml index 8b6ff6504..6a1570018 100644 --- a/charts/basedosdados-website/templates/ingress.yaml +++ b/charts/basedosdados-website/templates/ingress.yaml @@ -80,7 +80,7 @@ metadata: app.kubernetes.io/component: basedosdados-website app.kubernetes.io/name: {{ $name }} annotations: - nginx.ingress.kubernetes.io/rewrite-target: /es/$1 + nginx.ingress.kubernetes.io/rewrite-target: /{{ $domain.language }}/$1 nginx.ingress.kubernetes.io/use-regex: "true" {{- toYaml $domain.annotations | nindent 4 }} spec: diff --git a/next/next.config.js b/next/next.config.js index 313841104..650be6b1b 100644 --- a/next/next.config.js +++ b/next/next.config.js @@ -25,7 +25,7 @@ module.exports = { headers: [ { key: 'Access-Control-Allow-Origin', - value: 'https://basedosdados.org, https://data-basis.org, https://basedelosdatos.org, http://127.0.0.1, http://127.0.0.2, http://127.0.0.3', + value: 'https://basedosdados.org, https://data-basis.org, https://basedelosdatos.org, http://0.0.0.0:3000, http://0.0.0.0:3001, http://0.0.0.0:3002', }, ], }, diff --git a/next/package-lock.json b/next/package-lock.json index c8e80a49d..19b171855 100644 --- a/next/package-lock.json +++ b/next/package-lock.json @@ -1,11 +1,11 @@ { - "name": "bdd-next", + "name": "next", "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "bdd-next", + "name": "next", "version": "0.1.0", "dependencies": { "@chakra-ui/icons": "^1.1.7", diff --git a/next/package.json b/next/package.json index 2242ab70e..200a32712 100644 --- a/next/package.json +++ b/next/package.json @@ -6,12 +6,8 @@ ".next/cache" ], "scripts": { - "dev-basedosdados": "env-cmd -f .env.basedosdados next dev -p 3000 -H 127.0.0.1", - "dev-databasis": "env-cmd -f .env.databasis next dev -p 3000 -H 127.0.0.2", - "dev-basedelosdatos": "env-cmd -f .env.basedelosdatos next dev -p 3000 -H 127.0.0.3", - "build-basedosdados": "env-cmd -f .env.basedosdados next build", - "build-databasis": "env-cmd -f .env.databasis next build", - "build-basedelosdatos": "env-cmd -f .env.basedelosdatos next build", + "dev": "next dev", + "build": "next build", "start": "NODE_OPTIONS='-r next-logger' next start" }, "dependencies": { @@ -59,7 +55,6 @@ "remark-parse": "^11.0.0", "remark-stringify": "^11.0.0", "unified": "^11.0.5", - "unist-util-visit": "^5.0.0", - "env-cmd": "^10.1.0" + "unist-util-visit": "^5.0.0" } } From f8c96e331451ad671d2d29f6036792ae2a198c64 Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Fri, 6 Dec 2024 16:47:24 +1100 Subject: [PATCH 08/12] fix attempt: ingress yaml indentation --- .../templates/ingress.yaml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/charts/basedosdados-website/templates/ingress.yaml b/charts/basedosdados-website/templates/ingress.yaml index 6a1570018..43b2e2e00 100644 --- a/charts/basedosdados-website/templates/ingress.yaml +++ b/charts/basedosdados-website/templates/ingress.yaml @@ -10,19 +10,21 @@ metadata: app.kubernetes.io/component: basedosdados-website app.kubernetes.io/name: {{ $name }} annotations: - {{- toYaml .Values.website.ingress.annotations | nindent 4 }} + {{- with .Values.website.ingress.annotations }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: rules: - host: {{ .Values.website.ingress.host | quote }} http: paths: - - path: / - pathType: Prefix - backend: - service: - name: "{{ $name }}-service" - port: - number: 80 + - path: / + pathType: Prefix + backend: + service: + name: "{{ $name }}-service" + port: + number: 80 {{- with .Values.website.ingress.tls }} tls: {{- toYaml . | nindent 4 }} From 0c2786cb791eaddb4a9f6df8cef38e1c9ff273af Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Fri, 6 Dec 2024 16:51:43 +1100 Subject: [PATCH 09/12] trigger deploy --- next/pages/transparency.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/next/pages/transparency.js b/next/pages/transparency.js index 026add0f0..3a7b4ea27 100644 --- a/next/pages/transparency.js +++ b/next/pages/transparency.js @@ -426,4 +426,4 @@ export default function Transparency({ pages }) { ) -} +} \ No newline at end of file From 7f082ba79dec936e8fe32737a6add4a2e961e147 Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Fri, 6 Dec 2024 17:46:36 +1100 Subject: [PATCH 10/12] fix: populate value.yaml, trigger action --- charts/basedosdados-website/values.yaml | 72 +++++++++++++++---------- next/pages/terms.js | 2 +- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/charts/basedosdados-website/values.yaml b/charts/basedosdados-website/values.yaml index 5ccf701d3..cbd344e8e 100644 --- a/charts/basedosdados-website/values.yaml +++ b/charts/basedosdados-website/values.yaml @@ -5,51 +5,69 @@ website: # Deployment image image: - name: "ghcr.io/basedosdados/website" - tag: "production" # We use the production tag fot the website as a default + name: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}" + tag: "production" pullPolicy: "Always" # Number of replicas replicas: 1 # Specifying resources is recommended for production deployments - resources: {} - # limits: - # cpu: 500m - # memory: 1G - # requests: - # cpu: 100m - # memory: 500Mi + resources: + requests: + cpu: 100m + memory: 500Mi + limits: + cpu: 500m + memory: 1Gi # Additional environment variables to be passed to the website container. - env: [] - # - name: "SOME_ENV" - # value: "some-value" - envFrom: [] - # - secretRef: - # name: "some-secret" + env: + - name: "NEXT_PUBLIC_KEY_STRIPE" + value: "${{ secrets.NEXT_PUBLIC_KEY_STRIPE }}" + envFrom: + - secretRef: + name: basedosdados-website-development # Ingress configuration ingress: # Enable ingress - enabled: false + enabled: true # Host to be used in the ingress - host: "basedosdados-website.example.com" + host: "development.basedosdados.org" # Ingress annotations - annotations: {} - # kubernetes.io/ingress.class: nginx - # kubernetes.io/tls-acme: "true" + annotations: + cert-manager.io/issuer: "letsencrypt-production" + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/rewrite-target: / + nginx.ingress.kubernetes.io/ssl-redirect: "true" # TLS configuration - tls: [] - # - secretName: basedosdados-website-tls - # hosts: - # - basedosdados-website.example.com + tls: + - hosts: + - "development.basedosdados.org" + secretName: "development-basedosdados-org-tls" internationalDomains: - language: "es" - host: "basedelosdatos-website.example.com" - annotations: {} - tls: [] + host: "development.basedelosdatos.org" + annotations: + cert-manager.io/issuer: "letsencrypt-production" + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/ssl-redirect: "true" + tls: + - hosts: + - "development.basedelosdatos.org" + secretName: "development-basedelosdatos-org-tls" + - language: "en" + host: "development.data-basis.org" + annotations: + cert-manager.io/issuer: "letsencrypt-production" + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/ssl-redirect: "true" + tls: + - hosts: + - "development.data-basis.org" + secretName: "development-data-basis-org-tls" diff --git a/next/pages/terms.js b/next/pages/terms.js index 35f3ef3b5..c4ab985df 100644 --- a/next/pages/terms.js +++ b/next/pages/terms.js @@ -181,4 +181,4 @@ export default function TermsAndPolicies() { ) -} \ No newline at end of file +} From 0447bed75288e03e7d12df33c0bc7cd559c1e9d0 Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Fri, 6 Dec 2024 17:47:25 +1100 Subject: [PATCH 11/12] chore: echo generated values.yaml --- .github/workflows/cd-dev.yaml | 7 +++ charts/basedosdados-website/values.yaml | 65 ++++--------------------- 2 files changed, 17 insertions(+), 55 deletions(-) diff --git a/.github/workflows/cd-dev.yaml b/.github/workflows/cd-dev.yaml index fbe09d6be..1f3a5cade 100644 --- a/.github/workflows/cd-dev.yaml +++ b/.github/workflows/cd-dev.yaml @@ -109,6 +109,13 @@ jobs: secretName: "development-data-basis-org-tls" EOF + - name: Debug values.yaml + run: | + echo "Generated values.yaml content:" + cat values.yaml + echo "Validating YAML syntax:" + python3 -c "import yaml; yaml.safe_load(open('values.yaml'))" + - name: Deploy using Helm run: | helm upgrade --install basedosdados-website-development charts/basedosdados-website/. -n website -f values.yaml --wait diff --git a/charts/basedosdados-website/values.yaml b/charts/basedosdados-website/values.yaml index cbd344e8e..e9b146475 100644 --- a/charts/basedosdados-website/values.yaml +++ b/charts/basedosdados-website/values.yaml @@ -5,7 +5,7 @@ website: # Deployment image image: - name: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}" + name: "ghcr.io/basedosdados/website" tag: "production" pullPolicy: "Always" @@ -13,61 +13,16 @@ website: replicas: 1 # Specifying resources is recommended for production deployments - resources: - requests: - cpu: 100m - memory: 500Mi - limits: - cpu: 500m - memory: 1Gi + resources: {} - # Additional environment variables to be passed to the website container. - env: - - name: "NEXT_PUBLIC_KEY_STRIPE" - value: "${{ secrets.NEXT_PUBLIC_KEY_STRIPE }}" - envFrom: - - secretRef: - name: basedosdados-website-development + # Additional environment variables + env: [] + envFrom: [] # Ingress configuration ingress: - # Enable ingress - enabled: true - - # Host to be used in the ingress - host: "development.basedosdados.org" - - # Ingress annotations - annotations: - cert-manager.io/issuer: "letsencrypt-production" - kubernetes.io/ingress.class: nginx - nginx.ingress.kubernetes.io/rewrite-target: / - nginx.ingress.kubernetes.io/ssl-redirect: "true" - - # TLS configuration - tls: - - hosts: - - "development.basedosdados.org" - secretName: "development-basedosdados-org-tls" - - internationalDomains: - - language: "es" - host: "development.basedelosdatos.org" - annotations: - cert-manager.io/issuer: "letsencrypt-production" - kubernetes.io/ingress.class: nginx - nginx.ingress.kubernetes.io/ssl-redirect: "true" - tls: - - hosts: - - "development.basedelosdatos.org" - secretName: "development-basedelosdatos-org-tls" - - language: "en" - host: "development.data-basis.org" - annotations: - cert-manager.io/issuer: "letsencrypt-production" - kubernetes.io/ingress.class: nginx - nginx.ingress.kubernetes.io/ssl-redirect: "true" - tls: - - hosts: - - "development.data-basis.org" - secretName: "development-data-basis-org-tls" + enabled: false + host: "" + annotations: {} + tls: [] + internationalDomains: [] From 2c783b880348528ada0e22fdca569454021ee656 Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Sat, 7 Dec 2024 09:55:18 +1100 Subject: [PATCH 12/12] fix: Menu.js by locale --- next/components/molecules/Menu.js | 59 +++++-------------------------- 1 file changed, 9 insertions(+), 50 deletions(-) diff --git a/next/components/molecules/Menu.js b/next/components/molecules/Menu.js index 61f0b4232..4d8d70c64 100644 --- a/next/components/molecules/Menu.js +++ b/next/components/molecules/Menu.js @@ -999,52 +999,8 @@ export default function MenuNav({ simpleTemplate = false, userTemplate = false } let links; - if (typeof window === 'undefined') { - // Server-side rendering - use default (Portuguese) version - links = { - [t('data')]: `/search`, - [t('solutions')]: [ - { - icon: , - name: [t('exclusive_data')], - href: locale === 'en' ? "https://info.basedosdados.org/en/bd-pro" : - locale === 'es' ? "https://info.basedosdados.org/es/bd-pro" : - "https://info.basedosdados.org/bd-pro" - }, - { - icon: , - name: [t('data_courses')], - href: "https://info.basedosdados.org/bd-edu-sql" - }, - { - icon: , - name: [t('services')], - href: "/services" - }, - ], - [t('prices')]: "/prices", - [t('tutorials')]: [ - {name: [t('documentation')], href: - locale === "en" ? "https://basedosdados.github.io/sdk/en" : - locale === "es" ? "https://basedosdados.github.io/sdk/es" : - "https://basedosdados.github.io/sdk" - }, - {name: [t('youtube_videos')], href: "https://www.youtube.com/c/BasedosDados/featured"}, - {name: [t('blog')], href: "https://medium.com/basedosdados"} - ], - Blog: "/blog", - [t('institutional')]: [ - {name: [t('about_us')], href: "/about-us"}, - {name: [t('transparency')], href: "/transparency"}, - {name: [t('newsletter')], href: "https://info.basedosdados.org/newsletter"}, - {name: [t('jobs')], href: "https://info.basedosdados.org/carreiras"}, - {name: [t('faq')], href: "/faq"}, - ], - [t('contact')]: "/contact", - Button: [] - } - } else if (window.location.hostname === 'basedosdados.org' || window.location.hostname === '127.0.0.1') { - // Portuguese version + if (locale === "pt") { + links = { [t('data')]: `/search`, [t('solutions')]: [ @@ -1080,8 +1036,9 @@ export default function MenuNav({ simpleTemplate = false, userTemplate = false } [t('contact')]: "/contact", Button: [] } - } else if (window.location.hostname === 'data-basis.org' || window.location.hostname === '127.0.0.2') { - // English version + + } else if (locale === "en") { + links = { [t('data')]: `/search`, [t('solutions')]: [ @@ -1105,8 +1062,9 @@ export default function MenuNav({ simpleTemplate = false, userTemplate = false } [t('contact')]: "/contact", Button: [] } - } else if (window.location.hostname === 'basedelosdatos.org' || window.location.hostname === '127.0.0.3') { - // Spanish version + + } else if (locale === "es") { + links = { [t('data')]: `/search`, [t('solutions')]: [ @@ -1130,6 +1088,7 @@ export default function MenuNav({ simpleTemplate = false, userTemplate = false } [t('contact')]: "/contact", Button: [] } + } useEffect(() => {