-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f100fa
commit d556663
Showing
5 changed files
with
1,287 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Generate ConfigMap | ||
on: [push] | ||
|
||
jobs: | ||
push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Go ${{ matrix.go-version }} | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21.x' | ||
- name: Build Generator | ||
run: go build -o bin/generator ./generator/generator.go | ||
- name: Generate ConfigMap | ||
run: ./bin/generator | ||
# Commit all changed files back to the repository | ||
- uses: stefanzweifel/git-auto-commit-action@v4 | ||
id: auto_commit | ||
with: | ||
branch: main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
type ConfigFile struct { | ||
FileName string | ||
Contents string | ||
Lines []string | ||
} | ||
|
||
func main() { | ||
err := generateConfigMap() | ||
if err != nil { | ||
fmt.Printf("Error: %v\n", err) | ||
return | ||
} | ||
} | ||
func generateConfigMap() error { | ||
rootPath := "servers" | ||
pfx := len(rootPath) + 1 | ||
tpl := template.Must(template.ParseFiles("generator/templates/configmap.yaml")) | ||
|
||
var configFiles []ConfigFile | ||
|
||
err := filepath.Walk(rootPath, func(path string, info os.FileInfo, e1 error) error { | ||
if !info.IsDir() && strings.HasSuffix(path, ".yaml") { | ||
if e1 != nil { | ||
return e1 | ||
} | ||
|
||
file, err := os.Open(path) | ||
if err != nil { | ||
return err | ||
} | ||
fileScanner := bufio.NewScanner(file) | ||
fileScanner.Split(bufio.ScanLines) | ||
|
||
var lines []string | ||
|
||
for fileScanner.Scan() { | ||
lines = append(lines, fileScanner.Text()) | ||
} | ||
|
||
name := path[pfx:] | ||
|
||
configFiles = append(configFiles, ConfigFile{ | ||
FileName: name, | ||
Lines: lines, | ||
}) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
f, err := os.OpenFile("manifest/configmap.yaml", os.O_WRONLY+os.O_TRUNC, os.ModeExclusive) | ||
err = tpl.ExecuteTemplate(f, "configmap.yaml", configFiles) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: discord-bot-v3-config | ||
data: | ||
{{- range . }} | ||
{{.FileName}}: | | ||
{{- range .Lines }} | ||
{{ . }} | ||
{{- end -}} | ||
{{- end -}} |
Oops, something went wrong.