Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Adds services capabilities #638

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/container/docker_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package container

import (
"context"
"fmt"

"github.com/docker/docker/api/types"
"github.com/nektos/act/pkg/common"
Expand All @@ -14,10 +15,11 @@ func NewDockerNetworkCreateExecutor(name string) common.Executor {
return err
}

_, err = cli.NetworkCreate(ctx, name, types.NetworkCreate{})
network, err := cli.NetworkCreate(ctx, name, types.NetworkCreate{})
if err != nil {
return err
}
fmt.Printf("%#v", network.ID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use log instead of fmt, we should limit fmt only to formatting strings

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, it was a rogue line, my apologies


return nil
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/container/docker_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,6 @@ func (cr *containerReference) create() common.Executor {
OS: desiredPlatform[0],
}
}
fmt.Printf("%#v", len(input.Cmd))
fmt.Printf("%#v", config)
resp, err := cr.cli.ContainerCreate(ctx, config, &container.HostConfig{
Binds: input.Binds,
Mounts: mounts,
Expand Down
25 changes: 11 additions & 14 deletions pkg/runner/run_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func (rc *RunContext) startJobContainer() common.Executor {
"act-toolcache": "/toolcache",
"act-actions": "/actions",
},
// NetworkMode: "host",
Binds: binds,
Stdout: logWriter,
Stderr: logWriter,
Expand All @@ -140,7 +139,6 @@ func (rc *RunContext) startJobContainer() common.Executor {
"act-toolcache": "/toolcache",
"act-actions": "/actions",
},
// NetworkMode: "host",
Binds: binds,
Stdout: logWriter,
Stderr: logWriter,
Expand All @@ -156,16 +154,17 @@ func (rc *RunContext) startJobContainer() common.Executor {
copyToPath = filepath.Join(rc.Config.Workdir, copyToPath)
}

networkName := fmt.Sprintf("act-%s-network", rc.Run.JobID)
return common.NewPipelineExecutor(
rc.JobContainer.Pull(rc.Config.ForcePull),
rc.stopServiceContainers(),
rc.stopJobContainer(),
rc.removeNetwork(),
rc.createNetwork(),
rc.startServiceContainers(),
rc.removeNetwork(networkName),
rc.createNetwork(networkName),
rc.startServiceContainers(networkName),
rc.JobContainer.Create(),
rc.JobContainer.Start(false),
rc.JobContainer.ConnectToNetwork(defaultNetwork),
rc.JobContainer.ConnectToNetwork(networkName),
rc.JobContainer.CopyDir(copyToPath, rc.Config.Workdir+string(filepath.Separator)+".").IfBool(copyWorkspace),
rc.JobContainer.Copy(filepath.Dir(rc.Config.Workdir), &container.FileEntry{
Name: "workflow/event.json",
Expand All @@ -184,17 +183,15 @@ func (rc *RunContext) startJobContainer() common.Executor {
}
}

const defaultNetwork = "act_github_actions_network"

func (rc *RunContext) createNetwork() common.Executor {
func (rc *RunContext) createNetwork(name string) common.Executor {
return func(ctx context.Context) error {
return container.NewDockerNetworkCreateExecutor(defaultNetwork)(ctx)
return container.NewDockerNetworkCreateExecutor(name)(ctx)
}
}

func (rc *RunContext) removeNetwork() common.Executor {
func (rc *RunContext) removeNetwork(name string) common.Executor {
return func(ctx context.Context) error {
return container.NewDockerNetworkRemoveExecutor(defaultNetwork)(ctx)
return container.NewDockerNetworkRemoveExecutor(name)(ctx)
}
}

Expand All @@ -215,15 +212,15 @@ func (rc *RunContext) stopJobContainer() common.Executor {
}
}

func (rc *RunContext) startServiceContainers() common.Executor {
func (rc *RunContext) startServiceContainers(networkName string) common.Executor {
return func(ctx context.Context) error {
execs := []common.Executor{}
for _, c := range rc.ServiceContainers {
execs = append(execs, common.NewPipelineExecutor(
c.Pull(false),
c.Create(),
c.Start(false),
c.ConnectToNetwork(defaultNetwork),
c.ConnectToNetwork(networkName),
))
}
return common.NewParallelExecutor(execs...)(ctx)
Expand Down
7 changes: 2 additions & 5 deletions pkg/runner/testdata/services/push.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: services

on:
push:

on: push
jobs:
services:
name: Reproduction of failing Services interpolation
Expand All @@ -26,4 +23,4 @@ jobs:
run: |
echo "id: ${{ job.services.postgres.id }}"
echo "network: ${{ job.services.postgres.network }}"
echo "ports: ${{ job.services.postgres.ports }}"
echo "ports: ${{ job.services.postgres.ports }}"