Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some features improvement #11

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

x-lhan
Copy link

@x-lhan x-lhan commented Nov 2, 2017

What does this PR do?

  1. Provides support for registries that have basic/token auth mode enabled(Unable to handle authentication #1)
  2. Provides a flag to ignore SSL verification errors(Disable SSL validation #2)
  3. Fixes a potential problem that may lead to unnecessary tag removal(Deleting a tag also deletes all other images with this image ID. #9)
    This only happens when duplicate tags share the same hash. If one should be removed but the other should remain, both will be deleted.
  4. Some parameter adjustments around repo filter(Please see the comparison between previous and new behavior section below)
  5. Add dockerize support for a docker image with a small footage(~7MB)

What issues does this PR fix or reference?

#1
#2
#9

Previous Behavior

Parameters -repo and -tag were used for filtering repo/tag by regexp
Parameter -repos was used as the maximum repo count to fetch

New Behavior

Parameter changes include:
-username string
username for docker login
-password string
password for docker login
-insecure
ignore https verification error
-repos
matching repositories by name (allows multiple value separates by ,); If specifies will ignore -repo_regexp
-repo_regexp string
matching repositories (allows regexp) (default ".")
-max_repos int
max number of repositories to garbage collect (default to no limit)
-tag_regexp string
matching tags (allows regexp) (default ".
")

@yan-foto
Copy link
Member

yan-foto commented Nov 6, 2017

Wow! this is a huge PR. Thanks for the effort. Please give me some time to review it.

Copy link
Member

@yan-foto yan-foto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think from this commit, the only thing that we should keep are the insecure, user, and password flags. However, we should find a better way to read passwords and avoid plain texts in the command line (readable through history)

log "github.com/Sirupsen/logrus"
"github.com/docker/distribution/context"
schema2 "github.com/docker/distribution/manifest/schema2"
"github.com/docker/distribution/reference"
"github.com/docker/distribution/registry/client"
"github.com/heroku/docker-registry-client/registry"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we need this!?

// registry username (default = "")
username = flag.String("username", "", "registry username to login")
// registry password (default = "")
password = flag.String("password", "", "registry password to login")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fond of Plaintext passwords as args, we should do this in an extra step (just as mysql -u root -p does)

main.go Outdated
// Create registry object
r, err := client.NewRegistry(*registryURL, nil)
r, err := client.NewRegistry(ctx, *registryURL, wrapTransport)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context is not used anymore in Docker API. See this: 9931cc7

main.go Outdated
@@ -125,7 +154,7 @@ func main() {
logger.Fatalf("Could not parse repo from name! (err: %v)", err)
}

repo, err := client.NewRepository(repoName, *registryURL, nil)
repo, err := client.NewRepository(ctx, repoName, *registryURL, wrapTransport)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. ctx is not required.

main.go Outdated
// Maximum age of iamges to consider for deletion in days (default = 0)
day = flag.Int("day", 0, "max age in days")
// Maximum age of months to consider for deletion in days (default = 0)
month = flag.Int("month", 0, "max age in months")
// Maximum age of iamges to consider for deletion in years (default = 0)
year = flag.Int("year", 0, "max age in days")
// Regexp for images (default = .*)
repoRegexp = flag.String("repo", ".*", "matching repositories (allows regexp)")
repoRegexp = flag.String("repo", ".*", "matching repositories (allows mulitple value seperates by ,)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant as it's equal to '|' in a regular expression and IMHO does not provide any added value. 🙃

main.go Outdated
if err != nil {
log.Fatalf("Could not create registry object! (err: %s", err)
}

fetchAll := strings.Compare(*repoRegexp, ".*") == 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the side-effect when we use 2 different parameters for the same goal.

Copy link
Member

@yan-foto yan-foto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate on this bug? I'm not following what exactly is happening.

Copy link
Member

@yan-foto yan-foto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this? My favorite base image is alpine. Moreover, this guide is a generic way of generating a Docker image. I would remove it from the README and put it at best in the wiki

Copy link
Member

@yan-foto yan-foto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For such changes please use git rebase

Copy link
Member

@yan-foto yan-foto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As commented in the first commit of this PR, we should stick to regex and not complicate the whole procedure.

@yan-foto
Copy link
Member

yan-foto commented Nov 8, 2017

So I reviewed the first commits and the rest seems to be fixing typos and what seems to be reverting some changes. The following points are what to be done and what will be merged:

  1. Add insecure flag
  2. Read username in plaintext and password in next step hidden (similar to mysql -u username -p)

The following is going to be removed:

  1. New repo_regexp (see first review comments)
  2. Fix wrt. Deleting a tag also deletes all other images with this image ID. #9

I appreciate the PR. 👍

@x-lhan
Copy link
Author

x-lhan commented Nov 8, 2017

Thank you for your throughly review. Here are some illustrations regarding to your concerns:

  1. Plaintext password
    I agree with you. So I will try to add a parameter which promotes user to enter password. But I also think plaintext password parameter should be reserved for user who does not think this is an issue and will appreciate the non-interrupt configure(e.g. run as docker container and manage password from configuration system)

  2. Tag remove bug Deleting a tag also deletes all other images with this image ID. #9
    This happens if two or more tags have the same blob backed:
    if an image is tagged 3 times(no changes in between) with different names(e.g. latest, stable and snapshot-1) and pushed to the registry, running deckscrubber cmd (with the default latest of 1) instead of the latest tag remain all 3 tags will be removed.

  3. Repo Regex modification
    This modification is mainly not enforcing user to query all repo. This is required for users who do not authorized to do so. (With token-based auth mode, users can be assigned to only access to limited repos.)

  4. Dockerize
    Yes I have tested without any problem. Sure I can move this section into wiki.

Let me know if you have any different opinions.

@yan-foto
Copy link
Member

yan-foto commented Nov 9, 2017

It makes sense! Thanks. Please try to avoid commits that fix previous commits and just rebase if you think something needs to be changed. Otherwise the review procedure would be really confusing 😅

So I think we agree on all points 😄 !

@x-lhan
Copy link
Author

x-lhan commented Nov 9, 2017

Thank you for the tips. 👍
Just update the code according to our discussion. (Not sure how to submit a PR for wiki but I removed from README)

@@ -33,6 +33,8 @@ We run our own private registry on a server with limited storage and it was only
username for docker login
-password string
password for docker login
-promote
promote user to enter docker login password; If specified will ignore `-password`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave this out and see if any value is given after -password or not. If not, prompt user.


if *enterPwd {
fmt.Println("Enter registry login password:")
fmt.Scanln(password)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the proper way to read passwords in terminal. See here

Copy link
Member

@yan-foto yan-foto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comments.

2. Upgraded to support latest docker distribution API
3. Added support for native module
4. Fix an import package error owing renaming
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants