From 0fa6774bf50b0e0ba9f01e6c2e945bf35cb473dd Mon Sep 17 00:00:00 2001 From: architmallik7 Date: Thu, 19 Dec 2024 13:09:32 +0530 Subject: [PATCH] Revert "Merge pull request #272 from architmallik7/CI-15410-revert" This reverts commit 578fd017221c08aeec92a9f647568391554c3bee, reversing changes made to cb35f9c96d16b36de3c61f962b38aa40ae920d71. --- convert/drone/convert.go | 147 ++++++++++++++----------------------- convert/drone/yaml/spec.go | 3 +- go.mod | 2 +- go.sum | 32 ++++++++ samples/drone.yaml | 4 + 5 files changed, 95 insertions(+), 93 deletions(-) diff --git a/convert/drone/convert.go b/convert/drone/convert.go index 83f6ede3..c4e0c5c2 100644 --- a/convert/drone/convert.go +++ b/convert/drone/convert.go @@ -33,7 +33,6 @@ import ( // conversion context type context struct { pipeline []*v1.Pipeline - stage *v1.Pipeline } // Converter converts a Drone pipeline to a Harness @@ -141,17 +140,11 @@ func (d *Converter) convert(ctx *context) ([]byte, error) { // // create the pipeline spec - pipeline := &v2.Pipeline{ - Options: &v2.Default{ - Registry: convertRegistry(ctx.pipeline), - }, - } + pipeline := &v2.PipelineV1{} // create the harness pipeline resource - config := &v2.Config{ - Version: 1, - Kind: "pipeline", - Spec: pipeline, + config := &v2.ConfigV1{ + Pipeline: pipeline, } for _, from := range ctx.pipeline { @@ -165,23 +158,12 @@ func (d *Converter) convert(ctx *context) ([]byte, error) { case v1.KindPipeline: // TODO pipeline.name removed from spec // pipeline.Name = from.Name - - pipeline.Stages = append(pipeline.Stages, &v2.Stage{ - Name: from.Name, - Type: "ci", - When: convertCond(from.Trigger), - Delegate: convertNode(from.Node), - Spec: &v2.StageCI{ - Clone: convertClone(from.Clone), - Envs: copyenv(from.Environment), - Platform: convertPlatform(from.Platform), - Runtime: convertRuntime(from), - Steps: convertSteps(from, d.orgSecrets), - Volumes: convertVolumes(from.Volumes), - - // TODO support for delegate.selectors from from.Node - // TODO support for stage.variables - }, + runtime := determineRuntime(from) + pipeline.Stages = append(pipeline.Stages, &v2.StageV1{ + Name: from.Name, + Clone: convertCloneV1(&from.Clone), + Runtime: runtime, + Steps: convertSteps(from, d.orgSecrets), }) } } @@ -203,6 +185,13 @@ func (d *Converter) convert(ctx *context) ([]byte, error) { return out, nil } +func determineRuntime(from *v1.Pipeline) string { + if from.Runtime != "" { + return from.Runtime + } + return "machine" +} + func convertRegistry(src []*v1.Pipeline) *v2.Registry { // note that registry credentials in Drone are stored // at the stage level, but in Harness, we are proposing @@ -236,28 +225,39 @@ func convertRegistry(src []*v1.Pipeline) *v2.Registry { return dst } -func convertSteps(src *v1.Pipeline, orgSecrets []string) []*v2.Step { - var dst []*v2.Step - for _, v := range src.Services { - if v != nil { - dst = append(dst, convertBackground(v, orgSecrets)) - } - } +func convertSteps(src *v1.Pipeline, orgSecrets []string) []*v2.StepV1 { + var dst []*v2.StepV1 for _, v := range src.Steps { if v != nil { switch { case v.Detach: - dst = append(dst, convertBackground(v, orgSecrets)) + continue case isPlugin(v): - dst = append(dst, convertPlugin(v, orgSecrets)) + continue default: - dst = append(dst, convertRun(v, orgSecrets)) + stepV1 := &v2.StepV1{ + Name: v.Name, + Run: &v2.RunSpec{ + Container: &v2.ContainerSpec{ + Image: v.Image, + Connector: v.Connector, + }, + Env: convertVariables(v.Environment, orgSecrets), + Script: joinCommands(v.Commands), + }, + } + dst = append(dst, convertRun(stepV1, orgSecrets)) } } } + return dst } +func joinCommands(commands []string) string { + return strings.Join(commands, "\n") +} + func convertPlugin(src *v1.Step, orgSecrets []string) *v2.Step { return &v2.Step{ Name: src.Name, @@ -299,25 +299,19 @@ func convertBackground(src *v1.Step, orgSecrets []string) *v2.Step { } } -func convertRun(src *v1.Step, orgSecrets []string) *v2.Step { - return &v2.Step{ - Name: src.Name, - Type: "script", - When: convertCond(src.When), - Spec: &v2.StepExec{ - Image: src.Image, - Mount: convertMounts(src.Volumes), - Privileged: src.Privileged, - Pull: convertPull(src.Pull), - Shell: convertShell(src.Shell), - User: src.User, - Entrypoint: convertEntrypoint(src.Entrypoint), - Args: convertArgs(src.Entrypoint, src.Command), - Run: convertScript(src.Commands), - Envs: convertVariables(src.Environment, orgSecrets), - Resources: convertResourceLimits(&src.Resource), - // Volumes // FIX +func convertRun(src *v2.StepV1, orgSecrets []string) *v2.StepV1 { + runSpec := &v2.RunSpec{ + Container: &v2.ContainerSpec{ + Image: src.Run.Container.Image, + Connector: src.Run.Container.Connector, }, + Env: src.Run.Env, + Script: src.Run.Script, + } + + return &v2.StepV1{ + Name: src.Name, + Run: runSpec, } } @@ -626,45 +620,16 @@ func convertShell(src string) string { } } -func convertRuntime(src *v1.Pipeline) *v2.Runtime { - if src.Type == "kubernetes" { - return &v2.Runtime{ - Type: "kubernetes", - Spec: &v2.RuntimeKube{ - // TODO should harness support `dns_config` - // TODO should harness support `host_aliases` - // TODO support for `tolerations` - Annotations: src.Metadata.Annotations, - Labels: src.Metadata.Labels, - Namespace: src.Metadata.Namespace, - NodeSelector: src.NodeSelector, - Node: src.NodeName, - ServiceAccount: src.ServiceAccount, - Resources: convertResourceRequests(&src.Resource), - }, +func convertCloneV1(from *v1.Clone) *v2.CloneStageV1 { + // If from is nil, set Disabled to true + if from == nil { + return &v2.CloneStageV1{ + Disabled: true, } } - return &v2.Runtime{ - Type: "machine", - Spec: v2.RuntimeMachine{}, - } -} - -func convertClone(src v1.Clone) *v2.CloneStage { - dst := new(v2.CloneStage) - if v := src.Depth; v != 0 { - dst.Depth = int64(v) - } - if v := src.Disable; v { - dst.Disabled = true - } - if v := src.SkipVerify; v { - dst.Insecure = true + return &v2.CloneStageV1{ + Disabled: from.Disable || true, } - if v := src.Trace; v { - dst.Trace = true - } - return dst } func convertNode(src map[string]string) []string { diff --git a/convert/drone/yaml/spec.go b/convert/drone/yaml/spec.go index afd38962..28cf8a71 100644 --- a/convert/drone/yaml/spec.go +++ b/convert/drone/yaml/spec.go @@ -34,7 +34,7 @@ type ( Volumes []*Volume `json:"volumes,omitempty"` PullSecrets []string `json:"image_pull_secrets,omitempty" yaml:"image_pull_secrets"` Workspace Workspace `json:"workspace,omitempty"` - + Runtime string `json:"runtime,omitempty"` // Kubernetes Runner DnsConfig DnsConfig `json:"dns_config,omitempty" yaml:"dns_config"` HostAliases []HostAlias `json:"host_aliases,omitempty" yaml:"host_aliases"` @@ -114,6 +114,7 @@ type ( Volumes []*VolumeMount `json:"volumes,omitempty"` When Conditions `json:"when,omitempty"` WorkingDir string `json:"working_dir,omitempty" yaml:"working_dir"` + Connector string `json:"connector,omitempty"` } // Volume that can be mounted by containers. diff --git a/go.mod b/go.mod index 24f19035..c731063b 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/bmatcuk/doublestar v1.3.4 github.com/buildkite/yaml v2.1.0+incompatible github.com/docker/go-units v0.4.0 - github.com/drone/spec v0.0.0-20230919004456-7455b8913ff5 + github.com/drone/spec v0.0.0-20241217061713-8287b13d4d83 github.com/ghodss/yaml v1.0.0 github.com/google/go-cmp v0.5.9 github.com/google/subcommands v1.2.0 diff --git a/go.sum b/go.sum index 9d9545ac..6de0afef 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,38 @@ github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/drone/spec v0.0.0-20230919004456-7455b8913ff5 h1:NgAseJNQpJE3XtgJUPu4x7x5fcBjqZ3oKHDJfwBYdWk= github.com/drone/spec v0.0.0-20230919004456-7455b8913ff5/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241206074240-c0adc29201f6 h1:ag4sJrFRvWf9PxqN2JDurm2C3zCeKnHgp20ZaDkBiyg= +github.com/drone/spec v0.0.0-20241206074240-c0adc29201f6/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241206110716-6b0bc437f5d3 h1:waJqvC0pcxSVG0NNlVtyQ6Sp5cO+Rg/P9Z32XFSo4UU= +github.com/drone/spec v0.0.0-20241206110716-6b0bc437f5d3/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241206112721-895e54a426dc h1:mJUkCCiOITKFGkCRyq/taIpHmrffcgEH9OuWaiwZaA4= +github.com/drone/spec v0.0.0-20241206112721-895e54a426dc/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241206113347-76171b50a6b8 h1:WL+nD/36D3R1HlpqOmY7vxdYUttrL2V4a/VLky9v+Lk= +github.com/drone/spec v0.0.0-20241206113347-76171b50a6b8/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241208142400-ae8af91086e4 h1:fxCwzQpdO+VEy6nMLS8ybcknJ3/c5TPqFT5/HngSFx4= +github.com/drone/spec v0.0.0-20241208142400-ae8af91086e4/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241209071302-e62a5fc1bd39 h1:eszoTWMbPtCgTIfmlyetw9REFFYKpNGzmF2qZGdMGW0= +github.com/drone/spec v0.0.0-20241209071302-e62a5fc1bd39/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241209084510-3dd2a8f1d4b3 h1:4WJp6rVKGU7oj62FLy9+4azX0SCwcighbZqCM41rh84= +github.com/drone/spec v0.0.0-20241209084510-3dd2a8f1d4b3/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241209101256-fe5074a83f15 h1:/C0TNbUB9pkDp3BaCId7yP36ql0v8PxP9gAIKlUo5xA= +github.com/drone/spec v0.0.0-20241209101256-fe5074a83f15/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241209102330-ebcd688c5e4d h1:oO1u2FVMZatFfwr3Ie8MabGMpOJJwjA57IZmYUjbEOI= +github.com/drone/spec v0.0.0-20241209102330-ebcd688c5e4d/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241209102911-9e734bcf1284 h1:mVhtCMroPWWtG3mt7f8bSiKSUMeW7CFlKpaEzO381jM= +github.com/drone/spec v0.0.0-20241209102911-9e734bcf1284/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241209104116-8267461e9d39 h1:8FDyDR/YVW640O7ixz0iF9Bkut1J46063MgjHSCfrkQ= +github.com/drone/spec v0.0.0-20241209104116-8267461e9d39/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241209111925-fd1782c8fe08 h1:pk6ftD7tFlvUFiTfbLG27+nW6OqmupvVtJDCcsGo/HM= +github.com/drone/spec v0.0.0-20241209111925-fd1782c8fe08/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241209120745-6a698158554a h1:LVanuctoR9mDp46HW3f9onrseHuCJEjyUdmI7D/HMa0= +github.com/drone/spec v0.0.0-20241209120745-6a698158554a/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241216074748-007d660a33aa h1:O7PDHKB8a7V/LYjxNBoMbV8BZQKuyS2Bzos/wX/EZPk= +github.com/drone/spec v0.0.0-20241216074748-007d660a33aa/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241216100228-baf181e08e9a h1:ETm2Ce+C2phPXpjdKi4wNIV9IafXEK72y+2NsHTnEgg= +github.com/drone/spec v0.0.0-20241216100228-baf181e08e9a/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= +github.com/drone/spec v0.0.0-20241217061713-8287b13d4d83 h1:QoTKjUGxeE8IbVpWDJn96yTFL48CQ5NaZeNq40qoJks= +github.com/drone/spec v0.0.0-20241217061713-8287b13d4d83/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= diff --git a/samples/drone.yaml b/samples/drone.yaml index 546f1b2f..4d5c55be 100644 --- a/samples/drone.yaml +++ b/samples/drone.yaml @@ -6,6 +6,10 @@ name: default steps: - name: backend image: golang + environment: + PLUGIN_LOG_LEVEL: info + PLUGIN_ARTIFACT_REGION: us-east-1 + PLUGIN_ARTIFACT_BUCKET_NAME: unified-versioning-bucket commands: - go build - go test