Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lostbean committed Jun 27, 2024
0 parents commit 80e4be1
Show file tree
Hide file tree
Showing 89 changed files with 9,937 additions and 0 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Our desired pipeline using only a Nix shell environment
name: Check and build Kardinal

on:
push:
branches:
- main
tags:
- "v*.*.*"
pull_request:
branches:
- main

jobs:
check_nix:
name: Basic Check
runs-on: ubuntu-22.04
steps:
- name: git checkout
uses: actions/checkout@v3

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main

- name: Magic cache
uses: DeterminateSystems/magic-nix-cache-action@main

- name: Check Nixpkgs inputs
uses: DeterminateSystems/flake-checker-action@main
with:
fail-mode: true

# Nix-specific logic begins here
- name: Nix Check
run: |
nix flake check
- name: Check Go formatting
run: |
nix develop --command test -z $(gofmt -l .)
build_and_test_nix:
name: Test and build
needs: check_nix
runs-on: ubuntu-22.04
steps:
- name: git checkout
uses: actions/checkout@v3

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main

- name: Magic cache
uses: DeterminateSystems/magic-nix-cache-action@main

- name: Build Kardinal Manager images
run: |
nix build ./#containers.x86_64-linux.kardinal-manager.arm64 --no-link --print-out-paths
nix build ./#containers.x86_64-linux.kardinal-manager.amd64 --no-link --print-out-paths
88 changes: 88 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
.direnv
### VisualStudioCode template
.vscode/*


# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea
.idea/*

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/



### Go template
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

### macOS template
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


# local k8s files
.minikube/

# Python
.venv

# local build folders
istio-1.22.0/
kontrol-service/Run_kontrol_service
87 changes: 87 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Kardinal

## Developing instructions

1. Enter the dev shell and start the local cluster:

```bash
nix develop
```

2. You're also likely to use a local k8s, in this case minikube is available to use:

```bash
kubectl config set-context minikube
minikube start --driver=docker --cpus=10 --memory 8192 --disk-size 32g
minikube addons enable ingress
minikube addons enable metrics-server
istioctl install --set profile=demo -y
minikube dashboard
```

On a second terminal, start the tunnel:

```bash
minikube tunnel
```

## Deploying Kardinal Manager to local cluster

You can use tilt deploy and keeping the image hot-reloading:

```bash
tilt up
```

Or manually build it:

```bash
# First set the docker context to minikube
eval $(minikube docker-env)
docker load < $(nix build ./#kardinal-manager-container --no-link --print-out-paths)
kubectl apply -f kardinal-manager/deployment
```
## Deploying Redis Overlay Service to local cluster
Building and loading image into minikube:
```bash
# First set the docker context to minikube
eval $(minikube docker-env)
docker load < $(nix build ./#redis-proxy-overlay-container --no-link --print-out-paths)
```
To build and run the service directly:
```bash
nix run ./#redis-proxy-overlay
```
## Publishing multi-arch images
To publish multi-arch images, you can use the following command:
```bash
$(nix build .#publish-<SERVICE_NAME>-container --no-link --print-out-paths)/bin/push
# For instance, to publish the redis proxy overlay image:
$(nix build .#publish-redis-proxy-overlay-container --no-link --print-out-paths)/bin/push
```
## Running Kardinal CLI
To build and run the service directly:
```bash
nix run ./#kardinal-cli
```
### Regenerate gomod2nix.toml
You will need to do this every time a `go.mod` file is edited
```bash
nix develop
gomod2nix generate
```
39 changes: 39 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

# Custom build tool for nix flakes
def build_flake_image(ref, path = "", output = "", resultfile = "result", deps = []):
build_cmd = "nix build {path}#{output} --refresh --no-link --print-out-paths".format(
path = path,
output = output
)
commands = [
"RESULT_IMAGE=$({cmd})".format(cmd = build_cmd),
"docker image load -i ${RESULT_IMAGE}",
'IMG_NAME="$(tar -Oxf $RESULT_IMAGE manifest.json | jq -r ".[0].RepoTags[0]")"'.format(ref = ref),
"docker tag ${IMG_NAME} ${EXPECTED_REF}"
]
custom_build(
ref,
command = [
"nix-shell",
"--packages",
"coreutils",
"gnutar",
"jq",
"--run",
";\n".join(commands),
],
deps = deps,
)


image_name = "kurtosistech/kardinal-manager"

build_flake_image(image_name , ".", "kardinal-manager-container", deps=["./kardinal-manager"])

yaml_dir = "./kardinal-manager/deployment"
k8s_yaml(yaml=(yaml_dir + "/k8s.yaml"))

if k8s_context:
k8s_context(k8s_context)


20 changes: 20 additions & 0 deletions examples/voting-app/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3"
services:
azure-vote-back:
image: bitnami/redis:6.0.8
container_name: redis-prod
environment:
ALLOW_EMPTY_PASSWORD: "yes"
REDIS_PORT_NUMBER: "6379"
ports:
- "6379:6379"

azure-vote-front:
image: voting-app-ui
container_name: voting-app-ui
environment:
REDIS: redis-prod
ports:
- "80:80"
depends_on:
- azure-vote-back
Loading

0 comments on commit 80e4be1

Please sign in to comment.