forked from koderover/zadig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sonar image initialization & upgrade (koderover#1496)
* added sonar image into system integration Signed-off-by: Min Min <[email protected]> * added initialize logic Signed-off-by: Min Min <[email protected]>
- Loading branch information
Showing
4 changed files
with
151 additions
and
0 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
44 changes: 44 additions & 0 deletions
44
pkg/cli/upgradeassistant/internal/repository/models/basic_images.go
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,44 @@ | ||
/* | ||
Copyright 2022 The KodeRover Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package models | ||
|
||
import ( | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
) | ||
|
||
const ( | ||
ImageFromKoderover = "koderover" | ||
ImageFromCustom = "custom" | ||
) | ||
|
||
// BasicImage ... | ||
type BasicImage struct { | ||
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` | ||
Value string `bson:"value" json:"value"` | ||
Label string `bson:"label" json:"label"` | ||
ImageFrom string `bson:"image_from" json:"image_from"` | ||
CreateTime int64 `bson:"create_time" json:"create_time"` | ||
UpdateTime int64 `bson:"update_time" json:"update_time"` | ||
UpdateBy string `bson:"update_by" json:"update_by"` | ||
// New field since 1.12 | ||
// ImageType is the type of the image, currently only one type is supported called sonar | ||
ImageType string `bson:"image_type" json:"image_type"` | ||
} | ||
|
||
func (BasicImage) TableName() string { | ||
return "basic_image" | ||
} |
81 changes: 81 additions & 0 deletions
81
pkg/cli/upgradeassistant/internal/repository/mongodb/basic_imnages.go
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,81 @@ | ||
/* | ||
Copyright 2021 The KodeRover Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package mongodb | ||
|
||
import ( | ||
"context" | ||
"github.com/koderover/zadig/pkg/microservice/aslan/config" | ||
"github.com/koderover/zadig/pkg/microservice/aslan/core/common/repository/models" | ||
mongotool "github.com/koderover/zadig/pkg/tool/mongo" | ||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"time" | ||
) | ||
|
||
type BasicImageOpt struct { | ||
Value string `bson:"value"` | ||
Label string `bson:"label"` | ||
ImageFrom string `bson:"image_from"` | ||
ImageType string `bson:"image_type"` | ||
} | ||
|
||
type BasicImageColl struct { | ||
*mongo.Collection | ||
|
||
coll string | ||
} | ||
|
||
func NewBasicImageColl() *BasicImageColl { | ||
name := models.BasicImage{}.TableName() | ||
coll := &BasicImageColl{Collection: mongotool.Database(config.MongoDatabase()).Collection(name), coll: name} | ||
|
||
return coll | ||
} | ||
|
||
func (c *BasicImageColl) GetSonarTypeImage() ([]*models.BasicImage, error) { | ||
query := bson.M{} | ||
query["image_type"] = "sonar" | ||
|
||
ctx := context.Background() | ||
resp := make([]*models.BasicImage, 0) | ||
|
||
cursor, err := c.Collection.Find(ctx, query) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = cursor.All(ctx, &resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return resp, err | ||
} | ||
|
||
func (c *BasicImageColl) CreateZadigSonarImage() error { | ||
args := &models.BasicImage{ | ||
Value: "sonarsource/sonar-scanner-cli", | ||
Label: "sonar:latest", | ||
CreateTime: time.Now().Unix(), | ||
UpdateTime: time.Now().Unix(), | ||
UpdateBy: "system", | ||
ImageType: "sonar", | ||
} | ||
|
||
_, err := c.InsertOne(context.TODO(), args) | ||
return err | ||
} |
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