Skip to content

Commit

Permalink
Merge pull request #1043 from basedosdados/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
rdahis authored Dec 7, 2024
2 parents 05a1639 + c8a9533 commit 51bb8d5
Show file tree
Hide file tree
Showing 15 changed files with 343 additions and 97 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/cd-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,36 @@ 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: 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
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
99 changes: 89 additions & 10 deletions charts/basedosdados-website/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,106 @@
{{- 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 }}
{{- 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: "{{ .Values.website.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 }}
{{- 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: /{{ $domain.language }}/$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 }}
29 changes: 4 additions & 25 deletions charts/basedosdados-website/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,23 @@ website:
# Deployment image
image:
name: "ghcr.io/basedosdados/website"
tag: "production" # We use the production tag fot the website as a default
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

# Additional environment variables to be passed to the website container.
# Additional environment variables
env: []
# - name: "SOME_ENV"
# value: "some-value"
envFrom: []
# - secretRef:
# name: "some-secret"

# Ingress configuration
ingress:
# Enable ingress
enabled: false

# Host to be used in the ingress
host: "basedosdados-website.example.com"

# Ingress annotations
host: ""
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"

# TLS configuration
tls: []
# - secretName: basedosdados-website-tls
# hosts:
# - basedosdados-website.example.com
internationalDomains: []
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

0 comments on commit 51bb8d5

Please sign in to comment.