Skip to content

Commit

Permalink
Merge pull request #5 from draganm/rewrite
Browse files Browse the repository at this point in the history
Rewrite
  • Loading branch information
draganm authored Oct 31, 2023
2 parents 3c6cf54 + 79a6284 commit 11844f2
Show file tree
Hide file tree
Showing 18 changed files with 824 additions and 257 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: "1.20"
id: go
- uses: actions/checkout@v2
- name: Build
Expand Down
10 changes: 10 additions & 0 deletions .manifestor/manifestor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
render('deployment.yaml',{"name": "mfstr"}, "deployment.yaml")
render(
'ingress.yaml',
{
"hostnames": ["www.netice9.com","netice9.com"],
'serviceName': "foo",
'name': "bar",
},
"ingress.yaml",
)
39 changes: 39 additions & 0 deletions .manifestor/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
labels:
name: ${name}
name: ${name}
spec:
replicas: 1
revisionHistoryLimit: 3
selector:
matchLabels:
app: ${name}
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: ${name}
spec:
containers:
- image: registry.digitalocean.com/netice9/${name}:226b90e
imagePullPolicy: IfNotPresent
name: nin-home
ports:
- containerPort: 5001
name: http
protocol: TCP
resources:
limits:
cpu: 300m
memory: 300Mi
requests:
cpu: 300m
memory: 300Mi
restartPolicy: Always
26 changes: 26 additions & 0 deletions .manifestor/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
external-dns.alpha.kubernetes.io/hostname: "${hostnames.join(',')}"
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
cert-manager.io/cluster-issuer: letsencrypt-prod
name: ${name}
spec:
ingressClassName: nginx
rules:
_forEach: ${hostnames}
_template:
host: ${eachValue}
http:
paths:
- backend:
service:
name: ${eachValue}
port:
name: http
path: /
pathType: ImplementationSpecific
tls:
- hosts: ${hostnames}
secretName: nin-home-netice9-com-tls
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"cSpell.words": [
"envsubst",
"goja",
"Manifestor"
]
}
13 changes: 0 additions & 13 deletions Dockerfile

This file was deleted.

45 changes: 45 additions & 0 deletions encoder_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"fmt"
"os"
"path/filepath"

"gopkg.in/yaml.v3"
)

func manifestorProvider(outDir string) func(name string) (*yaml.Encoder, func() error, error) {

if outDir == "" {
return func(name string) (*yaml.Encoder, func() error, error) {
return yaml.NewEncoder(os.Stdout), func() error { return nil }, nil
}
}

return func(name string) (*yaml.Encoder, func() error, error) {
outPath := filepath.Join(outDir, name)
dir := filepath.Dir(outPath)
if dir != "" {
_, err := os.Stat(dir)
if os.IsNotExist(err) {
err = os.MkdirAll(dir, 0777)
if err != nil {
return nil, nil, fmt.Errorf("could not mkdir %s: %w", dir, err)
}
_, err = os.Stat(dir)
}

if err != nil {
return nil, nil, fmt.Errorf("could not stat %s: %w", dir, err)
}
}

f, err := os.OpenFile(outPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0777)

if err != nil {
return nil, nil, fmt.Errorf("could not open output file: %w", err)
}
return yaml.NewEncoder(f), f.Close, nil

}
}
47 changes: 37 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@
module github.com/draganm/manifestor

go 1.17
go 1.20

require (
github.com/dop251/goja v0.0.0-20220124171016-cfb079cdc7b4
github.com/drone/envsubst v1.0.2
github.com/urfave/cli/v2 v2.3.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
github.com/dop251/goja v0.0.0-20230919151941-fc55792775de
github.com/drone/envsubst v1.0.3
github.com/go-git/go-git/v5 v5.9.0
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.25.7
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
golang.org/x/text v0.3.6 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/skeema/knownhosts v1.2.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.13.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
Loading

0 comments on commit 11844f2

Please sign in to comment.