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

384 add kubernetes locally #385

Merged
merged 16 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ ARG MIGRATE_VERSION=4.15.2
ARG WATCH_VERSION=8.4.0
ARG CARGO_LLVM_COV_VERSION=0.5.36

RUN go install github.com/99designs/gqlgen@latest && \
go install github.com/golang/mock/mockgen@latest && \
RUN wget -O- https://carvel.dev/install.sh > install.sh && \
sudo bash install.sh && \
rm install.sh && \
go install github.com/mikefarah/yq/v4@latest && \
chmod -R a+w /go/pkg && \
curl -fSsl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions client/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

set -e

# recursively replace all default GRAPHQL_URI Dockerfile
# assignments in the /usr/share/nginx/html directory with
# the value of the GRAPHQL_URI environment variable
find /usr/share/nginx/html -type f -exec sed -i "s/aHR0cDovL2xvY2FsaG9zdDoxMDAwMAo=/$GRAPHQL_URI/g" {} \;
exec "$@"
13 changes: 13 additions & 0 deletions client/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ HOST=http://$(LOCAL_ADDRESS)
GRAPHQL_URI=$(HOST):$(shell yq '.services.graphql.env_var.set.GRAPHQL_PORT.default' $(PROJECT_CONF))
B64_GRAPHQL_URI=$(shell if [ `uname -s` == 'Darwin' ]; then printf $(GRAPHQL_URI) | base64; else printf $(GRAPHQL_URI) | base64 -w 0; fi)
NOHUP_LOG=$(RELATIVE_PROJECT_ROOT_PATH)/$(shell yq '.env_var.set.NOHUP_LOG.default' $(PROJECT_CONF))
GITHUB_ORG=$(shell yq '.[".github"].env_var.set.GITHUB_ORG.default' $(PROJECT_CONF))
GITHUB_REPO_NAME=$(shell yq '.[".github"].env_var.set.GITHUB_REPO_NAME.default' $(PROJECT_CONF))
GITHUB_REGISTRY=$(shell yq '.[".github"].workflows.env_var.set.GITHUB_REGISTRY.default' $(PROJECT_CONF))
CONTAINER_REGISTRY=$(GITHUB_REGISTRY)/$(GITHUB_ORG)/$(GITHUB_REPO_NAME)/$(APP_NAME)

dev:
@$(MAKE) start
Expand Down Expand Up @@ -159,6 +163,15 @@ up:
down:
docker compose -f ../docker/compose.yaml down

###################### k8s ######################

build-k8s:
cd $(RELATIVE_PROJECT_ROOT_PATH); \
docker build -f ./docker/client.Dockerfile -t $(CONTAINER_REGISTRY):latest .

push-k8s:
docker push $(CONTAINER_REGISTRY):latest

###################### utils ######################

date:
Expand Down
3 changes: 3 additions & 0 deletions docker/.gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ FROM gitpod/workspace-full:latest
ARG TF_VERSION=1.2.7

RUN bash -lc "rustup default stable" && \
wget -O- https://carvel.dev/install.sh > install.sh && \
sudo bash install.sh && \
rm install.sh && \
go install github.com/mikefarah/yq/v4@latest && \
sudo apt-get install bc -y && \
sudo apt-get clean && \
Expand Down
8 changes: 6 additions & 2 deletions docker/client.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM mxfactorial/client-base:v1 as builder1
FROM mxfactorial/client-base:v1 AS builder1

ARG GRAPHQL_URI
ARG GRAPHQL_URI=aHR0cDovL2xvY2FsaG9zdDoxMDAwMAo=

COPY client .

Expand All @@ -12,6 +12,10 @@ FROM nginx:latest

EXPOSE 80

COPY --from=builder1 /app/entrypoint.sh /docker-entrypoint.d/40-set-env-vars.sh

RUN chmod +x /docker-entrypoint.d/40-set-env-vars.sh

COPY --from=builder1 /app/.svelte-kit/output/prerendered/pages/index.html /usr/share/nginx/html

COPY --from=builder1 /app/.svelte-kit/output/client/ /usr/share/nginx/html
Expand Down
3 changes: 1 addition & 2 deletions docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ services:
REDIS_USERNAME: default
REDIS_PASSWORD: test
MEASURE_PORT: 10010
READINESS_CHECK_PATH: "/healthz"
depends_on:
redis:
condition: service_healthy
Expand All @@ -256,7 +257,5 @@ services:
build:
context: ../
dockerfile: ./docker/client.Dockerfile
args:
- GRAPHQL_URI=${GRAPHQL_URI:-aHR0cDovL2xvY2FsaG9zdDoxMDAwMAo=}
ports:
- "10009:80"
76 changes: 76 additions & 0 deletions k8s/balance-by-account.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#@ load("@ytt:data", "data")
#@ app = "balance-by-account"
#@ app_port = data.values.BALANCE_BY_ACCOUNT_PORT
#@ image_version = "latest"
#@ image = "{}/{}/{}/{}:{}".format(data.values.GITHUB_REGISTRY, data.values.GITHUB_ORG, data.values.GITHUB_REPO_NAME, app, image_version)
apiVersion: apps/v1
kind: Deployment
metadata:
name: #@ app + "-deployment"
labels:
app: #@ app
spec:
replicas: 1
selector:
matchLabels:
app: #@ app
template:
metadata:
labels:
app: #@ app
spec:
containers:
- name: #@ app
image: #@ image
ports:
- containerPort: #@ app_port
env:
- name: PGDATABASE
value: #@ data.values.PGDATABASE
- name: PGUSER
value: #@ data.values.PGUSER
- name: PGPASSWORD
value: #@ data.values.PGPASSWORD
- name: PGHOST
value: postgres
- name: PGPORT
value: #@ "{}".format(data.values.PGPORT)
- name: PG_MAX_CONNECTIONS
value: "20"
- name: PG_IDLE_TIMEOUT
value: "10000"
- name: PG_CONN_TIMEOUT
value: "500"
- name: READINESS_CHECK_PATH
value: #@ data.values.READINESS_CHECK_PATH
- name: #@ app.upper().replace("-", "_") + "_PORT"
value: #@ "{}".format(app_port)
livenessProbe:
httpGet:
path: #@ data.values.READINESS_CHECK_PATH
port: #@ app_port
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 5
readinessProbe:
httpGet:
path: #@ data.values.READINESS_CHECK_PATH
port: #@ app_port
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 5
---
apiVersion: v1
kind: Service
metadata:
name: #@ app
spec:
selector:
app: #@ app
ports:
- protocol: TCP
port: #@ app_port
targetPort: #@ app_port
type: ClusterIP
52 changes: 52 additions & 0 deletions k8s/client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#@ load("@ytt:data", "data")
#@ app = "client"
#@ app_port = 80
#@ image_version = "latest"
#@ image = "{}/{}/{}/{}:{}".format(data.values.GITHUB_REGISTRY, data.values.GITHUB_ORG, data.values.GITHUB_REPO_NAME, app, image_version)
apiVersion: apps/v1
kind: Deployment
metadata:
name: #@ app + "-deployment"
labels:
app: #@ app
spec:
replicas: 1
selector:
matchLabels:
app: #@ app
template:
metadata:
labels:
app: #@ app
spec:
containers:
- name: #@ app
image: #@ image
ports:
- containerPort: #@ app_port
env:
- name: GRAPHQL_URI
valueFrom:
configMapKeyRef:
name: client-config
key: GRAPHQL_URI
---
apiVersion: v1
kind: Service
metadata:
name: #@ app
spec:
selector:
app: #@ app
ports:
- protocol: TCP
port: #@ app_port
targetPort: #@ app_port
type: ClusterIP
---
apiVersion: v1
kind: ConfigMap
metadata:
name: client-config
data:
GRAPHQL_URI: aHR0cDovL2xvY2FsaG9zdDozMDAwMAo=
54 changes: 54 additions & 0 deletions k8s/event.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#@ load("@ytt:data", "data")
#@ app = "event"
#@ image_version = "latest"
#@ image = "{}/{}/{}/{}:{}".format(data.values.GITHUB_REGISTRY, data.values.GITHUB_ORG, data.values.GITHUB_REPO_NAME, app, image_version)
apiVersion: apps/v1
kind: Deployment
metadata:
name: #@ app + "-deployment"
labels:
app: #@ app
spec:
replicas: 1
selector:
matchLabels:
app: #@ app
template:
metadata:
labels:
app: #@ app
spec:
containers:
- name: #@ app
image: #@ image
env:
- name: PGDATABASE
value: #@ data.values.PGDATABASE
- name: PGUSER
value: #@ data.values.PGUSER
- name: PGPASSWORD
value: #@ data.values.PGPASSWORD
- name: PGHOST
value: postgres
- name: PGPORT
value: #@ "{}".format(data.values.PGPORT)
- name: REDIS_DB
value: #@ "{}".format(data.values.REDIS_DB)
- name: REDIS_HOST
#! todo: remove hardcode
value: redis
- name: REDIS_PORT
value: #@ "{}".format(data.values.REDIS_PORT)
- name: REDIS_USERNAME
value: #@ data.values.REDIS_USERNAME
- name: REDIS_PASSWORD
value: #@ data.values.REDIS_PASSWORD
livenessProbe:
exec:
command:
- /bin/sh
- -c
- echo
- -n
initialDelaySeconds: 5
periodSeconds: 5
78 changes: 78 additions & 0 deletions k8s/graphql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#@ load("@ytt:data", "data")
#@ app = "graphql"
#@ app_port = data.values.GRAPHQL_PORT
#@ image_version = "latest"
#@ image = "{}/{}/{}/{}:{}".format(data.values.GITHUB_REGISTRY, data.values.GITHUB_ORG, data.values.GITHUB_REPO_NAME, app, image_version)
apiVersion: apps/v1
kind: Deployment
metadata:
name: #@ app + "-deployment"
labels:
app: #@ app
spec:
replicas: 1
selector:
matchLabels:
app: #@ app
template:
metadata:
labels:
app: #@ app
spec:
containers:
- name: #@ app
image: #@ image
ports:
- containerPort: #@ app_port
env:
- name: RULE_URL
value: #@ "http://rule:" + "{}".format(data.values.RULE_PORT)
- name: REQUEST_CREATE_URL
value: #@ "http://request-create:" + "{}".format(data.values.REQUEST_CREATE_PORT)
- name: REQUEST_APPROVE_URL
value: #@ "http://request-approve:" + "{}".format(data.values.REQUEST_APPROVE_PORT)
- name: REQUEST_BY_ID_URL
value: #@ "http://request-by-id:" + "{}".format(data.values.REQUEST_BY_ID_PORT)
- name: REQUESTS_BY_ACCOUNT_URL
value: #@ "http://requests-by-account:" + "{}".format(data.values.REQUESTS_BY_ACCOUNT_PORT)
- name: TRANSACTIONS_BY_ACCOUNT_URL
value: #@ "http://transactions-by-account:" + "{}".format(data.values.TRANSACTIONS_BY_ACCOUNT_PORT)
- name: TRANSACTION_BY_ID_URL
value: #@ "http://transaction-by-id:" + "{}".format(data.values.TRANSACTION_BY_ID_PORT)
- name: BALANCE_BY_ACCOUNT_URL
value: #@ "http://balance-by-account:" + "{}".format(data.values.BALANCE_BY_ACCOUNT_PORT)
- name: READINESS_CHECK_PATH
value: #@ data.values.READINESS_CHECK_PATH
- name: RUST_LOG
value: "info"
- name: GRAPHQL_PORT
value: #@ "{}".format(app_port)
livenessProbe:
httpGet:
path: #@ data.values.READINESS_CHECK_PATH
port: #@ app_port
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 5
readinessProbe:
httpGet:
path: #@ data.values.READINESS_CHECK_PATH
port: #@ app_port
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 5
---
apiVersion: v1
kind: Service
metadata:
name: #@ app
spec:
selector:
app: #@ app
ports:
- protocol: TCP
port: #@ app_port
targetPort: #@ app_port
type: ClusterIP
2 changes: 2 additions & 0 deletions k8s/local/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RELATIVE_PROJECT_ROOT_PATH=$(shell REL_PATH="."; while [ $$(ls "$$REL_PATH" | grep project.yaml | wc -l | xargs) -eq 0 ]; do REL_PATH="$$REL_PATH./.."; done; printf '%s' "$$REL_PATH")
include $(RELATIVE_PROJECT_ROOT_PATH)/make/shared.mk
Loading