Skip to content

Commit

Permalink
Merge pull request #381 from tchughesiv/csv
Browse files Browse the repository at this point in the history
add DIGESTS flag for make csv
  • Loading branch information
openshift-merge-robot committed Feb 26, 2020
2 parents c8646f7 + f0a9868 commit 4930555
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,5 @@ make csv

# OR
# w/ sha lookup/replacement against registry.redhat.io
USER_TOKEN="<username>:<password>" make csv
DIGESTS=true USER_TOKEN="<username>:<password>" make csv
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
categories: Integration & Delivery
certified: "false"
containerImage: quay.io/kiegroup/kie-cloud-operator:1.4.0
createdAt: "2020-02-17 12:02:25"
createdAt: "2020-02-26 11:09:49"
description: Kie Cloud Operator for deployment and management of RHPAM/RHDM environments.
repository: https://github.com/kiegroup/kie-cloud-operator
support: Red Hat, Inc.
Expand Down Expand Up @@ -167,17 +167,17 @@ spec:
- name: PAM_SMARTROUTER_IMAGE_7.7.0
value: registry.redhat.io/rhpam-7/rhpam-smartrouter-rhel8:7.7.0
- name: OSE_CLI_IMAGE_7.7.0
value: registry.redhat.io/openshift3/ose-cli@sha256:7e356132f56fc4e3cf691ba5b0b5f063dc974c4cfe2f198c8c1b5f68cb9ccbdd
value: registry.redhat.io/openshift3/ose-cli@sha256:49f5a5a3f5e514c48200fefe6e68072573deb5bca607fa979e196f3a221ddcfd
- name: MYSQL_PROXY_IMAGE_7.7.0
value: registry.redhat.io/rhscl/mysql-57-rhel7@sha256:9a781abe7581cc141e14a7e404ec34125b3e89c008b14f4e7b41e094fd3049fe
- name: POSTGRESQL_PROXY_IMAGE_7.7.0
value: registry.redhat.io/rhscl/postgresql-10-rhel7@sha256:de3ab628b403dc5eed986a7f392c34687bddafee7bdfccfd65cecf137ade3dfd
- name: DATAGRID_IMAGE_7.7.0
value: registry.redhat.io/jboss-datagrid-7/datagrid73-openshift@sha256:cfd8c4ac1c495b766dd3ff1a85c35afe092858f8f65b52a5b044811719482236
- name: BROKER_IMAGE_7.7.0
value: registry.redhat.io/amq7/amq-broker@sha256:49adf926658cee75dafbb463cfc7b4f9a533d5f34c0e1622709263a5f64f8b1b
value: registry.redhat.io/amq7/amq-broker@sha256:ba5273b390a4762c21f005fdc92a837680417250dcd5e6d9d3c8f776e9cc372e
- name: OAUTH_PROXY_IMAGE
value: registry.redhat.io/openshift3/oauth-proxy@sha256:cd284eeb883b549c4578a1a07b1ee58ccbd0c8b62c0678a981b5ed65a6cf1c16
value: registry.redhat.io/openshift3/oauth-proxy@sha256:da75a08e875f76a58028715f402da670f5849317f354ace0e64702acd86b21ae
image: quay.io/kiegroup/kie-cloud-operator:1.4.0
imagePullPolicy: Always
name: kie-cloud-operator
Expand Down Expand Up @@ -275,17 +275,17 @@ spec:
name: rhpam-process-migration-rhel8
- image: registry.redhat.io/rhpam-7/rhpam-smartrouter-rhel8:7.7.0
name: rhpam-smartrouter-rhel8
- image: registry.redhat.io/openshift3/oauth-proxy@sha256:cd284eeb883b549c4578a1a07b1ee58ccbd0c8b62c0678a981b5ed65a6cf1c16
- image: registry.redhat.io/openshift3/oauth-proxy@sha256:da75a08e875f76a58028715f402da670f5849317f354ace0e64702acd86b21ae
name: oauth-proxy
- image: registry.redhat.io/openshift3/ose-cli@sha256:7e356132f56fc4e3cf691ba5b0b5f063dc974c4cfe2f198c8c1b5f68cb9ccbdd
- image: registry.redhat.io/openshift3/ose-cli@sha256:49f5a5a3f5e514c48200fefe6e68072573deb5bca607fa979e196f3a221ddcfd
name: ose-cli
- image: registry.redhat.io/rhscl/mysql-57-rhel7@sha256:9a781abe7581cc141e14a7e404ec34125b3e89c008b14f4e7b41e094fd3049fe
name: mysql-57-rhel7
- image: registry.redhat.io/rhscl/postgresql-10-rhel7@sha256:de3ab628b403dc5eed986a7f392c34687bddafee7bdfccfd65cecf137ade3dfd
name: postgresql-10-rhel7
- image: registry.redhat.io/jboss-datagrid-7/datagrid73-openshift@sha256:cfd8c4ac1c495b766dd3ff1a85c35afe092858f8f65b52a5b044811719482236
name: datagrid73-openshift
- image: registry.redhat.io/amq7/amq-broker@sha256:49adf926658cee75dafbb463cfc7b4f9a533d5f34c0e1622709263a5f64f8b1b
- image: registry.redhat.io/amq7/amq-broker@sha256:ba5273b390a4762c21f005fdc92a837680417250dcd5e6d9d3c8f776e9cc372e
name: amq-broker
replaces: kiecloud-operator.1.3.0
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
categories: Integration & Delivery
certified: "true"
containerImage: registry.redhat.io/rhpam-7/rhpam-rhel8-operator:7.7.0
createdAt: "2020-02-17 12:03:29"
createdAt: "2020-02-26 11:10:41"
description: Business Automation Operator for deployment and management of RHPAM/RHDM
environments.
repository: https://github.com/kiegroup/kie-cloud-operator
Expand Down Expand Up @@ -169,17 +169,17 @@ spec:
- name: PAM_SMARTROUTER_IMAGE_7.7.0
value: registry.redhat.io/rhpam-7/rhpam-smartrouter-rhel8:7.7.0
- name: OSE_CLI_IMAGE_7.7.0
value: registry.redhat.io/openshift3/ose-cli@sha256:7e356132f56fc4e3cf691ba5b0b5f063dc974c4cfe2f198c8c1b5f68cb9ccbdd
value: registry.redhat.io/openshift3/ose-cli@sha256:49f5a5a3f5e514c48200fefe6e68072573deb5bca607fa979e196f3a221ddcfd
- name: MYSQL_PROXY_IMAGE_7.7.0
value: registry.redhat.io/rhscl/mysql-57-rhel7@sha256:9a781abe7581cc141e14a7e404ec34125b3e89c008b14f4e7b41e094fd3049fe
- name: POSTGRESQL_PROXY_IMAGE_7.7.0
value: registry.redhat.io/rhscl/postgresql-10-rhel7@sha256:de3ab628b403dc5eed986a7f392c34687bddafee7bdfccfd65cecf137ade3dfd
- name: DATAGRID_IMAGE_7.7.0
value: registry.redhat.io/jboss-datagrid-7/datagrid73-openshift@sha256:cfd8c4ac1c495b766dd3ff1a85c35afe092858f8f65b52a5b044811719482236
- name: BROKER_IMAGE_7.7.0
value: registry.redhat.io/amq7/amq-broker@sha256:49adf926658cee75dafbb463cfc7b4f9a533d5f34c0e1622709263a5f64f8b1b
value: registry.redhat.io/amq7/amq-broker@sha256:ba5273b390a4762c21f005fdc92a837680417250dcd5e6d9d3c8f776e9cc372e
- name: OAUTH_PROXY_IMAGE
value: registry.redhat.io/openshift3/oauth-proxy@sha256:cd284eeb883b549c4578a1a07b1ee58ccbd0c8b62c0678a981b5ed65a6cf1c16
value: registry.redhat.io/openshift3/oauth-proxy@sha256:da75a08e875f76a58028715f402da670f5849317f354ace0e64702acd86b21ae
image: registry.redhat.io/rhpam-7/rhpam-rhel8-operator:7.7.0
imagePullPolicy: Always
name: business-automation-operator
Expand Down Expand Up @@ -277,17 +277,17 @@ spec:
name: rhpam-process-migration-rhel8
- image: registry.redhat.io/rhpam-7/rhpam-smartrouter-rhel8:7.7.0
name: rhpam-smartrouter-rhel8
- image: registry.redhat.io/openshift3/oauth-proxy@sha256:cd284eeb883b549c4578a1a07b1ee58ccbd0c8b62c0678a981b5ed65a6cf1c16
- image: registry.redhat.io/openshift3/oauth-proxy@sha256:da75a08e875f76a58028715f402da670f5849317f354ace0e64702acd86b21ae
name: oauth-proxy
- image: registry.redhat.io/openshift3/ose-cli@sha256:7e356132f56fc4e3cf691ba5b0b5f063dc974c4cfe2f198c8c1b5f68cb9ccbdd
- image: registry.redhat.io/openshift3/ose-cli@sha256:49f5a5a3f5e514c48200fefe6e68072573deb5bca607fa979e196f3a221ddcfd
name: ose-cli
- image: registry.redhat.io/rhscl/mysql-57-rhel7@sha256:9a781abe7581cc141e14a7e404ec34125b3e89c008b14f4e7b41e094fd3049fe
name: mysql-57-rhel7
- image: registry.redhat.io/rhscl/postgresql-10-rhel7@sha256:de3ab628b403dc5eed986a7f392c34687bddafee7bdfccfd65cecf137ade3dfd
name: postgresql-10-rhel7
- image: registry.redhat.io/jboss-datagrid-7/datagrid73-openshift@sha256:cfd8c4ac1c495b766dd3ff1a85c35afe092858f8f65b52a5b044811719482236
name: datagrid73-openshift
- image: registry.redhat.io/amq7/amq-broker@sha256:49adf926658cee75dafbb463cfc7b4f9a533d5f34c0e1622709263a5f64f8b1b
- image: registry.redhat.io/amq7/amq-broker@sha256:ba5273b390a4762c21f005fdc92a837680417250dcd5e6d9d3c8f776e9cc372e
name: amq-broker
replaces: businessautomation-operator.1.3.0
selector:
Expand Down
85 changes: 45 additions & 40 deletions tools/csv-gen/csv-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,53 +389,58 @@ func main() {
relatedImages = append(relatedImages, getRelatedImage(constants.Datagrid73ImageURL))
relatedImages = append(relatedImages, getRelatedImage(constants.Broker75ImageURL))

url := "https://" + constants.ImageRegistry
username := "" // anonymous
password := "" // anonymous
if userToken := strings.Split(os.Getenv("USER_TOKEN"), ":"); len(userToken) > 1 {
username = userToken[0]
password = userToken[1]
}
hub, err := registry.New(url, username, password)
if err != nil {
log.Error(err)
} else {
defaultCheckRedirect := hub.Client.CheckRedirect
for _, tagRef := range imageRef.Spec.Tags {
hub.Client.CheckRedirect = defaultCheckRedirect
if _, ok := imageShaMap[tagRef.From.Name]; !ok {
imageShaMap[tagRef.From.Name] = ""
imageName, imageTag, imageContext := defaults.GetImage(tagRef.From.Name)
repo := imageContext + "/" + imageName
tags, err := hub.Tags(repo)
if err != nil {
log.Error(err)
}
// do not follow redirects - this is critical so we can get the registry digest from Location in redirect response
hub.Client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}
if _, exists := find(tags, imageTag); exists {
req, err := http.NewRequest("GET", url+"/v2/"+repo+"/manifests/"+imageTag, nil)
if err != nil {
log.Error(err)
}
req.Header.Add("Accept", "application/vnd.docker.distribution.manifest.v2+json")
resp, err := hub.Client.Do(req)
if logs.GetBoolEnv("DIGESTS") {
url := "https://" + constants.ImageRegistry
if val, ok := os.LookupEnv("REGISTRY"); ok {
url = val
}
username := "" // anonymous
password := "" // anonymous
if userToken := strings.Split(os.Getenv("USER_TOKEN"), ":"); len(userToken) > 1 {
username = userToken[0]
password = userToken[1]
}
hub, err := registry.New(url, username, password)
if err != nil {
log.Error(err)
} else {
defaultCheckRedirect := hub.Client.CheckRedirect
for _, tagRef := range imageRef.Spec.Tags {
hub.Client.CheckRedirect = defaultCheckRedirect
if _, ok := imageShaMap[tagRef.From.Name]; !ok {
imageShaMap[tagRef.From.Name] = ""
imageName, imageTag, imageContext := defaults.GetImage(tagRef.From.Name)
repo := imageContext + "/" + imageName
tags, err := hub.Tags(repo)
if err != nil {
log.Error(err)
}
if resp != nil {
defer resp.Body.Close()
// do not follow redirects - this is critical so we can get the registry digest from Location in redirect response
hub.Client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}
if resp.StatusCode == 302 || resp.StatusCode == 301 {
digestURL, err := resp.Location()
if _, exists := find(tags, imageTag); exists {
req, err := http.NewRequest("GET", url+"/v2/"+repo+"/manifests/"+imageTag, nil)
if err != nil {
log.Error(err)
}
if digestURL != nil {
if url := strings.Split(digestURL.EscapedPath(), "/"); len(url) > 1 {
imageShaMap[tagRef.From.Name] = strings.ReplaceAll(tagRef.From.Name, ":"+imageTag, "@"+url[len(url)-1])
req.Header.Add("Accept", "application/vnd.docker.distribution.manifest.v2+json")
resp, err := hub.Client.Do(req)
if err != nil {
log.Error(err)
}
if resp != nil {
defer resp.Body.Close()
}
if resp.StatusCode == 302 || resp.StatusCode == 301 {
digestURL, err := resp.Location()
if err != nil {
log.Error(err)
}
if digestURL != nil {
if url := strings.Split(digestURL.EscapedPath(), "/"); len(url) > 1 {
imageShaMap[tagRef.From.Name] = strings.ReplaceAll(tagRef.From.Name, ":"+imageTag, "@"+url[len(url)-1])
}
}
}
}
Expand Down

0 comments on commit 4930555

Please sign in to comment.