GithubHelp home page GithubHelp logo

stuttgart-things / machineshop Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 6.91 MB

git based CLI interface for managing configuration as code

License: Apache License 2.0

Go 100.00%
binaries cli cobra-cli golang stuttgart-things templating vault

machineshop's Introduction

stuttgart-things

[sˈθɪŋz] - using modularity to speed up parallel builds

used for configuration code like gitops configuration, ansible playbooks, Dockerfiles or helm charts.


AnsibleDockerKubernetesTerraformStatic BadgePacker


Button Component



GeeksforGeeks logo

INFRASTRUCTURE AS CODE

ANSIBLE

sthings-base_os

INSTALL

CHECK RELEASES

# INSTALL ROLE - EXAMPLE VERSION
COLLECTION_VERSION=0.1.8
ansible-galaxy collection install -f \
https://github.com/stuttgart-things/stuttgart-things/releases/download/${COLLECTION_VERSION}/sthings-base_os-${COLLECTION_VERSION}.tar.gz

DEPLOY BINARIES (DEV-MACHINE PROFILE)

ansible-playbook sthings.base_os.download_install_binaries \
-i inv -vv \
-e target_host=all \
-e profile=dev \
-vv

Author Information

Patrick Hermann, stuttgart-things 03/2023
Christian Mueller, stuttgart-things 08/2023

machineshop's People

Contributors

patrick-hermann-sva avatar renovate[bot] avatar xiaomin-lai avatar xlai89 avatar

Stargazers

 avatar

machineshop's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/release-golang.yaml
.github/workflows/validate-golang.yaml
gomod
go.mod
  • go 1.22.3
  • github.com/go-git/go-billy/v5 v5.5.0
  • github.com/go-git/go-git/v5 v5.12.0
  • github.com/google/go-github/v62 v62.0.0
  • github.com/pterm/pterm v0.12.79
  • github.com/spf13/cobra v1.8.1
  • github.com/stuttgart-things/sthingsBase v0.1.41
  • github.com/stuttgart-things/sthingsCli v0.1.109
  • go.hein.dev/go-version v0.1.0
  • gopkg.in/yaml.v2 v2.4.0

  • Check this box to trigger a request for Renovate to run again on this repository

[FIX] - UPDATE TO CURRENT GOLANG VERSION

  • CREATE BRANCH
  • MAKE SURE YOU'RE USING GOLANG 1.22.3
  • REMOVE go.mod + go.sum
  • RUN GOLANG INIT
go mod init github.com/stuttgart-things/machineshop
go mod tidy
  • INSTALL TASK
  • TEST WITH task test
  • BUILD BINARY W/ task build

[FEATURE] - ADD ABILITY FOR COMMITING BRANCH/PR TO GIT REPO

WE WANT TO ADD A FEATURE FOR CREATING FILES, BRANCHES + PRS WITH ONE COMMAND OF MACHINESHOP

EASIEST PR CREATION (FILES+BRANCH+PR)

machineshop push --target pr \
--files "./lint.yaml:.github/workflows/call-ansible-lint.yaml, ./lint-profile.yaml:ansible-lint" \ # SOURCE(LOCAL):TARGET(BRANCH-REPO)
--repo machineshop \
--branch update-ansible-workflows \
--title added-lint-profile 

FLAGS + DEFAULTS

-> --repo NO DEFAULT / VALUE MANDATORY - NOT EMPTY
-> --title NO DEFAULT / VALUE MANDATORY - NOT EMPTY
-> --files NO DEFAULT / NOT MANDATORY
-> --owner [stuttgart-things]
-> --authorName=[os.Getenv("GITHUB_AUTHOR") machineShop]
-> --authorEmail=[os.Getenv("GITHUB_EMAIL") or [email protected]]
-> --token=[os.Getenv("GITHUB_TOKEN")]
-> --description=[title]
-> --commitMessage=[title]
-> --baseBranch[main]

  • How to auto merge (after pr was created)?
  • How to set labels on a pr?

machineShop subcommand code / functions to -> machineshop
github code / functions to -> sthings-cli github.go

[FIX] - LINITING ERRORS

level=warning msg="[config_reader] The configuration option `linters.errcheck.ignore` is deprecated, please use `linters.errcheck.exclude-functions`."
internal/git.go:[7](https://github.com/stuttgart-things/machineshop/actions/runs/9219246421/job/25364061737#step:4:9)4:10: Error return value of `w.Commit` is not checked (errcheck)
	w.Commit(commitMsg, &git.CommitOptions{})
	        ^
surveys/profiles.go:101:[8](https://github.com/stuttgart-things/machineshop/actions/runs/9219246421/job/25364061737#step:4:10)1: Error return value of `(github.com/pterm/pterm.TablePrinter).Render` is not checked (errcheck)
	pterm.DefaultTable.WithHasHeader().WithBoxed().WithData(repositoryTable).Render()
	                                                                               ^
cmd/create.go:100:25: Error return value of `sthingsCli.PushCommit` is not checked (errcheck)
			sthingsCli.PushCommit(client, ref, gitTree, groupName, repositoryName, authorName, authorEmail, commitMessage)
			                     ^
cmd/create.go:142:1: don't use `init` function (gochecknoinits)
func init() {
^
cmd/flow.go:16[9](https://github.com/stuttgart-things/machineshop/actions/runs/9219246421/job/25364061737#step:4:11):1: don't use `init` function (gochecknoinits)
func init() {
^
cmd/get.go:46:1: don't use `init` function (gochecknoinits)
func init() {
^
cmd/flow.go:58:16: string `git` has 4 occurrences, make it a constant (goconst)
		if source == "git" {
		             ^
internal/git.go:76:2: commentFormatting: put a space between `//` and comment text (gocritic)
	//Push the code to the remote
	^
internal/git.go:57:2: commentedOutCode: may want to remove commented-out code (gocritic)
	// err = fs.Remove(filePath2)
	^
surveys/install.go:42:21: builtinShadow: shadowing of predeclared identifier: error (gocritic)
				renderedScript, error := sthingsBase.RenderTemplateInline(string(scriptTemplate), "missingkey=error", "{{", "}}", allTemplateVariablesAndDefaults)
				                ^
surveys/install.go:92:5: nestingReduce: invert if cond, replace body with `continue`, move old body after the statement (gocritic)
				if binaryProfile[selectedProfile].Url != "" {
				^
surveys/profiles.go:29:2: commentedOutCode: may want to remove commented-out code (gocritic)
	// allKeys := []string{}
	^
surveys/profiles.go:39:4: commentedOutCode: may want to remove commented-out code (gocritic)
			// allKeys = append(allKeys, key)
			^
surveys/profiles.go:58:5: sloppyLen: len(allBinaries) >= 0 is always true (gocritic)
	if len(allBinaries) >= 0 {
	   ^
surveys/profiles.go:62:5: sloppyLen: len(allScripts) >= 0 is always true (gocritic)
	if len(allScripts) >= 0 {
	   ^
surveys/release.go:28:5: nestingReduce: invert if cond, replace body with `continue`, move old body after the statement (gocritic)
				if repositoryProfile[selectedProfile].Url != "" {
				^
internal/validation.go:22: File is not `gofmt`-ed with `-s` `-r 'interface{} -> any'` (gofmt)
func VerifyReadKeyValues(templateValues []string, log *sthingsBase.Logger, enableVault bool) map[string]interface{} {
cmd/flow.go:20: File is not `gofmt`-ed with `-s` `-r 'interface{} -> any'` (gofmt)
	defaults       = make(map[string]interface{})
cmd/render.go:30: File is not `gofmt`-ed with `-s` `-r 'interface{} -> any'` (gofmt)
	defaultVariables = make(map[string]interface{})
	flagVariables    = make(map[string]interface{})
internal/validation.go:20:7: G[10](https://github.com/stuttgart-things/machineshop/actions/runs/9219246421/job/25364061737#step:4:12)1: Potential hardcoded credentials (gosec)
const regexPatternVaultSecretPath = `.+/data/.+:.+`
      ^
internal/output.go:30: line is 144 characters (lll)
	pterm.DefaultCenter.Print(pterm.DefaultHeader.WithFullWidth().WithBackgroundStyle(pterm.NewStyle(pterm.BgLightCyan)).WithMargin(2).Sprint(cmd))
cmd/create.go:131: line is 171 characters (lll)
			err, pullRequestID := sthingsCli.CreatePullRequest(client, prSubject, prRepoOwner, sourceOwner, commitBranch, prRepo, sourceRepo, repoBranch, baseBranch, prDescription)
cmd/render.go:154: line is 158 characters (lll)
		renderedTemplate, err := sthingsBase.RenderTemplateInline(templateFile, renderOption, brackets[bracketFormat].begin, brackets[bracketFormat].end, variables)
cmd/root.go:43: line is 144 characters (lll)
	rootCmd.PersistentFlags().StringVar(&gitRepository, "git", "https://github.com/stuttgart-things/stuttgart-things.git", "source git repository")
surveys/install.go:107:13: `OVERWIRTE` is a misspelling of `OVERWRITE` (misspell)
					// ADD OVERWIRTE OPTION
					       ^
cmd/root.go:28:24: `infrasturcture` is a misspelling of `infrastructure` (misspell)
	Short: "machineShop - infrasturcture cli",
	                      ^
internal/output.go:44:95: unused-parameter: parameter 'overwrite' seems to be unused, consider removing or renaming it as _ (revive)
func HandleRenderOutput(outputFormat, destinationPath, renderedTemplate string, decodeBase64, overwrite bool) {
                                                                                              ^
cmd/render.go:44:32: unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _ (revive)
	Run: func(cmd *cobra.Command, args []string) {
	                              ^
cmd/get.go:21:32: unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _ (revive)
	Run: func(cmd *cobra.Command, args []string) {
	                              ^
cmd/flow.go:48:32: unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _ (revive)
	Run: func(cmd *cobra.Command, args []string) {
	                              ^
internal/output.go:55:21: unnecessary conversion (unconvert)
		fmt.Println(string(renderedTemplate))
		                  ^
internal/output.go:58:54: unnecessary conversion (unconvert)
		sthingsBase.WriteDataToFile(destinationPath, string(renderedTemplate))
		                                                   ^
surveys/install.go:104:64: unnecessary conversion (unconvert)
						renderedURL, _ := sthingsBase.RenderTemplateInline(string(url), "missingkey=zero", "{{", "}}", allTemplateVariablesAndDefaults)
						                                                         ^
internal/git.go:17:[11](https://github.com/stuttgart-things/machineshop/actions/runs/9219246421/job/25364061737#step:4:13)6: unnecessary leading newline (whitespace)

^
internal/output.go:22:83: unnecessary leading newline (whitespace)

^
internal/output.go:61:1: unnecessary trailing newline (whitespace)

^
internal/validation.go:29:30: unnecessary leading newline (whitespace)

^
internal/validation.go:64:3: unnecessary trailing newline (whitespace)

^
internal/validation.go:101:2: unnecessary trailing newline (whitespace)

^
cmd/push.go:49:6: ineffectual assignment to target (ineffassign)
					target = "orange"
					^
internal/output.go:18:87: Magic number: 50, in <argument> detected (mnd)
	logger = sthingsBase.StdOutFileLogger("/tmp/machineShop.log", "2006-01-02 15:04:05", 50, 3, 28)
	                                                                                     ^
internal/validation.go:17:84: Magic number: 50, in <argument> detected (mnd)
	log = sthingsBase.StdOutFileLogger("/tmp/machineShop.log", "2006-01-02 15:04:05", 50, 3, 28)
	                                                                                  ^
surveys/install.go:19:97: Magic number: 50, in <argument> detected (mnd)
	log              = sthingsBase.StdOutFileLogger("/tmp/machineShop.log", "2006-01-02 15:04:05", 50, 3, 28)
	                                                                                               ^
surveys/install.go:27:56: Magic number: 0600, in <argument> detected (mnd)
	sthingsBase.CreateNestedDirectoryStructure(scriptDir, 0600)
	                                                      ^
surveys/install.go:84:62: Magic number: 0600, in <argument> detected (mnd)
		sthingsBase.CreateNestedDirectoryStructure(tmpDownloadDir, 0600)
		                                                           ^
surveys/install.go:[13](https://github.com/stuttgart-things/machineshop/actions/runs/9219246421/job/25364061737#step:4:15)2:104: Magic number: 0700, in <argument> detected (mnd)
								sthingsCli.ExtractTarGzArchive(tmpDownloadDir+"/"+filepath.Base(url), tmpDownloadDir+"/"+name, 0700)
								                                                                                               ^
surveys/install.go:152:63: Magic number: 0755, in <argument> detected (mnd)
							sthingsBase.SetUnixFilePermissions(destinationBinPath, 0755)
							                                                       ^
cmd/flow.go:61:61: Magic number: 0777, in <argument> detected (mnd)
			sthingsBase.CreateNestedDirectoryStructure(workspaceDir, 0777)
			                                                         ^
surveys/profiles.go:66:2: naked return in func `SelectInstallProfiles` with 40 lines of code (nakedret)
	return
	^
internal/git.go:30:10: ST1005: error strings should not be capitalized (stylecheck)
		return fmt.Errorf("Could not git clone repository %s: %w", repository, err)
		       ^
internal/git.go:37:10: ST1005: error strings should not be capitalized (stylecheck)
		return fmt.Errorf("Could not get git worktree: %w", err)
		       ^
internal/git.go:45:10: ST1005: error strings should not be capitalized (stylecheck)
		return fmt.Errorf("Could not create new file: %w", err)
		       ^
surveys/profiles.go:[14](https://github.com/stuttgart-things/machineshop/actions/runs/9219246421/job/25364061737#step:4:16):2: ST1003: struct field Url should be URL (stylecheck)
	Url string `mapstructure:"url"`
	^
surveys/profiles.go:71:2: ST1003: struct field Url should be URL (stylecheck)
	Url     string `mapstructure:"url"`
	^

[FEATURE] - UPADTE FLOW

FOR TEMPLATING:

ONLY VARIABLES FOR ALREADY ASKED VARIABLES SHOULD BE POSSIBLE LIKE {{ varName }}

FOR WORKFLOW:

ADD SKIP OPTION FOR FOLLOWING (TO BE RENDERED) TEMPLATE

FOR SAVING FILE:

ADD FILE EXTENSION (e.g. .yaml) FIRST
ADD CURRENT DIR

[FEATURE] - ADD PYTHON LIKE DICT FEATURE FOR RENDER CMD

WE WANT TO ADD TO RENDER CMD:

  • THE ABILITY FOR PICKING OUT VALUES OUT OF A DICT (WHICH IS COMING FROM A YAML FILE WHICH WILL BE LOADED PRIOR)

TODO:

  • CREATE FUNC (IN THE GIVEN EXAMPLE) WHICH RETURNS THE ACTUAL VALUE FOR E.G. CPU OR RAM AND TAKES THE KEYS AS INPUT
// E.G func GetNestedKeys(dictName, dictKey, subKey string) (string)
// ram := GetNestedKeys("vmConfig", ...)
// fmt.Println(ram)

EXAMPLE STRUCTURE FOR YAML:

vmConfig:
  m:
    cpu: 6
    ram: 8192
  l:
    cpu: 8
    ram: 10240

TEST CODE FOR LOADING THE YAML

package main

import (
	"fmt"
	"os"

	"gopkg.in/yaml.v2"
)

func main() {
	obj := make(map[string]interface{})

	yamlFile, err := os.ReadFile("example.yaml")
	if err != nil {
		fmt.Printf("yamlFile.Get err #%v ", err)
	}
	err = yaml.Unmarshal(yamlFile, obj)
	if err != nil {
		fmt.Printf("Unmarshal: %v", err)
	}
	fmt.Println(obj)

	fmt.Println(obj["vmConfig"].(map[interface{}]interface{})["m"].(map[interface{}]interface{})["cpu"])
}

[FEATURE] [CREATE] - ADD DELETION OF BRANCH

// DeleteRef deletes a ref from a repository.
//
// GitHub API docs: https://docs.github.com/rest/git/refs#delete-a-reference
//
//meta:operation DELETE /repos/{owner}/{repo}/git/refs/{ref}
func (s *GitService) DeleteRef(ctx context.Context, owner string, repo string, ref string) (*Response, error) {
	ref = strings.TrimPrefix(ref, "refs/")
	u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, refURLEscape(ref))
	req, err := s.client.NewRequest("DELETE", u, nil)
	if err != nil {
		return nil, err
	}

	return s.client.Do(ctx, req, nil)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.