Skip to content

Commit 7b17d62

Browse files
committed
initial skaffold
1 parent 1ab614e commit 7b17d62

23 files changed

+2172
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Pull Request Lint
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- edited
8+
- reopened
9+
- synchronize
10+
11+
jobs:
12+
pr-lint:
13+
name: Check PR Title (Conventional Commits)
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: amannn/[email protected]
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
with:
20+
validateSingleCommit: true
21+
wip: true
22+
requireScope: false
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
10+
jobs:
11+
lint:
12+
name: Lint
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- uses: golangci/golangci-lint-action@v2
18+
with:
19+
version: v1.40.1

.github/workflows/release.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: release-build
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
19+
- name: Unshallow
20+
run: git fetch --prune --unshallow
21+
22+
- name: Set Docker Image Registry Env
23+
run: |
24+
echo DOCKER_IMAGE_REGISTRY=$(echo "${{ env.REGISTRY}}/${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
25+
26+
- name: Test DOCKER_IMAGE_REGISTRY value
27+
run: echo ${{ env.DOCKER_IMAGE_REGISTRY }}
28+
29+
- name: Set up Go
30+
uses: actions/setup-go@v1
31+
with:
32+
go-version: 1.17.x
33+
34+
- name: Run GoReleaser
35+
uses: goreleaser/goreleaser-action@v1
36+
with:
37+
version: latest
38+
args: release --rm-dist
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Get the version
43+
id: get_version
44+
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/v}
45+
46+
- name: Log in to the Container registry
47+
uses: docker/login-action@v1
48+
with:
49+
registry: ${{ env.REGISTRY }}
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
53+
- name: Build and push Docker image
54+
uses: docker/build-push-action@v2
55+
with:
56+
context: .
57+
push: true
58+
tags: |
59+
${{ env.DOCKER_IMAGE_REGISTRY }}:${{ steps.get_version.outputs.VERSION }}
60+
${{ env.DOCKER_IMAGE_REGISTRY }}:latest

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/helm-repo-updater.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM golang:1.17-alpine3.14 as builder
2+
RUN apk --no-cache add git
3+
WORKDIR /go/src/build
4+
COPY . .
5+
RUN export CGO_ENABLED=0 \
6+
&& mkdir -p dist \
7+
&& go mod vendor \
8+
&& go build -o dist/helm-repo-updater .
9+
10+
FROM alpine:3.14
11+
RUN wget -O /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.14.1/yq_linux_amd64 \
12+
&& chmod +x /usr/local/bin/yq
13+
COPY hack/ /usr/local/bin/
14+
COPY --from=builder /go/src/build/dist/ .
15+
16+
ENTRYPOINT ["./helm-repo-updater"]

cmd/root.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"text/template"
7+
8+
"github.com/docplanner/helm-repo-updater/internal/app/git"
9+
"github.com/docplanner/helm-repo-updater/internal/app/updater"
10+
"github.com/spf13/cobra"
11+
"github.com/spf13/viper"
12+
)
13+
14+
var cfgFile string
15+
16+
// HelmUpdaterConfig contains global configuration and required runtime data
17+
type HelmUpdaterConfig struct {
18+
DryRun bool
19+
LogLevel string
20+
AppName string
21+
UpdateApps []updater.ChangeEntry
22+
GitCommitMessage *template.Template
23+
GitCredentials *git.Credentials
24+
GitConf *git.Conf
25+
}
26+
27+
type GitConf struct {
28+
RepoURL string
29+
Branch string
30+
File string
31+
}
32+
33+
type UpdateApp struct {
34+
Name string
35+
File string
36+
Key string
37+
Image string
38+
}
39+
40+
// rootCmd represents the base command when called without any subcommands
41+
var rootCmd = &cobra.Command{
42+
Use: "helm-repo-updater",
43+
Short: "Helm repo updater",
44+
// Uncomment the following line if your bare application
45+
// has an action associated with it:
46+
// Run: func(cmd *cobra.Command, args []string) { },
47+
}
48+
49+
// Execute adds all child commands to the root command and sets flags appropriately.
50+
// This is called by main.main(). It only needs to happen once to the rootCmd.
51+
func Execute() {
52+
cobra.CheckErr(rootCmd.Execute())
53+
}
54+
55+
func init() {
56+
cobra.OnInitialize(initConfig)
57+
58+
// Here you will define your flags and configuration settings.
59+
// Cobra supports persistent flags, which, if defined here,
60+
// will be global for your application.
61+
62+
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.helm-repo-updater.yaml)")
63+
64+
// Cobra also supports local flags, which will only run
65+
// when this action is called directly.
66+
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
67+
}
68+
69+
// initConfig reads in config file and ENV variables if set.
70+
func initConfig() {
71+
if cfgFile != "" {
72+
// Use config file from the flag.
73+
viper.SetConfigFile(cfgFile)
74+
} else {
75+
// Find home directory.
76+
home, err := os.UserHomeDir()
77+
cobra.CheckErr(err)
78+
79+
// Search config in home directory with name ".helm-repo-updater" (without extension).
80+
viper.AddConfigPath(home)
81+
viper.SetConfigType("yaml")
82+
viper.SetConfigName(".helm-repo-updater")
83+
}
84+
85+
viper.AutomaticEnv() // read in environment variables that match
86+
87+
// If a config file is found, read it in.
88+
if err := viper.ReadInConfig(); err == nil {
89+
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
90+
}
91+
}

cmd/run.go

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path"
7+
"text/template"
8+
9+
"github.com/argoproj-labs/argocd-image-updater/pkg/log"
10+
"github.com/docplanner/helm-repo-updater/internal/app/git"
11+
"github.com/docplanner/helm-repo-updater/internal/app/updater"
12+
"github.com/spf13/cobra"
13+
)
14+
15+
var cfg = updater.HelmUpdaterConfig{}
16+
17+
// runCmd represents the run command
18+
var runCmd = &cobra.Command{
19+
Use: "run",
20+
Short: "Runs the helm repo updater",
21+
Run: func(cmd *cobra.Command, args []string) {
22+
gitUser, _ := cmd.Flags().GetString("git-commit-user")
23+
gitEmail, _ := cmd.Flags().GetString("git-commit-email")
24+
gitPass, _ := cmd.Flags().GetString("git-password")
25+
gitBranch, _ := cmd.Flags().GetString("git-branch")
26+
gitRepoURL, _ := cmd.Flags().GetString("git-repo-url")
27+
gitFile, _ := cmd.Flags().GetString("git-file")
28+
gitDir, _ := cmd.Flags().GetString("git-dir")
29+
sshKey, _ := cmd.Flags().GetString("ssh-private-key")
30+
appName, _ := cmd.Flags().GetString("app-name")
31+
logLevel, _ := cmd.Flags().GetString("loglevel")
32+
dryRun, _ := cmd.Flags().GetBool("dry-run")
33+
helmKVs, _ := cmd.Flags().GetStringToString("helm-key-values")
34+
35+
if err := log.SetLogLevel(logLevel); err != nil {
36+
fmt.Println(err)
37+
38+
os.Exit(1)
39+
}
40+
41+
if len(helmKVs) == 0 {
42+
err := cmd.Help()
43+
if err != nil {
44+
return
45+
}
46+
os.Exit(1)
47+
}
48+
49+
var updateApps []updater.ChangeEntry
50+
for k, v := range helmKVs {
51+
updateApps = append(updateApps, updater.ChangeEntry{
52+
Key: k,
53+
NewValue: v,
54+
})
55+
}
56+
57+
gitCredentials := &git.Credentials{
58+
Username: gitUser,
59+
Email: gitEmail,
60+
Password: gitPass,
61+
SSHPrivKey: sshKey,
62+
}
63+
64+
gitConf := &git.Conf{
65+
RepoURL: gitRepoURL,
66+
Branch: gitBranch,
67+
}
68+
69+
if tpl, err := template.New("commitMessage").Parse(git.DefaultGitCommitMessage); err != nil {
70+
log.Fatalf("could not parse commit message template: %v", err)
71+
72+
return
73+
} else {
74+
log.Debugf("Successfully parsed commit message template")
75+
76+
gitConf.Message = tpl
77+
}
78+
79+
cfg = updater.HelmUpdaterConfig{
80+
DryRun: dryRun,
81+
LogLevel: logLevel,
82+
AppName: appName,
83+
UpdateApps: updateApps,
84+
File: path.Join(gitDir, appName, gitFile),
85+
GitCredentials: gitCredentials,
86+
GitConf: gitConf,
87+
}
88+
89+
err := runImageUpdater(cfg)
90+
if err != nil {
91+
log.Errorf("Error: %v", err)
92+
}
93+
94+
},
95+
}
96+
97+
func runImageUpdater(cfg updater.HelmUpdaterConfig) error {
98+
99+
syncState := updater.NewSyncIterationState()
100+
101+
fmt.Println(cfg.UpdateApps)
102+
103+
err := func(cfg updater.HelmUpdaterConfig) error {
104+
log.Debugf("Processing application %s in directory %s", cfg.AppName, cfg.File)
105+
106+
err := updater.UpdateApplication(cfg, syncState)
107+
if err != nil {
108+
return err
109+
}
110+
111+
return nil
112+
}(cfg)
113+
if err != nil {
114+
return err
115+
}
116+
117+
return nil
118+
}
119+
120+
func init() {
121+
rootCmd.AddCommand(runCmd)
122+
123+
runCmd.Flags().String("git-commit-user", "", "Username to use for Git commits")
124+
runCmd.Flags().String("git-commit-email", "", "E-Mail address to use for Git commits")
125+
runCmd.Flags().String("git-password", "", "Password for github user")
126+
runCmd.Flags().String("git-branch", "develop", "branch")
127+
runCmd.Flags().String("git-repo-url", "", "git repo url")
128+
runCmd.Flags().String("git-file", "", "file eg. values.yaml")
129+
runCmd.Flags().String("git-dir", "", "file eg. /production/charts/")
130+
runCmd.Flags().String("app-name", "", "app name")
131+
runCmd.Flags().String("ssh-private-key", "", "ssh private key (only using ")
132+
runCmd.Flags().Bool("dry-run", false, "run in dry-run mode. If set to true, do not perform any changes")
133+
runCmd.Flags().String("loglevel", "info", "set the loglevel to one of trace|debug|info|warn|error")
134+
runCmd.Flags().StringToString("helm-key-values", nil, "helm key-values sets")
135+
136+
_ = runCmd.MarkFlagRequired("git-commit-user")
137+
_ = runCmd.MarkFlagRequired("git-commit-email")
138+
_ = runCmd.MarkFlagRequired("git-repo-url")
139+
_ = runCmd.MarkFlagRequired("git-file")
140+
_ = runCmd.MarkFlagRequired("git-dir")
141+
_ = runCmd.MarkFlagRequired("helm-key-values")
142+
_ = runCmd.MarkFlagRequired("app-name")
143+
144+
}

0 commit comments

Comments
 (0)