mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-29 13:21:10 +00:00
Services work - half baked ports field
This commit is contained in:
parent
8530770188
commit
7691b2b897
9 changed files with 52 additions and 42 deletions
|
@ -46,7 +46,8 @@ func TestExec(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestKubeExec(t *testing.T) {
|
||||
reader, err := os.Open("../samples/sample_1/pipeline.json")
|
||||
// reader, err := os.Open("../samples/sample_1/pipeline.json")
|
||||
reader, err := os.Open("../samples/sample_7_redis/pipeline.json")
|
||||
if err != nil {
|
||||
t.Errorf("Could not read pipeline %f", err)
|
||||
}
|
||||
|
|
|
@ -103,15 +103,17 @@ func (e *engine) Exec(ctx context.Context, step *backend.Step) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// for _, n := range proc.Networks {
|
||||
// svc := Service(e.namespace, n.Aliases[0], pod.Name, nil)
|
||||
// if svc == nil {
|
||||
// continue
|
||||
// }
|
||||
// if _, err := e.kubeClient.CoreV1().Services(e.namespace).Create(svc); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
for _, n := range step.Networks {
|
||||
if len(n.Aliases) > 0 {
|
||||
svc := Service(e.namespace, n.Aliases[0], pod.Name, step.Ports)
|
||||
if svc == nil {
|
||||
continue
|
||||
}
|
||||
if _, err := e.kubeClient.CoreV1().Services(e.namespace).Create(svc); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_, err = e.kubeClient.CoreV1().Pods(e.namespace).Create(pod)
|
||||
return err
|
||||
|
@ -249,15 +251,15 @@ func (e *engine) Destroy(ctx context.Context, conf *backend.Config) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// for _, n := range step.Networks {
|
||||
// svc := Service(e.namespace, n.Aliases[0], step.Alias, n.Ports)
|
||||
// if svc == nil {
|
||||
// continue
|
||||
// }
|
||||
// if err := e.client.CoreV1().Services(e.namespace).Delete(svc.Name, deleteOpts); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
for _, n := range step.Networks {
|
||||
svc := Service(e.namespace, n.Aliases[0], step.Alias, step.Ports)
|
||||
if svc == nil {
|
||||
continue
|
||||
}
|
||||
if err := e.kubeClient.CoreV1().Services(e.namespace).Delete(svc.Name, deleteOpts); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,24 +10,27 @@ import (
|
|||
)
|
||||
|
||||
func Pod(namespace string, step *backend.Step) (*v1.Pod, error) {
|
||||
|
||||
var vols []v1.Volume
|
||||
var volMounts []v1.VolumeMount
|
||||
for _, vol := range step.Volumes {
|
||||
vols = append(vols, v1.Volume{
|
||||
Name: volumeName(vol),
|
||||
VolumeSource: v1.VolumeSource{
|
||||
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
|
||||
ClaimName: volumeName(vol),
|
||||
ReadOnly: false,
|
||||
if step.WorkingDir != "" {
|
||||
for _, vol := range step.Volumes {
|
||||
vols = append(vols, v1.Volume{
|
||||
Name: volumeName(vol),
|
||||
VolumeSource: v1.VolumeSource{
|
||||
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
|
||||
ClaimName: volumeName(vol),
|
||||
ReadOnly: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
volMounts = append(volMounts, v1.VolumeMount{
|
||||
Name: volumeName(vol),
|
||||
MountPath: volumeMountPath(step.WorkingDir),
|
||||
//MountPath: volumeMountPath(vol.Target),
|
||||
})
|
||||
volMounts = append(volMounts, v1.VolumeMount{
|
||||
Name: volumeName(vol),
|
||||
MountPath: volumeMountPath(step.WorkingDir),
|
||||
//MountPath: volumeMountPath(vol.Target),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pullPolicy := v1.PullIfNotPresent
|
||||
|
@ -39,7 +42,7 @@ func Pod(namespace string, step *backend.Step) (*v1.Pod, error) {
|
|||
args := step.Command
|
||||
envs := mapToEnvVars(step.Environment)
|
||||
|
||||
if !strings.HasSuffix(step.Name, "_clone_0") {
|
||||
if _, hasScript := step.Environment["CI_SCRIPT"]; !strings.HasSuffix(step.Name, "_clone") && hasScript {
|
||||
command = []string{"/bin/sh", "-c"}
|
||||
args = []string{"echo $CI_SCRIPT | base64 -d | /bin/sh -e"}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package kubernetes
|
||||
|
||||
import (
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
)
|
||||
|
|
|
@ -3,7 +3,7 @@ package kubernetes
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
@ -27,7 +27,7 @@ func PersistentVolume(node, namespace, name string) *v1.PersistentVolume {
|
|||
StorageClassName: "local-storage",
|
||||
PersistentVolumeSource: v1.PersistentVolumeSource{
|
||||
Local: &v1.LocalVolumeSource{
|
||||
Path: "/tmp",
|
||||
Path: "/tmp/drone",
|
||||
},
|
||||
},
|
||||
NodeAffinity: &v1.VolumeNodeAffinity{
|
||||
|
|
|
@ -48,6 +48,7 @@ type (
|
|||
NetworkMode string `json:"network_mode,omitempty"`
|
||||
IpcMode string `json:"ipc_mode,omitempty"`
|
||||
Sysctls map[string]string `json:"sysctls,omitempty"`
|
||||
Ports []int `json:"ports,omitempty"`
|
||||
}
|
||||
|
||||
// Auth defines registry authentication credentials.
|
||||
|
|
|
@ -75,6 +75,7 @@
|
|||
"alias": "database",
|
||||
"image": "mysql:latest",
|
||||
"detach": true,
|
||||
"ports": [ 3306 ],
|
||||
"environment": {
|
||||
"CI": "pipec",
|
||||
"CI_BUILD_CREATED": "1486119586",
|
||||
|
@ -143,7 +144,7 @@
|
|||
{
|
||||
"name": "pipeline_step_0",
|
||||
"alias": "build",
|
||||
"image": "golang:1.7",
|
||||
"image": "golang:1.11",
|
||||
"working_dir": "/go/src/github.com/go-sql-driver/mysql",
|
||||
"environment": {
|
||||
"CI": "pipec",
|
||||
|
|
|
@ -4,7 +4,7 @@ workspace:
|
|||
|
||||
pipeline:
|
||||
build:
|
||||
image: golang:1.7
|
||||
image: golang:1.11
|
||||
environment:
|
||||
MYSQL_TEST_ADDR: database:3306
|
||||
commands:
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
"name": "pipeline_services_0",
|
||||
"alias": "redis1",
|
||||
"image": "redis:3.0",
|
||||
"ports": [ 6379 ],
|
||||
"detach": true,
|
||||
"environment": {
|
||||
"CI": "drone",
|
||||
|
@ -23,7 +24,7 @@
|
|||
"DRONE_WORKSPACE": "/go/src/github.com/drone/envsubst"
|
||||
},
|
||||
"volumes": [
|
||||
"/Users/bradrydzewski/code/src/github.com/laszlocph/drone-oss-08/cncd/pipeline/samples/sample_7_redis:/go/src/github.com/drone/envsubst"
|
||||
"pipeline_default:/go/src/github.com/drone/envsubst"
|
||||
],
|
||||
"networks": [
|
||||
{
|
||||
|
@ -40,6 +41,7 @@
|
|||
"name": "pipeline_services_1",
|
||||
"alias": "redis2",
|
||||
"image": "redis:3.0",
|
||||
"ports": [ 6379 ],
|
||||
"detach": true,
|
||||
"environment": {
|
||||
"CI": "drone",
|
||||
|
@ -55,7 +57,7 @@
|
|||
"DRONE_WORKSPACE": "/go/src/github.com/drone/envsubst"
|
||||
},
|
||||
"volumes": [
|
||||
"/Users/bradrydzewski/code/src/github.com/laszlocph/drone-oss-08/cncd/pipeline/samples/sample_7_redis:/go/src/github.com/drone/envsubst"
|
||||
"pipeline_default:/go/src/github.com/drone/envsubst"
|
||||
],
|
||||
"networks": [
|
||||
{
|
||||
|
@ -103,7 +105,7 @@
|
|||
"echo $CI_SCRIPT | base64 -d | /bin/sh -e"
|
||||
],
|
||||
"volumes": [
|
||||
"/Users/bradrydzewski/code/src/github.com/laszlocph/drone-oss-08/cncd/pipeline/samples/sample_7_redis:/go/src/github.com/drone/envsubst"
|
||||
"pipeline_default:/go/src/github.com/drone/envsubst"
|
||||
],
|
||||
"networks": [
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue