From fa70a33ec44f41f613f0935a8f8348ec9f0d07bb Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 12:58:44 +0100 Subject: [PATCH 01/25] feat: begin working on Go rewrite --- .editorconfig | 19 +++++ build-configs.yaml | 8 +++ cmd/build-configs/main.go | 13 ++++ go.mod | 13 ++++ go.sum | 12 ++++ internal/cli/generate.go | 28 ++++++++ internal/cli/root.go | 25 +++++++ internal/config/config.go | 70 +++++++++++++++++++ internal/config/go_cobra_cli.go | 9 +++ internal/config/nix.go | 11 +++ internal/config/templater.go | 5 ++ internal/templates/templates.go | 10 +++ .../templates/go-cobra-cli/.editorconfig | 19 +++++ .../go-cobra-cli/.github/workflows/flake.yaml | 0 .../templates/go-cobra-cli/flake.nix | 31 ++++++++ 15 files changed, 273 insertions(+) create mode 100644 .editorconfig create mode 100644 build-configs.yaml create mode 100644 cmd/build-configs/main.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/cli/generate.go create mode 100644 internal/cli/root.go create mode 100644 internal/config/config.go create mode 100644 internal/config/go_cobra_cli.go create mode 100644 internal/config/nix.go create mode 100644 internal/config/templater.go create mode 100644 internal/templates/templates.go create mode 100644 internal/templates/templates/go-cobra-cli/.editorconfig create mode 100644 internal/templates/templates/go-cobra-cli/.github/workflows/flake.yaml create mode 100644 internal/templates/templates/go-cobra-cli/flake.nix diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9c83f68 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.go] +indent_style = tab +indent_size = 4 + +[*.{md,yml,yaml}] +indent_style = space +indent_size = 2 + +[justfile] +indent_style = space +indent_size = 4 diff --git a/build-configs.yaml b/build-configs.yaml new file mode 100644 index 0000000..ea11968 --- /dev/null +++ b/build-configs.yaml @@ -0,0 +1,8 @@ +--- +name: build-configs +template: go-cobra-cli +parameters: + nix: + vendorHash: '' + goPackage: go_1_22 + buildGoModule: buildGo122Module diff --git a/cmd/build-configs/main.go b/cmd/build-configs/main.go new file mode 100644 index 0000000..38c3ebb --- /dev/null +++ b/cmd/build-configs/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "os" + + "github.com/ALT-F4-LLC/build-configs/internal/cli" +) + +func main() { + if err := cli.Execute(); err != nil { + os.Exit(1) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c3ed7c2 --- /dev/null +++ b/go.mod @@ -0,0 +1,13 @@ +module github.com/ALT-F4-LLC/build-configs + +go 1.21.7 + +require ( + github.com/spf13/cobra v1.8.0 + gopkg.in/yaml.v3 v3.0.1 +) + +require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..3926859 --- /dev/null +++ b/go.sum @@ -0,0 +1,12 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= +github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/cli/generate.go b/internal/cli/generate.go new file mode 100644 index 0000000..b5f1a55 --- /dev/null +++ b/internal/cli/generate.go @@ -0,0 +1,28 @@ +package cli + +import ( + "fmt" + + "github.com/ALT-F4-LLC/build-configs/internal/config" + "github.com/spf13/cobra" +) + +var generateCmd = &cobra.Command{ + Use: "generate", + Short: "Generates configuration from a project config file.", + + RunE: func(cmd *cobra.Command, args []string) error { + cfg, err := config.New(configFile) + if err != nil { + return fmt.Errorf("could not load config: %v", err) + } + + + + return nil + }, +} + +func init() { + rootCmd.AddCommand(generateCmd) +} diff --git a/internal/cli/root.go b/internal/cli/root.go new file mode 100644 index 0000000..fe7af7c --- /dev/null +++ b/internal/cli/root.go @@ -0,0 +1,25 @@ +package cli + +import "github.com/spf13/cobra" + +var ( + debug bool + configFile string +) + +var rootCmd = &cobra.Command{ + Use: "build-configs", + Short: "build-configs is a CLI for generating build configurations.", + Long: `build-configs is an easy-to-use, standardised configuration generator +built to ease development overhead when bootstrapping and updating +configuration in ALT-F4 projects.`, +} + +func Execute() error { + return rootCmd.Execute() +} + +func init() { + rootCmd.PersistentFlags().BoolVarP(&debug, "debug", "D", false, "debug mode") + rootCmd.PersistentFlags().StringVarP(&configFile, "config-file", "c", "build-configs.json", "path to the config file") +} diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..5983035 --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,70 @@ +package config + +import ( + "encoding/json" + "errors" + "fmt" + "os" + "path" + + "gopkg.in/yaml.v3" +) + +type Config struct { + Name string `json:"name" yaml:"name"` + Template string `json:"template" yaml:"template"` + Parameters map[string]interface{} `json:"parameters" yaml:"parameters"` +} + +func New(configPath string) (Config, error) { + b, err := os.ReadFile(configPath) + if err != nil { + return Config{}, err + } + + ext := path.Ext(configPath) + switch ext { + case "json": + return loadConfigJson(b) + case "yaml", "yml": + return loadConfigYaml(b) + } + + return Config{}, errors.New("unsupported file type; supported types are 'json', 'yaml' and 'yml'") +} + +func (c Config) GetTemplateParams() (Templater, error) { + switch c.Template { + case "go-cobra-cli": + var params GoCobraCliConfig + b, err := json.Marshal(c.Parameters) + if err != nil { + return params, err + } + if err := json.Unmarshal(b, ¶ms); err != nil { + return params, err + } + return params, nil + } + return nil, fmt.Errorf("unsupported template: %v", c.Template) +} + +func loadConfigJson(b []byte) (Config, error) { + var cfg Config + + if err := json.Unmarshal(b, &cfg); err != nil { + return cfg, err + } + + return cfg, nil +} + +func loadConfigYaml(b []byte) (Config, error) { + var cfg Config + + if err := yaml.Unmarshal(b, &cfg); err != nil { + return cfg, err + } + + return cfg, nil +} diff --git a/internal/config/go_cobra_cli.go b/internal/config/go_cobra_cli.go new file mode 100644 index 0000000..73d6af9 --- /dev/null +++ b/internal/config/go_cobra_cli.go @@ -0,0 +1,9 @@ +package config + +type GoCobraCliConfig struct { + Nix NixGoConfig `json:"nix,omitempty" yaml:"nix,omitempty"` +} + +func (c GoCobraCliConfig) Render() error { + return nil +} diff --git a/internal/config/nix.go b/internal/config/nix.go new file mode 100644 index 0000000..603e335 --- /dev/null +++ b/internal/config/nix.go @@ -0,0 +1,11 @@ +package config + +type NixConfig struct { + NixpkgsBranch string `json:"nixpkgsBranch,omitempty" yaml:"nixpkgsBranch,omitempty"` +} + +type NixGoConfig struct { + NixConfig + GoPackage string `json:"goPackage,omitempty" yaml:"goPackage,omitempty"` + BuildGoModule string `json:"buildGoModule,omitempty" yaml:"buildGoModule,omitempty"` +} diff --git a/internal/config/templater.go b/internal/config/templater.go new file mode 100644 index 0000000..fe5711f --- /dev/null +++ b/internal/config/templater.go @@ -0,0 +1,5 @@ +package config + +type Templater interface { + Render() error +} diff --git a/internal/templates/templates.go b/internal/templates/templates.go new file mode 100644 index 0000000..e1dd97c --- /dev/null +++ b/internal/templates/templates.go @@ -0,0 +1,10 @@ +package templates + +import "embed" + +//go:embed templates +var content embed.FS + +func RenderTemplate(name string, context interface{}) (string, error) { + return "", nil +} diff --git a/internal/templates/templates/go-cobra-cli/.editorconfig b/internal/templates/templates/go-cobra-cli/.editorconfig new file mode 100644 index 0000000..9c83f68 --- /dev/null +++ b/internal/templates/templates/go-cobra-cli/.editorconfig @@ -0,0 +1,19 @@ +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.go] +indent_style = tab +indent_size = 4 + +[*.{md,yml,yaml}] +indent_style = space +indent_size = 2 + +[justfile] +indent_style = space +indent_size = 4 diff --git a/internal/templates/templates/go-cobra-cli/.github/workflows/flake.yaml b/internal/templates/templates/go-cobra-cli/.github/workflows/flake.yaml new file mode 100644 index 0000000..e69de29 diff --git a/internal/templates/templates/go-cobra-cli/flake.nix b/internal/templates/templates/go-cobra-cli/flake.nix new file mode 100644 index 0000000..bb22148 --- /dev/null +++ b/internal/templates/templates/go-cobra-cli/flake.nix @@ -0,0 +1,31 @@ +{ + inputs.nixpkgs.url = "github:nixos/nixpkgs/{{ .Nix.NixpkgsBranch }}"; + + outputs = { flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ ]; + + perSystem = { config, pkgs, ... }: + let + inherit (pkgs) + {{ .Nix.GoPackage }} + just; + + name = "{{ .Name }}"; + CGO_ENABLED = "0"; + in + { + devShells.default = pkgs.mkShell { + buildInputs = [ just ]; + inputsFrom = [ config.packages.default ]; + }; + + packages.default = pkgs.{{ .Nix.BuildGoModule }} { + inherit name; + src = ./.; + vendorHash = "{{ .Nix.VendorHash }}"; + buildModules = [ "cmd/${name}" ]; + }; + }; + }; +} From 585b9217e20b0ac161b944e4ed3c792e3489820f Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 13:03:29 +0100 Subject: [PATCH 02/25] feat: config search paths --- internal/cli/generate.go | 11 +++++++++-- internal/cli/root.go | 2 +- internal/config/config.go | 8 ++++---- internal/config/find.go | 22 ++++++++++++++++++++++ 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 internal/config/find.go diff --git a/internal/cli/generate.go b/internal/cli/generate.go index b5f1a55..6e25038 100644 --- a/internal/cli/generate.go +++ b/internal/cli/generate.go @@ -12,14 +12,21 @@ var generateCmd = &cobra.Command{ Short: "Generates configuration from a project config file.", RunE: func(cmd *cobra.Command, args []string) error { + if configFile == "" { + configFile = config.FindConfigPath() + } + cfg, err := config.New(configFile) if err != nil { return fmt.Errorf("could not load config: %v", err) } + t, err := cfg.GetTemplater() + if err != nil { + return fmt.Errorf("could not create templater: %v", err) + } - - return nil + return t.Render() }, } diff --git a/internal/cli/root.go b/internal/cli/root.go index fe7af7c..9d41d7c 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -21,5 +21,5 @@ func Execute() error { func init() { rootCmd.PersistentFlags().BoolVarP(&debug, "debug", "D", false, "debug mode") - rootCmd.PersistentFlags().StringVarP(&configFile, "config-file", "c", "build-configs.json", "path to the config file") + rootCmd.PersistentFlags().StringVarP(&configFile, "config-file", "c", "", "path to the config file") } diff --git a/internal/config/config.go b/internal/config/config.go index 5983035..69740b8 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -17,23 +17,23 @@ type Config struct { } func New(configPath string) (Config, error) { - b, err := os.ReadFile(configPath) + b, err := os.ReadFile("./" + configPath) if err != nil { return Config{}, err } ext := path.Ext(configPath) switch ext { - case "json": + case ".json": return loadConfigJson(b) - case "yaml", "yml": + case ".yaml", ".yml": return loadConfigYaml(b) } return Config{}, errors.New("unsupported file type; supported types are 'json', 'yaml' and 'yml'") } -func (c Config) GetTemplateParams() (Templater, error) { +func (c Config) GetTemplater() (Templater, error) { switch c.Template { case "go-cobra-cli": var params GoCobraCliConfig diff --git a/internal/config/find.go b/internal/config/find.go new file mode 100644 index 0000000..2d5a159 --- /dev/null +++ b/internal/config/find.go @@ -0,0 +1,22 @@ +package config + +import "os" + +var searchPaths = []string{ + "build-configs.json", + "build-configs.yaml", + "build-configs.yml", +} + +func FindConfigPath() string { + var configPath string + + for _, p := range searchPaths { + if _, err := os.Stat("./" + p); err != nil { + continue + } + configPath = p + } + + return configPath +} From d3973a5db7055de355df0cca52f9f1e0b06127ff Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 13:26:43 +0100 Subject: [PATCH 03/25] feat: working template generation logic --- internal/cli/generate.go | 2 + internal/config/config.go | 2 +- internal/config/go_cobra_cli.go | 48 +++++++++++++++++++ internal/config/nix.go | 3 +- internal/templates/stored_name.go | 16 +++++++ internal/templates/templates.go | 17 +++++-- ...ke.yaml => .github__workflows__flake.yaml} | 0 7 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 internal/templates/stored_name.go rename internal/templates/templates/go-cobra-cli/{.github/workflows/flake.yaml => .github__workflows__flake.yaml} (100%) diff --git a/internal/cli/generate.go b/internal/cli/generate.go index 6e25038..7d4de42 100644 --- a/internal/cli/generate.go +++ b/internal/cli/generate.go @@ -26,6 +26,8 @@ var generateCmd = &cobra.Command{ return fmt.Errorf("could not create templater: %v", err) } + fmt.Printf("%+v\n", t) + return t.Render() }, } diff --git a/internal/config/config.go b/internal/config/config.go index 69740b8..c318916 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -36,7 +36,7 @@ func New(configPath string) (Config, error) { func (c Config) GetTemplater() (Templater, error) { switch c.Template { case "go-cobra-cli": - var params GoCobraCliConfig + params := NewGoCobraCliConfig(c) b, err := json.Marshal(c.Parameters) if err != nil { return params, err diff --git a/internal/config/go_cobra_cli.go b/internal/config/go_cobra_cli.go index 73d6af9..9d5ef89 100644 --- a/internal/config/go_cobra_cli.go +++ b/internal/config/go_cobra_cli.go @@ -1,9 +1,57 @@ package config +import ( + "fmt" + "os" + "strings" + + "github.com/ALT-F4-LLC/build-configs/internal/templates" +) + +var goCobraCliTemplates = []string{ + ".editorconfig", + ".github/workflows/flake.yaml", + "flake.nix", +} + type GoCobraCliConfig struct { + Config Nix NixGoConfig `json:"nix,omitempty" yaml:"nix,omitempty"` } +func NewGoCobraCliConfig(c Config) GoCobraCliConfig { + return GoCobraCliConfig{ + Config: c, + Nix: NixGoConfig{ + NixConfig: NixConfig{NixpkgsBranch: "unstable"}, + GoPackage: "go", + BuildGoModule: "buildGoModule", + }, + } +} + func (c GoCobraCliConfig) Render() error { + out := map[string]string{} + + for _, tmplPath := range goCobraCliTemplates { + sb := strings.Builder{} + err := templates.GoCobraCliTemplates.ExecuteTemplate( + &sb, + templates.PathToTemplate(tmplPath), + c, + ) + if err != nil { + return err + } + out["./" + tmplPath] = sb.String() + } + + for k, v := range out { + b := []byte(v) + if err := os.WriteFile(k, b, os.ModeAppend); err != nil { + return err + } + } + return nil } diff --git a/internal/config/nix.go b/internal/config/nix.go index 603e335..c2047aa 100644 --- a/internal/config/nix.go +++ b/internal/config/nix.go @@ -6,6 +6,7 @@ type NixConfig struct { type NixGoConfig struct { NixConfig - GoPackage string `json:"goPackage,omitempty" yaml:"goPackage,omitempty"` + GoPackage string `json:"goPackage,omitempty" yaml:"goPackage,omitempty"` BuildGoModule string `json:"buildGoModule,omitempty" yaml:"buildGoModule,omitempty"` + VendorHash string `json:"vendorHash,omitempty" yaml:"vendorHash,omitempty"` } diff --git a/internal/templates/stored_name.go b/internal/templates/stored_name.go new file mode 100644 index 0000000..789eb0f --- /dev/null +++ b/internal/templates/stored_name.go @@ -0,0 +1,16 @@ +package templates + +import "strings" + +const ( + pathDivider = "/" + templateDivider = "__" +) + +func PathToTemplate(p string) string { + return strings.ReplaceAll(p, pathDivider, templateDivider) +} + +func TemplateToPath(p string) string { + return strings.ReplaceAll(p, templateDivider, pathDivider) +} diff --git a/internal/templates/templates.go b/internal/templates/templates.go index e1dd97c..5a6c2e5 100644 --- a/internal/templates/templates.go +++ b/internal/templates/templates.go @@ -1,10 +1,17 @@ package templates -import "embed" +import ( + "embed" + "text/template" +) -//go:embed templates -var content embed.FS +var ( + //go:embed all:templates/go-cobra-cli/* + content embed.FS -func RenderTemplate(name string, context interface{}) (string, error) { - return "", nil + GoCobraCliTemplates *template.Template +) + +func init() { + GoCobraCliTemplates = template.Must(template.ParseFS(content, "templates/go-cobra-cli/*")) } diff --git a/internal/templates/templates/go-cobra-cli/.github/workflows/flake.yaml b/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml similarity index 100% rename from internal/templates/templates/go-cobra-cli/.github/workflows/flake.yaml rename to internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml From dee2ce32a89344d3c9b77122d37d5d6a2ea2cd72 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 13:27:06 +0100 Subject: [PATCH 04/25] fix: go compile error --- internal/config/go_cobra_cli.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/config/go_cobra_cli.go b/internal/config/go_cobra_cli.go index 9d5ef89..124f1c9 100644 --- a/internal/config/go_cobra_cli.go +++ b/internal/config/go_cobra_cli.go @@ -1,7 +1,6 @@ package config import ( - "fmt" "os" "strings" From c079f57003266e8fea301d5fb949740d0752b4f0 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 13:35:01 +0100 Subject: [PATCH 05/25] feat: working on flake ci template --- internal/config/go_cobra_cli.go | 1 + .../.github__workflows__flake.yaml | 55 +++++++++++++++++++ .../templates/go-cobra-cli/flake.nix | 2 +- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/internal/config/go_cobra_cli.go b/internal/config/go_cobra_cli.go index 124f1c9..007af9b 100644 --- a/internal/config/go_cobra_cli.go +++ b/internal/config/go_cobra_cli.go @@ -16,6 +16,7 @@ var goCobraCliTemplates = []string{ type GoCobraCliConfig struct { Config Nix NixGoConfig `json:"nix,omitempty" yaml:"nix,omitempty"` + PrivateModules string `json:"privateModules,omitempty" yaml:"privateModules,omitempty"` } func NewGoCobraCliConfig(c Config) GoCobraCliConfig { diff --git a/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml b/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml index e69de29..54a8034 100644 --- a/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml +++ b/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml @@ -0,0 +1,55 @@ +--- +name: Flake Check & Build + +on: + push: + branches: [main] + pull_request: + +env: + CACHIX_BINARY_CACHE: {{ .Nix.Cachix.BinaryCache }} + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: DeterminateSystems/nix-installer-action@main + - uses: cachix/cachix-action@v14 + with: + authToken: ${{"{{"}} secrets.ALTF4LLC_CACHIX_AUTH_TOKEN {{"}}"}} + name: ${{"{{"}} env.CACHIX_BINARY_CACHE {{"}}"}} + - uses: actions/checkout@v4 + - run: nix develop -c just check + + build: + needs: + - check + runs-on: ubuntu-latest + steps: + - uses: DeterminateSystems/nix-installer-action@main + - uses: cachix/cachix-action@v14 + with: + authToken: ${{"{{"}} secrets.ALTF4LLC_CACHIX_AUTH_TOKEN ${{"}}"}} + name: ${{"{{"}} env.CACHIX_BINARY_CACHE ${{"}}"}} + {{ if .PrivateModules }} + - id: generate-token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_ID ${{"}}"}} + owner: ${{"{{"}} github.repository_owner ${{"}}"}} + private-key: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_PRIVATE_KEY ${{"}}"}} + - uses: extractions/netrc@v2 + with: + machine: github.com + password: ${{"{{"}} steps.generate-token.outputs.token ${{"}}"}} + username: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_USER ${{"}}"}} + {{ end }} + - uses: actions/checkout@v4 + {{ if .PrivateModules }} + - run: cp --no-preserve=mode ~/.netrc /tmp/.netrc + {{ end }} + - run: nix develop -c just build + {{- if .PrivateModules -}} + - run: rm -rf /tmp/.netrc + if: success() || failure() + {{- end -}} diff --git a/internal/templates/templates/go-cobra-cli/flake.nix b/internal/templates/templates/go-cobra-cli/flake.nix index bb22148..cee3af9 100644 --- a/internal/templates/templates/go-cobra-cli/flake.nix +++ b/internal/templates/templates/go-cobra-cli/flake.nix @@ -1,7 +1,7 @@ { inputs.nixpkgs.url = "github:nixos/nixpkgs/{{ .Nix.NixpkgsBranch }}"; - outputs = { flake-parts, ... }: + outputs = inputs@{ flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs; } { systems = [ ]; From a7ae85a87455e287576071d5abdda7bdbd68fff1 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 13:38:12 +0100 Subject: [PATCH 06/25] feat: cachix config --- internal/config/go_cobra_cli.go | 2 +- internal/config/nix.go | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/config/go_cobra_cli.go b/internal/config/go_cobra_cli.go index 007af9b..b980d31 100644 --- a/internal/config/go_cobra_cli.go +++ b/internal/config/go_cobra_cli.go @@ -23,7 +23,7 @@ func NewGoCobraCliConfig(c Config) GoCobraCliConfig { return GoCobraCliConfig{ Config: c, Nix: NixGoConfig{ - NixConfig: NixConfig{NixpkgsBranch: "unstable"}, + NixConfig: NewNixConfig(), GoPackage: "go", BuildGoModule: "buildGoModule", }, diff --git a/internal/config/nix.go b/internal/config/nix.go index c2047aa..fb6690c 100644 --- a/internal/config/nix.go +++ b/internal/config/nix.go @@ -1,7 +1,21 @@ package config type NixConfig struct { - NixpkgsBranch string `json:"nixpkgsBranch,omitempty" yaml:"nixpkgsBranch,omitempty"` + Cachix NixCachixConfig `json:"cachix,omitempty" yaml:"cachix,omitempty"` + NixpkgsBranch string `json:"nixpkgsBranch,omitempty" yaml:"nixpkgsBranch,omitempty"` +} + +func NewNixConfig() NixConfig { + return NixConfig{ + NixpkgsBranch: "nixpkgs-unstable", + Cachix: NixCachixConfig{ + BinaryCache: "altf4llc", + }, + } +} + +type NixCachixConfig struct { + BinaryCache string `json:"binaryCache,omitempty" yaml:"binaryCache,omitempty"` } type NixGoConfig struct { From 813c71c8bf224aa2e13357e78bf098f0dfcb4851 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 13:51:12 +0100 Subject: [PATCH 07/25] feat: make new config for creating directories recursively work --- .github/workflows/flake.yaml | 37 ++++ .github/workflows/flake.yml | 17 -- flake.lock | 165 +++--------------- flake.nix | 106 +++-------- internal/config/go_cobra_cli.go | 14 +- internal/config/nix.go | 5 +- .../templates/{stored_name.go => paths.go} | 14 +- .../templates/go-cobra-cli/flake.nix | 2 +- .../templates/templates/go-cobra-cli/justfile | 13 ++ justfile | 13 ++ 10 files changed, 141 insertions(+), 245 deletions(-) create mode 100644 .github/workflows/flake.yaml delete mode 100644 .github/workflows/flake.yml rename internal/templates/{stored_name.go => paths.go} (54%) create mode 100644 internal/templates/templates/go-cobra-cli/justfile create mode 100644 justfile diff --git a/.github/workflows/flake.yaml b/.github/workflows/flake.yaml new file mode 100644 index 0000000..09fdbc3 --- /dev/null +++ b/.github/workflows/flake.yaml @@ -0,0 +1,37 @@ +--- +name: Flake Check & Build + +on: + push: + branches: [main] + pull_request: + +env: + CACHIX_BINARY_CACHE: altf4llc + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: DeterminateSystems/nix-installer-action@main + - uses: cachix/cachix-action@v14 + with: + authToken: ${{ secrets.ALTF4LLC_CACHIX_AUTH_TOKEN }} + name: ${{ env.CACHIX_BINARY_CACHE }} + - uses: actions/checkout@v4 + - run: nix develop -c just check + + build: + needs: + - check + runs-on: ubuntu-latest + steps: + - uses: DeterminateSystems/nix-installer-action@main + - uses: cachix/cachix-action@v14 + with: + authToken: ${{ secrets.ALTF4LLC_CACHIX_AUTH_TOKEN $}} + name: ${{ env.CACHIX_BINARY_CACHE $}} + + - uses: actions/checkout@v4 + + - run: nix develop -c just build \ No newline at end of file diff --git a/.github/workflows/flake.yml b/.github/workflows/flake.yml deleted file mode 100644 index 9fe7241..0000000 --- a/.github/workflows/flake.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: flake - -on: - pull_request: - push: - branches: - - main - -jobs: - build: - runs-on: ubuntu-22.04 - steps: - - uses: DeterminateSystems/nix-installer-action@v4 - - - uses: actions/checkout@v3 - - - run: nix build --json | jq "." diff --git a/flake.lock b/flake.lock index 038fa90..3584d8b 100644 --- a/flake.lock +++ b/flake.lock @@ -1,174 +1,61 @@ { "nodes": { - "advisory-db": { - "flake": false, - "locked": { - "lastModified": 1694620341, - "narHash": "sha256-5hV38PQ1roGn5oxWdmv7YRp684/9hypW/7nzcdLARZI=", - "owner": "rustsec", - "repo": "advisory-db", - "rev": "12719bd23b88573977c7ad7fe818b05e8fbc33b3", - "type": "github" - }, - "original": { - "owner": "rustsec", - "repo": "advisory-db", - "type": "github" - } - }, - "crane": { - "inputs": { - "flake-compat": "flake-compat", - "flake-utils": "flake-utils", - "nixpkgs": [ - "nixpkgs" - ], - "rust-overlay": "rust-overlay" - }, - "locked": { - "lastModified": 1693787605, - "narHash": "sha256-rwq5U8dy+a9JFny/73L0SJu1GfWwATMPMTp7D+mjHy8=", - "owner": "ipetkov", - "repo": "crane", - "rev": "8b4f7a4dab2120cf41e7957a28a853f45016bd9d", - "type": "github" - }, - "original": { - "owner": "ipetkov", - "repo": "crane", - "type": "github" - } - }, - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-utils": { + "flake-parts": { "inputs": { - "systems": "systems" + "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1692799911, - "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "lastModified": 1712014858, + "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" + "id": "flake-parts", + "type": "indirect" } }, - "flake-utils_2": { - "inputs": { - "systems": "systems_2" - }, + "nixpkgs": { "locked": { - "lastModified": 1694529238, - "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "lastModified": 1712883908, + "narHash": "sha256-icE1IJE9fHcbDfJ0+qWoDdcBXUoZCcIJxME4lMHwvSM=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a0c9e3aee1000ac2bfb0e5b98c94c946a5d180a9", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", "type": "github" } }, - "nixpkgs": { + "nixpkgs-lib": { "locked": { - "lastModified": 1694593561, - "narHash": "sha256-WSaIQZ5s9N9bDFkEMTw6P9eaZ9bv39ZhsiW12GtTNM0=", + "dir": "lib", + "lastModified": 1711703276, + "narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "1697b7d480449b01111e352021f46e5879e47643", + "rev": "d8fe5e6c92d0d190646fb9f1056741a229980089", "type": "github" }, "original": { + "dir": "lib", "owner": "NixOS", - "ref": "nixpkgs-unstable", + "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { - "advisory-db": "advisory-db", - "crane": "crane", - "flake-utils": "flake-utils_2", + "flake-parts": "flake-parts", "nixpkgs": "nixpkgs" } - }, - "rust-overlay": { - "inputs": { - "flake-utils": [ - "crane", - "flake-utils" - ], - "nixpkgs": [ - "crane", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1693707092, - "narHash": "sha256-HR1EnynBSPqbt+04/yxxqsG1E3n6uXrOl7SPco/UnYo=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "98ccb73e6eefc481da6039ee57ad8818d1ca8d56", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "systems_2": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 63b021c..1fbbf40 100644 --- a/flake.nix +++ b/flake.nix @@ -1,87 +1,31 @@ { - description = "Build configuration generation CLI tool."; - - inputs = { - advisory-db = { - url = "github:rustsec/advisory-db"; - flake = false; - }; - - crane = { - url = "github:ipetkov/crane"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - - flake-utils.url = "github:numtide/flake-utils"; - - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - }; - - outputs = { self, nixpkgs, crane, flake-utils, advisory-db, ... }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { inherit system; }; - - inherit (pkgs) lib; - - craneLib = crane.lib.${system}; - - src = lib.cleanSourceWith { - filter = templatesOrCargo; - src = ./.; - }; - - buildInputs = [ ] - ++ lib.optionals pkgs.stdenv.isDarwin [ pkgs.libiconv ]; - - cargoArtifacts = craneLib.buildDepsOnly { inherit src buildInputs; }; - - build-configs = - craneLib.buildPackage { inherit cargoArtifacts src buildInputs; }; - - templatesFilter = path: _type: builtins.match ".*template.*" path != null; - - templatesOrCargo = path: type: - (templatesFilter path type) || (craneLib.filterCargoSources path type); - in { - checks = { - inherit build-configs; - - build-configs-clippy = craneLib.cargoClippy { - inherit cargoArtifacts src buildInputs; - - cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + + outputs = inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + + perSystem = { config, pkgs, ... }: + let + inherit (pkgs) + go_1_22 + just; + + name = "build-configs"; + CGO_ENABLED = "0"; + in + { + devShells.default = pkgs.mkShell { + buildInputs = [ just ]; + inputsFrom = [ config.packages.default ]; }; - build-configs-doc = - craneLib.cargoDoc { inherit cargoArtifacts src buildInputs; }; - - build-configs-fmt = craneLib.cargoFmt { inherit src; }; - - build-configs-audit = - craneLib.cargoAudit { inherit src advisory-db; }; - - build-configs-nextest = craneLib.cargoNextest { - inherit cargoArtifacts src buildInputs; - partitions = 1; - partitionType = "count"; + packages.default = pkgs.buildGo122Module { + inherit name; + src = ./.; + vendorHash = ""; + buildModules = [ "cmd/${name}" ]; }; - } // lib.optionalAttrs (system == "x86_64-linux") { - build-configs-coverage = - craneLib.cargoTarpaulin { inherit cargoArtifacts src; }; }; - - packages.default = build-configs; - - apps.default = flake-utils.lib.mkApp { drv = build-configs; }; - - devShells.default = pkgs.mkShell { - inputsFrom = builtins.attrValues self.checks; - - buildInputs = [ ] - ++ lib.optionals pkgs.stdenv.isDarwin [ pkgs.libiconv ]; - - nativeBuildInputs = with pkgs; [ cargo rustc ]; - }; - }); + }; } diff --git a/internal/config/go_cobra_cli.go b/internal/config/go_cobra_cli.go index b980d31..a89b80f 100644 --- a/internal/config/go_cobra_cli.go +++ b/internal/config/go_cobra_cli.go @@ -11,12 +11,13 @@ var goCobraCliTemplates = []string{ ".editorconfig", ".github/workflows/flake.yaml", "flake.nix", + "justfile", } type GoCobraCliConfig struct { Config - Nix NixGoConfig `json:"nix,omitempty" yaml:"nix,omitempty"` - PrivateModules string `json:"privateModules,omitempty" yaml:"privateModules,omitempty"` + Nix NixGoConfig `json:"nix,omitempty" yaml:"nix,omitempty"` + PrivateModules string `json:"privateModules,omitempty" yaml:"privateModules,omitempty"` } func NewGoCobraCliConfig(c Config) GoCobraCliConfig { @@ -43,12 +44,15 @@ func (c GoCobraCliConfig) Render() error { if err != nil { return err } - out["./" + tmplPath] = sb.String() + out["./"+tmplPath] = sb.String() } for k, v := range out { - b := []byte(v) - if err := os.WriteFile(k, b, os.ModeAppend); err != nil { + if err := templates.EnsureDirExists(k); err != nil { + return err + } + + if err := os.WriteFile(k, []byte(v), 0644); err != nil { return err } } diff --git a/internal/config/nix.go b/internal/config/nix.go index fb6690c..8019aa3 100644 --- a/internal/config/nix.go +++ b/internal/config/nix.go @@ -3,14 +3,17 @@ package config type NixConfig struct { Cachix NixCachixConfig `json:"cachix,omitempty" yaml:"cachix,omitempty"` NixpkgsBranch string `json:"nixpkgsBranch,omitempty" yaml:"nixpkgsBranch,omitempty"` + Systems []string `json:"systems,omitempty" yaml:"systems,omitempty"` } func NewNixConfig() NixConfig { return NixConfig{ - NixpkgsBranch: "nixpkgs-unstable", Cachix: NixCachixConfig{ BinaryCache: "altf4llc", }, + + NixpkgsBranch: "nixpkgs-unstable", + Systems: []string{"x86_64-linux", "aarch64-linux", "x86_64-darwin", "aarch64-darwin"}, } } diff --git a/internal/templates/stored_name.go b/internal/templates/paths.go similarity index 54% rename from internal/templates/stored_name.go rename to internal/templates/paths.go index 789eb0f..2b1da81 100644 --- a/internal/templates/stored_name.go +++ b/internal/templates/paths.go @@ -1,6 +1,9 @@ package templates -import "strings" +import ( + "os" + "strings" +) const ( pathDivider = "/" @@ -14,3 +17,12 @@ func PathToTemplate(p string) string { func TemplateToPath(p string) string { return strings.ReplaceAll(p, templateDivider, pathDivider) } + +func EnsureDirExists(p string) error { + parts := strings.Split(p, pathDivider) + dir := strings.Join(parts[:len(parts)-1], pathDivider) + if dir == "." { + return nil + } + return os.MkdirAll(dir, 0755) +} diff --git a/internal/templates/templates/go-cobra-cli/flake.nix b/internal/templates/templates/go-cobra-cli/flake.nix index cee3af9..8d10df6 100644 --- a/internal/templates/templates/go-cobra-cli/flake.nix +++ b/internal/templates/templates/go-cobra-cli/flake.nix @@ -3,7 +3,7 @@ outputs = inputs@{ flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs; } { - systems = [ ]; + systems = [ {{range .Nix.Systems}}"{{.}}" {{end}}]; perSystem = { config, pkgs, ... }: let diff --git a/internal/templates/templates/go-cobra-cli/justfile b/internal/templates/templates/go-cobra-cli/justfile new file mode 100644 index 0000000..ea68670 --- /dev/null +++ b/internal/templates/templates/go-cobra-cli/justfile @@ -0,0 +1,13 @@ +build profile='default'{{ if .PrivateModules }} netrc="/tmp/.netrc=/tmp/.netrc"{{ end }}: + nix build \ + --json \ + --no-link \ + --print-build-logs \ + --sandbox \ + --sandbox-paths "{{"{{"}} netrc {{"}}"}}" \ + '.#{{"{{"}} profile {{"}}"}}' + +build-docker{{ if .PrivateModules }} netrc="/tmp/.netrc=/tmp/.netrc"{{ end }}: (build 'docker'{{ if .PrivateModules }} netrc{{ end }}) + +check: + nix flake check diff --git a/justfile b/justfile new file mode 100644 index 0000000..e02076f --- /dev/null +++ b/justfile @@ -0,0 +1,13 @@ +build profile='default': + nix build \ + --json \ + --no-link \ + --print-build-logs \ + --sandbox \ + --sandbox-paths "{{ netrc }}" \ + '.#{{ profile }}' + +build-docker: (build 'docker') + +check: + nix flake check From 5f7a5ee68d2b55d0462404b016192b282ceb8a3f Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:00:12 +0100 Subject: [PATCH 08/25] feat: more go-cobra-cli templates --- .github/workflows/golangci-lint.yaml | 27 +++++++++++++ .golangci.yaml | 5 +++ internal/config/go_cobra_cli.go | 14 ++++++- internal/config/golangci.go | 15 +++++++ .../templates/templates/go-cobra-cli/.envrc | 1 + .../.github__workflows__golangci-lint.yaml | 39 +++++++++++++++++++ .../templates/go-cobra-cli/.golangci.yaml | 9 +++++ 7 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/golangci-lint.yaml create mode 100644 .golangci.yaml create mode 100644 internal/config/golangci.go create mode 100644 internal/templates/templates/go-cobra-cli/.envrc create mode 100644 internal/templates/templates/go-cobra-cli/.github__workflows__golangci-lint.yaml create mode 100644 internal/templates/templates/go-cobra-cli/.golangci.yaml diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml new file mode 100644 index 0000000..1b6b833 --- /dev/null +++ b/.github/workflows/golangci-lint.yaml @@ -0,0 +1,27 @@ +name: golangci-lint + +on: + pull_request: + +permissions: + checks: write + contents: read + pull-requests: read + +jobs: + lint: + env: + CGO_ENABLED: 0 + GOPRIVATE: github.com/ALT-F4-LLC/quirk-service-kit + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - run: go mod download + - uses: golangci/golangci-lint-action@v4 + with: + skip-pkg-cache: true + args: ./... --timeout=5m diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..c487593 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,5 @@ +--- +issues: + exclude: + - "Error return value of `\(github.com/go-kit/log.Logger\).Log` is not checked" + diff --git a/internal/config/go_cobra_cli.go b/internal/config/go_cobra_cli.go index a89b80f..e3d59b6 100644 --- a/internal/config/go_cobra_cli.go +++ b/internal/config/go_cobra_cli.go @@ -9,20 +9,30 @@ import ( var goCobraCliTemplates = []string{ ".editorconfig", + ".envrc", ".github/workflows/flake.yaml", + ".github/workflows/golangci-lint.yaml", + ".golangci.yaml", "flake.nix", "justfile", } type GoCobraCliConfig struct { Config - Nix NixGoConfig `json:"nix,omitempty" yaml:"nix,omitempty"` - PrivateModules string `json:"privateModules,omitempty" yaml:"privateModules,omitempty"` + Nix NixGoConfig `json:"nix,omitempty" yaml:"nix,omitempty"` + Lint GolangCILintConfig `json:"lint,omitempty" yaml:"lint,omitempty"` + + PrivateModules string `json:"privateModules,omitempty" yaml:"privateModules,omitempty"` + GoVersion string `json:"goVersion,omitempty" yaml:"goVersion,omitempty"` } func NewGoCobraCliConfig(c Config) GoCobraCliConfig { return GoCobraCliConfig{ Config: c, + + GoVersion: "1.22", + + Lint: NewGolangCiLintConfig(), Nix: NixGoConfig{ NixConfig: NewNixConfig(), GoPackage: "go", diff --git a/internal/config/golangci.go b/internal/config/golangci.go new file mode 100644 index 0000000..48fcc68 --- /dev/null +++ b/internal/config/golangci.go @@ -0,0 +1,15 @@ +package config + +type GolangCILintConfig struct { + Exclude []string `json:"exclude,omitEmpty" yaml:"exclude,omitEmpty"` + ExtraExclude []string `json:"extraExclude,omitEmpty" yaml:"extraExclude,omitEmpty"` +} + +func NewGolangCiLintConfig() GolangCILintConfig { + return GolangCILintConfig{ + Exclude: []string{ + "Error return value of `\\(github.com/go-kit/log.Logger\\).Log` is not checked", + }, + ExtraExclude: []string{}, + } +} diff --git a/internal/templates/templates/go-cobra-cli/.envrc b/internal/templates/templates/go-cobra-cli/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/internal/templates/templates/go-cobra-cli/.envrc @@ -0,0 +1 @@ +use flake diff --git a/internal/templates/templates/go-cobra-cli/.github__workflows__golangci-lint.yaml b/internal/templates/templates/go-cobra-cli/.github__workflows__golangci-lint.yaml new file mode 100644 index 0000000..ea47e9b --- /dev/null +++ b/internal/templates/templates/go-cobra-cli/.github__workflows__golangci-lint.yaml @@ -0,0 +1,39 @@ +name: golangci-lint + +on: + pull_request: + +permissions: + checks: write + contents: read + pull-requests: read + +jobs: + lint: + env: + CGO_ENABLED: 0 + GOPRIVATE: github.com/ALT-F4-LLC/quirk-service-kit + runs-on: ubuntu-latest + steps: + {{ if .PrivateModules }} + - id: generate-token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_ID ${{"}}"}} + owner: ${{"{{"}} github.repository_owner ${{"}}"}} + private-key: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_PRIVATE_KEY ${{"}}"}} + - uses: extractions/netrc@v2 + with: + machine: github.com + password: ${{"{{"}} steps.generate-token.outputs.token ${{"}}"}} + username: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_USER ${{"}}"}} + {{ end }} + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - run: go mod download + - uses: golangci/golangci-lint-action@v4 + with: + skip-pkg-cache: true + args: ./... --timeout=5m diff --git a/internal/templates/templates/go-cobra-cli/.golangci.yaml b/internal/templates/templates/go-cobra-cli/.golangci.yaml new file mode 100644 index 0000000..c236fed --- /dev/null +++ b/internal/templates/templates/go-cobra-cli/.golangci.yaml @@ -0,0 +1,9 @@ +--- +issues: + exclude: + {{ range .Lint.Exclude -}} + - "{{ . }}" + {{- end }} + {{ range .Lint.ExtraExclude -}} + - "{{ . }}" + {{- end }} From e050e43537f7e2433e1fb7ae9a2cd47488a335e2 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:03:06 +0100 Subject: [PATCH 09/25] feat: working on whitespace fixes --- .github/workflows/flake.yaml | 9 ++++--- .github/workflows/golangci-lint.yaml | 2 +- .../.github__workflows__flake.yaml | 24 +++++++++---------- .../templates/templates/go-cobra-cli/justfile | 2 ++ justfile | 5 +--- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/.github/workflows/flake.yaml b/.github/workflows/flake.yaml index 09fdbc3..baa07ed 100644 --- a/.github/workflows/flake.yaml +++ b/.github/workflows/flake.yaml @@ -29,9 +29,8 @@ jobs: - uses: DeterminateSystems/nix-installer-action@main - uses: cachix/cachix-action@v14 with: - authToken: ${{ secrets.ALTF4LLC_CACHIX_AUTH_TOKEN $}} - name: ${{ env.CACHIX_BINARY_CACHE $}} - + authToken: ${{ secrets.ALTF4LLC_CACHIX_AUTH_TOKEN }} + name: ${{ env.CACHIX_BINARY_CACHE }} - uses: actions/checkout@v4 - - - run: nix develop -c just build \ No newline at end of file + - run: nix develop -c just build + \ No newline at end of file diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml index 1b6b833..981bd7c 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci-lint.yaml @@ -15,7 +15,7 @@ jobs: GOPRIVATE: github.com/ALT-F4-LLC/quirk-service-kit runs-on: ubuntu-latest steps: - + - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: diff --git a/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml b/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml index 54a8034..23294d6 100644 --- a/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml +++ b/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml @@ -29,27 +29,27 @@ jobs: - uses: DeterminateSystems/nix-installer-action@main - uses: cachix/cachix-action@v14 with: - authToken: ${{"{{"}} secrets.ALTF4LLC_CACHIX_AUTH_TOKEN ${{"}}"}} - name: ${{"{{"}} env.CACHIX_BINARY_CACHE ${{"}}"}} - {{ if .PrivateModules }} + authToken: ${{"{{"}} secrets.ALTF4LLC_CACHIX_AUTH_TOKEN {{"}}"}} + name: ${{"{{"}} env.CACHIX_BINARY_CACHE {{"}}"}} + {{ if .PrivateModules -}} - id: generate-token uses: actions/create-github-app-token@v1 with: - app-id: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_ID ${{"}}"}} - owner: ${{"{{"}} github.repository_owner ${{"}}"}} - private-key: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_PRIVATE_KEY ${{"}}"}} + app-id: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_ID {{"}}"}} + owner: ${{"{{"}} github.repository_owner {{"}}"}} + private-key: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_PRIVATE_KEY {{"}}"}} - uses: extractions/netrc@v2 with: machine: github.com - password: ${{"{{"}} steps.generate-token.outputs.token ${{"}}"}} - username: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_USER ${{"}}"}} - {{ end }} + password: ${{"{{"}} steps.generate-token.outputs.token {{"}}"}} + username: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_USER {{"}}"}} + {{ end -}} - uses: actions/checkout@v4 - {{ if .PrivateModules }} + {{ if .PrivateModules -}} - run: cp --no-preserve=mode ~/.netrc /tmp/.netrc - {{ end }} + {{ end -}} - run: nix develop -c just build - {{- if .PrivateModules -}} + {{ if .PrivateModules -}} - run: rm -rf /tmp/.netrc if: success() || failure() {{- end -}} diff --git a/internal/templates/templates/go-cobra-cli/justfile b/internal/templates/templates/go-cobra-cli/justfile index ea68670..9be666f 100644 --- a/internal/templates/templates/go-cobra-cli/justfile +++ b/internal/templates/templates/go-cobra-cli/justfile @@ -3,8 +3,10 @@ build profile='default'{{ if .PrivateModules }} netrc="/tmp/.netrc=/tmp/.netrc"{ --json \ --no-link \ --print-build-logs \ + {{- if .PrivateModules }} --sandbox \ --sandbox-paths "{{"{{"}} netrc {{"}}"}}" \ + {{ end -}} '.#{{"{{"}} profile {{"}}"}}' build-docker{{ if .PrivateModules }} netrc="/tmp/.netrc=/tmp/.netrc"{{ end }}: (build 'docker'{{ if .PrivateModules }} netrc{{ end }}) diff --git a/justfile b/justfile index e02076f..6b8c735 100644 --- a/justfile +++ b/justfile @@ -2,10 +2,7 @@ build profile='default': nix build \ --json \ --no-link \ - --print-build-logs \ - --sandbox \ - --sandbox-paths "{{ netrc }}" \ - '.#{{ profile }}' + --print-build-logs \'.#{{ profile }}' build-docker: (build 'docker') From cd6dcb0e1bd1160232d0c0e14d52861db213a21a Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:03:52 +0100 Subject: [PATCH 10/25] feat: fix for justfile indent --- .github/workflows/golangci-lint.yaml | 2 +- internal/templates/templates/go-cobra-cli/justfile | 2 +- justfile | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml index 981bd7c..1b6b833 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci-lint.yaml @@ -15,7 +15,7 @@ jobs: GOPRIVATE: github.com/ALT-F4-LLC/quirk-service-kit runs-on: ubuntu-latest steps: - + - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: diff --git a/internal/templates/templates/go-cobra-cli/justfile b/internal/templates/templates/go-cobra-cli/justfile index 9be666f..2e9ca51 100644 --- a/internal/templates/templates/go-cobra-cli/justfile +++ b/internal/templates/templates/go-cobra-cli/justfile @@ -6,7 +6,7 @@ build profile='default'{{ if .PrivateModules }} netrc="/tmp/.netrc=/tmp/.netrc"{ {{- if .PrivateModules }} --sandbox \ --sandbox-paths "{{"{{"}} netrc {{"}}"}}" \ - {{ end -}} + {{- end }} '.#{{"{{"}} profile {{"}}"}}' build-docker{{ if .PrivateModules }} netrc="/tmp/.netrc=/tmp/.netrc"{{ end }}: (build 'docker'{{ if .PrivateModules }} netrc{{ end }}) diff --git a/justfile b/justfile index 6b8c735..a9a415d 100644 --- a/justfile +++ b/justfile @@ -2,7 +2,8 @@ build profile='default': nix build \ --json \ --no-link \ - --print-build-logs \'.#{{ profile }}' + --print-build-logs \ + '.#{{ profile }}' build-docker: (build 'docker') From 6581ed855018c95ea9de18c97381e3dc534d28ee Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:04:36 +0100 Subject: [PATCH 11/25] fix: include vendorhash for app --- build-configs.yaml | 2 +- flake.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build-configs.yaml b/build-configs.yaml index ea11968..237a25f 100644 --- a/build-configs.yaml +++ b/build-configs.yaml @@ -3,6 +3,6 @@ name: build-configs template: go-cobra-cli parameters: nix: - vendorHash: '' + vendorHash: sha256-6B9O6ho4COpJy4HlkzQ0lk+ieezRO3xg9LyLHzoxYzc= goPackage: go_1_22 buildGoModule: buildGo122Module diff --git a/flake.nix b/flake.nix index 1fbbf40..63de98b 100644 --- a/flake.nix +++ b/flake.nix @@ -23,7 +23,7 @@ packages.default = pkgs.buildGo122Module { inherit name; src = ./.; - vendorHash = ""; + vendorHash = "sha256-6B9O6ho4COpJy4HlkzQ0lk+ieezRO3xg9LyLHzoxYzc="; buildModules = [ "cmd/${name}" ]; }; }; From d95ed1ba6605979f8d07f5351d59e12bc306e315 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:06:03 +0100 Subject: [PATCH 12/25] fix: use altf4llc-os cachix repo --- .github/workflows/flake.yaml | 2 +- build-configs.yaml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/flake.yaml b/.github/workflows/flake.yaml index baa07ed..9615e2e 100644 --- a/.github/workflows/flake.yaml +++ b/.github/workflows/flake.yaml @@ -7,7 +7,7 @@ on: pull_request: env: - CACHIX_BINARY_CACHE: altf4llc + CACHIX_BINARY_CACHE: altf4llc-os jobs: check: diff --git a/build-configs.yaml b/build-configs.yaml index 237a25f..d3455b5 100644 --- a/build-configs.yaml +++ b/build-configs.yaml @@ -3,6 +3,8 @@ name: build-configs template: go-cobra-cli parameters: nix: + cachix: + binaryCache: altf4llc-os vendorHash: sha256-6B9O6ho4COpJy4HlkzQ0lk+ieezRO3xg9LyLHzoxYzc= goPackage: go_1_22 buildGoModule: buildGo122Module From 8302569c59be245709052bf8c9eecf9844c9fe4d Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:08:47 +0100 Subject: [PATCH 13/25] feat: add docker build to go-cobra-cli flake --- .../templates/go-cobra-cli/flake.nix | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/internal/templates/templates/go-cobra-cli/flake.nix b/internal/templates/templates/go-cobra-cli/flake.nix index 8d10df6..552f7f6 100644 --- a/internal/templates/templates/go-cobra-cli/flake.nix +++ b/internal/templates/templates/go-cobra-cli/flake.nix @@ -20,11 +20,24 @@ inputsFrom = [ config.packages.default ]; }; - packages.default = pkgs.{{ .Nix.BuildGoModule }} { - inherit name; - src = ./.; - vendorHash = "{{ .Nix.VendorHash }}"; - buildModules = [ "cmd/${name}" ]; + packages = { + default = pkgs.{{ .Nix.BuildGoModule }} { + inherit name; + src = ./.; + vendorHash = "{{ .Nix.VendorHash }}"; + buildModules = [ "cmd/${name}" ]; + }; + + docker = pkgs.dockerTools.buildImage { + inherit name; + tag = version; + config = { + Entrypoint = [ "${config.packages.default}/bin/${name}" ]; + Env = [ + "SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" + ]; + }; + }; }; }; }; From 7631c633d6e2a4b423ad4bcaf3843ad060fc4e0c Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:27:43 +0100 Subject: [PATCH 14/25] feat: update architecture to be more DRY --- .github/workflows/flake.yaml | 1 - .github/workflows/golangci-lint.yaml | 1 - flake.nix | 23 ++++++-- internal/config/go_cobra_cli.go | 55 +++++++------------ internal/templates/templates.go | 55 ++++++++++++++++++- .../{go-cobra-cli => common/all}/.envrc | 0 .../{go-cobra-cli => common/go}/.editorconfig | 0 .../.github__workflows__golangci-lint.yaml | 4 +- .../go}/.golangci.yaml | 0 .../.github__workflows__flake.yaml | 10 ++-- .../templates/go-cobra-cli/flake.nix | 2 +- 11 files changed, 98 insertions(+), 53 deletions(-) rename internal/templates/templates/{go-cobra-cli => common/all}/.envrc (100%) rename internal/templates/templates/{go-cobra-cli => common/go}/.editorconfig (100%) rename internal/templates/templates/{go-cobra-cli => common/go}/.github__workflows__golangci-lint.yaml (95%) rename internal/templates/templates/{go-cobra-cli => common/go}/.golangci.yaml (100%) diff --git a/.github/workflows/flake.yaml b/.github/workflows/flake.yaml index 9615e2e..bbd3df8 100644 --- a/.github/workflows/flake.yaml +++ b/.github/workflows/flake.yaml @@ -33,4 +33,3 @@ jobs: name: ${{ env.CACHIX_BINARY_CACHE }} - uses: actions/checkout@v4 - run: nix develop -c just build - \ No newline at end of file diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml index 1b6b833..1aacaa1 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci-lint.yaml @@ -15,7 +15,6 @@ jobs: GOPRIVATE: github.com/ALT-F4-LLC/quirk-service-kit runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: diff --git a/flake.nix b/flake.nix index 63de98b..f71315b 100644 --- a/flake.nix +++ b/flake.nix @@ -20,11 +20,24 @@ inputsFrom = [ config.packages.default ]; }; - packages.default = pkgs.buildGo122Module { - inherit name; - src = ./.; - vendorHash = "sha256-6B9O6ho4COpJy4HlkzQ0lk+ieezRO3xg9LyLHzoxYzc="; - buildModules = [ "cmd/${name}" ]; + packages = { + default = pkgs.buildGo122Module { + inherit name; + src = ./.; + vendorHash = "sha256-6B9O6ho4COpJy4HlkzQ0lk+ieezRO3xg9LyLHzoxYzc="; + buildModules = [ "cmd/${name}" ]; + }; + + docker = pkgs.dockerTools.buildImage { + inherit name; + tag = "latest"; + config = { + Entrypoint = [ "${config.packages.default}/bin/${name}" ]; + Env = [ + "SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" + ]; + }; + }; }; }; }; diff --git a/internal/config/go_cobra_cli.go b/internal/config/go_cobra_cli.go index e3d59b6..3c496a3 100644 --- a/internal/config/go_cobra_cli.go +++ b/internal/config/go_cobra_cli.go @@ -1,22 +1,11 @@ package config import ( - "os" - "strings" + "text/template" "github.com/ALT-F4-LLC/build-configs/internal/templates" ) -var goCobraCliTemplates = []string{ - ".editorconfig", - ".envrc", - ".github/workflows/flake.yaml", - ".github/workflows/golangci-lint.yaml", - ".golangci.yaml", - "flake.nix", - "justfile", -} - type GoCobraCliConfig struct { Config Nix NixGoConfig `json:"nix,omitempty" yaml:"nix,omitempty"` @@ -42,30 +31,24 @@ func NewGoCobraCliConfig(c Config) GoCobraCliConfig { } func (c GoCobraCliConfig) Render() error { - out := map[string]string{} - - for _, tmplPath := range goCobraCliTemplates { - sb := strings.Builder{} - err := templates.GoCobraCliTemplates.ExecuteTemplate( - &sb, - templates.PathToTemplate(tmplPath), - c, - ) - if err != nil { - return err - } - out["./"+tmplPath] = sb.String() - } - - for k, v := range out { - if err := templates.EnsureDirExists(k); err != nil { - return err - } - - if err := os.WriteFile(k, []byte(v), 0644); err != nil { - return err - } + files, err := templates.RenderTemplates(map[*template.Template][]string{ + templates.AllCommonTemplates: { + ".envrc", + }, + templates.GoCommonTemplates: { + ".editorconfig", + ".github/workflows/golangci-lint.yaml", + ".golangci.yaml", + }, + templates.GoCobraCliTemplates: { + ".github/workflows/flake.yaml", + "flake.nix", + "justfile", + }, + }, c) + if err != nil { + return err } - return nil + return templates.WriteFiles(files) } diff --git a/internal/templates/templates.go b/internal/templates/templates.go index 5a6c2e5..9dddb26 100644 --- a/internal/templates/templates.go +++ b/internal/templates/templates.go @@ -2,16 +2,67 @@ package templates import ( "embed" + "os" + "strings" "text/template" ) var ( + //go:embed all:templates/common/all/* + allCommonFS embed.FS + + //go:embed all:templates/common/go/* + goCommonFS embed.FS + //go:embed all:templates/go-cobra-cli/* - content embed.FS + goCobraCliFS embed.FS + AllCommonTemplates *template.Template + GoCommonTemplates *template.Template GoCobraCliTemplates *template.Template ) func init() { - GoCobraCliTemplates = template.Must(template.ParseFS(content, "templates/go-cobra-cli/*")) + AllCommonTemplates = template.Must(template.ParseFS(allCommonFS, "templates/common/all/*")) + GoCommonTemplates = template.Must(template.ParseFS(goCommonFS, "templates/common/go/*")) + GoCobraCliTemplates = template.Must(template.ParseFS(goCobraCliFS, "templates/go-cobra-cli/*")) +} + +func RenderTemplates(in map[*template.Template][]string, context any) (map[string]string, error) { + files := map[string]string{} + + for tmpl, set := range in { + for _, tmplPath := range set { + out, err := RenderTemplate(tmpl, tmplPath, context) + if err != nil { + return files, err + } + + files["./"+tmplPath] = out + } + } + + return files, nil +} + +func RenderTemplate(t *template.Template, path string, context any) (string, error) { + sb := strings.Builder{} + if err := t.ExecuteTemplate(&sb, PathToTemplate(path), context); err != nil { + return "", err + } + return sb.String(), nil +} + +func WriteFiles(in map[string]string) error { + for k, v := range in { + if err := EnsureDirExists(k); err != nil { + return err + } + + if err := os.WriteFile(k, []byte(v), 0644); err != nil { + return err + } + } + + return nil } diff --git a/internal/templates/templates/go-cobra-cli/.envrc b/internal/templates/templates/common/all/.envrc similarity index 100% rename from internal/templates/templates/go-cobra-cli/.envrc rename to internal/templates/templates/common/all/.envrc diff --git a/internal/templates/templates/go-cobra-cli/.editorconfig b/internal/templates/templates/common/go/.editorconfig similarity index 100% rename from internal/templates/templates/go-cobra-cli/.editorconfig rename to internal/templates/templates/common/go/.editorconfig diff --git a/internal/templates/templates/go-cobra-cli/.github__workflows__golangci-lint.yaml b/internal/templates/templates/common/go/.github__workflows__golangci-lint.yaml similarity index 95% rename from internal/templates/templates/go-cobra-cli/.github__workflows__golangci-lint.yaml rename to internal/templates/templates/common/go/.github__workflows__golangci-lint.yaml index ea47e9b..b3390ca 100644 --- a/internal/templates/templates/go-cobra-cli/.github__workflows__golangci-lint.yaml +++ b/internal/templates/templates/common/go/.github__workflows__golangci-lint.yaml @@ -15,7 +15,7 @@ jobs: GOPRIVATE: github.com/ALT-F4-LLC/quirk-service-kit runs-on: ubuntu-latest steps: - {{ if .PrivateModules }} + {{ if .PrivateModules -}} - id: generate-token uses: actions/create-github-app-token@v1 with: @@ -27,7 +27,7 @@ jobs: machine: github.com password: ${{"{{"}} steps.generate-token.outputs.token ${{"}}"}} username: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_USER ${{"}}"}} - {{ end }} + {{ end -}} - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: diff --git a/internal/templates/templates/go-cobra-cli/.golangci.yaml b/internal/templates/templates/common/go/.golangci.yaml similarity index 100% rename from internal/templates/templates/go-cobra-cli/.golangci.yaml rename to internal/templates/templates/common/go/.golangci.yaml diff --git a/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml b/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml index 23294d6..29d3d3a 100644 --- a/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml +++ b/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml @@ -31,7 +31,7 @@ jobs: with: authToken: ${{"{{"}} secrets.ALTF4LLC_CACHIX_AUTH_TOKEN {{"}}"}} name: ${{"{{"}} env.CACHIX_BINARY_CACHE {{"}}"}} - {{ if .PrivateModules -}} +{{ if .PrivateModules -}} - id: generate-token uses: actions/create-github-app-token@v1 with: @@ -43,13 +43,13 @@ jobs: machine: github.com password: ${{"{{"}} steps.generate-token.outputs.token {{"}}"}} username: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_USER {{"}}"}} - {{ end -}} + {{- end -}} - uses: actions/checkout@v4 - {{ if .PrivateModules -}} +{{ if .PrivateModules -}} - run: cp --no-preserve=mode ~/.netrc /tmp/.netrc - {{ end -}} + {{- end -}} - run: nix develop -c just build - {{ if .PrivateModules -}} +{{ if .PrivateModules -}} - run: rm -rf /tmp/.netrc if: success() || failure() {{- end -}} diff --git a/internal/templates/templates/go-cobra-cli/flake.nix b/internal/templates/templates/go-cobra-cli/flake.nix index 552f7f6..2cb6b5c 100644 --- a/internal/templates/templates/go-cobra-cli/flake.nix +++ b/internal/templates/templates/go-cobra-cli/flake.nix @@ -30,7 +30,7 @@ docker = pkgs.dockerTools.buildImage { inherit name; - tag = version; + tag = "latest"; config = { Entrypoint = [ "${config.packages.default}/bin/${name}" ]; Env = [ From 43fc1774cee497dcffca64bd581cc362e9c6c655 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:30:43 +0100 Subject: [PATCH 15/25] feat: update golangci-lint config template --- .github/workflows/flake.yaml | 4 ++-- .golangci.yaml | 2 +- internal/cli/generate.go | 4 +++- internal/templates/templates/common/go/.golangci.yaml | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/flake.yaml b/.github/workflows/flake.yaml index bbd3df8..68df52f 100644 --- a/.github/workflows/flake.yaml +++ b/.github/workflows/flake.yaml @@ -31,5 +31,5 @@ jobs: with: authToken: ${{ secrets.ALTF4LLC_CACHIX_AUTH_TOKEN }} name: ${{ env.CACHIX_BINARY_CACHE }} - - uses: actions/checkout@v4 - - run: nix develop -c just build +- uses: actions/checkout@v4 +- run: nix develop -c just build diff --git a/.golangci.yaml b/.golangci.yaml index c487593..8321d68 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,5 +1,5 @@ --- issues: exclude: - - "Error return value of `\(github.com/go-kit/log.Logger\).Log` is not checked" + - Error return value of `\(github.com/go-kit/log.Logger\).Log` is not checked diff --git a/internal/cli/generate.go b/internal/cli/generate.go index 7d4de42..74c143e 100644 --- a/internal/cli/generate.go +++ b/internal/cli/generate.go @@ -26,7 +26,9 @@ var generateCmd = &cobra.Command{ return fmt.Errorf("could not create templater: %v", err) } - fmt.Printf("%+v\n", t) + if debug { + fmt.Printf("%+v\n", t) + } return t.Render() }, diff --git a/internal/templates/templates/common/go/.golangci.yaml b/internal/templates/templates/common/go/.golangci.yaml index c236fed..1084444 100644 --- a/internal/templates/templates/common/go/.golangci.yaml +++ b/internal/templates/templates/common/go/.golangci.yaml @@ -2,8 +2,8 @@ issues: exclude: {{ range .Lint.Exclude -}} - - "{{ . }}" + - {{ . }} {{- end }} {{ range .Lint.ExtraExclude -}} - - "{{ . }}" + - {{ . }} {{- end }} From ed2f2a796e52e45db0f617ca757225df1761b011 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:32:00 +0100 Subject: [PATCH 16/25] feat: update flake.yaml template --- .github/workflows/flake.yaml | 5 +++-- .../templates/go-cobra-cli/.github__workflows__flake.yaml | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/flake.yaml b/.github/workflows/flake.yaml index 68df52f..9615e2e 100644 --- a/.github/workflows/flake.yaml +++ b/.github/workflows/flake.yaml @@ -31,5 +31,6 @@ jobs: with: authToken: ${{ secrets.ALTF4LLC_CACHIX_AUTH_TOKEN }} name: ${{ env.CACHIX_BINARY_CACHE }} -- uses: actions/checkout@v4 -- run: nix develop -c just build + - uses: actions/checkout@v4 + - run: nix develop -c just build + \ No newline at end of file diff --git a/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml b/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml index 29d3d3a..174064a 100644 --- a/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml +++ b/internal/templates/templates/go-cobra-cli/.github__workflows__flake.yaml @@ -31,7 +31,7 @@ jobs: with: authToken: ${{"{{"}} secrets.ALTF4LLC_CACHIX_AUTH_TOKEN {{"}}"}} name: ${{"{{"}} env.CACHIX_BINARY_CACHE {{"}}"}} -{{ if .PrivateModules -}} + {{ if .PrivateModules -}} - id: generate-token uses: actions/create-github-app-token@v1 with: @@ -45,11 +45,11 @@ jobs: username: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_USER {{"}}"}} {{- end -}} - uses: actions/checkout@v4 -{{ if .PrivateModules -}} + {{ if .PrivateModules -}} - run: cp --no-preserve=mode ~/.netrc /tmp/.netrc {{- end -}} - run: nix develop -c just build -{{ if .PrivateModules -}} + {{ if .PrivateModules -}} - run: rm -rf /tmp/.netrc if: success() || failure() {{- end -}} From cf8a3c16bb6dcb8e186637d996842576ac1171cf Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:32:46 +0100 Subject: [PATCH 17/25] chore: remove old rust code, will be replaced --- Cargo.lock | 764 ------------------ Cargo.toml | 14 - example.json | 5 - src/cli/generate.rs | 15 - src/cli/mod.rs | 29 - src/config/dockerfile.rs | 33 - src/config/flake.rs | 73 -- src/config/library.rs | 17 - src/config/mod.rs | 98 --- src/config/pulumi.rs | 33 - src/config/service.rs | 25 - src/main.rs | 9 - src/template.rs | 269 ------ .../lambda/go/.github/workflows/go.yaml.j2 | 29 - .../.github/workflows/golangci-lint.yaml.j2 | 21 - src/template/lambda/go/.gitignore.j2 | 107 --- src/template/lambda/go/justfile.j2 | 24 - .../typescript/.circleci/config.yml.j2 | 162 ---- .../library/typescript/.eslintignore.j2 | 7 - .../library/typescript/.eslintrc.js.j2 | 23 - src/template/library/typescript/.gitignore.j2 | 154 ---- src/template/library/typescript/.npmignore.j2 | 13 - .../library/typescript/.prettierignore.j2 | 17 - .../library/typescript/.prettierrc.js.j2 | 14 - src/template/library/typescript/Dockerfile.j2 | 35 - .../library/typescript/jest.config.js.j2 | 15 - src/template/library/typescript/justfile.j2 | 51 -- .../library/typescript/tsconfig.json.j2 | 36 - .../pulumi/go/.circleci/config.yml.j2 | 188 ----- src/template/pulumi/go/.dockerignore.j2 | 8 - src/template/pulumi/go/.gitignore.j2 | 9 - src/template/pulumi/go/Dockerfile.j2 | 59 -- src/template/pulumi/go/Pulumi.yaml.j2 | 10 - src/template/pulumi/go/justfile.j2 | 63 -- .../pulumi/typescript/.circleci/config.yml.j2 | 188 ----- .../pulumi/typescript/.dockerignore.j2 | 8 - src/template/pulumi/typescript/.gitignore.j2 | 10 - src/template/pulumi/typescript/.npmrc.j2 | 6 - src/template/pulumi/typescript/Dockerfile.j2 | 56 -- src/template/pulumi/typescript/Pulumi.yaml.j2 | 8 - src/template/pulumi/typescript/justfile.j2 | 63 -- .../pulumi/typescript/tsconfig.json.j2 | 21 - .../service/go/.github/workflows/flake.yml.j2 | 17 - src/template/service/go/.gitignore.j2 | 105 --- .../typescript/.circleci/config.yml.j2 | 194 ----- .../service/typescript/.dockerignore.j2 | 12 - .../service/typescript/.eslintignore.j2 | 6 - .../service/typescript/.eslintrc.js.j2 | 29 - src/template/service/typescript/.npmrc.j2 | 6 - .../service/typescript/.prettierignore.j2 | 18 - .../service/typescript/.prettierrc.js.j2 | 14 - src/template/service/typescript/Dockerfile.j2 | 83 -- .../typescript/docker-entrypoint.sh.j2 | 30 - .../service/typescript/jest.config.js.j2 | 16 - src/template/service/typescript/justfile.j2 | 57 -- .../service/typescript/tsconfig.json.j2 | 30 - 56 files changed, 3406 deletions(-) delete mode 100644 Cargo.lock delete mode 100644 Cargo.toml delete mode 100644 example.json delete mode 100644 src/cli/generate.rs delete mode 100644 src/cli/mod.rs delete mode 100644 src/config/dockerfile.rs delete mode 100644 src/config/flake.rs delete mode 100644 src/config/library.rs delete mode 100644 src/config/mod.rs delete mode 100644 src/config/pulumi.rs delete mode 100644 src/config/service.rs delete mode 100644 src/main.rs delete mode 100644 src/template.rs delete mode 100644 src/template/lambda/go/.github/workflows/go.yaml.j2 delete mode 100644 src/template/lambda/go/.github/workflows/golangci-lint.yaml.j2 delete mode 100644 src/template/lambda/go/.gitignore.j2 delete mode 100644 src/template/lambda/go/justfile.j2 delete mode 100644 src/template/library/typescript/.circleci/config.yml.j2 delete mode 100644 src/template/library/typescript/.eslintignore.j2 delete mode 100644 src/template/library/typescript/.eslintrc.js.j2 delete mode 100644 src/template/library/typescript/.gitignore.j2 delete mode 100644 src/template/library/typescript/.npmignore.j2 delete mode 100644 src/template/library/typescript/.prettierignore.j2 delete mode 100644 src/template/library/typescript/.prettierrc.js.j2 delete mode 100644 src/template/library/typescript/Dockerfile.j2 delete mode 100644 src/template/library/typescript/jest.config.js.j2 delete mode 100644 src/template/library/typescript/justfile.j2 delete mode 100644 src/template/library/typescript/tsconfig.json.j2 delete mode 100644 src/template/pulumi/go/.circleci/config.yml.j2 delete mode 100644 src/template/pulumi/go/.dockerignore.j2 delete mode 100644 src/template/pulumi/go/.gitignore.j2 delete mode 100644 src/template/pulumi/go/Dockerfile.j2 delete mode 100644 src/template/pulumi/go/Pulumi.yaml.j2 delete mode 100644 src/template/pulumi/go/justfile.j2 delete mode 100644 src/template/pulumi/typescript/.circleci/config.yml.j2 delete mode 100644 src/template/pulumi/typescript/.dockerignore.j2 delete mode 100644 src/template/pulumi/typescript/.gitignore.j2 delete mode 100644 src/template/pulumi/typescript/.npmrc.j2 delete mode 100644 src/template/pulumi/typescript/Dockerfile.j2 delete mode 100644 src/template/pulumi/typescript/Pulumi.yaml.j2 delete mode 100644 src/template/pulumi/typescript/justfile.j2 delete mode 100644 src/template/pulumi/typescript/tsconfig.json.j2 delete mode 100644 src/template/service/go/.github/workflows/flake.yml.j2 delete mode 100644 src/template/service/go/.gitignore.j2 delete mode 100644 src/template/service/typescript/.circleci/config.yml.j2 delete mode 100644 src/template/service/typescript/.dockerignore.j2 delete mode 100644 src/template/service/typescript/.eslintignore.j2 delete mode 100644 src/template/service/typescript/.eslintrc.js.j2 delete mode 100644 src/template/service/typescript/.npmrc.j2 delete mode 100644 src/template/service/typescript/.prettierignore.j2 delete mode 100644 src/template/service/typescript/.prettierrc.js.j2 delete mode 100644 src/template/service/typescript/Dockerfile.j2 delete mode 100644 src/template/service/typescript/docker-entrypoint.sh.j2 delete mode 100644 src/template/service/typescript/jest.config.js.j2 delete mode 100644 src/template/service/typescript/justfile.j2 delete mode 100644 src/template/service/typescript/tsconfig.json.j2 diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 5e73baf..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,764 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "aho-corasick" -version = "0.7.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" -dependencies = [ - "memchr", -] - -[[package]] -name = "anyhow" -version = "1.0.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "block-buffer" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bstr" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45ea9b00a7b3f2988e9a65ad3917e62123c38dba709b666506207be96d1790b" -dependencies = [ - "memchr", - "serde", -] - -[[package]] -name = "build-configs" -version = "0.1.0" -dependencies = [ - "anyhow", - "clap", - "serde", - "serde_json", - "strum_macros", - "tera", -] - -[[package]] -name = "cc" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "clap" -version = "4.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec7a4128863c188deefe750ac1d1dfe66c236909f845af04beed823638dc1b2" -dependencies = [ - "bitflags", - "clap_derive", - "clap_lex", - "is-terminal", - "once_cell", - "strsim", - "termcolor", - "terminal_size", - "unicase", - "unicode-width", -] - -[[package]] -name = "clap_derive" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade" -dependencies = [ - "os_str_bytes", -] - -[[package]] -name = "cpufeatures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "digest" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "errno" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" -dependencies = [ - "errno-dragonfly", - "libc", - "winapi", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "generic-array" -version = "0.14.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "globset" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" -dependencies = [ - "aho-corasick", - "bstr", - "fnv", - "log", - "regex", -] - -[[package]] -name = "globwalk" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" -dependencies = [ - "bitflags", - "ignore", - "walkdir", -] - -[[package]] -name = "heck" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" - -[[package]] -name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - -[[package]] -name = "ignore" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" -dependencies = [ - "globset", - "lazy_static", - "log", - "memchr", - "regex", - "same-file", - "thread_local", - "walkdir", - "winapi-util", -] - -[[package]] -name = "io-lifetimes" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "is-terminal" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" -dependencies = [ - "hermit-abi", - "io-lifetimes", - "rustix", - "windows-sys", -] - -[[package]] -name = "itoa" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - -[[package]] -name = "linux-raw-sys" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" - -[[package]] -name = "log" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - -[[package]] -name = "os_str_bytes" -version = "6.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" - -[[package]] -name = "pest" -version = "2.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ab62d2fa33726dbe6321cc97ef96d8cde531e3eeaf858a058de53a8a6d40d8f" -dependencies = [ - "thiserror", - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf026e2d0581559db66d837fe5242320f525d85c76283c61f4d51a1238d65ea" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b27bd18aa01d91c8ed2b61ea23406a676b42d82609c6e2581fba42f0c15f17f" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pest_meta" -version = "2.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f02b677c1859756359fc9983c2e56a0237f18624a3789528804406b7e915e5d" -dependencies = [ - "once_cell", - "pest", - "sha2", -] - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - -[[package]] -name = "proc-macro2" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "regex" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" - -[[package]] -name = "rustix" -version = "0.36.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" -dependencies = [ - "bitflags", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys", - "windows-sys", -] - -[[package]] -name = "rustversion" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" - -[[package]] -name = "ryu" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "serde" -version = "1.0.152" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.152" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sha2" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "strum_macros" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn", -] - -[[package]] -name = "syn" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tera" -version = "1.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3df578c295f9ec044ff1c829daf31bb7581d5b3c2a7a3d87419afe1f2531438c" -dependencies = [ - "globwalk", - "lazy_static", - "pest", - "pest_derive", - "regex", - "serde", - "serde_json", - "unic-segment", -] - -[[package]] -name = "termcolor" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "terminal_size" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb20089a8ba2b69debd491f8d2d023761cbf196e999218c591fa1e7e15a21907" -dependencies = [ - "rustix", - "windows-sys", -] - -[[package]] -name = "thiserror" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "thread_local" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" -dependencies = [ - "once_cell", -] - -[[package]] -name = "typenum" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" - -[[package]] -name = "ucd-trie" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" - -[[package]] -name = "unic-char-property" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221" -dependencies = [ - "unic-char-range", -] - -[[package]] -name = "unic-char-range" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc" - -[[package]] -name = "unic-common" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc" - -[[package]] -name = "unic-segment" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4ed5d26be57f84f176157270c112ef57b86debac9cd21daaabbe56db0f88f23" -dependencies = [ - "unic-ucd-segment", -] - -[[package]] -name = "unic-ucd-segment" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2079c122a62205b421f499da10f3ee0f7697f012f55b675e002483c73ea34700" -dependencies = [ - "unic-char-property", - "unic-char-range", - "unic-ucd-version", -] - -[[package]] -name = "unic-ucd-version" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4" -dependencies = [ - "unic-common", -] - -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check", -] - -[[package]] -name = "unicode-ident" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" - -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "walkdir" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" -dependencies = [ - "same-file", - "winapi", - "winapi-util", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" - -[[package]] -name = "windows_i686_msvc" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index cab7a38..0000000 --- a/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "build-configs" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -anyhow = "1.0.68" -clap = { version = "4.1.1", features = ["derive", "unstable-doc"] } -serde = { version = "1.0.152", features = ["derive"] } -serde_json = "1.0.91" -strum_macros = "0.24.3" -tera = { version = "1", default-features = false } diff --git a/example.json b/example.json deleted file mode 100644 index c7a0321..0000000 --- a/example.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "pulumi-example", - "language": "typescript", - "template": "pulumi" -} diff --git a/src/cli/generate.rs b/src/cli/generate.rs deleted file mode 100644 index 6dddbc2..0000000 --- a/src/cli/generate.rs +++ /dev/null @@ -1,15 +0,0 @@ -use anyhow::Result; -use serde_json::from_str; -use std::fs::read_to_string; - -use crate::{config::Configuration, template}; - -pub fn run(config_path: &str) -> Result<()> { - let config_contents = read_to_string(config_path)?; - - let config: Configuration = from_str(&config_contents)?; - - template::render_templates(&config)?; - - Ok(()) -} diff --git a/src/cli/mod.rs b/src/cli/mod.rs deleted file mode 100644 index 84a12a3..0000000 --- a/src/cli/mod.rs +++ /dev/null @@ -1,29 +0,0 @@ -use anyhow::Result; -use clap::{Parser, Subcommand}; - -mod generate; - -#[derive(Parser)] -#[command(author, version, about, long_about = None)] -#[command(propagate_version = true)] -pub struct BuildConfigs { - #[command(subcommand)] - pub command: Commands, -} - -#[derive(Subcommand)] -pub enum Commands { - Generate { - #[arg(short, long)] - #[arg(default_value_t = String::from("build.json"))] - config_path: String, - }, -} - -pub fn run() -> Result<()> { - let cli = BuildConfigs::parse(); - - match &cli.command { - Commands::Generate { config_path } => generate::run(config_path), - } -} diff --git a/src/config/dockerfile.rs b/src/config/dockerfile.rs deleted file mode 100644 index 99fb198..0000000 --- a/src/config/dockerfile.rs +++ /dev/null @@ -1,33 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize, Debug)] -pub struct Configuration { - #[serde(default = "default_dockerfile_build_post_install")] - pub build_post_install: Vec, - - #[serde(default = "default_dockerfile_registry")] - pub registry: String, - - #[serde(default = "default_dockerfile_service_post_install")] - pub service_post_install: Vec, -} - -fn default_dockerfile_build_post_install() -> Vec { - vec![] -} - -fn default_dockerfile_service_post_install() -> Vec { - vec![] -} - -fn default_dockerfile_registry() -> String { - "677459762413.dkr.ecr.us-west-2.amazonaws.com".to_string() -} - -pub fn default_config() -> Configuration { - Configuration { - build_post_install: default_dockerfile_build_post_install(), - registry: default_dockerfile_registry(), - service_post_install: default_dockerfile_service_post_install(), - } -} diff --git a/src/config/flake.rs b/src/config/flake.rs deleted file mode 100644 index 227f41d..0000000 --- a/src/config/flake.rs +++ /dev/null @@ -1,73 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize, Debug)] -pub struct DevShell { - #[serde(default = "default_build_inputs")] - pub build_inputs: Vec, - - #[serde(default = "default_native_build_inputs")] - pub native_build_inputs: Vec, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct Package { - #[serde(default = "default_build_inputs")] - pub build_inputs: Vec, - - #[serde(default = "default_native_build_inputs")] - pub native_build_inputs: Vec, - - #[serde(default = "default_vendor_sha256")] - pub vendor_sha256: String, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct Configuration { - #[serde(default = "default_binary_cache")] - pub binary_cache: bool, - - #[serde(default = "default_devshell")] - pub devshell: DevShell, - - #[serde(default = "default_package")] - pub package: Package, -} - -fn default_binary_cache() -> bool { - false -} - -fn default_build_inputs() -> Vec { - vec![] -} - -fn default_native_build_inputs() -> Vec { - vec![] -} - -fn default_vendor_sha256() -> String { - "".to_string() -} - -pub fn default_devshell() -> DevShell { - DevShell { - build_inputs: default_build_inputs(), - native_build_inputs: default_native_build_inputs(), - } -} - -pub fn default_package() -> Package { - Package { - build_inputs: default_build_inputs(), - native_build_inputs: default_native_build_inputs(), - vendor_sha256: default_vendor_sha256(), - } -} - -pub fn default_config() -> Configuration { - Configuration { - binary_cache: default_binary_cache(), - devshell: default_devshell(), - package: default_package(), - } -} diff --git a/src/config/library.rs b/src/config/library.rs deleted file mode 100644 index 2d95b7d..0000000 --- a/src/config/library.rs +++ /dev/null @@ -1,17 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize, Debug)] -pub struct Configuration { - #[serde(default = "default_library_resource_class")] - pub resource_class: String, -} - -fn default_library_resource_class() -> String { - "small".to_string() -} - -pub fn default_library() -> Configuration { - Configuration { - resource_class: default_library_resource_class(), - } -} diff --git a/src/config/mod.rs b/src/config/mod.rs deleted file mode 100644 index b69e00a..0000000 --- a/src/config/mod.rs +++ /dev/null @@ -1,98 +0,0 @@ -use serde::{Deserialize, Serialize}; -use std::vec; -use strum_macros::Display; - -mod dockerfile; -mod flake; -mod library; -mod pulumi; -mod service; - -#[derive(Serialize, Deserialize, Debug)] -pub struct Dependencies { - #[serde(default = "default_dependencies_private")] - pub private: bool, -} - -#[derive(Serialize, Deserialize, Debug, Display, PartialEq)] -#[serde(rename_all = "lowercase")] -#[strum(serialize_all = "lowercase")] -pub enum Language { - Go, - Rust, - TypeScript, -} - -#[derive(Serialize, Deserialize, Debug, Display)] -#[serde(rename_all = "lowercase")] -#[strum(serialize_all = "lowercase")] -pub enum Product { - AltF4Llc, - Quirk, -} - -#[derive(Serialize, Deserialize, Debug, Display)] -#[serde(rename_all = "lowercase")] -#[strum(serialize_all = "lowercase")] -pub enum Template { - Lambda, - Library, - Pulumi, - Service, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct Configuration { - pub name: String, - pub language: Language, - pub template: Template, - - #[serde(default = "default_dependencies")] - pub dependencies: Dependencies, - - #[serde(default = "dockerfile::default_config")] - pub dockerfile: dockerfile::Configuration, - - #[serde(default = "default_environments")] - pub environments: Vec, - - #[serde(default = "flake::default_config")] - pub flake: flake::Configuration, - - #[serde(default = "library::default_library")] - pub library: library::Configuration, - - #[serde(default = "default_product")] - pub product: Product, - - #[serde(default = "pulumi::default_pulumi")] - pub pulumi: pulumi::Configuration, - - #[serde(default = "service::default_config")] - pub service: service::Configuration, - - #[serde(default = "default_version")] - pub version: String, -} - -fn default_dependencies_private() -> bool { - false -} - -fn default_dependencies() -> Dependencies { - Dependencies { - private: default_dependencies_private(), - } -} - -fn default_environments() -> Vec { - vec![] -} - -fn default_product() -> Product { - Product::AltF4Llc -} - -fn default_version() -> String { - "0.1.0".to_string() -} diff --git a/src/config/pulumi.rs b/src/config/pulumi.rs deleted file mode 100644 index 19a248f..0000000 --- a/src/config/pulumi.rs +++ /dev/null @@ -1,33 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize, Debug)] -pub struct Configuration { - #[serde(default = "default_eks_cluster")] - pub eks_cluster: String, - - #[serde(default = "default_npm")] - pub npm: bool, - - #[serde(default = "default_resource_class")] - pub resource_class: String, -} - -fn default_eks_cluster() -> String { - "".to_string() -} - -fn default_npm() -> bool { - false -} - -fn default_resource_class() -> String { - "small".to_string() -} - -pub fn default_pulumi() -> Configuration { - Configuration { - eks_cluster: default_eks_cluster(), - npm: default_npm(), - resource_class: default_resource_class(), - } -} diff --git a/src/config/service.rs b/src/config/service.rs deleted file mode 100644 index ecce4d3..0000000 --- a/src/config/service.rs +++ /dev/null @@ -1,25 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize, Debug)] -pub struct Configuration { - #[serde(default = "default_database")] - pub database: bool, - - #[serde(default = "default_tests")] - pub tests: Vec, -} - -fn default_database() -> bool { - false -} - -fn default_tests() -> Vec { - vec![] -} - -pub fn default_config() -> Configuration { - Configuration { - database: default_database(), - tests: default_tests(), - } -} diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 90233d7..0000000 --- a/src/main.rs +++ /dev/null @@ -1,9 +0,0 @@ -use anyhow::Result; - -mod cli; -mod config; -mod template; - -fn main() -> Result<()> { - cli::run() -} diff --git a/src/template.rs b/src/template.rs deleted file mode 100644 index 6647a65..0000000 --- a/src/template.rs +++ /dev/null @@ -1,269 +0,0 @@ -use std::{ - fs::{create_dir_all, write}, - path::Path, -}; - -use anyhow::Result; -use tera::{Context, Tera}; - -use crate::config::{Configuration, Language, Template}; - -#[derive(Debug)] -pub struct TemplateFile<'a> { - pub name: &'a str, -} - -pub fn get_templates(config: &Configuration) -> Vec<(&str, &str)> { - match config.template { - Template::Library => match config.language { - Language::Go => { - vec![] - } - Language::Rust => { - vec![] - } - Language::TypeScript => { - vec![ - ( - ".circleci/config.yml", - include_str!("./template/library/typescript/.circleci/config.yml.j2"), - ), - ( - "Dockerfile", - include_str!("./template/library/typescript/Dockerfile.j2"), - ), - ( - ".eslintignore", - include_str!("./template/library/typescript/Dockerfile.j2"), - ), - ( - ".eslintrc.js", - include_str!("./template/library/typescript/Dockerfile.j2"), - ), - ( - ".gitignore", - include_str!("./template/library/typescript/.gitignore.j2"), - ), - ( - "jest.config.js", - include_str!("./template/library/typescript/jest.config.js.j2"), - ), - ( - "justfile", - include_str!("./template/library/typescript/justfile.j2"), - ), - ( - ".npmignore", - include_str!("./template/library/typescript/.npmignore.j2"), - ), - ( - ".prettierignore", - include_str!("./template/library/typescript/.prettierignore.j2"), - ), - ( - ".prettierrc.js", - include_str!("./template/library/typescript/.prettierrc.js.j2"), - ), - ( - "tsconfig.json", - include_str!("./template/library/typescript/tsconfig.json.j2"), - ), - ] - } - }, - Template::Pulumi => match config.language { - Language::Go => { - vec![ - ( - ".circleci/config.yml", - include_str!("./template/pulumi/go/.circleci/config.yml.j2"), - ), - ( - ".dockerignore", - include_str!("./template/pulumi/go/.dockerignore.j2"), - ), - ( - ".gitignore", - include_str!("./template/pulumi/go/.gitignore.j2"), - ), - ( - "Dockerfile", - include_str!("./template/pulumi/go/Dockerfile.j2"), - ), - ( - "Pulumi.yaml", - include_str!("./template/pulumi/go/Pulumi.yaml.j2"), - ), - ("justfile", include_str!("./template/pulumi/go/justfile.j2")), - ] - } - Language::Rust => { - vec![] - } - Language::TypeScript => { - vec![ - ( - ".circleci/config.yml", - include_str!("./template/pulumi/typescript/.circleci/config.yml.j2"), - ), - ( - ".dockerignore", - include_str!("./template/pulumi/typescript/.dockerignore.j2"), - ), - ( - ".gitignore", - include_str!("./template/pulumi/typescript/.gitignore.j2"), - ), - ( - "Dockerfile", - include_str!("./template/pulumi/typescript/Dockerfile.j2"), - ), - ( - "Pulumi.yaml", - include_str!("./template/pulumi/typescript/Pulumi.yaml.j2"), - ), - ( - "justfile", - include_str!("./template/pulumi/typescript/justfile.j2"), - ), - ( - "tsconfig.json", - include_str!("./template/pulumi/typescript/tsconfig.json.j2"), - ), - ] - } - }, - Template::Service => match config.language { - Language::Go => { - vec![ - ( - ".github/workflows/flake.yml", - include_str!("./template/service/go/.github/workflows/flake.yml.j2"), - ), - ( - ".gitignore", - include_str!("./template/service/go/.gitignore.j2"), - ), - ] - } - Language::Rust => { - vec![] - } - Language::TypeScript => { - vec![ - ( - ".circleci/config.yml", - include_str!("./template/service/typescript/.circleci/config.yml.j2"), - ), - ( - "Dockerfile", - include_str!("./template/service/typescript/Dockerfile.j2"), - ), - ( - ".dockerignore", - include_str!("./template/service/typescript/.dockerignore.j2"), - ), - ( - ".eslintignore", - include_str!("./template/service/typescript/.eslintignore.j2"), - ), - ( - ".eslintrc.js", - include_str!("./template/service/typescript/.eslintrc.js.j2"), - ), - ( - "justfile", - include_str!("./template/service/typescript/justfile.j2"), - ), - ( - ".npmrc", - include_str!("./template/service/typescript/.npmrc.j2"), - ), - ( - "docker-entrypoint.sh", - include_str!("./template/service/typescript/docker-entrypoint.sh.j2"), - ), - ( - "jest.config.js", - include_str!("./template/service/typescript/jest.config.js.j2"), - ), - ( - ".prettierignore", - include_str!("./template/service/typescript/.prettierignore.j2"), - ), - ( - ".prettierrc.js", - include_str!("./template/service/typescript/.prettierrc.js.j2"), - ), - ( - "tsconfig.json", - include_str!("./template/service/typescript/tsconfig.json.j2"), - ), - ] - } - }, - Template::Lambda => match config.language { - Language::Go => { - vec![ - ( - ".github/workflows/go.yaml", - include_str!("./template/lambda/go/.github/workflows/go.yaml.j2"), - ), - ( - ".github/workflows/golangci-lint.yaml", - include_str!( - "./template/lambda/go/.github/workflows/golangci-lint.yaml.j2" - ), - ), - ( - ".gitignore", - include_str!("./template/lambda/go/.gitignore.j2"), - ), - ("justfile", include_str!("./template/lambda/go/justfile.j2")), - ] - } - Language::Rust => { - vec![] - } - Language::TypeScript => { - vec![] - } - }, - } -} - -pub fn render_templates(config: &Configuration) -> Result<()> { - let template_files = get_templates(&config); - let mut tera = Tera::default(); - - tera.add_raw_templates(template_files.clone())?; - - let test_unit = "unit".to_string(); - let test_unit_included = config.service.tests.contains(&test_unit); - - for (key, _) in template_files { - if key == ".npmrc" && !config.dependencies.private { - continue; - } - - if key == "jest.config.js" && !test_unit_included { - continue; - } - - let context = Context::from_serialize(&config)?; - - let data = tera.render(key, &context)?; - - let path = Path::new(key); - - let parent = path.parent().unwrap().to_str().unwrap(); - - if parent != "" { - create_dir_all(parent)?; - } - - write(path, data)?; - } - - Ok(()) -} diff --git a/src/template/lambda/go/.github/workflows/go.yaml.j2 b/src/template/lambda/go/.github/workflows/go.yaml.j2 deleted file mode 100644 index f135fa3..0000000 --- a/src/template/lambda/go/.github/workflows/go.yaml.j2 +++ /dev/null @@ -1,29 +0,0 @@ -name: go - -on: - pull_request: - push: - branches: [main] - tags: ["*"] - -jobs: - package: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-go@v4 - with: - go-version: '1.20' - - - uses: extractions/setup-just@v1 - - - run: just package - if: github.ref != 'refs/heads/main' - - - run: just deploy dev - if: github.ref == 'refs/heads/main' - env: - AWS_ACCESS_KEY_ID: ${% raw %}{{ secrets.AWS_ACCESS_KEY_ID }}{% endraw %} - AWS_DEFAULT_REGION: ${% raw %}{{ secrets.AWS_DEFAULT_REGION }}{% endraw %} - AWS_SECRET_ACCESS_KEY: ${% raw %}{{ secrets.AWS_SECRET_ACCESS_KEY }}{% endraw %} diff --git a/src/template/lambda/go/.github/workflows/golangci-lint.yaml.j2 b/src/template/lambda/go/.github/workflows/golangci-lint.yaml.j2 deleted file mode 100644 index 26f0e7b..0000000 --- a/src/template/lambda/go/.github/workflows/golangci-lint.yaml.j2 +++ /dev/null @@ -1,21 +0,0 @@ -name: golangci-lint - -on: - pull_request: - -permissions: - contents: read - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-go@v4 - with: - go-version: '1.20' - - - uses: golangci/golangci-lint-action@v3 - with: - version: v1.54 diff --git a/src/template/lambda/go/.gitignore.j2 b/src/template/lambda/go/.gitignore.j2 deleted file mode 100644 index 843cfdb..0000000 --- a/src/template/lambda/go/.gitignore.j2 +++ /dev/null @@ -1,107 +0,0 @@ -*.zip -.direnv -/bootstrap -/openapi-spec.json -/result - -# Created by https://www.toptal.com/developers/gitignore/api/go,linux,macos,windows -# Edit at https://www.toptal.com/developers/gitignore?templates=go,linux,macos,windows - -### Go ### -# 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 - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### macOS ### -# 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 - -### macOS Patch ### -# iCloud generated files -*.icloud - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/go,linux,macos,windows diff --git a/src/template/lambda/go/justfile.j2 b/src/template/lambda/go/justfile.j2 deleted file mode 100644 index a9f0e74..0000000 --- a/src/template/lambda/go/justfile.j2 +++ /dev/null @@ -1,24 +0,0 @@ -generate rest_api_id stage_name: - aws apigateway get-export \ - --export-type "oas30" \ - --rest-api-id "{% raw %}{{ rest_api_id }}{% endraw %}" \ - --stage-name "{% raw %}{{ stage_name }}{% endraw %}" \ - openapi-spec.json | jq -r "." - rm -rf internal/quirk_private - mkdir -p internal/quirk_private - oapi-codegen \ - -generate "types,client" \ - -package quirk_private \ - openapi-spec.json > internal/quirk_private/client.gen.go - -package: - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ - go build -ldflags="-s -w" -tags lambda.norpc ./cmd/bootstrap - zip lambda.zip bootstrap - -deploy environment: package - aws lambda update-function-code \ - --function-name "{% if product != 'altf4llc' %}{{ product }}-{% endif %}{{ name }}-{% raw %}{{ environment }}{% endraw %}" \ - --output json \ - --zip-file "fileb://lambda.zip" \ - | jq ".CodeSha256" diff --git a/src/template/library/typescript/.circleci/config.yml.j2 b/src/template/library/typescript/.circleci/config.yml.j2 deleted file mode 100644 index 6e06922..0000000 --- a/src/template/library/typescript/.circleci/config.yml.j2 +++ /dev/null @@ -1,162 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -orbs: - aws-cli: circleci/aws-cli@3.1.3 - -parameters: - image_tag: - default: "{{ product }}-{{ name }}" - type: string - registry: - default: "{{ dockerfile.registry }}" - type: string - -commands: - setup-base: - steps: - - checkout - - - aws-cli/install - - - run: - name: Install Doppler CLI - latest - command: | - (curl -Ls https://cli.doppler.com/install.sh \ - || wget -qO- https://cli.doppler.com/install.sh) \ - | sh -s -- --no-install --no-package-manager - - mkdir -p /tmp/doppler - mv ./doppler /tmp/doppler/doppler - - echo 'export PATH=/tmp/doppler:"$PATH"' >> "$BASH_ENV" - - - run: - name: Install Just CLI - latest - command: | - curl \ - --proto '=https' \ - --tlsv1.2 -sSf https://just.systems/install.sh \ - | bash -s -- --to /tmp/just - - echo 'export PATH=/tmp/just:"$PATH"' >> "$BASH_ENV" - - - setup_remote_docker: - docker_layer_caching: true - version: 20.10.17 - - - run: - name: Login to ECR - command: just login - -jobs: - build: - docker: - - image: cimg/base:current - resource_class: small - - steps: - - setup-base - - - run: - name: Build images - command: just build "${CIRCLE_SHA1}" - - - run: - name: Push images - command: just push "${CIRCLE_SHA1}" - - lint: - docker: - - image: << pipeline.parameters.registry >>/<< pipeline.parameters.image_tag >>:${CIRCLE_SHA1} - aws_auth: - aws_access_key_id: $AWS_ACCESS_KEY_ID - aws_secret_access_key: $AWS_SECRET_ACCESS_KEY - resource_class: small - working_directory: /usr/src/app - - steps: - - run: - name: Run lint - command: just lint - - test: - docker: - - image: << pipeline.parameters.registry >>/<< pipeline.parameters.image_tag >>:${CIRCLE_SHA1} - aws_auth: - aws_access_key_id: $AWS_ACCESS_KEY_ID - aws_secret_access_key: $AWS_SECRET_ACCESS_KEY - resource_class: {{ library.resource_class }} - working_directory: /usr/src/app - - steps: - - run: - name: Run tests - command: just test - - - store_artifacts: - path: ./coverage - - - store_test_results: - path: ./coverage - - publish: - docker: - - image: cimg/base:current - resource_class: small - - steps: - - setup-base - - - run: - name: Publish package - command: | - export CURRENT_TAG="$(git describe --tags --abbrev=0)" - export CURRENT_VERSION=$(cat package.json | jq -r ".version") - - if [ "$CURRENT_TAG" != "$CURRENT_VERSION" ]; then - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc - - docker container run \ - --env DOPPLER_TOKEN \ - --rm \ - --tty \ - --volume "$(pwd)/.npmrc:/usr/src/app/.npmrc" \ - << pipeline.parameters.registry >>/<< pipeline.parameters.image_tag >>:${CIRCLE_SHA1} \ - just publish - else - echo "Skipped publish due to no changes in version." - fi - -workflows: - build-preview-update: - jobs: - - build: - context: - - altf4llc-aws - - - lint: - context: - - altf4llc-aws - requires: - - build - - - test: - context: - - altf4llc-aws - requires: - - build - - - publish: - context: - - altf4llc-aws - filters: - branches: - only: - - main - requires: - - test - -version: 2.1 diff --git a/src/template/library/typescript/.eslintignore.j2 b/src/template/library/typescript/.eslintignore.j2 deleted file mode 100644 index b0afc7a..0000000 --- a/src/template/library/typescript/.eslintignore.j2 +++ /dev/null @@ -1,7 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -**/*.js -**/*.d.ts diff --git a/src/template/library/typescript/.eslintrc.js.j2 b/src/template/library/typescript/.eslintrc.js.j2 deleted file mode 100644 index 684ef68..0000000 --- a/src/template/library/typescript/.eslintrc.js.j2 +++ /dev/null @@ -1,23 +0,0 @@ -//░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -//░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -//░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -// DO NOT UPDATE: This file is managed by "build-configs" - -module.exports = { - env: { - es2021: true, - node: true, - }, - extends: [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "prettier", - ], - parser: "@typescript-eslint/parser", - parserOptions: { - ecmaVersion: "latest", - sourceType: "module", - }, - plugins: ["@typescript-eslint"], - rules: {}, -}; diff --git a/src/template/library/typescript/.gitignore.j2 b/src/template/library/typescript/.gitignore.j2 deleted file mode 100644 index e931147..0000000 --- a/src/template/library/typescript/.gitignore.j2 +++ /dev/null @@ -1,154 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -lib/**/**/*.js -lib/**/**/*.d.ts -lib/**/**/*.map -index.js -index.d.ts -index.js.map -.npmrc - -### Node ### -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* -.pnpm-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# Snowpack dependency directory (https://snowpack.dev/) -web_modules/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variable files -.env -.env.development.local -.env.test.local -.env.production.local -.env.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next -out - -# Nuxt.js build / generate output -.nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# vuepress v2.x temp and cache directory -.temp - -# Docusaurus cache and generated files -.docusaurus - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# yarn v2 -.yarn/cache -.yarn/unplugged -.yarn/build-state.yml -.yarn/install-state.gz -.pnp.* - -### Node Patch ### -# Serverless Webpack directories -.webpack/ - -# Optional stylelint cache - -# SvelteKit build / generate output -.svelte-kit - -# End of https://www.toptal.com/developers/gitignore/api/node diff --git a/src/template/library/typescript/.npmignore.j2 b/src/template/library/typescript/.npmignore.j2 deleted file mode 100644 index aa19aef..0000000 --- a/src/template/library/typescript/.npmignore.j2 +++ /dev/null @@ -1,13 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -.circleci/ -.eslintignore -.eslintrc.js -Dockerfile -build.json -jest.config.js -jest.config.setup.js -justfile diff --git a/src/template/library/typescript/.prettierignore.j2 b/src/template/library/typescript/.prettierignore.j2 deleted file mode 100644 index b6847de..0000000 --- a/src/template/library/typescript/.prettierignore.j2 +++ /dev/null @@ -1,17 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -**/*.js -**/*.d.ts -coverage/ - -### APPLICATION ### -lib/**/**/*.js -lib/**/**/*.d.ts -lib/**/**/*.map -index.js -index.d.ts -index.js.map -.npmrc diff --git a/src/template/library/typescript/.prettierrc.js.j2 b/src/template/library/typescript/.prettierrc.js.j2 deleted file mode 100644 index 49aa21b..0000000 --- a/src/template/library/typescript/.prettierrc.js.j2 +++ /dev/null @@ -1,14 +0,0 @@ -//░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -//░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -//░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -// DO NOT UPDATE: This file is managed by "build-configs" - -module.exports = { - printWidth: 80, - semi: true, - singleQuote: true, - tabWidth: 4, - useTabs: false, - trailingComma: "all", - bracketSpacing: true -}; diff --git a/src/template/library/typescript/Dockerfile.j2 b/src/template/library/typescript/Dockerfile.j2 deleted file mode 100644 index 6d30959..0000000 --- a/src/template/library/typescript/Dockerfile.j2 +++ /dev/null @@ -1,35 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -FROM public.ecr.aws/docker/library/node:18 as build - -RUN apt-get update \ - && apt-get install --yes \ - apt-transport-https \ - bash \ - ca-certificates \ - curl \ - gnupg \ - && curl -sLf --retry 3 --tlsv1.2 --proto "=https" 'https://packages.doppler.com/public/cli/gpg.DE2A7741A397C129.key' | apt-key add - \ - && echo "deb https://packages.doppler.com/public/cli/deb/debian any-version main" | tee /etc/apt/sources.list.d/doppler-cli.list \ - && apt-get update && apt-get install doppler \ - && curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin \ - && rm -rf /var/lib/apt/lists/* - -WORKDIR /usr/src/app - -COPY package.json yarn.lock ./ - -RUN yarn install --frozen-lockfile - -COPY .eslintignore .eslintrc.js .npmignore jest.config.js tsconfig.json ./ - -COPY index.ts index.ts -COPY justfile justfile -COPY lib/ lib/ -{% for command in dockerfile.build_post_install -%} -{{ command | safe }} -{% endfor %} -RUN yarn build diff --git a/src/template/library/typescript/jest.config.js.j2 b/src/template/library/typescript/jest.config.js.j2 deleted file mode 100644 index f022618..0000000 --- a/src/template/library/typescript/jest.config.js.j2 +++ /dev/null @@ -1,15 +0,0 @@ -//░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -//░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -//░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -// DO NOT UPDATE: This file is managed by "build-configs" - -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ -module.exports = { - collectCoverage: true, - coverageReporters: ["json", "lcov", "text"], - preset: "ts-jest", - reporters: ["default", ["jest-junit", { outputDirectory: "./coverage" }]], - setupFiles: ["/jest.config.setup.js"], - testEnvironment: "node", - testMatch: ["**/__tests__/**/*.[t]s?(x)", "**/?(*.)+(spec|test).[t]s?(x)"], -}; diff --git a/src/template/library/typescript/justfile.j2 b/src/template/library/typescript/justfile.j2 deleted file mode 100644 index dac2229..0000000 --- a/src/template/library/typescript/justfile.j2 +++ /dev/null @@ -1,51 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -set shell := ["bash", "-c"] - -build sha: - docker buildx build \ - --progress "plain" \ - --tag "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{sha}}{% endraw %}" \ - . - -clean: - rm -rf coverage/ - rm -rf node_modules/ - rm -rf index.js.map - rm -rf index.js - rm -rf index.d.ts - - find ./lib -name "*.map" | xargs rm -rf {} \; - find ./lib -name "*.d.ts" | xargs rm -rf {} \; - find ./lib -name "*.js" | xargs rm -rf {} \; - -login: - aws ecr get-login-password \ - --region "us-west-2" | docker login \ - --password-stdin \ - --username AWS \ - "{{ dockerfile.registry }}" - -install: clean - doppler run --config "circleci" --project "{{ product }}-{{ name }}" -- \ - yarn install - -lint: - npx eslint . - -test $PULUMI_TEST_MODE="true" +FILES="": - npx jest \ - --collectCoverage \ - --runInBand \ - {% raw %}{{FILES}}{% endraw %} - -publish: - doppler run --config "circleci" --project "{{ product }}-{{ name }}" -- \ - npm publish - -push sha: - docker image push \ - "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{sha}}{% endraw %}" diff --git a/src/template/library/typescript/tsconfig.json.j2 b/src/template/library/typescript/tsconfig.json.j2 deleted file mode 100644 index b30bc51..0000000 --- a/src/template/library/typescript/tsconfig.json.j2 +++ /dev/null @@ -1,36 +0,0 @@ -//░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -//░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -//░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -// DO NOT UPDATE: This file is managed by "build-configs" - -{ - "compilerOptions": { - "target": "es2018", - "module": "commonjs", - "lib": [ - "es2018", - "esnext.asynciterable" - ], - "allowJs": false, - "sourceMap": true, - "downlevelIteration": true, - "strict": true, - "noImplicitAny": true, - "strictNullChecks": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "resolveJsonModule": true, - "skipLibCheck": true, - "inlineSources": true, - "declaration": true - }, - "exclude": [ - "dist", - "node_modules", - "**/*.spec.ts" - ], - "include": [ - "index.ts", - "./lib/**/*" - ] -} diff --git a/src/template/pulumi/go/.circleci/config.yml.j2 b/src/template/pulumi/go/.circleci/config.yml.j2 deleted file mode 100644 index 23bdf8f..0000000 --- a/src/template/pulumi/go/.circleci/config.yml.j2 +++ /dev/null @@ -1,188 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -orbs: - aws-cli: circleci/aws-cli@3.1.3 - -parameters: - image_tag: - default: "{{ product }}-{{ name }}" - type: string - registry: - default: "{{ dockerfile.registry }}" - type: string - -commands: - login-ecr: - steps: - - run: - name: Login to ECR - command: just login - -jobs: - build: - docker: - - image: cimg/base:current - resource_class: small - - steps: - - aws-cli/install -{% if dependencies.private %} - - run: - name: Install Doppler CLI - latest - command: | - (curl -Ls https://cli.doppler.com/install.sh \ - || wget -qO- https://cli.doppler.com/install.sh) \ - | sh -s -- --no-install --no-package-manager - - mkdir -p /tmp/doppler - mv ./doppler /tmp/doppler/doppler - - echo 'export PATH=/tmp/doppler:"$PATH"' >> "$BASH_ENV" -{% endif %} - - run: - name: Install Just CLI - latest - command: | - curl \ - --proto '=https' \ - --tlsv1.2 -sSf https://just.systems/install.sh \ - | bash -s -- --to /tmp/just - - echo 'export PATH=/tmp/just:"$PATH"' >> "$BASH_ENV" - - - setup_remote_docker: - docker_layer_caching: true - version: 20.10.17 - - - checkout - - - login-ecr - - - run: - name: Build images - command: just build "${CIRCLE_SHA1}" - - - run: - name: Push images - command: just push "${CIRCLE_SHA1}" -{% if pulumi.resource_class is matching("altf4llc/machine-") %} - - persist_to_workspace: - root: . - paths: - - justfile -{%- endif %} - - pulumi: -{%- if pulumi.resource_class is matching("altf4llc/machine-") %} - machine: true -{%- else %} - docker: - - image: << pipeline.parameters.registry >>/<< pipeline.parameters.image_tag >>:${CIRCLE_SHA1} - aws_auth: - aws_access_key_id: $AWS_ACCESS_KEY_ID - aws_secret_access_key: $AWS_SECRET_ACCESS_KEY -{%- endif %} - parameters: - command: - type: string - stack: - type: string - resource_class: {{ pulumi.resource_class | safe }} -{%- if pulumi.resource_class is not matching("altf4llc/machine-") %} - working_directory: /usr/src/app -{%- endif %} - - steps: -{%- if pulumi.resource_class is matching("altf4llc/machine-") %} - - attach_workspace: - at: . - - - login-ecr - - - run: - name: Pull image - command: | - just pull ${CIRCLE_SHA1} -{% if pulumi.eks_cluster != "" %} - - run: - name: Update kubeconfig - command: | - docker container run \ - --env DOPPLER_TOKEN \ - --interactive \ - --rm \ - --tty \ - --volume "$(pwd)/.kube:/root/.kube" \ - << pipeline.parameters.registry >>/<< pipeline.parameters.image_tag >>:${CIRCLE_SHA1} \ - just update-kubeconfig -{% endif %} - - run: - name: Run << parameters.command >> << parameters.stack >> - command: | - docker container run \ - --env DOPPLER_TOKEN \ - --interactive \ - --rm \ - --tty \ - {%- if pulumi.eks_cluster != "" %} - --volume "$(pwd)/.kube:/root/.kube" \ - {%- endif %} - << pipeline.parameters.registry >>/<< pipeline.parameters.image_tag >>:${CIRCLE_SHA1} \ - just << parameters.command >> << parameters.stack >> -{%- if pulumi.eks_cluster != "" %} - - run: - name: Clean environment - command: | - sudo rm -rf .kube/ - when: always -{%- endif %} -{%- else %} - - run: - name: Run << parameters.command >> << parameters.stack >> - command: | - just << parameters.command >> << parameters.stack >> -{%- endif %} - -workflows: - build-preview-update: - jobs: - - build: - context: - - altf4llc-aws -{% for environment in environments %} - - pulumi: - name: refresh-{{ environment }} - command: refresh - stack: {{ environment }} - context: - - altf4llc-aws - requires: - - build -{% endfor -%} -{% for environment in environments %} - - pulumi: - name: preview-{{ environment }} - command: preview - stack: {{ environment }} - context: - - altf4llc-aws - requires: - - refresh-{{ environment }} -{% endfor -%} -{% for environment in environments %} - - pulumi: - name: update-{{ environment }} - command: update - stack: {{ environment }} - context: - - altf4llc-aws - filters: - branches: - only: - - main - requires: - - preview-{{ environment }} -{% endfor %} -version: 2.1 diff --git a/src/template/pulumi/go/.dockerignore.j2 b/src/template/pulumi/go/.dockerignore.j2 deleted file mode 100644 index 6e5d46f..0000000 --- a/src/template/pulumi/go/.dockerignore.j2 +++ /dev/null @@ -1,8 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -.circleci -build.json -README.md diff --git a/src/template/pulumi/go/.gitignore.j2 b/src/template/pulumi/go/.gitignore.j2 deleted file mode 100644 index 9017bc8..0000000 --- a/src/template/pulumi/go/.gitignore.j2 +++ /dev/null @@ -1,9 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -/bin/ -{%- if pulumi.eks_cluster != "" -%} -.kube/ -{%- endif %} diff --git a/src/template/pulumi/go/Dockerfile.j2 b/src/template/pulumi/go/Dockerfile.j2 deleted file mode 100644 index 8de12d9..0000000 --- a/src/template/pulumi/go/Dockerfile.j2 +++ /dev/null @@ -1,59 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -FROM public.ecr.aws/docker/library/golang:1.20 as build - -WORKDIR /usr/src/app - -COPY go.mod go.sum ./ - -RUN go mod download -x - -COPY cmd/ cmd/ -COPY internal/ internal/ - -RUN go build -v ./cmd/... - -FROM public.ecr.aws/docker/library/golang:1.20 - -ENV PATH="/root/.pulumi/bin:$PATH" - -RUN apt-get update && apt-get install --yes \ - apt-transport-https \ - bash \ - ca-certificates \ - curl \ - gnupg \ - unzip \ - && curl -sLf --retry 3 --tlsv1.2 --proto "=https" 'https://packages.doppler.com/public/cli/gpg.DE2A7741A397C129.key' | apt-key add - \ - && echo "deb https://packages.doppler.com/public/cli/deb/debian any-version main" | tee /etc/apt/sources.list.d/doppler-cli.list \ - && apt-get update && apt-get install doppler \ - && curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin \ -{%- if pulumi.eks_cluster != "" %} - && curl -sL https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip \ - && unzip awscliv2.zip \ - && aws/install \ - && rm -rf \ - awscliv2.zip \ - aws \ - /usr/local/aws-cli/v2/*/dist/aws_completer \ - /usr/local/aws-cli/v2/*/dist/awscli/data/ac.index \ - /usr/local/aws-cli/v2/*/dist/awscli/examples \ - && curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" \ - && install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl \ -{%- endif %} - && curl -fsSL https://get.pulumi.com -o /root/setup_pulumi.sh \ - && chmod +x /root/setup_pulumi.sh \ - && /root/setup_pulumi.sh \ - && rm -rf /root/setup_pulumi.sh \ - && rm -rf /var/lib/apt/lists/* - -WORKDIR /usr/src/app -COPY --from=build /usr/src/app/{{ product }}-{{ name }} /usr/local/bin/{{ product }}-{{ name }} -COPY justfile justfile -COPY Pulumi.yaml Pulumi.yaml -{% for command in dockerfile.build_post_install -%} -{{ command | safe }} -{% endfor -%} diff --git a/src/template/pulumi/go/Pulumi.yaml.j2 b/src/template/pulumi/go/Pulumi.yaml.j2 deleted file mode 100644 index 1e1ce13..0000000 --- a/src/template/pulumi/go/Pulumi.yaml.j2 +++ /dev/null @@ -1,10 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -name: "{% if product != 'altf4llc' %}{{ product }}-{% endif %}{{ name }}" -runtime: - name: "go" - options: - binary: "{{ product }}-{{ name }}" diff --git a/src/template/pulumi/go/justfile.j2 b/src/template/pulumi/go/justfile.j2 deleted file mode 100644 index c331f52..0000000 --- a/src/template/pulumi/go/justfile.j2 +++ /dev/null @@ -1,63 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -set shell := ["bash", "-c"] - -build sha: - docker buildx build \ - --progress "plain" \ - --tag "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{sha}}{% endraw %}-build" \ - --target "build" \ - . - - docker buildx build \ - --cache-from "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{sha}}{% endraw %}-build" \ - --progress "plain" \ - --tag "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{sha}}{% endraw %}" \ - . - -login: - aws ecr get-login-password \ - --region "us-west-2" | docker login \ - --password-stdin \ - --username AWS \ - "{{ dockerfile.registry }}" - -pull sha: - docker image pull \ - "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{sha}}{% endraw %}" - -push sha: - docker image push \ - "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{sha}}{% endraw %}" - -preview stack: - doppler run --config "circleci" --project "{{ product }}-{{ name }}" -- \ - pulumi preview \ - --diff \ - --non-interactive \ - --stack "{% raw %}{{stack}}{% endraw %}" - -refresh stack: - doppler run --config "circleci" --project "{{ product }}-{{ name }}" -- \ - pulumi refresh \ - --diff \ - --non-interactive \ - --skip-preview \ - --stack "{% raw %}{{stack}}{% endraw %}" \ - --yes - -update stack: - doppler run --config "circleci" --project "{{ product }}-{{ name }}" -- \ - pulumi update \ - --diff \ - --non-interactive \ - --stack "{% raw %}{{stack}}{% endraw %}" \ - --yes -{% if pulumi.eks_cluster != "" %} -update-kubeconfig: - doppler run --config "circleci" --project "{{ product }}-{{ name }}" -- \ - aws eks update-kubeconfig --name "{{ pulumi.eks_cluster }}" -{% endif -%} diff --git a/src/template/pulumi/typescript/.circleci/config.yml.j2 b/src/template/pulumi/typescript/.circleci/config.yml.j2 deleted file mode 100644 index 23bdf8f..0000000 --- a/src/template/pulumi/typescript/.circleci/config.yml.j2 +++ /dev/null @@ -1,188 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -orbs: - aws-cli: circleci/aws-cli@3.1.3 - -parameters: - image_tag: - default: "{{ product }}-{{ name }}" - type: string - registry: - default: "{{ dockerfile.registry }}" - type: string - -commands: - login-ecr: - steps: - - run: - name: Login to ECR - command: just login - -jobs: - build: - docker: - - image: cimg/base:current - resource_class: small - - steps: - - aws-cli/install -{% if dependencies.private %} - - run: - name: Install Doppler CLI - latest - command: | - (curl -Ls https://cli.doppler.com/install.sh \ - || wget -qO- https://cli.doppler.com/install.sh) \ - | sh -s -- --no-install --no-package-manager - - mkdir -p /tmp/doppler - mv ./doppler /tmp/doppler/doppler - - echo 'export PATH=/tmp/doppler:"$PATH"' >> "$BASH_ENV" -{% endif %} - - run: - name: Install Just CLI - latest - command: | - curl \ - --proto '=https' \ - --tlsv1.2 -sSf https://just.systems/install.sh \ - | bash -s -- --to /tmp/just - - echo 'export PATH=/tmp/just:"$PATH"' >> "$BASH_ENV" - - - setup_remote_docker: - docker_layer_caching: true - version: 20.10.17 - - - checkout - - - login-ecr - - - run: - name: Build images - command: just build "${CIRCLE_SHA1}" - - - run: - name: Push images - command: just push "${CIRCLE_SHA1}" -{% if pulumi.resource_class is matching("altf4llc/machine-") %} - - persist_to_workspace: - root: . - paths: - - justfile -{%- endif %} - - pulumi: -{%- if pulumi.resource_class is matching("altf4llc/machine-") %} - machine: true -{%- else %} - docker: - - image: << pipeline.parameters.registry >>/<< pipeline.parameters.image_tag >>:${CIRCLE_SHA1} - aws_auth: - aws_access_key_id: $AWS_ACCESS_KEY_ID - aws_secret_access_key: $AWS_SECRET_ACCESS_KEY -{%- endif %} - parameters: - command: - type: string - stack: - type: string - resource_class: {{ pulumi.resource_class | safe }} -{%- if pulumi.resource_class is not matching("altf4llc/machine-") %} - working_directory: /usr/src/app -{%- endif %} - - steps: -{%- if pulumi.resource_class is matching("altf4llc/machine-") %} - - attach_workspace: - at: . - - - login-ecr - - - run: - name: Pull image - command: | - just pull ${CIRCLE_SHA1} -{% if pulumi.eks_cluster != "" %} - - run: - name: Update kubeconfig - command: | - docker container run \ - --env DOPPLER_TOKEN \ - --interactive \ - --rm \ - --tty \ - --volume "$(pwd)/.kube:/root/.kube" \ - << pipeline.parameters.registry >>/<< pipeline.parameters.image_tag >>:${CIRCLE_SHA1} \ - just update-kubeconfig -{% endif %} - - run: - name: Run << parameters.command >> << parameters.stack >> - command: | - docker container run \ - --env DOPPLER_TOKEN \ - --interactive \ - --rm \ - --tty \ - {%- if pulumi.eks_cluster != "" %} - --volume "$(pwd)/.kube:/root/.kube" \ - {%- endif %} - << pipeline.parameters.registry >>/<< pipeline.parameters.image_tag >>:${CIRCLE_SHA1} \ - just << parameters.command >> << parameters.stack >> -{%- if pulumi.eks_cluster != "" %} - - run: - name: Clean environment - command: | - sudo rm -rf .kube/ - when: always -{%- endif %} -{%- else %} - - run: - name: Run << parameters.command >> << parameters.stack >> - command: | - just << parameters.command >> << parameters.stack >> -{%- endif %} - -workflows: - build-preview-update: - jobs: - - build: - context: - - altf4llc-aws -{% for environment in environments %} - - pulumi: - name: refresh-{{ environment }} - command: refresh - stack: {{ environment }} - context: - - altf4llc-aws - requires: - - build -{% endfor -%} -{% for environment in environments %} - - pulumi: - name: preview-{{ environment }} - command: preview - stack: {{ environment }} - context: - - altf4llc-aws - requires: - - refresh-{{ environment }} -{% endfor -%} -{% for environment in environments %} - - pulumi: - name: update-{{ environment }} - command: update - stack: {{ environment }} - context: - - altf4llc-aws - filters: - branches: - only: - - main - requires: - - preview-{{ environment }} -{% endfor %} -version: 2.1 diff --git a/src/template/pulumi/typescript/.dockerignore.j2 b/src/template/pulumi/typescript/.dockerignore.j2 deleted file mode 100644 index 6e5d46f..0000000 --- a/src/template/pulumi/typescript/.dockerignore.j2 +++ /dev/null @@ -1,8 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -.circleci -build.json -README.md diff --git a/src/template/pulumi/typescript/.gitignore.j2 b/src/template/pulumi/typescript/.gitignore.j2 deleted file mode 100644 index 5e671a9..0000000 --- a/src/template/pulumi/typescript/.gitignore.j2 +++ /dev/null @@ -1,10 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -/bin/ -{%- if pulumi.eks_cluster != "" -%} -.kube/ -{%- endif %} -/node_modules/ diff --git a/src/template/pulumi/typescript/.npmrc.j2 b/src/template/pulumi/typescript/.npmrc.j2 deleted file mode 100644 index 0a47871..0000000 --- a/src/template/pulumi/typescript/.npmrc.j2 +++ /dev/null @@ -1,6 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -//registry.npmjs.org/:_authToken=${NPM_TOKEN} diff --git a/src/template/pulumi/typescript/Dockerfile.j2 b/src/template/pulumi/typescript/Dockerfile.j2 deleted file mode 100644 index 84ae43c..0000000 --- a/src/template/pulumi/typescript/Dockerfile.j2 +++ /dev/null @@ -1,56 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -FROM public.ecr.aws/docker/library/node:18 -{% if dependencies.private -%} -ARG NPM_TOKEN -ENV NPM_TOKEN ${NPM_TOKEN} -{%- endif -%} -ENV PATH="/root/.pulumi/bin:$PATH" - -RUN apt-get update && apt-get install --yes \ - apt-transport-https \ - bash \ - ca-certificates \ - curl \ - gnupg \ - unzip \ - && curl -sLf --retry 3 --tlsv1.2 --proto "=https" 'https://packages.doppler.com/public/cli/gpg.DE2A7741A397C129.key' | apt-key add - \ - && echo "deb https://packages.doppler.com/public/cli/deb/debian any-version main" | tee /etc/apt/sources.list.d/doppler-cli.list \ - && apt-get update && apt-get install doppler \ - && curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin \ -{%- if pulumi.eks_cluster != "" %} - && curl -sL https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip \ - && unzip awscliv2.zip \ - && aws/install \ - && rm -rf \ - awscliv2.zip \ - aws \ - /usr/local/aws-cli/v2/*/dist/aws_completer \ - /usr/local/aws-cli/v2/*/dist/awscli/data/ac.index \ - /usr/local/aws-cli/v2/*/dist/awscli/examples \ - && curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" \ - && install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl \ -{%- endif %} - && curl -fsSL https://get.pulumi.com -o /root/setup_pulumi.sh \ - && chmod +x /root/setup_pulumi.sh \ - && /root/setup_pulumi.sh \ - && rm -rf /root/setup_pulumi.sh \ - && rm -rf /var/lib/apt/lists/* - -WORKDIR /usr/src/app - -COPY {% if dependencies.private %}.npmrc {% endif %}package.json yarn.lock ./ - -RUN yarn install --frozen-lockfile - -COPY resource/ resource/ -COPY index.ts index.ts -COPY tsconfig.json tsconfig.json -COPY justfile justfile -COPY Pulumi.yaml Pulumi.yaml -{% for command in dockerfile.build_post_install -%} -{{ command | safe }} -{% endfor -%} diff --git a/src/template/pulumi/typescript/Pulumi.yaml.j2 b/src/template/pulumi/typescript/Pulumi.yaml.j2 deleted file mode 100644 index 2bd8661..0000000 --- a/src/template/pulumi/typescript/Pulumi.yaml.j2 +++ /dev/null @@ -1,8 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -name: "{% if product != 'altf4llc' %}{{ product }}-{% endif %}{{ name }}" -runtime: - name: "nodejs" diff --git a/src/template/pulumi/typescript/justfile.j2 b/src/template/pulumi/typescript/justfile.j2 deleted file mode 100644 index 4c8aac1..0000000 --- a/src/template/pulumi/typescript/justfile.j2 +++ /dev/null @@ -1,63 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -set shell := ["bash", "-c"] - -build sha{% if dependencies.private %} $NPM_TOKEN=`doppler secrets get --plain --config "circleci" --project "{{ product }}-{{ name }}" NPM_TOKEN`{% endif %}: - docker buildx build \ -{%- if dependencies.private %} - --build-arg NPM_TOKEN \ -{%- endif %} - --progress "plain" \ - --tag "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{sha}}{% endraw %}" \ - . - -install: - rm -rf node_modules - yarn install - -login: - aws ecr get-login-password \ - --region "us-west-2" | docker login \ - --password-stdin \ - --username AWS \ - "{{ dockerfile.registry }}" - -pull sha: - docker image pull \ - "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{sha}}{% endraw %}" - -push sha: - docker image push \ - "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{sha}}{% endraw %}" - -preview stack: - doppler run --config "circleci" --project "{{ product }}-{{ name }}" -- \ - pulumi preview \ - --diff \ - --non-interactive \ - --stack "{% raw %}{{stack}}{% endraw %}" - -refresh stack: - doppler run --config "circleci" --project "{{ product }}-{{ name }}" -- \ - pulumi refresh \ - --diff \ - --non-interactive \ - --skip-preview \ - --stack "{% raw %}{{stack}}{% endraw %}" \ - --yes - -update stack: - doppler run --config "circleci" --project "{{ product }}-{{ name }}" -- \ - pulumi update \ - --diff \ - --non-interactive \ - --stack "{% raw %}{{stack}}{% endraw %}" \ - --yes -{% if pulumi.eks_cluster != "" %} -update-kubeconfig: - doppler run --config "circleci" --project "{{ product }}-{{ name }}" -- \ - aws eks update-kubeconfig --name "{{ pulumi.eks_cluster }}" -{% endif -%} diff --git a/src/template/pulumi/typescript/tsconfig.json.j2 b/src/template/pulumi/typescript/tsconfig.json.j2 deleted file mode 100644 index 061d284..0000000 --- a/src/template/pulumi/typescript/tsconfig.json.j2 +++ /dev/null @@ -1,21 +0,0 @@ -//░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -//░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -//░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -// DO NOT UPDATE: This file is managed by "build-configs" - -{ - "compilerOptions": { - "strict": true, - "outDir": "bin", - "target": "es2016", - "module": "commonjs", - "moduleResolution": "node", - "sourceMap": true, - "experimentalDecorators": true, - "pretty": true, - "noFallthroughCasesInSwitch": true, - "noImplicitReturns": true, - "forceConsistentCasingInFileNames": true - }, - "files": ["index.ts"] -} diff --git a/src/template/service/go/.github/workflows/flake.yml.j2 b/src/template/service/go/.github/workflows/flake.yml.j2 deleted file mode 100644 index 85e6f4f..0000000 --- a/src/template/service/go/.github/workflows/flake.yml.j2 +++ /dev/null @@ -1,17 +0,0 @@ -name: flake - -on: - pull_request: - push: - branches: - - main - -jobs: - build: - runs-on: ubuntu-22.04 - steps: - - uses: DeterminateSystems/nix-installer-action@v4 - - - uses: actions/checkout@v3 - - - run: nix build --json diff --git a/src/template/service/go/.gitignore.j2 b/src/template/service/go/.gitignore.j2 deleted file mode 100644 index aec4d08..0000000 --- a/src/template/service/go/.gitignore.j2 +++ /dev/null @@ -1,105 +0,0 @@ -### Nix ### -.netrc -result - -# Created by https://www.toptal.com/developers/gitignore/api/go,linux,macos,windows -# Edit at https://www.toptal.com/developers/gitignore?templates=go,linux,macos,windows - -### Go ### -# 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 - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### macOS ### -# 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 - -### macOS Patch ### -# iCloud generated files -*.icloud - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# End of https://www.toptal.com/developers/gitignore/api/go,linux,macos,windows diff --git a/src/template/service/typescript/.circleci/config.yml.j2 b/src/template/service/typescript/.circleci/config.yml.j2 deleted file mode 100644 index 42a4222..0000000 --- a/src/template/service/typescript/.circleci/config.yml.j2 +++ /dev/null @@ -1,194 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -orbs: - aws-cli: circleci/aws-cli@3.1.3 - -parameters: - image_tag: - default: "{{ product }}-{{ name }}" - type: string - registry: - default: "{{ dockerfile.registry }}" - type: string - -commands: - setup-base: - steps: - - aws-cli/install -{% if dependencies.private %} - - run: - name: Install Doppler CLI - latest - command: | - (curl -Ls https://cli.doppler.com/install.sh \ - || wget -qO- https://cli.doppler.com/install.sh) \ - | sh -s -- --no-install --no-package-manager - - mkdir -p /tmp/doppler - mv ./doppler /tmp/doppler/doppler - - echo 'export PATH=/tmp/doppler:"$PATH"' >> "$BASH_ENV" -{% endif %} - - run: - name: Install Just CLI - latest - command: | - curl \ - --proto '=https' \ - --tlsv1.2 -sSf https://just.systems/install.sh \ - | bash -s -- --to /tmp/just - - echo 'export PATH=/tmp/just:"$PATH"' >> "$BASH_ENV" - - - checkout - - - setup_remote_docker: - docker_layer_caching: true - version: 20.10.17 - - - run: - name: Login to ECR - command: just login - -jobs: - build: - docker: - - image: cimg/base:current - resource_class: small - - steps: - - setup-base - - - run: - name: Build images - command: just build "${CIRCLE_SHA1}" - - - run: - name: Push images - command: | - just push "${CIRCLE_SHA1}-build" - just push "${CIRCLE_SHA1}" -{% if service.tests is containing("lint") %} - test-lint: - docker: - - image: << pipeline.parameters.registry >>/<< pipeline.parameters.image_tag >>:${CIRCLE_SHA1}-build - aws_auth: - aws_access_key_id: $AWS_ACCESS_KEY_ID - aws_secret_access_key: $AWS_SECRET_ACCESS_KEY - resource_class: small - working_directory: /usr/src/app - - steps: - - run: - name: Run lint - command: just lint -{%- endif -%} -{% if service.tests is containing("migrate") %} - - test-migrate: - docker: - - image: << pipeline.parameters.registry >>/<< pipeline.parameters.image_tag >>:${CIRCLE_SHA1}-build - aws_auth: - aws_access_key_id: $AWS_ACCESS_KEY_ID - aws_secret_access_key: $AWS_SECRET_ACCESS_KEY - environment: - POSTGRESQL_DBNAME: "postgres" - POSTGRESQL_HOST: "postgres" - POSTGRESQL_PASSWORD: "secret" - POSTGRESQL_USER: "postgres" - - image: cimg/postgres:15.1 - name: "postgres" - environment: - POSTGRES_PASSWORD: "secret" - resource_class: small - working_directory: /usr/src/app - - steps: - - run: - name: Wait for database - command: | - dockerize -wait "tcp://${POSTGRESQL_HOST}:5432" -timeout 1m - - - run: - name: Run migrate - command: | - ./docker-entrypoint.sh migrate -{%- endif -%} -{% if service.tests is containing("unit") %} - - test-unit: - docker: - - image: << pipeline.parameters.registry >>/<< pipeline.parameters.image_tag >>:${CIRCLE_SHA1}-build - aws_auth: - aws_access_key_id: $AWS_ACCESS_KEY_ID - aws_secret_access_key: $AWS_SECRET_ACCESS_KEY - resource_class: small - working_directory: /usr/src/app - - steps: - - run: - name: Run units - command: just test - - - store_artifacts: - path: ./coverage - - - store_test_results: - path: ./coverage -{% endif %} - tag: - docker: - - image: cimg/base:current - resource_class: small - - steps: - - setup-base - - - run: - name: Pull images - command: | - just pull ${CIRCLE_SHA1} - - - run: - name: Push tags - command: | - export CURRENT_TAG="$(git describe --tags --abbrev=0)" - export CURRENT_VERSION=$(cat package.json | jq -r ".version") - - if [ "$CURRENT_TAG" != "$CURRENT_VERSION" ]; then - just tag ${CIRCLE_SHA1} ${CURRENT_VERSION} - just push ${CURRENT_VERSION} - else - echo "Skipped push due to no changes in version." - fi - -workflows: - build-test-tag: - jobs: - - build: - context: - - altf4llc-aws -{% for test in service.tests %} - - test-{{ test }}: - context: - - altf4llc-aws - requires: - - build -{% endfor %} - - tag: - context: - - altf4llc-aws - filters: - branches: - only: main - requires: -{%- if service.tests | length > 0 %} -{%- for test in service.tests %} - - test-{{ test }} -{%- endfor %} -{%- else %} - - build -{%- endif %} - -version: 2.1 diff --git a/src/template/service/typescript/.dockerignore.j2 b/src/template/service/typescript/.dockerignore.j2 deleted file mode 100644 index 69ccb67..0000000 --- a/src/template/service/typescript/.dockerignore.j2 +++ /dev/null @@ -1,12 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -.circleci/ -.git/ -coverage/ -node_modules -docker-compose.yaml -Dockerfile -README.md diff --git a/src/template/service/typescript/.eslintignore.j2 b/src/template/service/typescript/.eslintignore.j2 deleted file mode 100644 index 679064e..0000000 --- a/src/template/service/typescript/.eslintignore.j2 +++ /dev/null @@ -1,6 +0,0 @@ -**/*.d.ts -**/*.js -dist/* -react.graphql.ts -request.graphql.ts -src/migration/* diff --git a/src/template/service/typescript/.eslintrc.js.j2 b/src/template/service/typescript/.eslintrc.js.j2 deleted file mode 100644 index 31372dd..0000000 --- a/src/template/service/typescript/.eslintrc.js.j2 +++ /dev/null @@ -1,29 +0,0 @@ -//░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -//░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -//░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -// DO NOT UPDATE: This file is managed by "build-configs" - -module.exports = { - env: { - es2021: true, - node: true, - }, - extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"], - parser: "@typescript-eslint/parser", - parserOptions: { - ecmaVersion: "latest", - sourceType: "module", - }, - plugins: ["@typescript-eslint"], - rules: { - "@typescript-eslint/ban-types": [ - "error", - { - extendDefaults: true, - types: { - "{}": false, - }, - }, - ], - }, -}; diff --git a/src/template/service/typescript/.npmrc.j2 b/src/template/service/typescript/.npmrc.j2 deleted file mode 100644 index 0a47871..0000000 --- a/src/template/service/typescript/.npmrc.j2 +++ /dev/null @@ -1,6 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -//registry.npmjs.org/:_authToken=${NPM_TOKEN} diff --git a/src/template/service/typescript/.prettierignore.j2 b/src/template/service/typescript/.prettierignore.j2 deleted file mode 100644 index 084b29f..0000000 --- a/src/template/service/typescript/.prettierignore.j2 +++ /dev/null @@ -1,18 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -**/*.js -**/*.d.ts -coverage/ - -### APPLICATION ### -lib/**/**/*.js -lib/**/**/*.d.ts -lib/**/**/*.map -index.js -index.d.ts -index.js.map -.npmrc -request.graphql.ts diff --git a/src/template/service/typescript/.prettierrc.js.j2 b/src/template/service/typescript/.prettierrc.js.j2 deleted file mode 100644 index 49aa21b..0000000 --- a/src/template/service/typescript/.prettierrc.js.j2 +++ /dev/null @@ -1,14 +0,0 @@ -//░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -//░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -//░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -// DO NOT UPDATE: This file is managed by "build-configs" - -module.exports = { - printWidth: 80, - semi: true, - singleQuote: true, - tabWidth: 4, - useTabs: false, - trailingComma: "all", - bracketSpacing: true -}; diff --git a/src/template/service/typescript/Dockerfile.j2 b/src/template/service/typescript/Dockerfile.j2 deleted file mode 100644 index 80ad44c..0000000 --- a/src/template/service/typescript/Dockerfile.j2 +++ /dev/null @@ -1,83 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -FROM public.ecr.aws/docker/library/node:18-alpine3.16 as build -{%- if dependencies.private %} - -ARG NPM_TOKEN -{%- endif %} -{% if service.database %} -ENV DOCKERIZE_VERSION v0.6.1 -{% endif %} -RUN apk add --no-cache \ - bash \ - curl \ -{%- if service.database %} - wget \ -{%- endif %} -{%- if service.database %} - && wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ - && tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ - && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ -{%- endif %} - && curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin -{% if service.database %} -RUN yarn global add envsub@4.0.7 -{% endif %} -WORKDIR /usr/src/app - -COPY {% if dependencies.private %}.npmrc {% endif %}package.json yarn.lock ./ -{% if dependencies.private %} -RUN yarn install --frozen-lockfile \ - && rm -rf .npmrc -{% else %} -RUN yarn install --frozen-lockfile -{% endif %} -COPY .eslintignore ./.eslintignore -COPY .eslintrc.js ./.eslintrc.js -COPY .prettierignore ./.eslintignore -COPY .prettierrc.js ./.eslintrc.js -COPY docker-entrypoint.sh ./docker-entrypoint.sh -COPY justfile ./justfile -COPY src ./src -COPY tsconfig.json ./tsconfig.json -{% for command in dockerfile.build_post_install -%} -{{ command | safe }} -{% endfor %} -RUN yarn build - -ENTRYPOINT [ "./docker-entrypoint.sh" ] - - -FROM public.ecr.aws/docker/library/node:18-alpine3.16 as service - -{%- if dependencies.private %} - -ARG NPM_TOKEN -{%- endif %} -{% if service.database %} -RUN yarn global add envsub@4.0.7 -{% endif %} -WORKDIR /usr/src/app - -COPY {% if dependencies.private %}.npmrc {% endif %}package.json yarn.lock ./ -{% if dependencies.private %} -RUN yarn install \ - --frozen-lockfile \ - --production \ - && rm -rf .npmrc -{% else %} -RUN yarn install \ - --frozen-lockfile \ - --production -{% endif %} -COPY --from=build /usr/src/app/dist . -COPY docker-entrypoint.sh . -{% for command in dockerfile.service_post_install -%} -{{ command | safe }} -{% endfor %} -EXPOSE 9001 - -ENTRYPOINT [ "./docker-entrypoint.sh" ] diff --git a/src/template/service/typescript/docker-entrypoint.sh.j2 b/src/template/service/typescript/docker-entrypoint.sh.j2 deleted file mode 100644 index dcb4def..0000000 --- a/src/template/service/typescript/docker-entrypoint.sh.j2 +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -set -euxo pipefail - -if [ "$1" == "start" ]; then - yarn start -{%- if service.database %} -elif [ "$1" == "migrate" ]; then - npx envsubh \ - --env POSTGRESQL_USER \ - --env POSTGRESQL_PASSWORD \ - --env POSTGRESQL_HOST \ - --env POSTGRESQL_PORT \ - --env POSTGRESQL_DBNAME \ - ormconfig.json.template ormconfig.json - npx ts-node \ - --transpile-only \ - ./node_modules/typeorm/cli.js \ - migration:run - rm -rf ./ormconfig.json -{%- endif %} -else - echo "Invalid command provided." - exit 1 -fi diff --git a/src/template/service/typescript/jest.config.js.j2 b/src/template/service/typescript/jest.config.js.j2 deleted file mode 100644 index 396fd5f..0000000 --- a/src/template/service/typescript/jest.config.js.j2 +++ /dev/null @@ -1,16 +0,0 @@ -//░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -//░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -//░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -// DO NOT UPDATE: This file is managed by "build-configs" - -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ -module.exports = { - collectCoverage: true, - coverageDirectory: "./coverage", - coverageReporters: ["json", "lcov", "text"], - modulePathIgnorePatterns: ["/dist"], - preset: "ts-jest", - reporters: ["default", ["jest-junit", { outputDirectory: "./coverage" }]], - testEnvironment: "node", - testMatch: ["**/__tests__/**/*.[t]s?(x)", "**/?(*.)+(spec|test).[t]s?(x)"], -}; diff --git a/src/template/service/typescript/justfile.j2 b/src/template/service/typescript/justfile.j2 deleted file mode 100644 index ae4e8ec..0000000 --- a/src/template/service/typescript/justfile.j2 +++ /dev/null @@ -1,57 +0,0 @@ -#░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -#░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -#░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -# DO NOT UPDATE: This file is managed by "build-configs" - -set shell := ["bash", "-c"] - -build sha{% if dependencies.private %} $NPM_TOKEN=`doppler secrets get --plain --config "circleci" --project "{{ product }}-{{ name }}" NPM_TOKEN`{% endif %}: - docker buildx build \ -{%- if dependencies.private %} - --build-arg NPM_TOKEN \ -{%- endif %} - --progress "plain" \ - --tag "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{sha}}{% endraw %}-build" \ - --target "build" \ - . - - docker buildx build \ -{%- if dependencies.private %} - --build-arg NPM_TOKEN \ -{%- endif %} - --cache-from "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{sha}}{% endraw %}-build" \ - --progress "plain" \ - --tag "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{sha}}{% endraw %}" \ - --target "service" \ - . - -install: - rm -rf node_modules - yarn install -{% if service.tests is containing("lint") %} -lint: - npx eslint . -{% endif %} -login: - aws ecr get-login-password \ - --region "us-west-2" | docker login \ - --password-stdin \ - --username AWS \ - "{{ dockerfile.registry }}" - -pull tag: - docker image pull \ - "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{tag}}{% endraw %}" - -push tag: - docker image push \ - "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{tag}}{% endraw %}" - -tag sha version: - docker image tag \ - "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{sha}}{% endraw %}" \ - "{{ dockerfile.registry }}/{{ product }}-{{ name }}:{% raw %}{{version}}{% endraw %}" -{% if service.tests is containing("unit") %} -test: - npx jest -{%- endif -%} diff --git a/src/template/service/typescript/tsconfig.json.j2 b/src/template/service/typescript/tsconfig.json.j2 deleted file mode 100644 index a6c75a1..0000000 --- a/src/template/service/typescript/tsconfig.json.j2 +++ /dev/null @@ -1,30 +0,0 @@ -//░█▀█░█░█░▀█▀░█▀█░░░░░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄ -//░█▀█░█░█░░█░░█░█░▄▄▄░█░█░█▀▀░█░█░█▀▀░█▀▄░█▀█░░█░░█▀▀░█░█ -//░▀░▀░▀▀▀░░▀░░▀▀▀░░░░░▀▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀░ -// DO NOT UPDATE: This file is managed by "build-configs" - -{ - "compilerOptions": { - "target": "es2018", - "module": "commonjs", - "lib": ["es2018", "esnext.asynciterable"], - "allowJs": false, - "sourceMap": true, - "outDir": "./dist", - "downlevelIteration": true, - "strict": true, - "noImplicitAny": true, - "strictNullChecks": true, - "moduleResolution": "node", - "esModuleInterop": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "forceConsistentCasingInFileNames": true, - "resolveJsonModule": true, - "skipLibCheck": true, - "inlineSources": true, - "sourceRoot": "/" - }, - "exclude": ["dist", "node_modules", "**/*.spec.ts"], - "include": ["./src/**/*"] -} From d9e0cb7467aa769663712566257f3a33a43136e7 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:34:15 +0100 Subject: [PATCH 18/25] fix: resolve linting issue --- internal/config/golangci.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/config/golangci.go b/internal/config/golangci.go index 48fcc68..73ae17b 100644 --- a/internal/config/golangci.go +++ b/internal/config/golangci.go @@ -1,8 +1,8 @@ package config type GolangCILintConfig struct { - Exclude []string `json:"exclude,omitEmpty" yaml:"exclude,omitEmpty"` - ExtraExclude []string `json:"extraExclude,omitEmpty" yaml:"extraExclude,omitEmpty"` + Exclude []string `json:"exclude,omitempty" yaml:"exclude,omitempty"` + ExtraExclude []string `json:"extraExclude,omitempty" yaml:"extraExclude,omitempty"` } func NewGolangCiLintConfig() GolangCILintConfig { From bdc2a74832fa2334bbf5bff5ec3bab6232dc1975 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Wed, 17 Apr 2024 19:36:55 +0100 Subject: [PATCH 19/25] feat: version command --- internal/cli/version.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 internal/cli/version.go diff --git a/internal/cli/version.go b/internal/cli/version.go new file mode 100644 index 0000000..83a2322 --- /dev/null +++ b/internal/cli/version.go @@ -0,0 +1,21 @@ +package cli + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var Version = "git" + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Shows the version number of build-configs, then exits.", + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("build-configs version '%s'\n", Version) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +} From 1a0629bbc38d076b97d775540c6f326e87ef9450 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Wed, 17 Apr 2024 19:38:40 +0100 Subject: [PATCH 20/25] feat: include versioning in nix build --- flake.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index f71315b..b8a5f6d 100644 --- a/flake.nix +++ b/flake.nix @@ -12,6 +12,7 @@ just; name = "build-configs"; + version = "0.1.0"; CGO_ENABLED = "0"; in { @@ -22,7 +23,10 @@ packages = { default = pkgs.buildGo122Module { - inherit name; + inherit name version; + GOFLAGS = [ + "-ldflags='github.com/ALT-F4-LLC/build-configs/internal/cli.Version=${version}'" + ]; src = ./.; vendorHash = "sha256-6B9O6ho4COpJy4HlkzQ0lk+ieezRO3xg9LyLHzoxYzc="; buildModules = [ "cmd/${name}" ]; From ef55947d4aa50c596163675ea721fa39d6927e85 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Thu, 18 Apr 2024 00:18:08 +0100 Subject: [PATCH 21/25] fix: update ldflags value to fix compile error --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index b8a5f6d..1d65968 100644 --- a/flake.nix +++ b/flake.nix @@ -25,7 +25,7 @@ default = pkgs.buildGo122Module { inherit name version; GOFLAGS = [ - "-ldflags='github.com/ALT-F4-LLC/build-configs/internal/cli.Version=${version}'" + "-ldflags=github.com/ALT-F4-LLC/build-configs/internal/cli.Version=${version}" ]; src = ./.; vendorHash = "sha256-6B9O6ho4COpJy4HlkzQ0lk+ieezRO3xg9LyLHzoxYzc="; From 3f51777ca087fdfef9957200e06aadb7b595ce4c Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Thu, 18 Apr 2024 01:22:42 +0100 Subject: [PATCH 22/25] feat: go-lambda templates --- internal/config/config.go | 10 ++ internal/config/deploy.go | 12 +++ internal/config/go_cobra_cli.go | 13 +-- internal/config/go_lambda.go | 57 +++++++++++ internal/config/quirk.go | 11 +++ internal/templates/templates.go | 12 ++- .../templates/common/go/.golangci.yaml | 4 +- .../go-lambda/.github__workflows__flake.yaml | 97 +++++++++++++++++++ .../templates/templates/go-lambda/flake.nix | 36 +++++++ .../templates/templates/go-lambda/justfile | 56 +++++++++++ .../templates/go-lambda/nix__lambda.nix | 22 +++++ 11 files changed, 319 insertions(+), 11 deletions(-) create mode 100644 internal/config/deploy.go create mode 100644 internal/config/go_lambda.go create mode 100644 internal/config/quirk.go create mode 100644 internal/templates/templates/go-lambda/.github__workflows__flake.yaml create mode 100644 internal/templates/templates/go-lambda/flake.nix create mode 100644 internal/templates/templates/go-lambda/justfile create mode 100644 internal/templates/templates/go-lambda/nix__lambda.nix diff --git a/internal/config/config.go b/internal/config/config.go index c318916..d62e025 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -45,6 +45,16 @@ func (c Config) GetTemplater() (Templater, error) { return params, err } return params, nil + case "go-lambda": + params := NewGoLambdaConfig(c) + b, err := json.Marshal(c.Parameters) + if err != nil { + return params, err + } + if err := json.Unmarshal(b, ¶ms); err != nil { + return params, err + } + return params, nil } return nil, fmt.Errorf("unsupported template: %v", c.Template) } diff --git a/internal/config/deploy.go b/internal/config/deploy.go new file mode 100644 index 0000000..86804df --- /dev/null +++ b/internal/config/deploy.go @@ -0,0 +1,12 @@ +package config + +type DeployConfig struct { + RoleARN string `json:"roleArn,omitempty" yaml:"roleArn,omitempty"` + Region string `json:"region,omitempty" yaml:"region,omitempty"` +} + +func NewDeployConfig() DeployConfig { + return DeployConfig{ + Region: "us-west-2", + } +} diff --git a/internal/config/go_cobra_cli.go b/internal/config/go_cobra_cli.go index 3c496a3..1d984bc 100644 --- a/internal/config/go_cobra_cli.go +++ b/internal/config/go_cobra_cli.go @@ -1,18 +1,15 @@ package config import ( - "text/template" - "github.com/ALT-F4-LLC/build-configs/internal/templates" ) type GoCobraCliConfig struct { Config - Nix NixGoConfig `json:"nix,omitempty" yaml:"nix,omitempty"` - Lint GolangCILintConfig `json:"lint,omitempty" yaml:"lint,omitempty"` - - PrivateModules string `json:"privateModules,omitempty" yaml:"privateModules,omitempty"` - GoVersion string `json:"goVersion,omitempty" yaml:"goVersion,omitempty"` + GoVersion string `json:"goVersion,omitempty" yaml:"goVersion,omitempty"` + Lint GolangCILintConfig `json:"lint,omitempty" yaml:"lint,omitempty"` + Nix NixGoConfig `json:"nix,omitempty" yaml:"nix,omitempty"` + PrivateModules string `json:"privateModules,omitempty" yaml:"privateModules,omitempty"` } func NewGoCobraCliConfig(c Config) GoCobraCliConfig { @@ -31,7 +28,7 @@ func NewGoCobraCliConfig(c Config) GoCobraCliConfig { } func (c GoCobraCliConfig) Render() error { - files, err := templates.RenderTemplates(map[*template.Template][]string{ + files, err := templates.RenderTemplates(templates.RenderMap{ templates.AllCommonTemplates: { ".envrc", }, diff --git a/internal/config/go_lambda.go b/internal/config/go_lambda.go new file mode 100644 index 0000000..6ca4b99 --- /dev/null +++ b/internal/config/go_lambda.go @@ -0,0 +1,57 @@ +package config + +import ( + "github.com/ALT-F4-LLC/build-configs/internal/templates" +) + +type GoLambdaConfig struct { + Config + GoVersion string `json:"goVersion,omitempty" yaml:"goVersion,omitempty"` + Lint GolangCILintConfig `json:"lint,omitempty" yaml:"lint,omitempty"` + Nix NixGoConfig `json:"nix,omitempty" yaml:"nix,omitempty"` + Quirk QuirkConfig `json:"quirk,omitempty" yaml:"quirk,omitempty"` + Deploy DeployConfig `json:"deploy,omitempty" yaml:"deploy,omitempty"` + PrivateModules string `json:"privateModules,omitempty" yaml:"privateModules,omitempty"` + Lambdas []string `json:"lambdas,omitempty" yaml:"lambdas,omitempty"` +} + +func NewGoLambdaConfig(c Config) GoLambdaConfig { + return GoLambdaConfig{ + Config: c, + GoVersion: "1.22", + Lint: NewGolangCiLintConfig(), + Quirk: NewQuirkConfig(c), + Deploy: NewDeployConfig(), + Lambdas: []string{c.Name}, + + Nix: NixGoConfig{ + NixConfig: NewNixConfig(), + GoPackage: "go", + BuildGoModule: "buildGoModule", + }, + } +} + +func (c GoLambdaConfig) Render() error { + files, err := templates.RenderTemplates(templates.RenderMap{ + templates.AllCommonTemplates: { + ".envrc", + }, + templates.GoCommonTemplates: { + ".editorconfig", + ".github/workflows/golangci-lint.yaml", + ".golangci.yaml", + }, + templates.GoLambdaTemplates: { + ".github/workflows/flake.yaml", + "nix/lambda.nix", + "flake.nix", + "justfile", + }, + }, c) + if err != nil { + return err + } + + return templates.WriteFiles(files) +} diff --git a/internal/config/quirk.go b/internal/config/quirk.go new file mode 100644 index 0000000..7be56d4 --- /dev/null +++ b/internal/config/quirk.go @@ -0,0 +1,11 @@ +package config + +type QuirkConfig struct { + Service string `json:"service,omitempty" yaml:"service,omitempty"` +} + +func NewQuirkConfig(c Config) QuirkConfig { + return QuirkConfig{ + Service: c.Name, + } +} diff --git a/internal/templates/templates.go b/internal/templates/templates.go index 9dddb26..1443b80 100644 --- a/internal/templates/templates.go +++ b/internal/templates/templates.go @@ -17,18 +17,28 @@ var ( //go:embed all:templates/go-cobra-cli/* goCobraCliFS embed.FS + //go:embed all:templates/go-lambda/* + goLambdaFS embed.FS + AllCommonTemplates *template.Template GoCommonTemplates *template.Template GoCobraCliTemplates *template.Template + GoLambdaTemplates *template.Template ) +// RenderMap maps a template set to the filenames* that should be written. +// * - filenames are the end result filenames, not the template names with +// substitution placeholders. +type RenderMap = map[*template.Template][]string + func init() { AllCommonTemplates = template.Must(template.ParseFS(allCommonFS, "templates/common/all/*")) GoCommonTemplates = template.Must(template.ParseFS(goCommonFS, "templates/common/go/*")) GoCobraCliTemplates = template.Must(template.ParseFS(goCobraCliFS, "templates/go-cobra-cli/*")) + GoLambdaTemplates = template.Must(template.ParseFS(goLambdaFS, "templates/go-lambda/*")) } -func RenderTemplates(in map[*template.Template][]string, context any) (map[string]string, error) { +func RenderTemplates(in RenderMap, context any) (map[string]string, error) { files := map[string]string{} for tmpl, set := range in { diff --git a/internal/templates/templates/common/go/.golangci.yaml b/internal/templates/templates/common/go/.golangci.yaml index 1084444..678626c 100644 --- a/internal/templates/templates/common/go/.golangci.yaml +++ b/internal/templates/templates/common/go/.golangci.yaml @@ -1,9 +1,9 @@ --- issues: exclude: - {{ range .Lint.Exclude -}} + {{- range .Lint.Exclude }} - {{ . }} {{- end }} - {{ range .Lint.ExtraExclude -}} + {{- range .Lint.ExtraExclude }} - {{ . }} {{- end }} diff --git a/internal/templates/templates/go-lambda/.github__workflows__flake.yaml b/internal/templates/templates/go-lambda/.github__workflows__flake.yaml new file mode 100644 index 0000000..de59bb2 --- /dev/null +++ b/internal/templates/templates/go-lambda/.github__workflows__flake.yaml @@ -0,0 +1,97 @@ +--- +name: Check, Build, Deploy* + +on: + push: + branches: [main] + pull_request: + +env: + CACHIX_BINARY_CACHE: {{ .Nix.Cachix.BinaryCache }} + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: DeterminateSystems/nix-installer-action@main + - uses: cachix/cachix-action@v14 + with: + authToken: ${{"{{"}} secrets.ALTF4LLC_CACHIX_AUTH_TOKEN {{"}}"}} + name: ${{"{{"}} env.CACHIX_BINARY_CACHE {{"}}"}} + - uses: actions/checkout@v4 + - run: nix develop -c just check + + build: + needs: + - check + runs-on: ubuntu-latest + strategy: + matrix: + profile: + {{- range .Lambdas }} + - {{ . }} + {{- end }} + steps: + - uses: DeterminateSystems/nix-installer-action@main + - uses: cachix/cachix-action@v14 + with: + authToken: ${{"{{"}} secrets.ALTF4LLC_CACHIX_AUTH_TOKEN {{"}}"}} + name: ${{"{{"}} env.CACHIX_BINARY_CACHE {{"}}"}} + {{- if .PrivateModules }} + - id: generate-token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_ID {{"}}"}} + owner: ${{"{{"}} github.repository_owner {{"}}"}} + private-key: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_PRIVATE_KEY {{"}}"}} + - uses: extractions/netrc@v2 + with: + machine: github.com + password: ${{"{{"}} steps.generate-token.outputs.token {{"}}"}} + username: ${{"{{"}} secrets.ALTF4LLC_GITHUB_APP_USER {{"}}"}} + {{- end }} + - uses: actions/checkout@v4 + {{- if .PrivateModules }} + - run: cp --no-preserve=mode ~/.netrc /tmp/.netrc + {{- end }} + - run: nix develop -c just build "${{"{{"}} matrix.profile {{"}}"}}" + - run: nix develop -c just package "${{"{{"}} matrix.profile {{"}}"}}" + - uses: actions/upload-artifact@v4 + with: + name: "zip-${{"{{"}} matrix.profile {{"}}"}}" + path: "dist/${{"{{"}} matrix.profile {{"}}"}}/lambda.zip" + if-no-files-found: error + retention-days: 7 + {{- if .PrivateModules }} + - run: rm -rf /tmp/.netrc + if: success() || failure() + {{- end }} + + deploy-dev: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + permissions: + id-token: write + contents: read + needs: build + strategy: + matrix: + profile: + {{- range .Lambdas }} + - {{ . }} + {{- end }} + steps: + - uses: aws-actions/configure-aws-credentials@v4 + with: + aws-region: {{ .Deploy.Region }} + role-to-assume: {{ .Deploy.RoleARN }} + - uses: actions/download-artifact@v4 + with: + name: "zip-${{"{{"}} matrix.profile {{"}}"}}" + path: "dist/${{"{{"}} matrix.profile {{"}}"}}/lambda.zip" + - uses: DeterminateSystems/nix-installer-action@main + - uses: cachix/cachix-action@v14 + with: + authToken: ${{"{{"}} secrets.ALTF4LLC_CACHIX_AUTH_TOKEN {{"}}"}} + name: ${{"{{"}} env.CACHIX_BINARY_CACHE {{"}}"}} + - run: nix develop -c just deploy dev "${{"{{"}} matrix.profile {{"}}"}}" diff --git a/internal/templates/templates/go-lambda/flake.nix b/internal/templates/templates/go-lambda/flake.nix new file mode 100644 index 0000000..1f35873 --- /dev/null +++ b/internal/templates/templates/go-lambda/flake.nix @@ -0,0 +1,36 @@ +{ + inputs.nixpkgs.url = "github:nixos/nixpkgs/{{ .Nix.NixpkgsBranch }}"; + + outputs = inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ {{range .Nix.Systems}}"{{.}}" {{end}}]; + + perSystem = { config, pkgs, ... }: + let + inherit (pkgs) + {{ .Nix.GoPackage }} + just; + + lambdas = { + {{- range $fn := .Lambdas }} + {{ $fn }} = pkgs.callPackage ./nix/lambda.nix { name = "{{ $fn }}"; }; + {{- end }} + }; + in + { + devShells.default = pkgs.mkShell { + {{ if .PrivateModules -}} + GOPRIVATE = "{{ .PrivateModules }}"; + {{- end }} + buildInputs = [ just ]; + inputsFrom = [ + {{- range .Lambdas }} + config.packages.{{.}} + {{- end }} + ]; + }; + + packages = { } // lambdas; + }; + }; +} diff --git a/internal/templates/templates/go-lambda/justfile b/internal/templates/templates/go-lambda/justfile new file mode 100644 index 0000000..dc2315d --- /dev/null +++ b/internal/templates/templates/go-lambda/justfile @@ -0,0 +1,56 @@ +build profile{{ if .PrivateModules }} netrc="/tmp/.netrc=/tmp/.netrc"{{ end }}: + nix build \ + --json \ + --no-link \ + --print-build-logs \ + {{- if .PrivateModules }} + --sandbox \ + --sandbox-paths "{{"{{"}} netrc {{"}}"}}" \ + {{- end }} + '.#{{"{{"}} profile {{"}}"}}' + +check: + nix flake check + +package profile{{ if .PrivateModules }} netrc="/tmp/.netrc=/tmp/.netrc"{{ end }}: + #!/usr/bin/env bash + set -euxo pipefail + DERIVATION=$(just build "{{"{{"}} profile {{"}}"}}" "{{"{{"}} netrc {{"}}"}}") + OUTPUT=$(echo $DERIVATION | jq -r ".[0].outputs.out") + mkdir -p dist/{{"{{"}} profile {{"}}"}} + install -m 755 $OUTPUT/bin/{{"{{"}} profile {{"}}"}} dist/{{"{{"}} profile {{"}}"}}/bootstrap + (cd dist/{{"{{"}} profile {{"}}"}} && zip lambda.zip bootstrap) + +package-all{{ if .PrivateModules }} netrc="/tmp/.netrc=/tmp/.netrc"{{ end }}: + {{- range .Lambdas }} + just package "{{.}}"{{ if $.PrivateModules }} {{"{{"}} netrc {{"}}"}}{{ end }} + {{- end }} + +package-native lambda: + #!/usr/bin/env bash + set -euxo pipefail + mkdir -p dist/{{"{{"}} lambda {{"}}"}} + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ + go build \ + -ldflags="-s -w" + -o dist/{{"{{"}} lambda {{"}}"}}/bootstrap \ + -tags lambda.norpc + ./cmd/{{"{{"}} lambda {{"}}"}} + (cd dist/{{"{{"}} lambda {{"}}"}} && zip lambda.zip bootstrap) + +package-native-all: + {{- range .Lambdas }} + just package-native "{{.}}" + {{- end }} + +deploy environment lambda: + aws lambda update-function-code \ + --function-name "quirk-{{"{{"}} environment {{"}}"}}-{{.Quirk.Service}}-{{"{{"}} lambda {{"}}"}}" \ + --output json \ + --zip-file "fileb://dist/{{"{{"}} lambda {{"}}"}}/lambda.zip" \ + | jq ".CodeSha256" + +deploy-all environment: + {{- range .Lambdas }} + just deploy "{{"{{"}} environment {{"}}"}}" "{{.}}" + {{- end }} diff --git a/internal/templates/templates/go-lambda/nix__lambda.nix b/internal/templates/templates/go-lambda/nix__lambda.nix new file mode 100644 index 0000000..772d193 --- /dev/null +++ b/internal/templates/templates/go-lambda/nix__lambda.nix @@ -0,0 +1,22 @@ +{ + {{ .Nix.BuildGoModule }}, + name, +}: + +{{ .Nix.BuildGoModule }} { + inherit name; + ldflags = ["-s" "-w"]; + src = ../.; + subPackages = ["cmd/${name}"]; + tags = ["lambda.norpc"]; + vendorHash = ""; + + {{ if .PrivateModules -}} + GOPRIVATE = "{{ .PrivateModules }}"; + {{- end }} + + preBuild = '' + export HOME=/tmp + ls -alh $HOME/.netrc + ''; +} From fa6bcca1da47d15718606d192bb9c590879fd279 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Thu, 18 Apr 2024 01:35:43 +0100 Subject: [PATCH 23/25] docs: update readme and add example configs --- README.md | 39 +++++++++++++++++++++++- examples/go-cobra-cli/build-configs.yaml | 10 ++++++ examples/go-lambda/build-configs.yaml | 16 ++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 examples/go-cobra-cli/build-configs.yaml create mode 100644 examples/go-lambda/build-configs.yaml diff --git a/README.md b/README.md index 7773651..d3f691d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,39 @@ # build-configs -CLI for generating build configurations. + +[![License: Apache 2.0](https://img.shields.io/github/license/ALT-F4-LLC/build-configs)](./LICENSE) +[![Build Status](https://img.shields.io/github/actions/workflow/status/ALT-F4-LLC/build-configs/.github/workflows/flake.yaml)](https://github.com/ALT-F4-LLC/build-configs/actions) + +build-configs is an easy-to-use, standardised configuration generator built to +ease development overhead when bootstrapping and updating configuration in +ALT-F4 projects. + +It was built primarily to solve problems within ALT-F4, but was chosen to be an +open source project in order to demonstrate how the issue of type-standard +configuration updates in a polyrepo environment could be implemented. + +## Installation + +Installing build-configs can be done via Nix or by Go binary install: + +```shell +$ nix profile install 'github:ALT-F4-LLC/build-configs#default' # with nix +$ go install github.com/ALT-F4-LLC/build-configs@latest # with go +``` + +## Examples + +Some example configurations for our template types exist in the +[`examples`](./examples/) directory of the repo. + +## Contributing + +While this is an internal project at ALT-F4, we still welcome contributions from +the community in case you can spot an improvement or a suggestion! + +Feel free to raise PRs and issues against this repository, but also understand +that as this _is_ an internal piece of tooling, some opinionations in templates +and/or logic will be present and we may be stubborn with them! + +## License + +build-configs is licensed under the [Apache License version 2.0](./LICENSE). diff --git a/examples/go-cobra-cli/build-configs.yaml b/examples/go-cobra-cli/build-configs.yaml new file mode 100644 index 0000000..4c33379 --- /dev/null +++ b/examples/go-cobra-cli/build-configs.yaml @@ -0,0 +1,10 @@ +--- +name: project-name +template: go-cobra-cli +parameters: + nix: + cachix: + binaryCache: altf4llc-os + vendorHash: sha256-6B9O6ho4COpJy4HlkzQ0lk+ieezRO3xg9LyLHzoxYzc= + goPackage: go_1_22 + buildGoModule: buildGo122Module diff --git a/examples/go-lambda/build-configs.yaml b/examples/go-lambda/build-configs.yaml new file mode 100644 index 0000000..39f983a --- /dev/null +++ b/examples/go-lambda/build-configs.yaml @@ -0,0 +1,16 @@ +--- +name: project-name +template: go-lambda +parameters: + lambdas: + - lambda1 + - lambda2 + privateModules: "github.com/ALT-F4-LLC/quirk-service-kit" + quirk: + service: lambdatest + deploy: + roleArn: 'arn:aws:iam::1234567890:role/gha-lambda-test-deploy-dev-role' + nix: + vendorHash: '' + goPackage: go_1_22 + buildGoModule: buildGo122Module From a8892b724b7076a41573e6cabe0cc65a47b9d6c4 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Thu, 18 Apr 2024 01:38:25 +0100 Subject: [PATCH 24/25] docs: add usage steps --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index d3f691d..8027cf3 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,16 @@ $ nix profile install 'github:ALT-F4-LLC/build-configs#default' # with nix $ go install github.com/ALT-F4-LLC/build-configs@latest # with go ``` +## Usage + +To generate configuration with build-configs, you can use the `generate` +subcommand in a directory with a `build-configs.yaml` or `build-configs.json` +file present. See [Examples](#examples) for help with this. + +```shell +$ build-configs generate +``` + ## Examples Some example configurations for our template types exist in the From c3795d806280ef940184d73a0b6eb23230f71744 Mon Sep 17 00:00:00 2001 From: Hayden Young <22327045+hbjydev@users.noreply.github.com> Date: Thu, 18 Apr 2024 01:44:47 +0100 Subject: [PATCH 25/25] feat: add logic for a .bcignore file --- internal/templates/ignore.go | 31 +++++++++++++++++++++++++++++++ internal/templates/templates.go | 18 +++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 internal/templates/ignore.go diff --git a/internal/templates/ignore.go b/internal/templates/ignore.go new file mode 100644 index 0000000..bd7fb2f --- /dev/null +++ b/internal/templates/ignore.go @@ -0,0 +1,31 @@ +package templates + +import ( + "os" + "strings" +) + +func HasIgnoreFile(configDir string) bool { + _, err := os.Stat(configDir+"/.bcignore") + return err == nil +} + +func GetIgnoredFiles(configDir string) (files []string, err error) { + if !HasIgnoreFile(configDir) { + return + } + + b, err := os.ReadFile(configDir+"/.bcignore") + if err != nil { + return + } + + for _, line := range strings.Split(string(b), "\n") { + if strings.HasPrefix(line, "#") { + continue + } + files = append(files, line) + } + + return +} diff --git a/internal/templates/templates.go b/internal/templates/templates.go index 1443b80..dd8ca79 100644 --- a/internal/templates/templates.go +++ b/internal/templates/templates.go @@ -2,7 +2,9 @@ package templates import ( "embed" + "fmt" "os" + "slices" "strings" "text/template" ) @@ -64,12 +66,22 @@ func RenderTemplate(t *template.Template, path string, context any) (string, err } func WriteFiles(in map[string]string) error { - for k, v := range in { - if err := EnsureDirExists(k); err != nil { + for filename, contents := range in { + if err := EnsureDirExists(filename); err != nil { return err } - if err := os.WriteFile(k, []byte(v), 0644); err != nil { + ignored, err := GetIgnoredFiles(".") + if err != nil { + return fmt.Errorf("failed to get ignored files: %v", err) + } + + // Skip over files in the .bcignore file + if slices.Contains(ignored, filename) { + continue + } + + if err := os.WriteFile(filename, []byte(contents), 0644); err != nil { return err } }