Skip to content

Commit

Permalink
Rename k8x to c8x with all variants
Browse files Browse the repository at this point in the history
  • Loading branch information
nhh committed Jan 25, 2025
1 parent f31734b commit a566a0a
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 117 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ jobs:
with:
go-version: '1.23'
- name: Build
run: go build -o k8x-linux-x86_64 .
run: go build -o c8x-linux-x86_64 .
- name: Upload Go test results
uses: actions/upload-artifact@v4
with:
retention-days: 7
name: k8x-linux-x86_64
path: ./k8x-linux-x86_64
name: c8x-linux-x86_64
path: ./c8x-linux-x86_64
build-macos:
if: startsWith(github.ref, 'refs/tags/')
runs-on: macos-latest
Expand All @@ -36,13 +36,13 @@ jobs:
with:
go-version: '1.23'
- name: Build
run: go build -o k8x-darwin-x86_64 .
run: go build -o c8x-darwin-x86_64 .
- name: Upload Go test results
uses: actions/upload-artifact@v4
with:
retention-days: 7
name: k8x-darwin-x86_64
path: ./k8x-darwin-x86_64
name: c8x-darwin-x86_64
path: ./c8x-darwin-x86_64
build-windows:
if: startsWith(github.ref, 'refs/tags/')
runs-on: windows-latest
Expand All @@ -53,13 +53,13 @@ jobs:
with:
go-version: '1.23'
- name: Build
run: go build -o k8x-windows-x86_64.exe .
run: go build -o c8x-windows-x86_64.exe .
- name: Upload Go test results
uses: actions/upload-artifact@v4
with:
retention-days: 7
name: k8x-windows-x86_64.exe
path: ./k8x-windows-x86_64.exe
name: c8x-windows-x86_64.exe
path: ./c8x-windows-x86_64.exe
release:
if: startsWith(github.ref, 'refs/tags/')
permissions:
Expand All @@ -76,4 +76,4 @@ jobs:
- name: Create github release
uses: ncipollo/release-action@v1
with:
artifacts: "./*/k8x-*"
artifacts: "./*/c8x-*"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ c8x.exe
c8x
*.tsx
.idea/
k8x
c8x
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Deploy and manage typesafe apps to kubernetes
## Features:

- .env integration
- K8X_MY_VARIABLE
- C8X_MY_VARIABLE
- Automatic namespace handling
- Auto create/upgrade namespaces
- Quickstart
Expand Down
6 changes: 3 additions & 3 deletions cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/glamour"
"github.com/charmbracelet/lipgloss"
"github.com/kubernetix/k8x/v1/internal/k8s"
"github.com/kubernetix/k8x/v1/internal/ts"
"github.com/kubernetix/c8x/internal/k8s"
"github.com/kubernetix/c8x/internal/ts"
"github.com/spf13/cobra"
"os"
"strings"
Expand Down Expand Up @@ -108,7 +108,7 @@ func (m model) View() string {
}

func (m model) headerView() string {
title := titleStyle.Render("k8x render view")
title := titleStyle.Render("c8x render view")
line := strings.Repeat("─", max(0, m.viewport.Width-lipgloss.Width(title)))
return lipgloss.JoinHorizontal(lipgloss.Center, title, line)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/install.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cmd

import (
"github.com/kubernetix/k8x/v1/internal/k8s"
"github.com/kubernetix/k8x/v1/internal/ts"
"github.com/kubernetix/c8x/internal/k8s"
"github.com/kubernetix/c8x/internal/ts"
"github.com/spf13/cobra"
"os"
)
Expand All @@ -16,7 +16,7 @@ func init() {

var install = &cobra.Command{
Use: "install",
Short: "Install a chart.tsx file into your k8s cluster",
Short: "Install a chart file into your k8s cluster",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
_ = cmd.Help()
Expand Down
51 changes: 24 additions & 27 deletions cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,42 @@ func init() {
rootCmd.AddCommand(newCmd)
}

var chartTsx = `/// <reference types="@kubernetix/types" />
var chartTsx = `
import {Chart} from "c8x"
export default () => (
<chart name={""} version={""} >
</chart>
)
// TODO: fix the compiler issues to have a working deployment
export default (): Chart => {}
`

var packageJson = `{
"name": "{{.packageName}}",
"private": true,
"version": "0.0.0",
"version": "0.0.1",
"dependencies": {
"@kubernetix/types": "0.0.1"
"c8x": "0.0.1"
},
"chart": {
"appVersion": "1.0.0",
"kubeVersion": "1.31",
"type": "application",
"keywords": [
"cms",
"wordpress",
"author"
],
"home": "https://github.com/kubernetix/charts/wordpress",
"maintainers": [
"Niklas Hanft"
],
"icon": null,
"deprecated": false,
"annotations": []
}
"appVersion": "1.0.0",
"kubeVersion": "1.31",
"type": "application",
"keywords": [
"cms",
"wordpress",
"author"
],
"home": "https://github.com/kubernetix/charts/wordpress",
"maintainers": [
"Niklas Hanft"
],
"icon": null,
"deprecated": false,
"annotations": []
}
`

var newCmd = &cobra.Command{
Use: "new",
Short: "Initialize a k8x chart. (chart.tsx, package.json)",
Example: "k8x new wordpress",
Use: "init",
Short: "Initialize a c8x chart. (index.ts, package.json)",
Example: "c8x init wordpress",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.Help()
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

var rootCmd = &cobra.Command{
Use: "k8x",
Use: "c8x",
Short: "Install and manage kubernets apps with tsx",
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
Expand Down
5 changes: 2 additions & 3 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ func init() {
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print version control information",
Example: "k8x new wordpress",
Use: "version",
Short: "Print version control information",
Run: func(cmd *cobra.Command, args []string) {
buildInfo, _ := debug.ReadBuildInfo()
fmt.Println(buildInfo.String())
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/kubernetix/k8x/v1
module github.com/kubernetix/c8x

go 1.22.0

Expand Down
2 changes: 1 addition & 1 deletion internal/dotenv/.env.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# These should be ignored, because K8X_ prefix is missing
# These should be ignored, because C8X_ prefix is missing
KEY=VALUE
HEY="LOL"

Expand Down
8 changes: 4 additions & 4 deletions internal/dotenv/dotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func Load() error {
envToLoad := os.Getenv("K8X_ENV")
envToLoad := os.Getenv("C8X_ENV")

if envToLoad == "" {
// Defaults to this file
Expand Down Expand Up @@ -58,12 +58,12 @@ func Load() error {
// Make KEY="VALUE" to KEY=VALUE
value := strings.Replace(pair[1], "\"", "", -1)

if !strings.HasPrefix(key, "K8X_") {
// Skip all variables that dont start with K8X_
if !strings.HasPrefix(key, "C8X_") {
// Skip all variables that dont start with C8X_
continue
}

key = strings.Replace(key, "K8X_", "", -1)
key = strings.Replace(key, "C8X_", "", -1)

err := os.Setenv(key, value)

Expand Down
4 changes: 2 additions & 2 deletions internal/dotenv/dotenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ func TestLoad(t *testing.T) {
_ = Load()

if os.Getenv("KEY") != "" {
t.Fatalf(`KEY is not empty! Loading env variables without K8X prefix`)
t.Fatalf(`KEY is not empty! Loading env variables without c8x prefix`)
}

if os.Getenv("HEY") != "" {
t.Fatalf(`HEY is not empty! Loading env variables without K8X prefix`)
t.Fatalf(`HEY is not empty! Loading env variables without c8x prefix`)
}

if os.Getenv("TEST") != "TEST" {
Expand Down
2 changes: 1 addition & 1 deletion internal/k8s/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func PatchAndTransform(export map[string]interface{}) Chart {
// Todo add error handling
func ApplyChart(chart Chart) {
// create and open a temporary file
f, err := os.CreateTemp("", "k8x-tmpfile-") // in Go version older than 1.17 you can use ioutil.TempFile
f, err := os.CreateTemp("", "c8x-tmpfile-") // in Go version older than 1.17 you can use ioutil.TempFile
if err != nil {
log.Fatal(err)
}
Expand Down
16 changes: 8 additions & 8 deletions internal/ts/ts.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Load(path string, debug bool) string {
EntryPoints: []string{path},
Bundle: true,
Write: false,
GlobalName: "k8x",
GlobalName: "c8x",
Format: api.FormatIIFE,
}

Expand Down Expand Up @@ -53,11 +53,11 @@ func __jsEnvGet(name string) interface{} {
for _, e := range os.Environ() {
pair := strings.Split(e, "=")

if strings.Index(pair[0], "K8X_") == -1 {
if strings.Index(pair[0], "C8X_") == -1 {
continue
}

if name != strings.Replace(pair[0], "K8X_", "", 1) {
if name != strings.Replace(pair[0], "C8X_", "", 1) {
continue
}

Expand Down Expand Up @@ -89,11 +89,11 @@ func __jsEnvGetAsObject(name string) interface{} {

for _, e := range os.Environ() {
pair := strings.Split(e, "=")
if strings.Index(pair[0], "K8X_") == -1 {
if strings.Index(pair[0], "C8X_") == -1 {
continue
}

if !strings.HasPrefix(strings.Replace(pair[0], "K8X_", "", 1), name) {
if !strings.HasPrefix(strings.Replace(pair[0], "C8X_", "", 1), name) {
continue
}

Expand Down Expand Up @@ -180,7 +180,7 @@ func injectChartInfo(vm *goja.Runtime, path string) {
func Run(code string, path string) map[string]interface{} {
vm := goja.New()

// Todo handle this better because one creates k8x the other expects it to exist
// Todo handle this better because one creates c8x the other expects it to exist
injectEnv(vm)
injectChartInfo(vm, path)

Expand All @@ -190,13 +190,13 @@ func Run(code string, path string) map[string]interface{} {
panic(err)
}

k8x, ok := goja.AssertFunction(vm.Get("k8x").ToObject(vm).Get("default"))
c8x, ok := goja.AssertFunction(vm.Get("c8x").ToObject(vm).Get("default"))

if !ok {
panic("Please make sure you are exporting a function: export default () => ({})")
}

obj, err := k8x(goja.Undefined())
obj, err := c8x(goja.Undefined())

if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"github.com/kubernetix/k8x/v1/cmd"
"github.com/kubernetix/k8x/v1/internal/dotenv"
"github.com/kubernetix/c8x/cmd"
"github.com/kubernetix/c8x/internal/dotenv"
"runtime"
)

Expand Down
40 changes: 1 addition & 39 deletions npm/charts/README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1 @@
# k8x charts

## How it looks?
[whoami chart](/whoami/chart.ts).
```ts
/// <reference types="@kubernetix/types" />

import MyIngress, { MyIngressProps } from "./components/ingress";
import Deployment, { MyDeploymentProps } from "./components/deployment";
import Service from "./components/service";

const values: {
namespace: string;
ingress: MyIngressProps;
deployment: MyDeploymentProps;
} = {
namespace: $env.get<string>("WHOAMI_NAMESPACE") ?? "default",
deployment: {
replicas: $env.get<number>("WHOAMI_REPLICAS") ?? 1,
},
ingress: {
domain: $env.get<string>("WHOAMI_DOMAIN") ?? "example.com",
},
};

export default (): Chart => ({
namespace: {
kind: "Namespace",
apiVersion: "v1",
metadata: { name: values.namespace },
},
components: [
MyIngress(values.ingress),
Deployment(values.deployment),
Service(),
],
});

```
# c8x charts
8 changes: 4 additions & 4 deletions npm/charts/whoami/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# General config (default, dev)
export K8X_KUBECONFIG=~/.kube/config
export K8X_WHOAMI_NAMESPACE=whoami
export K8X_WHOAMI_REPLICAS=1
export K8X_WHOAMI_DOMAIN=whoami.pfusch.dev
export C8X_KUBECONFIG=~/.kube/config
export C8X_WHOAMI_NAMESPACE=whoami
export C8X_WHOAMI_REPLICAS=1
export C8X_WHOAMI_DOMAIN=whoami.pfusch.dev
6 changes: 3 additions & 3 deletions npm/charts/whoami/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# K8X whoami chart
# c8x whoami chart

[![Deploy whoami chart](https://github.com/kubernetix/charts/actions/workflows/whoami.yml/badge.svg)](https://github.com/kubernetix/charts/actions/workflows/whoami.yml)

This chart is an example chart to demonstrate the features of k8x
This chart is an example chart to demonstrate the features of c8x

`source .env.example && k8x render chart`
`source .env.example && c8x render chart`
Loading

0 comments on commit a566a0a

Please sign in to comment.