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

refract: rename orasfile to oci file #82

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions tibuild/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ const docTemplate = `{
"component": {
"type": "string"
},
"oras": {
"$ref": "#/definitions/service.OrasFile"
"ociFile": {
"$ref": "#/definitions/service.OciFile"
},
"platform": {
"type": "string"
Expand Down Expand Up @@ -570,7 +570,7 @@ const docTemplate = `{
}
}
},
"service.OrasFile": {
"service.OciFile": {
"type": "object",
"properties": {
"file": {
Expand Down Expand Up @@ -684,7 +684,7 @@ const docTemplate = `{
"name": {
"type": "string"
},
"orasArtifacts": {
"ociArtifacts": {
"type": "array",
"items": {
"$ref": "#/definitions/service.OciArtifact"
Expand Down
8 changes: 4 additions & 4 deletions tibuild/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@
"component": {
"type": "string"
},
"oras": {
"$ref": "#/definitions/service.OrasFile"
"ociFile": {
"$ref": "#/definitions/service.OciFile"
},
"platform": {
"type": "string"
Expand Down Expand Up @@ -558,7 +558,7 @@
}
}
},
"service.OrasFile": {
"service.OciFile": {
"type": "object",
"properties": {
"file": {
Expand Down Expand Up @@ -672,7 +672,7 @@
"name": {
"type": "string"
},
"orasArtifacts": {
"ociArtifacts": {
"type": "array",
"items": {
"$ref": "#/definitions/service.OciArtifact"
Expand Down
8 changes: 4 additions & 4 deletions tibuild/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ definitions:
properties:
component:
type: string
oras:
$ref: '#/definitions/service.OrasFile'
ociFile:
$ref: '#/definitions/service.OciFile'
platform:
type: string
sha256URL:
Expand Down Expand Up @@ -165,7 +165,7 @@ definitions:
tag:
type: string
type: object
service.OrasFile:
service.OciFile:
properties:
file:
type: string
Expand Down Expand Up @@ -252,7 +252,7 @@ definitions:
type: array
name:
type: string
orasArtifacts:
ociArtifacts:
items:
$ref: '#/definitions/service.OciArtifact'
type: array
Expand Down
16 changes: 8 additions & 8 deletions tibuild/pkg/rest/service/dev_build_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ func (s DevbuildServer) inflate(entity *DevBuild) {
}
if entity.Status.BuildReport != nil {
for i, bin := range entity.Status.BuildReport.Binaries {
if bin.URL == "" && bin.OrasFile != nil {
entity.Status.BuildReport.Binaries[i].URL = s.oras_to_file_url(*bin.OrasFile)
if bin.URL == "" && bin.OciFile != nil {
entity.Status.BuildReport.Binaries[i].URL = s.ociFileToUrl(*bin.OciFile)
}
}
}
Expand Down Expand Up @@ -394,7 +394,7 @@ func collectTektonArtifacts(pipelines []TektonPipeline, report *BuildReport) {
for _, pipeline := range pipelines {
report.GitHash = pipeline.GitHash
for _, files := range pipeline.OciArtifacts {
report.Binaries = append(report.Binaries, oras_to_files(pipeline.Platform, files)...)
report.Binaries = append(report.Binaries, ociArtifactToFiles(pipeline.Platform, files)...)
}
for _, image := range pipeline.Images {
img := ImageArtifact{Platform: pipeline.Platform, URL: image.URL}
Expand Down Expand Up @@ -455,16 +455,16 @@ func getLatestEndAt(pipelines []TektonPipeline) *time.Time {
return latest_endat
}

func oras_to_files(platform Platform, oras OciArtifact) []BinArtifact {
func ociArtifactToFiles(platform Platform, artifact OciArtifact) []BinArtifact {
var rt []BinArtifact
for _, file := range oras.Files {
rt = append(rt, BinArtifact{Platform: platform, OrasFile: &OrasFile{Repo: oras.Repo, Tag: oras.Tag, File: file}})
for _, file := range artifact.Files {
rt = append(rt, BinArtifact{Platform: platform, OciFile: &OciFile{Repo: artifact.Repo, Tag: artifact.Tag, File: file}})
}
return rt
}

func (s DevbuildServer) oras_to_file_url(oras OrasFile) string {
return fmt.Sprintf("%s/%s?tag=%s&file=%s", s.OciFileserverURL, oras.Repo, oras.Tag, oras.File)
func (s DevbuildServer) ociFileToUrl(artifact OciFile) string {
return fmt.Sprintf("%s/%s?tag=%s&file=%s", s.OciFileserverURL, artifact.Repo, artifact.Tag, artifact.File)
}

type DevBuildRepository interface {
Expand Down
8 changes: 4 additions & 4 deletions tibuild/pkg/rest/service/dev_build_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func TestDevBuildGet(t *testing.T) {
Jenkins: &mockedJenkins,
Now: time.Now,
TektonViewURL: "http://tekton.net",
OciFileserverURL: "http://orasdownload.net",
OciFileserverURL: "http://ocidownload.net",
}

t.Run("ok", func(t *testing.T) {
Expand All @@ -285,13 +285,13 @@ func TestDevBuildGet(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "https://cd.pingcap.net//blue/organizations/jenkins/devbuild/detail/devbuild/4/pipeline", entity.Status.PipelineViewURL)
})
t.Run("render oras file", func(t *testing.T) {
t.Run("render oci file", func(t *testing.T) {
mockedRepo.saved = DevBuild{ID: 1,
Spec: DevBuildSpec{Product: ProductTidb, Version: "v6.1.2", Edition: EnterpriseEdition, GitRef: "pull/23", PluginGitRef: "master"},
Status: DevBuildStatus{PipelineBuildID: 4, BuildReport: &BuildReport{Binaries: []BinArtifact{{OrasFile: &OrasFile{Repo: "repo", Tag: "tag", File: "file"}}}}}}
Status: DevBuildStatus{PipelineBuildID: 4, BuildReport: &BuildReport{Binaries: []BinArtifact{{OciFile: &OciFile{Repo: "repo", Tag: "tag", File: "file"}}}}}}
entity, err := server.Get(context.TODO(), 1, DevBuildGetOption{})
require.NoError(t, err)
require.Equal(t, "http://orasdownload.net/repo?tag=tag&file=file", entity.Status.BuildReport.Binaries[0].URL)
require.Equal(t, "http://ocidownload.net/repo?tag=tag&file=file", entity.Status.BuildReport.Binaries[0].URL)
})
t.Run("render tekton pipeline", func(t *testing.T) {
mockedRepo.saved = DevBuild{ID: 1,
Expand Down
14 changes: 7 additions & 7 deletions tibuild/pkg/rest/service/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ type TektonPipeline struct {
Platform Platform `json:"platform,omitempty"`
PipelineStartAt *time.Time `json:"pipelineStartAt,omitempty"`
PipelineEndAt *time.Time `json:"pipelineEndAt,omitempty"`
OciArtifacts []OciArtifact `json:"orasArtifacts,omitempty"`
OciArtifacts []OciArtifact `json:"ociArtifacts,omitempty"`
Images []ImageArtifact `json:"images,omitempty"`
}

Expand Down Expand Up @@ -300,14 +300,14 @@ var (
)

type BinArtifact struct {
Component string `json:"component,omitempty"`
Platform Platform `json:"platform"`
URL string `json:"url"`
Sha256URL string `json:"sha256URL"`
OrasFile *OrasFile `json:"oras,omitempty"`
Component string `json:"component,omitempty"`
Platform Platform `json:"platform"`
URL string `json:"url"`
Sha256URL string `json:"sha256URL"`
OciFile *OciFile `json:"ociFile,omitempty"`
}

type OrasFile struct {
type OciFile struct {
Repo string `json:"repo"`
Tag string `json:"tag"`
File string `json:"file"`
Expand Down
14 changes: 7 additions & 7 deletions tibuild/pkg/webhook/service/cloudevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func convertOciArtifacts(pipeline tekton.PipelineRun) []rest.OciArtifact {
if r.Name == "pushed-binaries" {
v, err := convertOciArtifact(r.Value.StringVal)
if err != nil {
slog.Error("can not parse oras file", "error", err.Error())
slog.Error("can not parse oci file", "error", err.Error())
// this make error can be seen by frontend, and not block other result
v = &rest.OciArtifact{Repo: "parse_error", Tag: r.Value.StringVal, Files: []string{"error_parse_artifact"}}
}
Expand All @@ -148,7 +148,7 @@ func convertOciArtifacts(pipeline tekton.PipelineRun) []rest.OciArtifact {
return rt
}

type TektonOrasStruct struct {
type TektonOciArtifactStruct struct {
OCI struct {
Repo string `json:"repo"`
Tag string `json:"tag"`
Expand All @@ -158,15 +158,15 @@ type TektonOrasStruct struct {
}

func convertOciArtifact(text string) (*rest.OciArtifact, error) {
tekton_oras := TektonOrasStruct{}
err := yaml.Unmarshal([]byte(text), &tekton_oras)
tekton_oci_artifact := TektonOciArtifactStruct{}
err := yaml.Unmarshal([]byte(text), &tekton_oci_artifact)
if err != nil {
return nil, err
}
return &rest.OciArtifact{
Repo: tekton_oras.OCI.Repo,
Tag: tekton_oras.OCI.Tag,
Files: tekton_oras.Files,
Repo: tekton_oci_artifact.OCI.Repo,
Tag: tekton_oci_artifact.OCI.Tag,
Files: tekton_oci_artifact.Files,
}, nil
}

Expand Down
Loading