Skip to content

Commit 5e82591

Browse files
pawan-59kartik-579prakash100198manish-agrawal-aikripanshdevtron
authored
merge main into ref-chart-4-15-fix (#2601)
* fixed migration query in 90th migration (#2586) * updated wiring for TelemetryEventClientExtended.go (#2588) * feat: Provide description for Chart Types (#2585) * chart description provided with the api call * added code to provide chart description with the api call * refined the code for poviding chart description * mitigated nil pointer exception in ChartService * refactoring * changes in sql files Co-authored-by: Manish Agrawal <[email protected]> * sql script semicolon fix (#2590) * Ci Build config API backward compatibilty (#2598) * docker build config added as backward compatible changes * dependency injection fix Co-authored-by: kartik-579 <[email protected]> Co-authored-by: Prakash Kumar <[email protected]> Co-authored-by: Manish Agrawal <[email protected]> Co-authored-by: kripanshdevtron <[email protected]>
1 parent 879c185 commit 5e82591

File tree

10 files changed

+99
-19
lines changed

10 files changed

+99
-19
lines changed

api/appbean/AppDetail.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,19 @@ type GitMaterial struct {
4242
}
4343

4444
type DockerConfig struct {
45-
DockerRegistry string `json:"dockerRegistry" validate:"required"`
46-
DockerRepository string `json:"dockerRepository" validate:"required"`
47-
CiBuildConfig *bean.CiBuildConfigBean `json:"ciBuildConfig" validate:"required"`
48-
CheckoutPath string `json:"checkoutPath"`
45+
DockerRegistry string `json:"dockerRegistry" validate:"required"`
46+
DockerRepository string `json:"dockerRepository" validate:"required"`
47+
CiBuildConfig *bean.CiBuildConfigBean `json:"ciBuildConfig"`
48+
DockerBuildConfig *DockerBuildConfig `json:"dockerBuildConfig,omitempty"` // Deprecated, should use CiBuildConfig for development
49+
CheckoutPath string `json:"checkoutPath"`
50+
}
51+
52+
type DockerBuildConfig struct {
53+
GitCheckoutPath string `json:"gitCheckoutPath,omitempty" validate:"required"`
54+
DockerfileRelativePath string `json:"dockerfileRelativePath,omitempty" validate:"required"`
55+
Args map[string]string `json:"args,omitempty"`
56+
TargetPlatform string `json:"targetPlatform"`
57+
DockerBuildOptions map[string]string `json:"dockerBuildOptions,omitempty"`
4958
}
5059

5160
type DeploymentTemplate struct {

api/restHandler/BatchOperationRestHandler_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
package restHandler
1919

2020
import (
21-
"github.com/devtron-labs/devtron/pkg/apis/devtron/v1"
2221
"testing"
22+
23+
v1 "github.com/devtron-labs/devtron/pkg/apis/devtron/v1"
2324
)
2425

2526
func Test_validatePipeline(t *testing.T) {
@@ -82,3 +83,4 @@ func Test_validatePipeline(t *testing.T) {
8283
}
8384
})
8485
}
86+
}

api/restHandler/CoreAppRestHandler.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository"
3939
repository2 "github.com/devtron-labs/devtron/pkg/cluster/repository"
4040
"github.com/devtron-labs/devtron/pkg/pipeline"
41+
bean2 "github.com/devtron-labs/devtron/pkg/pipeline/bean"
4142
"github.com/devtron-labs/devtron/pkg/sql"
4243
"github.com/devtron-labs/devtron/pkg/team"
4344
"github.com/devtron-labs/devtron/pkg/user"
@@ -1244,7 +1245,18 @@ func (handler CoreAppRestHandlerImpl) createGitMaterials(appId int, gitMaterials
12441245
// create docker config
12451246
func (handler CoreAppRestHandlerImpl) createDockerConfig(appId int, dockerConfig *appBean.DockerConfig, userId int32) (error, int) {
12461247
handler.logger.Infow("Create App - creating docker config", "appId", appId, "DockerConfig", dockerConfig)
1247-
1248+
dockerBuildConfig := dockerConfig.DockerBuildConfig
1249+
if dockerBuildConfig != nil {
1250+
dockerConfig.CheckoutPath = dockerBuildConfig.GitCheckoutPath
1251+
dockerConfig.CiBuildConfig = &bean2.CiBuildConfigBean{
1252+
DockerBuildConfig: &bean2.DockerBuildConfig{
1253+
DockerfilePath: dockerBuildConfig.DockerfileRelativePath,
1254+
DockerBuildOptions: dockerBuildConfig.DockerBuildOptions,
1255+
Args: dockerBuildConfig.Args,
1256+
TargetPlatform: dockerBuildConfig.TargetPlatform,
1257+
},
1258+
}
1259+
}
12481260
createDockerConfigRequest := &bean.CiConfigRequest{
12491261
AppId: appId,
12501262
UserId: userId,

client/telemetry/TelemetryEventClientExtended.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ func NewTelemetryEventClientImplExtended(logger *zap.SugaredLogger, client *http
5353
ciWorkflowRepository pipelineConfig.CiWorkflowRepository, cdWorkflowRepository pipelineConfig.CdWorkflowRepository,
5454
dockerArtifactStoreRepository repository.DockerArtifactStoreRepository,
5555
materialRepository pipelineConfig.MaterialRepository, ciTemplateRepository pipelineConfig.CiTemplateRepository,
56-
chartRepository chartRepoRepository.ChartRepository, moduleRepository moduleRepo.ModuleRepository, serverDataStore *serverDataStore.ServerDataStore, userAuditService user.UserAuditService) (*TelemetryEventClientImplExtended, error) {
56+
chartRepository chartRepoRepository.ChartRepository, moduleRepository moduleRepo.ModuleRepository,
57+
serverDataStore *serverDataStore.ServerDataStore, userAuditService user.UserAuditService,
58+
ciBuildConfigService pipeline.CiBuildConfigService) (*TelemetryEventClientImplExtended, error) {
5759

5860
cron := cron.New(
5961
cron.WithChain())
@@ -72,6 +74,7 @@ func NewTelemetryEventClientImplExtended(logger *zap.SugaredLogger, client *http
7274
materialRepository: materialRepository,
7375
ciTemplateRepository: ciTemplateRepository,
7476
chartRepository: chartRepository,
77+
ciBuildConfigService: ciBuildConfigService,
7578
TelemetryEventClientImpl: &TelemetryEventClientImpl{
7679
cron: cron,
7780
logger: logger,

pkg/chart/ChartService.go

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ import (
2222
"context"
2323
"encoding/json"
2424
"fmt"
25+
2526
"github.com/devtron-labs/devtron/internal/constants"
27+
2628
//"github.com/devtron-labs/devtron/pkg/pipeline"
2729

2830
"github.com/devtron-labs/devtron/internal/sql/repository/app"
2931
chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository"
3032
"github.com/devtron-labs/devtron/pkg/pipeline/history"
3133

32-
repository4 "github.com/devtron-labs/devtron/pkg/cluster/repository"
33-
"github.com/devtron-labs/devtron/pkg/sql"
34-
dirCopy "github.com/otiai10/copy"
3534
"io/ioutil"
3635
"net/http"
3736
"os"
@@ -41,6 +40,10 @@ import (
4140
"strings"
4241
"time"
4342

43+
repository4 "github.com/devtron-labs/devtron/pkg/cluster/repository"
44+
"github.com/devtron-labs/devtron/pkg/sql"
45+
dirCopy "github.com/otiai10/copy"
46+
4447
repository2 "github.com/argoproj/argo-cd/v2/pkg/apiclient/repository"
4548
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
4649
"github.com/devtron-labs/devtron/client/argocdServer/repository"
@@ -951,11 +954,16 @@ type chartRef struct {
951954
UserUploaded bool `json:"userUploaded"`
952955
}
953956

957+
type ChartRefMetaData struct {
958+
ChartDescription string `json:"chartDescription"`
959+
}
960+
954961
type chartRefResponse struct {
955-
ChartRefs []chartRef `json:"chartRefs"`
956-
LatestChartRef int `json:"latestChartRef"`
957-
LatestAppChartRef int `json:"latestAppChartRef"`
958-
LatestEnvChartRef int `json:"latestEnvChartRef,omitempty"`
962+
ChartRefs []chartRef `json:"chartRefs"`
963+
LatestChartRef int `json:"latestChartRef"`
964+
LatestAppChartRef int `json:"latestAppChartRef"`
965+
LatestEnvChartRef int `json:"latestEnvChartRef,omitempty"`
966+
ChartsMetadata map[string]ChartRefMetaData `json:"chartMetadata"` // chartName vs Metadata
959967
}
960968

961969
type ChartYamlStruct struct {
@@ -995,14 +1003,28 @@ func (impl ChartServiceImpl) ChartRefAutocomplete() ([]chartRef, error) {
9951003
}
9961004

9971005
func (impl ChartServiceImpl) ChartRefAutocompleteForAppOrEnv(appId int, envId int) (*chartRefResponse, error) {
998-
chartRefResponse := &chartRefResponse{}
1006+
chartRefResponse := &chartRefResponse{
1007+
ChartsMetadata: make(map[string]ChartRefMetaData),
1008+
}
9991009
var chartRefs []chartRef
1010+
10001011
results, err := impl.chartRefRepository.GetAll()
10011012
if err != nil {
10021013
impl.logger.Errorw("error in fetching chart config", "err", err)
10031014
return chartRefResponse, err
10041015
}
10051016

1017+
resultsMetadata, err := impl.chartRefRepository.GetAllChartMetadata()
1018+
if err != nil {
1019+
impl.logger.Errorw("error in fetching chart metadata", "err", err)
1020+
return chartRefResponse, err
1021+
}
1022+
for _, resultMetadata := range resultsMetadata {
1023+
chartRefMetadata := ChartRefMetaData{
1024+
ChartDescription: resultMetadata.ChartDescription,
1025+
}
1026+
chartRefResponse.ChartsMetadata[resultMetadata.ChartName] = chartRefMetadata
1027+
}
10061028
var LatestAppChartRef int
10071029
for _, result := range results {
10081030
if len(result.Name) == 0 {
@@ -1013,6 +1035,7 @@ func (impl ChartServiceImpl) ChartRefAutocompleteForAppOrEnv(appId int, envId in
10131035
LatestAppChartRef = result.Id
10141036
}
10151037
}
1038+
10161039
chart, err := impl.chartRepository.FindLatestChartForAppByAppId(appId)
10171040
if err != nil && err != pg.ErrNoRows {
10181041
impl.logger.Errorw("error in fetching latest chart", "err", err)

pkg/chartRepo/repository/ChartRepoRepository.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
package chartRepoRepository
1919

2020
import (
21+
"strings"
22+
2123
"github.com/devtron-labs/devtron/internal/sql/models"
2224
"github.com/devtron-labs/devtron/internal/sql/repository"
2325
"github.com/devtron-labs/devtron/pkg/sql"
2426
"github.com/go-pg/pg"
25-
"strings"
2627
)
2728

2829
type Chart struct {
@@ -334,11 +335,18 @@ type ChartRef struct {
334335
sql.AuditLog
335336
}
336337

338+
type ChartRefMetaData struct {
339+
tableName struct{} `sql:"chart_ref_metadata" pg:",discard_unknown_columns"`
340+
ChartName string `sql:"chart_name,pk"`
341+
ChartDescription string `sql:"chart_description"`
342+
}
343+
337344
type ChartRefRepository interface {
338345
Save(chartRepo *ChartRef) error
339346
GetDefault() (*ChartRef, error)
340347
FindById(id int) (*ChartRef, error)
341348
GetAll() ([]*ChartRef, error)
349+
GetAllChartMetadata() ([]*ChartRefMetaData, error)
342350
FindByVersionAndName(name, version string) (*ChartRef, error)
343351
CheckIfDataExists(name string, version string) (bool, error)
344352
FetchChart(name string) ([]*ChartRef, error)
@@ -397,6 +405,12 @@ func (impl ChartRefRepositoryImpl) GetAll() ([]*ChartRef, error) {
397405
return chartRefs, err
398406
}
399407

408+
func (impl ChartRefRepositoryImpl) GetAllChartMetadata() ([]*ChartRefMetaData, error) {
409+
var chartRefMetaDatas []*ChartRefMetaData
410+
err := impl.dbConnection.Model(&chartRefMetaDatas).Select()
411+
return chartRefMetaDatas, err
412+
}
413+
400414
func (impl ChartRefRepositoryImpl) CheckIfDataExists(name string, version string) (bool, error) {
401415
repo := &ChartRef{}
402416
return impl.dbConnection.Model(repo).

scripts/sql/90_ci_build_config.up.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ ALTER TABLE ci_template
2020
ADD COLUMN IF NOT EXISTS ci_build_config_id integer;
2121

2222
ALTER TABLE ONLY public.ci_template
23-
ADD CONSTRAINT IF NOT EXISTS ci_template_ci_build_config_id_fkey FOREIGN KEY (ci_build_config_id) REFERENCES public.ci_build_config(id);
23+
ADD CONSTRAINT ci_template_ci_build_config_id_fkey FOREIGN KEY (ci_build_config_id) REFERENCES public.ci_build_config(id);
2424

2525

2626
ALTER TABLE ci_template_override
2727
ADD COLUMN IF NOT EXISTS ci_build_config_id integer;
2828

2929
ALTER TABLE ONLY public.ci_template_override
30-
ADD CONSTRAINT IF NOT EXISTS ci_template_override_ci_build_config_id_fkey FOREIGN KEY (ci_build_config_id) REFERENCES public.ci_build_config(id);
30+
ADD CONSTRAINT ci_template_override_ci_build_config_id_fkey FOREIGN KEY (ci_build_config_id) REFERENCES public.ci_build_config(id);
3131

3232
ALTER TABLE ci_workflow
3333
ADD COLUMN IF NOT EXISTS ci_build_type varchar(100);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE "public"."chart_ref_metadata" CASCADE;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Table Definition
2+
CREATE TABLE "public"."chart_ref_metadata" (
3+
"chart_name" varchar(100) NOT NULL,
4+
"chart_description" text NOT NULL,
5+
PRIMARY KEY ("chart_name")
6+
);
7+
8+
---Inserting Records-----
9+
INSERT INTO "chart_ref_metadata" ("chart_name", "chart_description") VALUES
10+
('Rollout Deployment', 'Chart to deploy an advanced version of Deployment that supports blue-green and canary deployments. It requires a rollout controller to run inside the cluster to function.');
11+
INSERT INTO "chart_ref_metadata" ("chart_name", "chart_description") VALUES
12+
('CronJob & Job', 'Chart to deploy a Job/CronJob. Job is a controller object that represents a finite task and CronJob can be used to schedule creation of Jobs.');
13+
INSERT INTO "chart_ref_metadata" ("chart_name", "chart_description") VALUES
14+
('Knative', 'Chart to deploy an Open-Source Enterprise-level solution to deploy Serverless apps.');
15+
INSERT INTO "chart_ref_metadata" ("chart_name", "chart_description") VALUES
16+
('Deployment', 'Chart to deploy a Deployment that runs multiple replicas of your application and automatically replaces any instances that fail or become unresponsive.');

wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)