Skip to content

Commit

Permalink
chore: add garden.io
Browse files Browse the repository at this point in the history
to make it much more easy to start with local development in an kubernetes cluster environment which is a large shift left and improves developer expirience

Signed-off-by: Manuel Ruck <[email protected]>
  • Loading branch information
Manuel Ruck authored and ManAnRuck committed May 8, 2024
1 parent 681c005 commit bc0553d
Show file tree
Hide file tree
Showing 93 changed files with 1,851 additions and 234 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ docker_volumes
.turbo
.github
build
dist
dist
manifests
.garden
16 changes: 16 additions & 0 deletions .gardenignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.log
/data/
.vs
node_modules
.github/workflows/*.env
infra/*.yaml
configuration/*
!configuration/*.example
docker_volumes/*/*
!/**/.gitkeep
/services/cron-jobs/push-send-queued/.env
.turbo
out
build
/.env
manifests
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ docker_volumes/*/*
.turbo
out
build
/.env
/.env
.garden
4 changes: 3 additions & 1 deletion bundestag.io/admin/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ logs
.env*
.next
*.log
.turbo
.turbo
manifests
.garden
41 changes: 41 additions & 0 deletions bundestag.io/admin/garden.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
kind: Build
name: admin
description: Admin
type: container
source:
path: ../../
include:
- ./**/*
- ./infra/Dockerfile.service
spec:
dockerfile: ./infra/Dockerfile.service
buildArgs:
NODE_VERSION: 18.18.2
SERVICE: bundestag.io-admin
SERVICE_PATH: bundestag.io/admin

---
kind: Deploy
name: admin
type: kubernetes
description: Deploy the Admin
dependencies: [build.admin, deploy.bundestag-io-api]

spec:
files: [./manifests/*] # <--- Tell Garden what manifests to use

defaultTarget: # <--- This tells Garden what "target" to use for logs, code syncing and more
kind: Deployment
name: admin

# Patch the K8s manifests for the api service so that we can set the correct image
patchResources:
- name: admin
kind: Deployment
patch:
spec:
template:
spec:
containers:
- name: admin
image: ${actions.build.admin.outputs.deploymentImageId} # <--- Reference the output from the Build action
34 changes: 34 additions & 0 deletions bundestag.io/admin/manifests/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: admin
labels:
app: admin
spec:
replicas: 1
selector:
matchLabels:
app: admin
template:
metadata:
labels:
app: admin
spec:
containers:
- name: admin
image: democracy/bundestag.io-admin:3.2.0
imagePullPolicy: IfNotPresent
env:
- name: PORT
value: '4003'
ports:
- containerPort: 4003
name: http
protocol: TCP
resources:
limits:
cpu: '1'
memory: 1Gi
requests:
cpu: 10m
memory: 90Mi
19 changes: 19 additions & 0 deletions bundestag.io/admin/manifests/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: admin
labels:
app: admin
spec:
ingressClassName: nginx
rules:
- host: 'admin.${var.hostname}'
http:
paths:
- backend:
service:
name: admin
port:
number: 80
path: /
pathType: Prefix
15 changes: 15 additions & 0 deletions bundestag.io/admin/manifests/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: admin
name: admin
spec:
type: ClusterIP
ports:
- name: http
port: 80
protocol: TCP
targetPort: 4003
selector:
app: admin
3 changes: 3 additions & 0 deletions bundestag.io/api/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ logs
build
*.log
docker-compose*
manifests
.garden
.turbo
51 changes: 51 additions & 0 deletions bundestag.io/api/garden.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
kind: Build
name: bundestag-io-api
description: Bundestag.io API
type: container
source:
path: ../../
include:
- ./**/*
- ./infra/Dockerfile.service
spec:
dockerfile: ./infra/Dockerfile.service
targetStage:
$if: ${this.mode == "sync"}
$then: dev
$else: runner
buildArgs:
NODE_VERSION: 18.18.2
SERVICE: bundestag.io
SERVICE_PATH: bundestag.io/api

---
kind: Deploy
name: bundestag-io-api
type: kubernetes
description: Deploy the bundestag.io API
dependencies: [build.bundestag-io-api, deploy.mongo]

spec:
files: [./manifests/*] # <--- Tell Garden what manifests to use

defaultTarget: # <--- This tells Garden what "target" to use for logs, code syncing and more
kind: Deployment
name: bundestag-io-api

sync:
paths:
- containerPath: /app/bundestag.io/api/src
sourcePath: src
mode: one-way

# Patch the K8s manifests for the api service so that we can set the correct image
patchResources:
- name: bundestag-io-api
kind: Deployment
patch:
spec:
template:
spec:
containers:
- name: bundestag-io-api
image: ${actions.build.bundestag-io-api.outputs.deploymentImageId} # <--- Reference the output from the Build action
36 changes: 36 additions & 0 deletions bundestag.io/api/manifests/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: bundestag-io-api
labels:
app: bundestag-io-api
spec:
replicas: 1
selector:
matchLabels:
app: bundestag-io-api
template:
metadata:
labels:
app: bundestag-io-api
spec:
containers:
- name: bundestag-io-api
image: democracy/bundestag.io:0.1.58
imagePullPolicy: IfNotPresent
env:
- name: PORT
value: '4000'
- name: DB_URL
value: mongodb://democracy-mongo:27017/bundestagio
ports:
- containerPort: 4000
name: http
protocol: TCP
resources:
limits:
cpu: '1'
memory: 1Gi
requests:
cpu: 10m
memory: 90Mi
19 changes: 19 additions & 0 deletions bundestag.io/api/manifests/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: bundestag-io-api
labels:
app: bundestag-io-api
spec:
ingressClassName: nginx
rules:
- host: 'bundestag-io-api.${var.hostname}'
http:
paths:
- backend:
service:
name: bundestag-io-api
port:
number: 80
path: /
pathType: Prefix
15 changes: 15 additions & 0 deletions bundestag.io/api/manifests/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: bundestag-io-api
name: bundestag-io-api
spec:
type: ClusterIP
ports:
- name: http
port: 80
protocol: TCP
targetPort: 4000
selector:
app: bundestag-io-api
5 changes: 3 additions & 2 deletions bundestag.io/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"build": "tsc",
"prebuild": "pnpm run generate",
"start": "node build/index.js",
"dev": "ts-node-dev --watch=resolvers,schemas --respawn src/index.ts",
"dev": "tsx watch src/index.ts",
"predev": "pnpm run generate",
"lint": "pnpm lint:ts && pnpm lint:exports",
"lint:es": "eslint src --ext .js,.jsx,.ts,.tsx",
"lint:ts": "tsc --noEmit",
Expand Down Expand Up @@ -50,8 +51,8 @@
"eslint-plugin-prettier": "5.0.1",
"jest": "29.7.0",
"prettier": "3.0.3",
"ts-node-dev": "2.0.0",
"ts-unused-exports": "10.0.1",
"tsx": "^4.8.2",
"typescript": "5.2.2"
}
}
8 changes: 3 additions & 5 deletions infra/Dockerfile.service
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
ARG NODE_VERSION

FROM node:${NODE_VERSION}-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
ARG SERVICE
ENV SERVICE ${SERVICE}
ARG SERVICE_PATH
ENV SERVICE_PATH ${SERVICE_PATH}
RUN corepack enable
RUN pnpm install turbo --global

FROM base AS builder
RUN apk add --no-cache libc6-compat
Expand All @@ -17,7 +14,7 @@ RUN apk update
WORKDIR /app

COPY . .
RUN turbo prune --scope=$SERVICE --docker
RUN pnpm dlx turbo prune --scope=$SERVICE --docker
# FIX ERROR: failed to solve: cannot copy to non-directory: …/app/services/qr-code-handler/node_modules/tsup-config
RUN find . -name "node_modules" -type d -exec rm -rf {} +

Expand Down Expand Up @@ -51,6 +48,7 @@ WORKDIR /app
# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 runuser
RUN corepack enable

COPY --from=installer_prod /app .

Expand All @@ -60,4 +58,4 @@ COPY --from=installer_prod /app .

# USER runuser

CMD cd $SERVICE_PATH && pnpm start
CMD cd $SERVICE_PATH && npm start
6 changes: 6 additions & 0 deletions infra/democracy-api/garden.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Deploy
name: democracy-api
type: kubernetes
spec:
files:
- ./manifests/*
14 changes: 14 additions & 0 deletions infra/democracy-api/manifests/ConfigMap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

apiVersion: v1
kind: ConfigMap
metadata:
name: democracy-api-config
data:
BUNDESTAGIO_SERVER_URL: http://bundestagio-srv:3100/
DB_URL: mongodb://democracy-mongo:27017/democracy
DEBUG: "true"
GRAPHIQL: "true"
NODE_ENV: development
SMS_SIMULATE: "true"
SMS_VERIFICATION: "false"
STAGE: internal
Loading

0 comments on commit bc0553d

Please sign in to comment.