Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b75cb6
commit 8f7466c
Showing
11 changed files
with
565 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
tmp | ||
_output | ||
library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Dockerfile used to verify openshift/library via ci-operator | ||
FROM registry.svc.ci.openshift.org/openshift/release:golang-1.13 as builder | ||
WORKDIR /go/src/github.com/openshift/library | ||
COPY . . | ||
RUN make verify-gofmt | ||
RUN make build | ||
|
||
FROM registry.svc.ci.openshift.org/openshift/origin-v4.0:base | ||
RUN yum install -y git make | ||
COPY --from=builder /go/src/github.com/openshift/library /go/src/github.com/openshift/library | ||
RUN chmod 777 /go/src/github.com/openshift/library | ||
WORKDIR /go/src/github.com/openshift/library | ||
ENTRYPOINT [] | ||
CMD ["make", "verify-pullrequest"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# If no documents are specified, use these as the default | ||
DOCUMENTS ?= official,community | ||
|
||
ifeq ($(MATCHALL),true) | ||
MATCHALLTAGS=--match-all | ||
endif | ||
|
||
.DEFAULT_GOAL := help | ||
|
||
verify: verify-gofmt verify-pullrequest ## Run verifications. Example: make verify | ||
.PHONY: verify | ||
|
||
verify-gofmt: ## Run gofmt verification. Example: make verify-gofmt | ||
hack/verify-gofmt.sh | ||
.PHONY: verify-gofmt | ||
|
||
verify-pullrequest: ## Run pull request verification. Example: make verify-pullrequest | ||
hack/verify-pullrequest.sh $(DOCUMENTS) | ||
.PHONY: verify-pullrequest | ||
|
||
# Using -race here since we are running concurrently | ||
build: ## Build the library executable. Example: make build | ||
go version | ||
go build -race | ||
.PHONY: build | ||
|
||
import: ## Run the import script. Example: make import | ||
./library import --documents=$(DOCUMENTS) --tags=$(TAGS) $(MATCHALLTAGS) --dir=$(DIR) | ||
.PHONY: import | ||
|
||
vendor: ## Vendor Go Dependencies. Example: make vendor | ||
go mod vendor | ||
.PHONY: vendor | ||
|
||
clean: ## Clean up the workspace. Example: make clean | ||
rm -f library | ||
rm -rf _output/ | ||
.PHONY: clean | ||
|
||
help: ## Print this help. Example: make help | ||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | ||
.PHONY: help | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package v1 | ||
|
||
// ItemImageStream is an object that describes an OpenShift ImageStream that we need to import | ||
type ItemImageStream struct { | ||
Location string `yaml:"location"` | ||
Docs string `yaml:"docs"` | ||
Regex string `yaml:"regex"` | ||
Suffix string `yaml:"suffix"` | ||
Tags []string `yaml:"tags"` | ||
} | ||
|
||
// ItemTemplate is an object that describes an OpenShift Template that we need to import | ||
type ItemTemplate struct { | ||
Location string `yaml:"location"` | ||
Docs string `yaml:"docs"` | ||
Regex string `yaml:"regex"` | ||
Suffix string `yaml:"suffix"` | ||
Tags []string `yaml:"tags"` | ||
} | ||
|
||
// Item is a container that holds ItemImageStreams and ItemTemplates | ||
type Item struct { | ||
ImageStreams []ItemImageStream `yaml:"imagestreams"` | ||
Templates []ItemTemplate `yaml:"templates"` | ||
} | ||
|
||
type Document struct { | ||
Variables map[string]string | ||
} | ||
|
||
// DocumentData is the data section of a library document | ||
type DocumentData struct { | ||
Data map[string]Item | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
"strings" | ||
|
||
"github.com/ghodss/yaml" | ||
|
||
imageapiv1 "github.com/openshift/api/image/v1" | ||
templateapiv1 "github.com/openshift/api/template/v1" | ||
) | ||
|
||
func writeToFile(data []byte, filePath string) error { | ||
return ioutil.WriteFile(filePath, data, os.ModePerm) | ||
} | ||
|
||
func replaceVariables(d *[]byte, v map[string]string) error { | ||
for k, v := range v { | ||
*d = []byte(strings.ReplaceAll(string(*d), fmt.Sprintf("{%s}", k), fmt.Sprintf("%s", v))) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func fetchURL(path string) ([]byte, error) { | ||
resp, err := http.Get(path) | ||
if err != nil { | ||
return []byte{}, err | ||
} | ||
defer resp.Body.Close() | ||
if resp.StatusCode != 200 { | ||
return []byte{}, fmt.Errorf("%d", resp.StatusCode) | ||
} | ||
|
||
return ioutil.ReadAll(resp.Body) | ||
} | ||
|
||
func unMarshalTemplate(body []byte, t *templateapiv1.Template) error { | ||
body, err := yaml.YAMLToJSON(body) | ||
if err != nil { | ||
return fmt.Errorf("Unable to convert yaml to json: %v", err) | ||
} | ||
if jerr := json.Unmarshal(body, &t); jerr != nil { | ||
return fmt.Errorf("Error unmarshaling data: %v", err) | ||
|
||
} | ||
return nil | ||
} | ||
|
||
func unMarshalImageStream(body []byte, is *imageapiv1.ImageStream) error { | ||
body, err := yaml.YAMLToJSON(body) | ||
if err != nil { | ||
return fmt.Errorf("Unable to convert yaml to json: %v", err) | ||
} | ||
if jerr := json.Unmarshal(body, &is); jerr != nil { | ||
return fmt.Errorf("Error unmarshaling data: %v", err) | ||
|
||
} | ||
return nil | ||
} | ||
|
||
func unMarshalImageStreamList(body []byte, isl *imageapiv1.ImageStreamList) error { | ||
body, err := yaml.YAMLToJSON(body) | ||
if err != nil { | ||
return fmt.Errorf("Unable to convert yaml to json: %v", err) | ||
} | ||
if jerr := json.Unmarshal(body, &isl); jerr != nil { | ||
return fmt.Errorf("Error unmarshaling data: %v", err) | ||
|
||
} | ||
return nil | ||
} |
Oops, something went wrong.