Skip to content

Commit

Permalink
fix #9 Support concurrent jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammedikinci committed May 15, 2022
1 parent 9f14d3d commit ba7c07c
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 87 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,29 @@ helper:
index.js
```

## parallel

default: false

If you want to run parallel job, you must add `parallel` field and the stage must be in workflow(position doesn't matter)

```yaml
workflow:
- testStage
- parallelJob
- run
...
parallelJob:
image: node:current-alpine3.15
copyFiles: true
soloExecution: true
parallel: true
script:
- ls -a
```

# Tests

```sh
Expand All @@ -178,7 +201,7 @@ go test ./...
# Checklist

- Implement web interface
- Support concurrent jobs
- Support concurrent jobs ✅[Issue#9](https://github.com/muhammedikinci/pin/issues/9)
- Add working with remote docker deamon support
- Change image pulling logs (get only status logs)✅[Issue#1](https://github.com/muhammedikinci/pin/issues/1)
- Add custom ignore configuration to copyFiles for project files (like gitignore) ✅[Issue#7](https://github.com/muhammedikinci/pin/issues/7)
Expand Down
2 changes: 1 addition & 1 deletion pkg/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Apply(name string, filepath string) error {
currentRunner := Runner{}

if err := currentRunner.run(pipeline); err != nil {
currentRunner.infoLog.Println(err.Error())
fmt.Println(err.Error())
return err
}

Expand Down
35 changes: 23 additions & 12 deletions pkg/job.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package pin

import (
"log"

"github.com/docker/docker/api/types/container"
"github.com/muhammedikinci/pin/pkg/interfaces"
)

type Job struct {
Name string
Image string
Script []string
WorkDir string
CopyFiles bool
Status int
SoloExecution bool
Port []Port
CopyIgnore []string
RemoveContainer bool
Previous *Job
ErrorChannel chan error
Name string
Image string
Script []string
WorkDir string
CopyFiles bool
SoloExecution bool
Port []Port
CopyIgnore []string
IsParallel bool
Previous *Job
ErrorChannel chan error
Container container.ContainerCreateCreatedBody
InfoLog *log.Logger
ImageManager interfaces.ImageManager
ContainerManager interfaces.ContainerManager
ShellCommander interfaces.ShellCommander
}

type Port struct {
Expand Down
36 changes: 18 additions & 18 deletions pkg/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type Pipeline struct {
Workflow []Job
Workflow []*Job
LogsWithTime bool
}

Expand All @@ -29,8 +29,8 @@ func parse() (Pipeline, error) {

job.Name = v

if i > 0 {
job.Previous = &pipeline.Workflow[i-1]
if i > 0 && (!job.IsParallel || !pipeline.Workflow[i-1].IsParallel) {
job.Previous = pipeline.Workflow[i-1]
}

pipeline.Workflow = append(pipeline.Workflow, job)
Expand All @@ -41,41 +41,41 @@ func parse() (Pipeline, error) {
return pipeline, nil
}

func generateJob(configMap map[string]interface{}) (Job, error) {
func generateJob(configMap map[string]interface{}) (*Job, error) {
image, err := getJobImage(configMap["image"])

if err != nil {
return Job{}, err
return &Job{}, err
}

workDir, err := getWorkDir(configMap["workdir"])

if err != nil {
return Job{}, err
return &Job{}, err
}

copyFiles, err := getCopyFiles(configMap["copyfiles"])

if err != nil {
return Job{}, err
return &Job{}, err
}

soloExecution := getBool(configMap["soloexecution"], false)
removeContainer := getBool(configMap["removecontainer"], true)
isParallel := getBool(configMap["parallel"], false)
copyIgnore := getStringArray(configMap["copyignore"])
script := getStringArray(configMap["script"])
port := getJobPort(configMap["port"])

var job Job = Job{
Image: image,
Script: script,
CopyFiles: copyFiles,
WorkDir: workDir,
SoloExecution: soloExecution,
RemoveContainer: removeContainer,
Port: port,
CopyIgnore: copyIgnore,
ErrorChannel: make(chan error, 1),
var job *Job = &Job{
Image: image,
Script: script,
CopyFiles: copyFiles,
WorkDir: workDir,
SoloExecution: soloExecution,
IsParallel: isParallel,
Port: port,
CopyIgnore: copyIgnore,
ErrorChannel: make(chan error, 1),
}

return job, nil
Expand Down
Loading

0 comments on commit ba7c07c

Please sign in to comment.