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

Kubernetes for local dev #118

Merged
merged 85 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
74049bf
Get volumes working in k3s
rmunn Jun 13, 2023
7174aad
Remove namespace from secrets for now
rmunn Jun 13, 2023
dd62dc6
Fix "invalid base64" error in secrets.yaml
rmunn Jun 13, 2023
e37a7b3
Populate Kubernetes dev secrets
rmunn Jun 13, 2023
34a824b
First pass at a Kubernetes setup for local dev
rmunn Jun 14, 2023
7adca7c
Add "localdev" task to get git container running
rmunn Jun 14, 2023
d8ec41a
Task for SSH setup is now working
rmunn Jun 14, 2023
c24372a
Use Skaffold instead of custom-built solution
rmunn Jun 15, 2023
e9d475c
Increase memory limits so Hasura isn't OOM killed
rmunn Jun 15, 2023
2bb077e
Fix CORS error in local k8s dev
rmunn Jun 15, 2023
08f5f88
Add dev.languagedepot.org hostname for local dev
rmunn Jun 15, 2023
351cb12
Restore the k8s "languagedepot" namespace
rmunn Jun 16, 2023
37032f5
Fix login process - use Svelte-Kit load properly
rmunn Jun 19, 2023
9d3eb39
Fix SHA1 hashing during SSR
rmunn Jun 19, 2023
c87d0a3
Add k8s deployment setup for docker-desktop
rmunn Jun 19, 2023
f28baa0
Work around issue with recent Node Docker images
rmunn Jun 19, 2023
f83ee84
Node 18 doesn't have webcrypto module
rmunn Jun 19, 2023
64d98e8
Turn off https during local dev
rmunn Jun 19, 2023
a8d5ad6
Fix BACKEND_HOST env var
rmunn Jun 19, 2023
b1c9efb
First attempt: speeding up skaffold dev reloading
rmunn Jun 20, 2023
ee8ebc6
More attempts at speeding up skaffold dev
rmunn Jun 21, 2023
2775ff8
Attempt to split Hasura into separate deployment
rmunn Jun 23, 2023
e03e891
Merge branch 'develop' into chore/k8s-for-local-dev
rmunn Jun 23, 2023
2187c87
Pin Node version to 20.2 for now
rmunn Jun 26, 2023
8d99fb3
Have hasura pod wait for backend to be healthy
rmunn Jun 26, 2023
d1767ef
Rename hg-repos-pvc.yaml to just pvc.yaml
rmunn Jun 26, 2023
d94f200
Move db PVC into pvc.yaml and create skaffold hook
rmunn Jun 26, 2023
69fa1db
Add namespace to pvc.yaml
rmunn Jun 26, 2023
de86efb
Attempt to get correct ports for local UI dev
rmunn Jun 26, 2023
2564637
Increase memory for dev containers
rmunn Jun 26, 2023
52574d6
Greatly increase memory request for dotnet watch
rmunn Jun 26, 2023
89c73c2
Avoid merge conflict
rmunn Jun 26, 2023
172c7c2
Pre-populate Sena-3 repo in k8s deployment
rmunn Jun 27, 2023
1942832
Specify Mercurial Docker image more precisely
rmunn Jun 27, 2023
e146b51
Deploy Hasura metadata as part of container image
rmunn Jun 27, 2023
28bc26c
Remove db deployment from skaffold dev
rmunn Jun 27, 2023
6c0ea9b
Hasura no longer needs to wait on backend
rmunn Jun 27, 2023
78ada23
Attempt to use Kustomize for dev mode
rmunn Jun 27, 2023
67b1c6c
Split UI out into separate pod
rmunn Jun 28, 2023
90b5550
change schema file generation responsibility from vite to dotnet
hahn-kev Jun 28, 2023
aee8942
Fix dotnet generation of GraphQL files
rmunn Jun 28, 2023
aa3f735
Fix SVG train-track heights not adjusting
rmunn Jun 28, 2023
4cf5faa
Update Database Startup procedures
hahn-kev Jun 29, 2023
ced78b8
Add migrate-db task to Taskfile
hahn-kev Jun 29, 2023
212ad16
Move Hasura container back inside lexbox pod
rmunn Jun 29, 2023
60ac444
Add initContainer for DB migrations in lexbox pod
rmunn Jun 29, 2023
0547001
Speed up Docker builds by caching packages
rmunn Jun 30, 2023
eecf9af
Attempt to cache nuget packages in k8s dev
rmunn Jun 30, 2023
f7a88cb
Cache NuGet packages in Docker image instead
rmunn Jun 30, 2023
f09a80f
Reorder skaffold.yaml to be slightly more robust
rmunn Jun 30, 2023
95c1bae
Put backend before frontend in skaffold.yaml
rmunn Jun 30, 2023
bc031c6
Put staging deployment back how it was
rmunn Jul 3, 2023
3c70976
Update skaffold to version 2.6.0
rmunn Jul 4, 2023
ac02e28
Remove dev.languageforge.org from staging k8s proxy
rmunn Jul 4, 2023
5737454
Node bug is fixed, revert to current Node version
rmunn Jul 4, 2023
77e0155
Have Vite listen on all interfaces
rmunn Jul 4, 2023
c0f2ad4
Use correct port for ingress-lexbox communication
rmunn Jul 4, 2023
8d9fe0a
Add skaffold profiles for running locally
rmunn Jul 5, 2023
9ca7d76
Add DOTNET_URLS env to lexbox in dev mode
rmunn Jul 5, 2023
bd4e905
Merge branch 'develop' into chore/k8s-for-local-dev
rmunn Jul 5, 2023
9f0a038
Upgrade NuGet packages in Testing.csproj
rmunn Jul 5, 2023
4f19dfb
Merge branch 'develop' into chore/k8s-for-local-dev
rmunn Jul 5, 2023
1859901
only proxy from vite in local dev not in a container. Forward some mi…
hahn-kev Jul 6, 2023
8784cb5
fix goesToErrorPage error
hahn-kev Jul 6, 2023
311ff21
add collector-config.yaml to gitignore
hahn-kev Jul 6, 2023
345cd3c
add missing dockerfile syntax to dev.Dockerfile
hahn-kev Jul 6, 2023
3d51cc4
update minor inconsistencies in readme.
hahn-kev Jul 6, 2023
560bacd
remove Cors bypass on backend
hahn-kev Jul 6, 2023
3a32b67
force skaffold to run on the `docker-desktop` context
hahn-kev Jul 6, 2023
e686f3e
Minor README fix
rmunn Jul 7, 2023
0a5f005
Merge branch 'develop' into chore/k8s-for-local-dev
hahn-kev Jul 17, 2023
2cba39e
revert login without hashed password
hahn-kev Jul 17, 2023
123cd1b
set reasonable default limits on UI deployment
hahn-kev Jul 17, 2023
4d914cf
add kustomization.yaml layers for prod and staging
hahn-kev Jul 17, 2023
50f6279
setup ingress configuration for staging overlay
hahn-kev Jul 17, 2023
7032010
refactor dev overlay secrets into patches
hahn-kev Jul 17, 2023
17775dd
add setup step to create local.env file for dev
hahn-kev Jul 17, 2023
1658b5f
changed imagePullPolicy back to Always for base but IfNotPresent for…
hahn-kev Jul 17, 2023
0979a42
remove hasura from skaffold.yaml
hahn-kev Jul 17, 2023
aa2ed76
fix issue with deployments still trying to reference secrets. Fix mis…
hahn-kev Jul 17, 2023
fcf0d8c
fix password hash for login to wait for the promise to resolve
hahn-kev Jul 18, 2023
56394d4
change dotnet port to 5158 instead of 80 across the board. Expose db …
hahn-kev Jul 18, 2023
b21be5b
Rearrange README a bit, mention extra Windows setup
rmunn Jul 7, 2023
f152551
Revert "Add "localdev" task to get git container running"
rmunn Jul 18, 2023
73901a5
Remove localdev-deployment.yaml
rmunn Jul 18, 2023
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ riderModule.iml
**/MercurialExtensions/
backend/Testing/SyncReverseProxy/TestData.cs
.task
deployment/id_lexbox_k8sdev.pub
deployment/dev/collector-config.yaml
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ You may need to add the following line to your `/etc/hosts` or `C:\Windows\syste
```
127.0.0.1 resumable.localhost
127.0.0.1 hg.localhost
127.0.0.1 dev.languagedepot.org
```

If you want to test out Honeycomb traces, you will need to set the `HONEYCOMB_API_KEY` environment variable in
the `.env` file.
the `deployment/secrets.yaml` file.
You can get the key from [here](https://ui.honeycomb.io/sil-language-forge/environments/test/api_keys)

---
Expand Down
7 changes: 4 additions & 3 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
Expand All @@ -12,17 +13,17 @@ COPY . .
#
# move them into the proper sub folders, based on the name of the project
# RUN for file in $(ls *.csproj); do mkdir -p ${file%.*}/ && mv $file ${file%.*}/; done
RUN dotnet restore "LexBoxApi/LexBoxApi.csproj"
RUN --mount=type=cache,target=/root/.nuget/packages dotnet restore "LexBoxApi/LexBoxApi.csproj"
# COPY . .
# WORKDIR "/LexBoxApi"

ARG APP_VERSION
LABEL version=$APP_VERSION

RUN dotnet build /p:InformationalVersion=$APP_VERSION "/LexBoxApi/LexBoxApi.csproj" -c Release -o /app/build
RUN --mount=type=cache,target=/root/.nuget/packages dotnet build /p:InformationalVersion=$APP_VERSION "/LexBoxApi/LexBoxApi.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish /p:InformationalVersion=$APP_VERSION "/LexBoxApi/LexBoxApi.csproj" -c Release -o /app/publish
RUN --mount=type=cache,target=/root/.nuget/packages dotnet publish /p:InformationalVersion=$APP_VERSION "/LexBoxApi/LexBoxApi.csproj" -c Release -o /app/publish
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this docker file isn't used for local dev does this make any difference?


FROM base AS final
WORKDIR /app
Expand Down
1 change: 1 addition & 0 deletions backend/LexBoxApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

var app = builder.Build();
app.Logger.LogInformation("LexBox-api version: {version}", AppVersionService.Version);
app.UseCors(x => x.AllowAnyOrigin()); // TODO: Allow only specific clients (e.g., frontend)
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.All,
Expand Down
27 changes: 27 additions & 0 deletions backend/LexBoxApi/Services/DevSchemaWriterService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using HotChocolate.Execution;

namespace LexBoxApi.Services;

public class DevSchemaWriterService : IHostedService
{
private readonly RequestExecutorProxy _executorProxy;
private readonly ILogger<DevSchemaWriterService> _logger;
public DevSchemaWriterService(IRequestExecutorResolver executorResolver, ILogger<DevSchemaWriterService> logger)
{
_logger = logger;
_executorProxy = new RequestExecutorProxy(executorResolver, Schema.DefaultName);
}

public async Task StartAsync(CancellationToken cancellationToken)
{
var schema = await _executorProxy.GetSchemaAsync(cancellationToken);
await using var file = File.Open("../../frontend/schema.graphql", FileMode.Create);
await SchemaPrinter.PrintAsync(schema, file, true, cancellationToken);
_logger.LogInformation("Schema written frontend/schema.graphql");
}

public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
9 changes: 9 additions & 0 deletions backend/LexBoxApi/dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
EXPOSE 80
EXPOSE 443
WORKDIR /src/backend
# Copy the main source project files
COPY */*.csproj *.sln ./
# move them into the proper sub folders, based on the name of the project
RUN for file in $(ls *.csproj); do dir=${file%.*} mkdir -p ${file%.*}/ && mv $file ${file%.*}/ && dotnet restore ${file%.*}/${file}; done

COPY . .
WORKDIR /src/backend/LexBoxApi
RUN mkdir /src/frontend
ENV DockerDev=true
CMD dotnet watch run -lp docker --property:InformationalVersion=dockerDev
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
}
},
"LexBoxApi": {
"Url": "https://localhost:7075"
"Url": "http://localhost:5158"
}
}
3 changes: 3 additions & 0 deletions deployment/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
version: '3'

tasks:
db-up:
cmds:
- kubectl apply -f ./base/db-deployment.yaml
lexbox-update:
cmds:
- kubectl apply -f ./lexbox-deployment.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
kind: ConfigMap
metadata:
name: email-config
namespace: languagedepot
data:
email-from: "Value"

Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,16 @@ apiVersion: v1
kind: Service
metadata:
name: db
namespace: languagedepot
labels:
app: db
spec:
type: ClusterIP
clusterIP: None
selector:
app: db

---

# https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: db-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: weekly-snapshots-retain-4 # provided by LTOps
hahn-kev marked this conversation as resolved.
Show resolved Hide resolved
ports:
- port: 5432

---

Expand All @@ -33,6 +21,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: db
namespace: languagedepot
labels:
app: db
spec:
Expand Down Expand Up @@ -87,4 +76,4 @@ spec:
volumes:
- name: data
persistentVolumeClaim:
claimName: db-data
claimName: db-data # established in pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Service
metadata:
name: hg
namespace: languagedepot
labels:
app: hg
spec:
Expand All @@ -25,12 +26,14 @@ apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: hgresumable-cache
namespace: languagedepot
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: weekly-snapshots-retain-4 # provided by LTOps

---

Expand All @@ -39,6 +42,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: hg
namespace: languagedepot
labels:
app: hg
spec:
Expand Down Expand Up @@ -89,10 +93,18 @@ spec:
- name: repos
mountPath: /var/vcs/public

initContainers:
- name: populate-test-repos
image: busybox:1.36.1
command: ['sh', '-c', "if [ ! -d /repos/sena-3 ]; then wget -O sena-3.zip 'https://drive.google.com/uc?export=download&id=1I-hwc0RHoQqW774gbS5qR-GHa1E7BlsS'; unzip -q sena-3.zip -d /repos/; fi"]
volumeMounts:
- name: repos
mountPath: /repos

volumes:
- name: cache
persistentVolumeClaim:
claimName: hgresumable-cache
- name: repos
persistentVolumeClaim:
claimName: hg-repos # established in hg-repos-pvc.yaml
claimName: hg-repos # established in pvc.yaml
13 changes: 13 additions & 0 deletions deployment/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: languagedepot

resources:
- config-map.yaml
- secrets.yaml
hahn-kev marked this conversation as resolved.
Show resolved Hide resolved
- pvc.yaml
- db-deployment.yaml
- hg-deployment.yaml
- lexbox-deployment.yaml
- ui-deployment.yaml
- proxy-deployment.yaml
Loading