Skip to content

Commit

Permalink
feat: add helm repos from deps, update project dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Jun 17, 2024
1 parent a4becbb commit d38d04c
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.21
go-version: 1.22
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
- uses: docker/login-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.21
go-version: 1.22
- uses: golangci/golangci-lint-action@v3
- uses: docker/login-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.21
go-version: 1.22
- uses: golangci/golangci-lint-action@v3
- uses: docker/login-action@v3
with:
Expand Down
21 changes: 14 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
FROM alpine/helm:3.10.2 as helm
FROM alpine/helm:3.15.2 as helm

FROM debian:10.11-slim
FROM debian:12-slim

COPY --from=helm /usr/bin/helm /usr/bin/helm

RUN apt-get update \
&& apt-get install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common curl ca-certificates \
&& curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - \
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" \
&& apt-get update \
&& apt-get install -y docker-ce
&& apt-get install -y ca-certificates curl \
&& install -m 0755 -d /etc/apt/keyrings \
&& curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc \
&& chmod a+r /etc/apt/keyrings/docker.asc

RUN echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null

RUN apt-get update \
&& apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

COPY samo /usr/bin/samo
49 changes: 49 additions & 0 deletions cmd/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type helmFlags struct {
Dir string `mapstructure:"helm-dir"`
Registry string `mapstructure:"helm-registry"`
AbsoluteDir bool `mapstructure:"helm-absolute-dir"`
AddRepoDeps bool `mapstructure:"helm-add-repo-deps"`
}

func createHelmCmd() *cobra.Command {
Expand All @@ -48,6 +49,7 @@ func createHelmCmd() *cobra.Command {
addStringFlag(cmd, "helm-push-type", "", "harbor", "helm repository push type. Values: upload,harbor [deprecated]")
addStringFlag(cmd, "helm-registry", "", "", "helm OCI registry")
addBoolFlag(cmd, "helm-absolute-dir", "", false, "helm chart absolute directory (skip add project name in path)")
addBoolFlag(cmd, "helm-add-repo-deps", "", false, "add https repositories from dependencies")

addChildCmd(cmd, createHelmBuildCmd())
addChildCmd(cmd, createHelmPushCmd())
Expand Down Expand Up @@ -77,6 +79,53 @@ func helmClean(flags helmFlags) {
}
}

func helmAddRepoDeps(h *chart.Chart) {

index := false
for _, d := range h.Metadata.Dependencies {
repo := d.Repository
if len(repo) > 0 && strings.HasPrefix(repo, "https://") {
helmAddRepository(repo)
index = true
}
}

// update index of the added repository
if index {
tools.ExecCmd("helm", "repo", "update")
}
}

func helmAddRepository(repo string) {

// create name from URL
name := strings.TrimPrefix(repo, "https://")
index := strings.Index(name, "/")
if index >= 0 {
name = name[:index]
}
name = envRegexp.ReplaceAllString(name, "_")

// add repository
var command []string
command = append(command, "repo", "add")
command = append(command, name, repo)
tools.ExecCmd("helm", command...)
}

var envRegexp = createRegexp()

// initialize yaml file configuration source
func createRegexp() *regexp.Regexp {

// initialize the regex for EnvConfigSource
tmp, err := regexp.Compile("[^a-zA-Z0-9]+")
if err != nil {
panic(err)
}
return tmp
}

// deprecated
func helmAddRepo(flags helmFlags) {
if len(flags.Repo) == 0 {
Expand Down
5 changes: 5 additions & 0 deletions cmd/helm_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func helmBuild(project *Project, flags helmBuildFlags) {
helmClean(flags.Helm)
// add and update custom helm repo
helmAddRepo(flags.Helm)
// add repo from chart dependencies
if flags.Helm.AddRepoDeps {
chart := loadChart(project, flags.Helm)
helmAddRepoDeps(chart)
}

// filter resources to output dir
buildHelmChart(flags, project)
Expand Down
5 changes: 5 additions & 0 deletions cmd/helm_deps_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func helmDepsUpdate(project *Project, flags helmDepsUpdateFlags) {

c := loadChart(project, flags.Helm)

// add repo from chart dependencies
if flags.Helm.AddRepoDeps {
helmAddRepoDeps(c)
}

notFound := true
update := false
for _, d := range c.Metadata.Dependencies {
Expand Down
5 changes: 5 additions & 0 deletions cmd/helm_deps_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func helmDepsValidate(project *Project, flags helmDepsValidateFlags) {
chart := loadChart(project, flags.Helm)
failed := false

// add repo from chart dependencies
if flags.Helm.AddRepoDeps {
helmAddRepoDeps(chart)
}

log.Info("Dependencies validation", log.F("validate-type", flags.ValidateType).F("chart", chart.Name()).F("version", chart.Metadata.Version))

fmt.Println("Dependencies:")
Expand Down
6 changes: 6 additions & 0 deletions cmd/helm_lock_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ func createHelmLockUpdateCmd() *cobra.Command {

func helmLockUpdate(project *Project, flags helmLockUpdateFlags) {

// add repo from chart dependencies
if flags.Helm.AddRepoDeps {
chart := loadChart(project, flags.Helm)
helmAddRepoDeps(chart)
}

dir := helmDir(project, flags.Helm)

// update helm Chart.lock
Expand Down
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/lorislab/samo

go 1.21

toolchain go1.21.4
go 1.22.0

require (
github.com/Masterminds/semver/v3 v3.2.1
Expand All @@ -14,7 +12,7 @@ require (
github.com/spf13/viper v1.19.0
go.hein.dev/go-version v0.1.0
gopkg.in/yaml.v2 v2.4.0
helm.sh/helm/v3 v3.14.3
helm.sh/helm/v3 v3.15.2
)

require (
Expand All @@ -28,7 +26,7 @@ require (
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

require github.com/rs/zerolog v1.33.0
Expand Down
9 changes: 5 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
Expand Down Expand Up @@ -233,9 +234,9 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
helm.sh/helm/v3 v3.14.3 h1:HmvRJlwyyt9HjgmAuxHbHv3PhMz9ir/XNWHyXfmnOP4=
helm.sh/helm/v3 v3.14.3/go.mod h1:v6myVbyseSBJTzhmeE39UcPLNv6cQK6qss3dvgAySaE=
helm.sh/helm/v3 v3.15.2 h1:/3XINUFinJOBjQplGnjw92eLGpgXXp1L8chWPkCkDuw=
helm.sh/helm/v3 v3.15.2/go.mod h1:FzSIP8jDQaa6WAVg9F+OkKz7J0ZmAga4MABtTbsb9WQ=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=

0 comments on commit d38d04c

Please sign in to comment.