Skip to content

Commit

Permalink
Rely on credential manager or docker configuration to get repository …
Browse files Browse the repository at this point in the history
…authentication information
  • Loading branch information
Christophe VILA committed Apr 4, 2022
1 parent 7b309c9 commit 4f37f1b
Show file tree
Hide file tree
Showing 13 changed files with 1,367 additions and 348 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/github-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release on github
on:
push:
tags:
- 'v*'
jobs:
build:
name: Make release
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.17'
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 1
path: ${{ github.workspace }}/src/github.com/cvila84/helm-image
- name: Make release
run: |
cd ${{ github.workspace }}/src/github.com/cvila84/helm-image
make dist
- name: Publish release
uses: softprops/action-gh-release@v1
with:
prerelease: true
files: ${{ github.workspace }}/src/github.com/cvila84/helm-image/_dist/helm-image*
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## Version 1.0.7 - 04/04/2022
* Rely on credential manager (only windows) or docker configuration to get repository authentication information
* Bump to containerd 1.6.2

## Version 1.0.6 - 08/11/2021
* Added -o flag to save command (set the output file name)

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dist_linux:
rm -rf bin && mkdir -p $(DIST)
GOOS=linux GOARCH=amd64 go get -t -v ./...
GOOS=linux GOARCH=amd64 go build -o bin/$(BINARY_LINUX) -ldflags $(LDFLAGS) main.go
curl -L https://github.com/containerd/containerd/releases/download/v1.3.4/containerd-1.3.4.linux-amd64.tar.gz -o containerd.tar.gz
curl -L https://github.com/containerd/containerd/releases/download/v1.6.2/containerd-1.6.2-linux-amd64.tar.gz -o containerd.tar.gz
tar xvf containerd.tar.gz
tar czvf $(DIST)/$(TAR_LINUX) bin README.md LICENSE plugin.yaml

Expand All @@ -24,6 +24,6 @@ dist_windows:
rm -rf bin && mkdir -p $(DIST)
GOOS=windows GOARCH=amd64 go get -t -v ./...
GOOS=windows GOARCH=amd64 go build -o bin/$(BINARY_WINDOWS) -ldflags $(LDFLAGS) main.go
curl -L https://github.com/cvila84/containerd/releases/download/v1.3.4/containerd-1.3.4.windows-amd64.tar.gz -o containerd.tar.gz
curl -L https://github.com/containerd/containerd/releases/download/v1.6.2/containerd-1.6.2-windows-amd64.tar.gz -o containerd.tar.gz
tar xvf containerd.tar.gz
tar czvf $(DIST)/${TAR_WINDOWS} bin README.md LICENSE plugin.yaml
88 changes: 64 additions & 24 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ func (l *imagesList) get() []string {
return images
}

func (l *imagesList) contains(image string) bool {
if _, ok := l.images[image]; ok {
return true
} else {
return false
}
}

type taskErrors struct {
errors []error
mu sync.Mutex
Expand Down Expand Up @@ -171,16 +179,24 @@ func addContainerImages(images *imagesList, path string, verbose bool, debug boo
log.Printf("Searching for deployment images in %s...\n", path)
}
for _, container := range deployment.Spec.Template.Spec.Containers {
if verbose {
fmt.Printf("Found %s\n", container.Image)
if !images.contains(container.Image) {
if verbose {
fmt.Printf("Found %s\n", container.Image)
}
images.add(container.Image)
} else if debug {
fmt.Printf("Ignoring %s\n", container.Image)
}
images.add(container.Image)
}
for _, container := range deployment.Spec.Template.Spec.InitContainers {
if verbose {
fmt.Printf("Found %s\n", container.Image)
if !images.contains(container.Image) {
if verbose {
fmt.Printf("Found %s\n", container.Image)
}
images.add(container.Image)
} else if debug {
fmt.Printf("Ignoring %s\n", container.Image)
}
images.add(container.Image)
}
}
statefulSet, ok := manifest.(*appsv1.StatefulSet)
Expand All @@ -189,16 +205,24 @@ func addContainerImages(images *imagesList, path string, verbose bool, debug boo
log.Printf("Searching for statefulset images in %s...\n", path)
}
for _, container := range statefulSet.Spec.Template.Spec.Containers {
if verbose {
fmt.Printf("Found %s\n", container.Image)
if !images.contains(container.Image) {
if verbose {
fmt.Printf("Found %s\n", container.Image)
}
images.add(container.Image)
} else if debug {
fmt.Printf("Ignoring %s\n", container.Image)
}
images.add(container.Image)
}
for _, container := range statefulSet.Spec.Template.Spec.InitContainers {
if verbose {
fmt.Printf("Found %s\n", container.Image)
if !images.contains(container.Image) {
if verbose {
fmt.Printf("Found %s\n", container.Image)
}
images.add(container.Image)
} else if debug {
fmt.Printf("Ignoring %s\n", container.Image)
}
images.add(container.Image)
}
}
jobs, ok := manifest.(*batchv1.Job)
Expand All @@ -207,16 +231,24 @@ func addContainerImages(images *imagesList, path string, verbose bool, debug boo
log.Printf("Searching for job images in %s...\n", path)
}
for _, container := range jobs.Spec.Template.Spec.Containers {
if verbose {
fmt.Printf("Found %s\n", container.Image)
if !images.contains(container.Image) {
if verbose {
fmt.Printf("Found %s\n", container.Image)
}
images.add(container.Image)
} else if debug {
fmt.Printf("Ignoring %s\n", container.Image)
}
images.add(container.Image)
}
for _, container := range jobs.Spec.Template.Spec.InitContainers {
if verbose {
fmt.Printf("Found %s\n", container.Image)
if !images.contains(container.Image) {
if verbose {
fmt.Printf("Found %s\n", container.Image)
}
images.add(container.Image)
} else if debug {
fmt.Printf("Ignoring %s\n", container.Image)
}
images.add(container.Image)
}
}
cronJobs, ok := manifest.(*batchv1beta1.CronJob)
Expand All @@ -225,16 +257,24 @@ func addContainerImages(images *imagesList, path string, verbose bool, debug boo
log.Printf("Searching for cron job images in %s...\n", path)
}
for _, container := range cronJobs.Spec.JobTemplate.Spec.Template.Spec.Containers {
if verbose {
fmt.Printf("Found %s\n", container.Image)
if !images.contains(container.Image) {
if verbose {
fmt.Printf("Found %s\n", container.Image)
}
images.add(container.Image)
} else if debug {
fmt.Printf("Ignoring %s\n", container.Image)
}
images.add(container.Image)
}
for _, container := range cronJobs.Spec.JobTemplate.Spec.Template.Spec.InitContainers {
if verbose {
fmt.Printf("Found %s\n", container.Image)
if !images.contains(container.Image) {
if verbose {
fmt.Printf("Found %s\n", container.Image)
}
images.add(container.Image)
} else if debug {
fmt.Printf("Ignoring %s\n", container.Image)
}
images.add(container.Image)
}
}
return nil
Expand Down
7 changes: 6 additions & 1 deletion cmd/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/containerd/containerd/namespaces"
"github.com/gemalto/helm-image/internal/containerd"
"github.com/gemalto/helm-image/internal/credentials"
"github.com/gemalto/helm-image/internal/registry"
"github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/chart/loader"
Expand Down Expand Up @@ -134,7 +135,11 @@ func (s *saveCmd) save() error {
}
ctx := namespaces.WithNamespace(context.Background(), "default")
for _, auth := range s.auths {
registry.AddAuthRegistry(auth)
login, password, err := credentials.GetAuth(auth)
if err != nil && l.debug {
log.Printf("Warning: cannot get authentication information: %s\n", err)
}
registry.AddAuthRegistry(auth, login, password)
}
for _, image := range includedImages {
err = containerd.PullImage(ctx, client, registry.ConsoleCredentials, image, l.debug)
Expand Down
136 changes: 124 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,22 +1,134 @@
module github.com/gemalto/helm-image

go 1.15
go 1.17

require (
github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68 // indirect
github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1
github.com/containerd/containerd v1.4.3
github.com/containerd/console v1.0.3
github.com/containerd/containerd v1.6.2
github.com/danieljoos/wincred v1.1.2
github.com/docker/distribution v2.7.1+incompatible
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.0.2
github.com/spf13/cobra v1.3.0
helm.sh/helm/v3 v3.8.0
k8s.io/api v0.23.4
k8s.io/client-go v0.23.4
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Microsoft/go-winio v0.5.1 // indirect
github.com/Microsoft/hcsshim v0.9.2 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/containerd/cgroups v1.0.3 // indirect
github.com/containerd/continuity v0.2.2 // indirect
github.com/containerd/fifo v1.0.0 // indirect
github.com/containerd/ttrpc v1.1.0 // indirect
github.com/containerd/typeurl v1.0.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/cli v20.10.11+incompatible // indirect
github.com/docker/docker v20.10.12+incompatible // indirect
github.com/docker/docker-credential-helpers v0.6.4 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-logr/logr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/googleapis v1.4.0 // indirect
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.0.1
github.com/opencontainers/selinux v1.8.0 // indirect
github.com/spf13/cobra v1.1.1
helm.sh/helm/v3 v3.5.1
k8s.io/api v0.20.1
k8s.io/client-go v0.20.1
rsc.io/letsencrypt v0.0.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/sys/mountinfo v0.5.0 // indirect
github.com/moby/sys/signal v0.6.0 // indirect
github.com/moby/term v0.0.0-20210610120745-9d4ed1856297 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/runc v1.1.0 // indirect
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
github.com/opencontainers/selinux v1.10.0 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.30.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
go.opencensus.io v0.23.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/net v0.0.0-20220107192237-5cfca573fb4d // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
google.golang.org/grpc v1.43.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/apiextensions-apiserver v0.23.1 // indirect
k8s.io/apimachinery v0.23.4 // indirect
k8s.io/cli-runtime v0.23.1 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
oras.land/oras-go v1.1.0 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/kustomize/api v0.10.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/docker/distribution v2.7.1+incompatible => github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible
Loading

0 comments on commit 4f37f1b

Please sign in to comment.