Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Domínios internacionais #1025

Merged
merged 11 commits into from
Dec 6, 2024
21 changes: 21 additions & 0 deletions .github/workflows/cd-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/cd-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/cd-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
83 changes: 80 additions & 3 deletions charts/basedosdados-website/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 }}
6 changes: 6 additions & 0 deletions charts/basedosdados-website/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ website:
# - secretName: basedosdados-website-tls
# hosts:
# - basedosdados-website.example.com

internationalDomains:
- language: "es"
host: "basedelosdatos-website.example.com"
annotations: {}
tls: []
37 changes: 35 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 4 additions & 0 deletions next/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions next/components/atoms/DomainComponent.js
Original file line number Diff line number Diff line change
@@ -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;
}
Loading