Skip to content

Commit 055ca1a

Browse files
authored
Merge pull request #605 from basedosdados/development
Development
2 parents 04d23eb + 339ed71 commit 055ca1a

File tree

12 files changed

+348
-71
lines changed

12 files changed

+348
-71
lines changed

.github/workflows/cd-dev.yaml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Deploy (Development)
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Release Docker Image (Development)"]
6+
types:
7+
- completed
8+
workflow_dispatch:
9+
10+
env:
11+
IMAGE_NAME: ghcr.io/basedosdados/website:development
12+
13+
jobs:
14+
deploy-development:
15+
if: ${{ github.event.workflow_run.conclusion == 'success' }} || ${{ github.event_name == 'workflow_dispatch' }}
16+
name: Deploy (Development)
17+
runs-on: ubuntu-latest
18+
environment:
19+
name: development
20+
url: https://development.basedosdados.org
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3.3.0
25+
with:
26+
ref: development
27+
28+
- name: Import Secrets
29+
id: import_secrets
30+
uses: hashicorp/vault-action@v2.4.1
31+
with:
32+
url: https://vault.basedosdados.org
33+
token: ${{ secrets.VAULT_TOKEN }}
34+
secrets: |
35+
secret/data/gcp_credentials/basedosdados-dev GCP_SA_KEY_BASE64 | GCP_SA_KEY_BASE64 ;
36+
secret/data/gcp_credentials/basedosdados-dev GCP_PROJECT_ID | GCP_PROJECT_ID ;
37+
secret/data/gcp_credentials/basedosdados-dev GKE_CLUSTER_NAME | GKE_CLUSTER_NAME ;
38+
secret/data/gcp_credentials/basedosdados-dev GKE_CLUSTER_ZONE | GKE_CLUSTER_ZONE ;
39+
40+
- name: Setup Google Cloud CLI
41+
uses: google-github-actions/setup-gcloud@v0.2.1
42+
with:
43+
service_account_key: ${{ steps.import_secrets.outputs.GCP_SA_KEY_BASE64 }}
44+
project_id: ${{ steps.import_secrets.outputs.GCP_PROJECT_ID }}
45+
export_default_credentials: true
46+
47+
- name: Get GKE credentials
48+
uses: google-github-actions/get-gke-credentials@v0.2.1
49+
with:
50+
cluster_name: ${{ steps.import_secrets.outputs.GKE_CLUSTER_NAME }}
51+
location: ${{ steps.import_secrets.outputs.GKE_CLUSTER_ZONE }}
52+
credentials: ${{ steps.import_secrets.outputs.GCP_SA_KEY_BASE64 }}
53+
54+
- name: Write values.yaml file
55+
run: |
56+
cat << EOF > values.yaml
57+
website:
58+
name: "basedosdados-website-development"
59+
image:
60+
name: "ghcr.io/basedosdados/website"
61+
tag: "development"
62+
pullPolicy: "Always"
63+
replicas: 1
64+
resources:
65+
requests:
66+
cpu: 100m
67+
memory: 500Mi
68+
limits:
69+
cpu: 500m
70+
memory: 1Gi
71+
env: []
72+
envFrom:
73+
- secretRef:
74+
name: basedosdados-website-development
75+
ingress:
76+
enabled: true
77+
host: "development.basedosdados.org"
78+
annotations:
79+
cert-manager.io/issuer: "letsencrypt-production"
80+
kubernetes.io/ingress.class: nginx
81+
nginx.ingress.kubernetes.io/rewrite-target: /
82+
nginx.ingress.kubernetes.io/ssl-redirect: "true"
83+
tls:
84+
- hosts:
85+
- "development.basedosdados.org"
86+
secretName: "development-basedosdados-org-tls"
87+
EOF
88+
89+
- name: Deploy using Helm
90+
run: |
91+
helm upgrade --install basedosdados-website-development charts/basedosdados-website/. -n website -f values.yaml --wait

.github/workflows/cd-v2.yaml

Lines changed: 0 additions & 63 deletions
This file was deleted.

.github/workflows/release-chart.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Release Helm Chart
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- ".github/workflows/release-chart.yaml"
9+
- "charts/**/*"
10+
11+
jobs:
12+
release-helm-chart:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v1
17+
18+
- name: Configure Git
19+
run: |
20+
git config user.name "$GITHUB_ACTOR"
21+
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
22+
23+
- name: Run chart-releaser
24+
uses: helm/chart-releaser-action@v1.0.0
25+
env:
26+
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

.github/workflows/ci-v2.yaml renamed to .github/workflows/release-dev.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
name: CI
1+
name: Release Docker Image (Development)
22

33
on:
44
push:
55
branches:
6-
- nextjs
7-
workflow_dispatch:
6+
- development
7+
paths:
8+
- ".github/workflows/release.yaml"
9+
- "next/**/*"
810

911
jobs:
10-
build-container:
11-
if: github.ref_name == 'nextjs'
12-
name: Build and publish container image
12+
release-docker-image-development:
13+
name: Release Docker Image (Development)
1314
runs-on: ubuntu-latest
1415
environment:
1516
name: development
@@ -24,7 +25,7 @@ jobs:
2425
- name: Checkout
2526
uses: actions/checkout@v3
2627
with:
27-
ref: nextjs
28+
ref: development
2829

2930
- name: Login to GitHub Container Registry
3031
uses: docker/login-action@v2
@@ -42,4 +43,3 @@ jobs:
4243
tags: ${{ env.IMAGE_NAME }}
4344
build-args: |
4445
NEXT_PUBLIC_API_URL=${{ env.NEXT_PUBLIC_API_URL }}
45-

.github/workflows/release.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Release Docker Image (Production)
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- ".github/workflows/release.yaml"
9+
- "next/**/*"
10+
11+
jobs:
12+
release-docker-image-production:
13+
name: Release Docker Image (Production)
14+
runs-on: ubuntu-latest
15+
environment:
16+
name: production
17+
env:
18+
NEXT_PORT: ${{ vars.NEXT_PORT }}
19+
NEXT_PUBLIC_API_URL: ${{ vars.NEXT_PUBLIC_API_URL }}
20+
NEXT_PUBLIC_SITE_NAME: ${{ vars.NEXT_PUBLIC_SITE_NAME }}
21+
NODE_ENV: ${{ vars.NODE_ENV }}
22+
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:production
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v3
27+
with:
28+
ref: main
29+
30+
- name: Login to GitHub Container Registry
31+
uses: docker/login-action@v2
32+
with:
33+
registry: ghcr.io
34+
username: ${{ github.repository_owner }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Build and push
38+
uses: docker/build-push-action@v3
39+
with:
40+
context: next
41+
file: next/Dockerfile
42+
push: true
43+
tags: ${{ env.IMAGE_NAME }}
44+
build-args: |
45+
NEXT_PUBLIC_API_URL=${{ env.NEXT_PUBLIC_API_URL }}

charts/.gitkeep

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v2
2+
name: basedosdados-website
3+
description: Deploys the basedosdados website
4+
5+
type: application
6+
7+
version: 0.0.1
8+
9+
appVersion: "0.0.1"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ .Values.website.name }}
5+
labels:
6+
app.kubernetes.io/component: basedosdados-website
7+
app.kubernetes.io/name: {{ .Values.website.name }}
8+
annotations:
9+
rollme: {{ randAlphaNum 5 | quote }}
10+
spec:
11+
replicas: {{ .Values.website.replicas }}
12+
strategy:
13+
type: RollingUpdate
14+
rollingUpdate:
15+
maxSurge: 50%
16+
maxUnavailable: 50%
17+
selector:
18+
matchLabels:
19+
app.kubernetes.io/component: basedosdados-website
20+
app.kubernetes.io/name: {{ .Values.website.name }}
21+
minReadySeconds: 5
22+
template:
23+
metadata:
24+
labels:
25+
app.kubernetes.io/component: basedosdados-website
26+
app.kubernetes.io/name: {{ .Values.website.name }}
27+
annotations:
28+
rollme: {{ randAlphaNum 5 | quote }}
29+
spec:
30+
containers:
31+
- name: basedosdados-website
32+
image: "{{ .Values.website.image.name }}:{{ .Values.website.image.tag }}"
33+
imagePullPolicy: {{ .Values.website.image.pullPolicy }}
34+
ports:
35+
- name: http
36+
containerPort: 3000
37+
env:
38+
{{- with .Values.website.env }}
39+
{{- toYaml . | nindent 12 }}
40+
{{- end }}
41+
{{- with .Values.website.envFrom }}
42+
envFrom:
43+
{{- toYaml . | nindent 12 }}
44+
{{- end }}
45+
{{- with .Values.website.resources }}
46+
resources:
47+
{{- toYaml . | nindent 12 }}
48+
{{- end }}
49+
readinessProbe:
50+
httpGet:
51+
path: /
52+
port: 3000
53+
initialDelaySeconds: 5
54+
periodSeconds: 10
55+
restartPolicy: Always
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{{- if .Values.website.ingress.enabled }}
2+
apiVersion: networking.k8s.io/v1
3+
kind: Ingress
4+
metadata:
5+
name: {{ .Values.website.name }}-ingress
6+
labels:
7+
app.kubernetes.io/component: basedosdados-website
8+
app.kubernetes.io/name: {{ .Values.website.name }}
9+
annotations:
10+
{{- toYaml .Values.website.ingress.annotations | nindent 4 }}
11+
spec:
12+
rules:
13+
- host: {{ .Values.website.ingress.host | quote }}
14+
http:
15+
paths:
16+
- path: /
17+
pathType: Prefix
18+
backend:
19+
service:
20+
name: "{{ .Values.website.name }}-service"
21+
port:
22+
number: 80
23+
{{- with .Values.website.ingress.tls }}
24+
tls:
25+
{{- toYaml . | nindent 4 }}
26+
{{- end }}
27+
{{- end }}

0 commit comments

Comments
 (0)