Skip to content

Commit

Permalink
Remove ContainerMaxLifetime; fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
GuessWhoSamFoo committed Aug 7, 2023
1 parent 715ac6d commit a4792b3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/container/host_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (e *HostEnvironment) Create(_ []string, _ []string) common.Executor {
}
}

func (e *HostEnvironment) ConnectToNetwork(name string) common.Executor {
func (e *HostEnvironment) ConnectToNetwork(_ string) common.Executor {
return func(ctx context.Context) error {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/runner/job_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type jobInfo interface {
result(result string)
}

//nolint:contextcheck,gocyclo
func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executor {
steps := make([]common.Executor, 0)
preSteps := make([]common.Executor, 0)
Expand Down Expand Up @@ -87,7 +88,7 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo

postExec := useStepLogger(rc, stepModel, stepStagePost, step.post())
if postExecutor != nil {
// run the post exector in reverse order
// run the post executor in reverse order
postExecutor = postExec.Finally(postExecutor)
} else {
postExecutor = postExec
Expand All @@ -101,7 +102,6 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo
// always allow 1 min for stopping and removing the runner, even if we were cancelled
ctx, cancel := context.WithTimeout(common.WithLogger(context.Background(), common.Logger(ctx)), time.Minute)
defer cancel()
err = info.stopContainer()(ctx) //nolint:contextcheck

logger := common.Logger(ctx)
logger.Infof("Cleaning up services for job %s", rc.JobName)
Expand Down
16 changes: 7 additions & 9 deletions pkg/runner/run_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ import (
"regexp"
"runtime"
"strings"
"time"

"github.com/opencontainers/selinux/go-selinux"

"github.com/nektos/act/pkg/common"
"github.com/nektos/act/pkg/container"
"github.com/nektos/act/pkg/exprparser"
"github.com/nektos/act/pkg/model"
"github.com/opencontainers/selinux/go-selinux"
)

// RunContext contains info about current job
Expand Down Expand Up @@ -276,7 +274,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
}

// add service containers
for serviceId, spec := range rc.Run.Job().Services {
for serviceID, spec := range rc.Run.Job().Services {
// interpolate env
interpolatedEnvs := make(map[string]string, len(spec.Env))
for k, v := range spec.Env {
Expand All @@ -288,10 +286,10 @@ func (rc *RunContext) startJobContainer() common.Executor {
}
username, password, err = rc.handleServiceCredentials(ctx, spec.Credentials)
if err != nil {
return fmt.Errorf("failed to handle service %s credentials: %w", serviceId, err)
return fmt.Errorf("failed to handle service %s credentials: %w", serviceID, err)
}
serviceBinds, serviceMounts := rc.GetServiceBindsAndMounts(spec.Volumes)
serviceContainerName := createContainerName(rc.jobContainerName(), serviceId)
serviceContainerName := createContainerName(rc.jobContainerName(), serviceID)
c := container.NewContainer(&container.NewContainerInput{
Name: serviceContainerName,
WorkingDir: ext.ToContainerPath(rc.Config.Workdir),
Expand All @@ -308,7 +306,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
Platform: rc.Config.ContainerArchitecture,
Options: spec.Options,
NetworkMode: networkName,
NetworkAliases: []string{serviceId},
NetworkAliases: []string{serviceID},
ValidVolumes: rc.Config.ValidVolumes,
})
rc.ServiceContainers = append(rc.ServiceContainers, c)
Expand All @@ -325,7 +323,7 @@ func (rc *RunContext) startJobContainer() common.Executor {

rc.JobContainer = container.NewContainer(&container.NewContainerInput{
Cmd: nil,
Entrypoint: []string{"/bin/sleep", fmt.Sprint(rc.Config.ContainerMaxLifetime.Round(time.Second).Seconds())},
Entrypoint: []string{"/usr/bin/tail", "-f", "/dev/null"},
WorkingDir: ext.ToContainerPath(rc.Config.Workdir),
Image: image,
Username: username,
Expand Down Expand Up @@ -460,7 +458,7 @@ func (rc *RunContext) pullServicesImages(forcePull bool) common.Executor {
}
}

func (rc *RunContext) startServiceContainers(networkName string) common.Executor {
func (rc *RunContext) startServiceContainers(_ string) common.Executor {
return func(ctx context.Context) error {
execs := []common.Executor{}
for _, c := range rc.ServiceContainers {
Expand Down
5 changes: 1 addition & 4 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import (
"fmt"
"os"
"runtime"
"time"

log "github.com/sirupsen/logrus"

docker_container "github.com/docker/docker/api/types/container"
"github.com/nektos/act/pkg/common"
"github.com/nektos/act/pkg/model"
log "github.com/sirupsen/logrus"
)

// Runner provides capabilities to run GitHub actions
Expand Down Expand Up @@ -60,7 +58,6 @@ type Config struct {
ReplaceGheActionWithGithubCom []string // Use actions from GitHub Enterprise instance to GitHub
ReplaceGheActionTokenWithGithubCom string // Token of private action repo on GitHub.
Matrix map[string]map[string]bool // Matrix config to run
ContainerMaxLifetime time.Duration // the max lifetime of job containers
ContainerNetworkMode docker_container.NetworkMode // the network mode of job containers (the value of --network)
ValidVolumes []string // only volumes (and bind mounts) in this slice can be mounted on the job container or service containers
}
Expand Down

0 comments on commit a4792b3

Please sign in to comment.