mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-11 17:50:58 +00:00
initial load of yaml working
This commit is contained in:
parent
113ebda3ff
commit
fbab49c68d
28 changed files with 522 additions and 393 deletions
56
act/container/docker_pull.go
Normal file
56
act/container/docker_pull.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package container
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/nektos/act/pkg/common"
|
||||
)
|
||||
|
||||
// NewDockerPullExecutorInput the input for the NewDockerPullExecutor function
|
||||
type NewDockerPullExecutorInput struct {
|
||||
DockerExecutorInput
|
||||
Image string
|
||||
}
|
||||
|
||||
// NewDockerPullExecutor function to create a run executor for the container
|
||||
func NewDockerPullExecutor(input NewDockerPullExecutorInput) common.Executor {
|
||||
return func() error {
|
||||
input.Logger.Infof("docker pull %v", input.Image)
|
||||
|
||||
if input.Dryrun {
|
||||
return nil
|
||||
}
|
||||
|
||||
imageRef := cleanImage(input.Image)
|
||||
input.Logger.Debugf("pulling image '%v'", imageRef)
|
||||
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cli.NegotiateAPIVersion(input.Ctx)
|
||||
|
||||
reader, err := cli.ImagePull(input.Ctx, imageRef, types.ImagePullOptions{})
|
||||
_ = input.logDockerResponse(reader, err != nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func cleanImage(image string) string {
|
||||
imageParts := len(strings.Split(image, "/"))
|
||||
if imageParts == 1 {
|
||||
image = fmt.Sprintf("docker.io/library/%s", image)
|
||||
} else if imageParts == 2 {
|
||||
image = fmt.Sprintf("docker.io/%s", image)
|
||||
}
|
||||
|
||||
return image
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue