1
0
Fork 0

Add exec pipeline support

This commit is contained in:
Lauris BH 2022-07-30 19:52:50 +03:00
parent 60d4f9e2fd
commit 0ba7c597ee
No known key found for this signature in database
GPG Key ID: DFDE60A0093EB926
6 changed files with 45 additions and 6 deletions

View File

@ -10,7 +10,7 @@ Currently supports converting only from Drone CI pipeline format with limited fu
## Drone pipeline supported features
* `kind` - must be `pipeline`
* `type` - only `docker` supported
* `type` - only `docker` and `exec` are supported
* `name`
* `platform`
* `os`

View File

@ -193,7 +193,7 @@ func (d DronePipeline) Convert(pipeline *Pipeline) (*transform.Pipeline, error)
if pipeline.Kind != "pipeline" {
return nil, transform.UnsupportedError
}
if pipeline.Type != "docker" {
if pipeline.Type != "docker" && pipeline.Type != "exec" {
return nil, transform.UnsupportedError
}
if pipeline.Platform != nil && len(pipeline.Platform.Version) > 0 {
@ -338,9 +338,15 @@ func (d DronePipeline) Convert(pipeline *Pipeline) (*transform.Pipeline, error)
if err != nil {
return nil, err
}
var image string
if pipeline.Type == "docker" {
image = d.ConvertImage(step.Image)
} else if pipeline.Type == "exec" {
image = "bash"
}
p.Steps = append(p.Steps, &transform.Step{
Name: step.Name,
Image: d.ConvertImage(step.Image),
Image: image,
Pull: step.Pull == "always",
Environment: env,
Secrets: secrets,

View File

@ -37,7 +37,7 @@ func TestTransformSimple(t *testing.T) {
})
require.NoError(t, err)
require.Len(t, pipelines, 2)
require.Len(t, pipelines, 3)
pipeline := getPipelineByName(pipelines, "build")
require.NotNil(t, pipeline, "build pipeline not found")
@ -120,4 +120,16 @@ func TestTransformSimple(t *testing.T) {
assert.Equal(t, "staging", pipeline.Steps[0].When.Environment)
assert.ElementsMatch(t, []string{"build"}, pipeline.DependsOn)
pipeline = getPipelineByName(pipelines, "update-nlb")
require.NotNil(t, pipeline, "update-nlb pipeline not found")
assert.True(t, pipeline.SkipClone)
require.Len(t, pipeline.Steps, 1)
assert.Equal(t, "update", pipeline.Steps[0].Name)
assert.Equal(t, "bash", pipeline.Steps[0].Image)
assert.Len(t, pipeline.Steps[0].Commands, 1)
assert.ElementsMatch(t, []string{"deploy"}, pipeline.DependsOn)
}

View File

@ -103,3 +103,22 @@ steps:
refs:
- refs/tags/v*
- refs/tags/RELEASE-*
---
kind: pipeline
type: exec
name: update-nlb
depends_on:
- deploy
clone:
disable: true
node:
server: nlb
steps:
- name: update
commands:
- systemctl reload haproxy

View File

@ -14,7 +14,7 @@ var UnsupportedError = errors.New("unsupported pipeline")
type Step struct {
Name string `yaml:"-"`
Image string `yaml:"image"`
Image string `yaml:"image,omitempty"`
Pull bool `yaml:"pull,omitempty"`
Environment []string `yaml:"environment,omitempty"`
Secrets Secrets `yaml:"secrets,omitempty"`

View File

@ -4,7 +4,9 @@
package transform
import "strings"
import (
"strings"
)
type Secret struct {
Source string `yaml:"source"`