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

Add regexp filtering for dockertags #23

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7ac0a73
Add ability to just list tags matching regular expression provided as…
haad Oct 2, 2022
4458226
Add github action automation for build/release
haad Oct 2, 2022
a6f95fa
Bump github/super-linter from 4.9.2 to 4.9.6
dependabot[bot] Oct 2, 2022
15fb8af
Bump goreleaser/goreleaser-action from 2 to 3
dependabot[bot] Oct 2, 2022
cd5a3da
Bump github.com/aws/aws-sdk-go from 1.44.108 to 1.44.109
dependabot[bot] Oct 2, 2022
6c61bb6
Some lint fixes
haad Oct 3, 2022
767af55
Merge pull request #2 from haad/dependabot/github_actions/goreleaser/…
haad Oct 3, 2022
a8f1500
Merge pull request #1 from haad/dependabot/github_actions/github/supe…
haad Oct 3, 2022
a6c6668
Merge pull request #3 from haad/dependabot/go_modules/github.com/aws/…
haad Oct 3, 2022
4ea192d
Bump goreleaser/goreleaser-action from 3 to 4
dependabot[bot] Dec 18, 2022
d3059f2
Bump github/super-linter from 4.9.6 to 4.10.1
dependabot[bot] Jan 22, 2023
d7d2122
Bump github.com/aws/aws-sdk-go from 1.44.109 to 1.44.214
dependabot[bot] Mar 5, 2023
6fecc63
ECR pagination setup
jozefhalgas Dec 7, 2023
386e8df
Merge pull request #31 from jozefhalgas/feature/ecr-pagination
haad Dec 8, 2023
3ddc0ac
Merge pull request #22 from haad/dependabot/github_actions/github/sup…
haad Jan 10, 2024
f27aa09
Merge pull request #14 from haad/dependabot/github_actions/goreleaser…
haad Jan 10, 2024
a205985
Merge pull request #29 from haad/dependabot/go_modules/github.com/aws…
haad Jan 10, 2024
d3ca775
Update goreleaser
haad Jan 10, 2024
c3490f4
Use proper repo name.
haad Jan 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
labels:
- dependencies
schedule:
interval: "weekly"
day: sunday
- package-ecosystem: "github-actions"
directory: "/"
labels:
- dependencies
- actions
schedule:
day: sunday
interval: weekly
37 changes: 37 additions & 0 deletions .github/labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# https://github.com/marketplace/actions/github-labeler
- name: bug
color: "fbca04"
description: "This issue/PR relates to a bug."
- name: deprecated
color: "fef2c0"
description: "This issue/PR relates to a deprecated module."
- name: docs
color: "4071a5"
description: "This issue/PR relates to or includes documentation."
- name: enhancement
color: "ededed"
description: "This issue/PR relates to a feature request."
- name: feature
color: "006b75"
description: "This issue/PR relates to a feature request."
- name: major
color: "c6476b"
description: "Marks an important and likely breaking change."
- name: packaging
color: "4071a5"
description: "Packaging category"
- name: performance
color: "555555"
description: "Relates to product or testing performance."
- name: skip-changelog
color: "eeeeee"
description: "Can be missed from the changelog."
- name: stale
color: "eeeeee"
description: "Not updated in long time, will be closed soon."
- name: wontfix
color: "eeeeee"
description: "This will not be worked on"
- name: test
color: "0e8a16"
description: "This PR relates to tests, QA, CI."
551 changes: 551 additions & 0 deletions .github/linters/.gitleaks.toml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .github/linters/.hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
##########################
## Hadolint config file ##
##########################
ignored:
- DL3018
10 changes: 10 additions & 0 deletions .github/linters/.jscpd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"threshold": 15,
"reporters": [
"consoleFull"
],
"ignore": [
"**/__snapshots__/**"
],
"absolute": true
}
27 changes: 27 additions & 0 deletions .github/linters/.markdown-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
###########################
###########################
## Markdown Linter rules ##
###########################
###########################

###############
# Rules by id #
###############
MD004: false # Unordered list style
MD014: false
MD024: false
MD007:
indent: 2 # Unordered list indentation
MD013:
line_length: 400 # Line length 80 is far to short
MD026:
punctuation: ".,;:!。,;:" # List of not allowed
MD029: false # Ordered list item prefix
MD033: false # Allow inline HTML
MD036: false # Emphasis used instead of a heading

#################
# Rules by tags #
#################
blank_lines: false # Error on blank lines
26 changes: 26 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Format and labels used aim to match those used by Ansible project
categories:
- title: 'Major Changes'
labels:
- 'major' # c6476b
- title: 'Minor Changes'
labels:
- 'feature' # 006b75
- 'enhancement' # ededed
- 'performance' # 555555
- title: 'Bugfixes'
labels:
- 'fix'
- 'bugfix'
- 'bug' # fbca04
- 'docs' # 4071a5
- 'packaging' # 4071a5
- 'test' # #0e8a16
- title: 'Deprecations'
labels:
- 'deprecated' # fef2c0
exclude-labels:
- 'skip-changelog'
template: |
## Changes
$CHANGES
67 changes: 67 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '25 23 * * 2'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
43 changes: 43 additions & 0 deletions .github/workflows/go-release-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Generate release-artifacts

on:
push:
tags:
- "*"

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
env:
DOCKER_CLI_EXPERIMENTAL: "enabled"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Docker Login
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_PAT }}

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.2

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --rm-dist --debug
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
18 changes: 18 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Release Drafter

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master
- 'releases/**'
- 'stable/**'

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27 changes: 27 additions & 0 deletions .github/workflows/superlinter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Super-Linter

# Run this workflow every time a new commit pushed to your repository
on: push

jobs:
# Set the job key. The key is displayed as the job name
# when a job name is not provided
super-lint:
# Name the Job
name: Lint code base
# Set the type of machine to run on
runs-on: ubuntu-latest

steps:
# Checks out a copy of your repository on the ubuntu-latest machine
- name: Checkout code
uses: actions/checkout@v3

# Runs the Super-Linter action
- name: Run Super-Linter
uses: github/super-linter@v4.10.1
env:
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILTER_REGEX_EXCLUDE: vendor/.*|integration/.*|\.github/.*
VALIDATE_BASH: false
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -33,3 +33,6 @@ _testmain.go
/dockertags
/bin
/dist
/build

dist/
21 changes: 21 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
run:
timeout: 5m
modules-download-mode: readonly

linters:
disable:
- golint
- typecheck
- structcheck
enable:
- errcheck
- goimports
- gocritic
- govet
- staticcheck

issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
85 changes: 85 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 1

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- 386
- amd64
- arm64

dockers:
- dockerfile: Dockerfile-release
# use: buildx
goos: linux
goarch: amd64
image_templates:
- ghcr.io/haad/{{ .ProjectName }}:{{ .Tag }}-amd64
build_flag_templates:
- --platform=linux/amd64
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- dockerfile: Dockerfile-release
# use: buildx
goos: linux
goarch: arm64
image_templates:
- ghcr.io/haad/{{ .ProjectName }}:{{ .Tag }}-arm64v8
build_flag_templates:
- --platform=linux/arm64/v8
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
checksum:
name_template: "checksums.txt"
algorithm: sha256

snapshot:
name_template: "{{ incpatch .Version }}-next"

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
- "^vendor:"
35 changes: 35 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
exclude: build/
- id: destroyed-symlinks
- id: detect-private-key
exclude: .github/linters
- id: check-ast
- id: check-case-conflict
- id: debug-statements
- repo: https://github.com/Yelp/detect-secrets
rev: v1.2.0
hooks:
- id: detect-secrets
exclude: build/|.travis.yml|.github/linters
- repo: https://github.com/golangci/golangci-lint
rev: v1.49.0
hooks:
- id: golangci-lint
# - repo: https://github.com/tekwizely/pre-commit-golang
# rev: v1.0.0-beta.5
# hooks:
# - id: go-mod-tidy
# - id: go-test-mod
# - id: go-revive
# - id: go-sec-mod
# - id: go-lint
# # - id: go-critic
# # - id: golangci-lint
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: go
go:
- '1.14'
- "1.18"
env:
global:
- secure: YtIXb4e4cHUWP5awg1q/x7eBsRULWM4CBZUvYs7U/pMre52oaCkT0IRCZ/sWfUiU8x6ax9NytrcF5JudH9uhysNDqcJcPyBmifloY0DEC9V2tGnnm/VeOS8nKVYbgJcFqsu4x9gdTfUC6HZ/hkTwIQih57ig5STeFX21eLAWSyUkyxq2QpM56Yhtxuc6IZ/K0uOFbLn0A2cV46Cwlln6lwDmTt23MWb8ZMwggd+EUptoj6kvQCJxuoP09k7xLIg6FB/lgKHsGqnIhEvt/A87vSCttYbBRN3CT8qgbVYKsL37nML3QH2akMkHacHSB7tEZCl+sTuK7b6T3fr3OrhuHZFjk2Q2JvFKMuVvv7m1bOulurA++WCOrxKq9CLqKaL51k2XzEr0BrqO2bWWMpEEq4JuTcRM5uCi2IORzyCPhO4li527GFHyQs1bDrdPcSm9xmlw9/QIqaS0g+3v7ve2qEVQpNLHlVkidb9D2nFztVFOnUfHUKwYvK/CT/bxuwZd2t65Jex1faVmyo3SCztHGs9UUzS72TrzT7GRj7azXvygRC9Fx1kuDCRHDVERw8dHGircYuu2XpqSL+iuQwY5pIP8Ql1tD9rJojN/oYm51u5rCRgYA/NyEuPAlloEj1M50Iut6blNeYY3J1sVCwVyTXnjLJupJaFSMs1wS22GHks=
- secure: YtIXb4e4cHUWP5awg1q/x7eBsRULWM4CBZUvYs7U/pMre52oaCkT0IRCZ/sWfUiU8x6ax9NytrcF5JudH9uhysNDqcJcPyBmifloY0DEC9V2tGnnm/VeOS8nKVYbgJcFqsu4x9gdTfUC6HZ/hkTwIQih57ig5STeFX21eLAWSyUkyxq2QpM56Yhtxuc6IZ/K0uOFbLn0A2cV46Cwlln6lwDmTt23MWb8ZMwggd+EUptoj6kvQCJxuoP09k7xLIg6FB/lgKHsGqnIhEvt/A87vSCttYbBRN3CT8qgbVYKsL37nML3QH2akMkHacHSB7tEZCl+sTuK7b6T3fr3OrhuHZFjk2Q2JvFKMuVvv7m1bOulurA++WCOrxKq9CLqKaL51k2XzEr0BrqO2bWWMpEEq4JuTcRM5uCi2IORzyCPhO4li527GFHyQs1bDrdPcSm9xmlw9/QIqaS0g+3v7ve2qEVQpNLHlVkidb9D2nFztVFOnUfHUKwYvK/CT/bxuwZd2t65Jex1faVmyo3SCztHGs9UUzS72TrzT7GRj7azXvygRC9Fx1kuDCRHDVERw8dHGircYuu2XpqSL+iuQwY5pIP8Ql1tD9rJojN/oYm51u5rCRgYA/NyEuPAlloEj1M50Iut6blNeYY3J1sVCwVyTXnjLJupJaFSMs1wS22GHks=
before_install:
- sudo apt-get update -q
- mkdir -p $GOPATH/bin
@@ -17,6 +17,6 @@ deploy:
skip_cleanup: true
api_key: $GITHUB_TOKEN
file_glob: true
file: 'dist/*.{tar.gz,zip}'
file: "dist/*.{tar.gz,zip}"
on:
tags: true
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.14 AS build
FROM golang:1.18 AS build
WORKDIR /go/src/github.com/wantedly/dockertags
COPY go.mod go.sum ./
RUN go mod download
6 changes: 6 additions & 0 deletions Dockerfile-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM golang:1.18 AS build

FROM scratch
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY dockertags /bin/dockertags
ENTRYPOINT ["/bin/dockertags"]
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME := dockertags
VERSION := v0.3.0
VERSION := v0.3.1
REVISION := $(shell git rev-parse --short HEAD)

SRCS := $(shell find . -name '*.go' -type f)
@@ -16,6 +16,7 @@ bin/$(NAME): $(SRCS)
clean:
rm -rf bin/*
rm -rf dist/*
rm -rf build/*

.PHONY: cross-build
cross-build:
5 changes: 5 additions & 0 deletions dockerhub.go
Original file line number Diff line number Diff line change
@@ -8,15 +8,20 @@ import (
"path"
)

// DockerHubAuthURLBase Docker base auth url
const DockerHubAuthURLBase = "https://auth.docker.io/token"

// DockerHubAPIURLBase registry url
const DockerHubAPIURLBase = "https://registry.hub.docker.com/v2/"

// DockerHubAuthResponse struc containing response from dockerhub after authentication
type DockerHubAuthResponse struct {
Token string `json:"token"`
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"` // It's always 300 (sec) at this moment
}

// DockerHubTagsResponse list of tags
type DockerHubTagsResponse struct {
Name string `json:"name"`
Tags []string `json:"tags"`
37 changes: 28 additions & 9 deletions ecr.go
Original file line number Diff line number Diff line change
@@ -10,24 +10,43 @@ import (
)

func retrieveFromECR(image string) ([]string, error) {
svc := ecr.New(session.New())
session, err := session.NewSession()
allTags := []string{}
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
return nil, aerr
}
return nil, err
}

svc := ecr.New(session)
input := &ecr.DescribeImagesInput{
RepositoryName: aws.String(image),
Filter: &ecr.DescribeImagesFilter{
TagStatus: aws.String("TAGGED"), // extract tagged images only
},
}

result, err := svc.DescribeImages(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
return nil, aerr
for {
result, err := svc.DescribeImages(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
return nil, aerr
}
return nil, err
}

tags := extractEcrTagNames(result.ImageDetails)
allTags = append(allTags, tags...)
// Check if there are more results
if result.NextToken == nil {
// No more results, break out of the loop
break
}
return nil, err
// Set the next token for the next iteration
input.NextToken = result.NextToken
}

tags := extractEcrTagNames(result.ImageDetails)
return tags, nil
return allTags , nil
}

func extractEcrTagNames(images []*ecr.ImageDetail) []string {
11 changes: 6 additions & 5 deletions gcr.go
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ func fetchBearer(repo string, image string) (string, error) {
url := constructGCRAuthURL(repo, image)
body, err := httpGet(url, "", &BasicAuthInfo{
Username: "_token",
Password: token.AccessToken,
Password: token.AccessToken, //pragma: allowlist secret
})
if err != nil {
return "", err
@@ -80,15 +80,16 @@ func parseGCRTagsResponse(manifests gcrTagsResponse) gcrImages {
}

func extractGCRTagNames(images gcrImages) []string {
tags := []string{}
var tags []string
sort.Slice(images, func(i, j int) bool {
return images[i].TimeUploadedMs > images[j].TimeUploadedMs
}) // sort Newset -> Oldest

for _, image := range images {
for _, tag := range image.Tag {
tags = append(tags, tag)
}
// for _, tag := range image.Tag {
// tags = append(tags, tag)
// }
tags = append(tags, image.Tag...)
}
return tags
}
17 changes: 13 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
module dockertags

go 1.14
go 1.18

require (
github.com/aws/aws-sdk-go v1.32.12
github.com/docker/distribution v2.7.1+incompatible
github.com/aws/aws-sdk-go v1.44.214
github.com/docker/distribution v2.8.1+incompatible
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1
)

require (
cloud.google.com/go/compute v1.10.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/net v0.1.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)
78 changes: 54 additions & 24 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,36 +1,66 @@
cloud.google.com/go v0.34.0 h1:eOI3/cP2VTU6uZLDYAoic+eyzzB9YyGmJ7eIjl8rOPg=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/aws/aws-sdk-go v1.32.12 h1:l/djCeLI4ggBFWLlYUGTqkHraoLnVMubNlLXPdEtoYc=
github.com/aws/aws-sdk-go v1.32.12/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
cloud.google.com/go/compute v1.10.0 h1:aoLIYaA1fX3ywihqpBk2APQKOo20nXsp1GEZQbx5Jk4=
cloud.google.com/go/compute v1.10.0/go.mod h1:ER5CLbMxl90o2jtNbGSbtfOpQKR0t15FOtRsugnLrlU=
github.com/aws/aws-sdk-go v1.44.214 h1:YzDuC+9UtrAOUkItlK7l3BvKI9o6qAog9X8i289HORc=
github.com/aws/aws-sdk-go v1.44.214/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug=
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68=
github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 h1:lxqLZaMad/dJHMFZH0NiNpiEZI/nhgWhe4wgzpE+MuA=
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
23 changes: 16 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
@@ -3,17 +3,20 @@ package main
import (
"fmt"
"os"
"regexp"
"strings"

"github.com/docker/distribution/reference"
)

const Usage = `Usage:
dockertags IMAGENAME
`
// Usage string
const Usage = `Usage: dockertags IMAGENAME [REGEXP]`

func main() {
if len(os.Args) != 2 {
var tags []string
var re *regexp.Regexp

if len(os.Args) > 3 {
fmt.Fprintln(os.Stderr, Usage)
os.Exit(1)
}
@@ -25,7 +28,9 @@ func main() {
}
repo, image := reference.SplitHostname(ref)

var tags []string
if len(os.Args) == 3 {
re, _ = regexp.Compile(os.Args[2])
}

switch {
case repo == "docker.io" || repo == "hub.docker.com":
@@ -37,7 +42,7 @@ func main() {

tags = t
case repo == "quay.io":
t, err := retriveFromQuay(image)
t, err := retrieveFromQuay(image)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
@@ -66,6 +71,10 @@ func main() {
}

for _, tag := range tags {
fmt.Println(tag)
if re == nil {
fmt.Println(tag)
} else if re.MatchString(tag) {
fmt.Println(tag)
}
}
}
5 changes: 4 additions & 1 deletion quay.go
Original file line number Diff line number Diff line change
@@ -7,15 +7,18 @@ import (
"path"
)

// QuayURLBase base repository url
const QuayURLBase = "https://quay.io/api/v1/repository/"

// QuayTag struct mapped to Quay
type QuayTag struct {
Revision bool `json:"revision"`
StartTs int `json:"start_ts"`
Name string `json:"name"`
DockerImageID string `json:"docker_image_id"`
}

// QuayTagsResponse list of tags from quay
type QuayTagsResponse struct {
HasAdditional bool `json:"has_additional"`
Page int `json:"page"`
@@ -33,7 +36,7 @@ func constructQuayURL(image string) (string, error) {
return u.String(), nil
}

func retriveFromQuay(image string) ([]string, error) {
func retrieveFromQuay(image string) ([]string, error) {
url, err := constructQuayURL(image)
if err != nil {
return nil, err
19 changes: 16 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
@@ -2,17 +2,24 @@ package main

import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
)

// BasicAuthInfo struct mapping user/pass for base auth
type BasicAuthInfo struct {
Username string
Password string
}

func httpGet(url, apiToken string, basicAuth *BasicAuthInfo) (string, error) {
req, _ := http.NewRequest("GET", url, nil)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return "", err
}

if apiToken != "" {
req.Header.Set("Authorization", "Bearer "+apiToken)
}
@@ -26,16 +33,22 @@ func httpGet(url, apiToken string, basicAuth *BasicAuthInfo) (string, error) {
if err != nil {
return "", err
}
defer resp.Body.Close()
defer bodyClose(resp.Body) // ignoring error

b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}

if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("HTTP error!\nURL: %s\nstatus code: %d\nbody:\n%s\n", url, resp.StatusCode, string(b))
return "", fmt.Errorf("http error: URL: %s, status code: %d,\nbody:\n%s", url, resp.StatusCode, string(b))
}

return string(b), nil
}

func bodyClose(c io.Closer) {
if err := c.Close(); err != nil {
log.Fatal(err)
}
}