Skip to content

Commit

Permalink
return error from docker build. Action workingdir. workingdir for Act…
Browse files Browse the repository at this point in the history
…ion attach
  • Loading branch information
frantjc committed Jan 16, 2024
1 parent 7deffd6 commit bfb86cd
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BIN = /usr/local/bin
GOOS = $(shell $(GO) env GOOS)
GOARCH = $(shell $(GO) env GOARCH)

SEMVER ?= 0.13.9
SEMVER ?= 0.13.10

.DEFAULT: install

Expand Down
12 changes: 5 additions & 7 deletions command/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"fmt"

"github.com/frantjc/forge"
"github.com/frantjc/forge/internal/containerfs"
"github.com/spf13/cobra"
)

func hookAttach(cmd *cobra.Command, stdoutUsed ...bool) func(context.Context, forge.Container) {
func hookAttach(cmd *cobra.Command, workingDir string, stdoutUsed ...bool) func(context.Context, forge.Container) {
return func(ctx context.Context, c forge.Container) {
var (
streams = commandStreams(cmd, stdoutUsed...)
Expand All @@ -22,20 +21,19 @@ func hookAttach(cmd *cobra.Command, stdoutUsed ...bool) func(context.Context, fo
return
}

_, err = c.Exec(
if _, err = c.Exec(
ctx,
&forge.ContainerConfig{
Entrypoint: []string{"bash"},
WorkingDir: containerfs.WorkingDir,
WorkingDir: workingDir,
},
streams,
)
if err != nil {
); err != nil {
_, _ = c.Exec(
ctx,
&forge.ContainerConfig{
Entrypoint: []string{"sh"},
WorkingDir: containerfs.WorkingDir,
WorkingDir: workingDir,
},
streams,
)
Expand Down
4 changes: 2 additions & 2 deletions command/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/frantjc/forge"
"github.com/frantjc/forge/concourse"
"github.com/frantjc/forge/forgeconcourse"
"github.com/frantjc/forge/internal/containerfs"
"github.com/frantjc/forge/internal/contaminate"
"github.com/frantjc/forge/internal/hooks"
"github.com/frantjc/forge/ore"
Expand All @@ -34,7 +35,6 @@ func newResource(method string) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
var (
ctx = cmd.Context()
_ = forge.LoggerFrom(ctx)
name = args[0]
pipeline = &concourse.Pipeline{}
file io.Reader
Expand Down Expand Up @@ -86,7 +86,7 @@ func newResource(method string) *cobra.Command {
}

if attach {
hooks.ContainerStarted.Listen(hookAttach(cmd))
hooks.ContainerStarted.Listen(hookAttach(cmd, containerfs.WorkingDir))
}

var o forge.Ore = cr
Expand Down
8 changes: 3 additions & 5 deletions command/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/docker/docker/client"
"github.com/frantjc/forge"
"github.com/frantjc/forge/forgeazure"
"github.com/frantjc/forge/internal/containerfs"
"github.com/frantjc/forge/internal/hooks"
"github.com/frantjc/forge/ore"
"github.com/frantjc/forge/runtime/docker"
Expand All @@ -26,18 +27,15 @@ func NewTask() *cobra.Command {
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
var (
ctx = cmd.Context()
_ = forge.LoggerFrom(ctx)
)
ctx := cmd.Context()

c, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return err
}

if attach {
hooks.ContainerStarted.Listen(hookAttach(cmd))
hooks.ContainerStarted.Listen(hookAttach(cmd, containerfs.WorkingDir))
}

t := &ore.Task{
Expand Down
9 changes: 3 additions & 6 deletions command/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ func NewUse() *cobra.Command {
SilenceErrors: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
var (
ctx = cmd.Context()
_ = forge.LoggerFrom(ctx)
)
ctx := cmd.Context()

globalContext, err := githubactions.NewGlobalContextFromPath(ctx, workdir)
globalContext, err := githubactions.NewGlobalContextFromPath(workdir)
if err != nil {
globalContext = githubactions.NewGlobalContextFromEnv()
}
Expand All @@ -60,7 +57,7 @@ func NewUse() *cobra.Command {
}

if attach {
hooks.ContainerStarted.Listen(hookAttach(cmd))
hooks.ContainerStarted.Listen(hookAttach(cmd, forgeactions.DefaultMapping.Workspace))
}

a := &ore.Action{
Expand Down
1 change: 1 addition & 0 deletions forgeactions/action_metadata_to_container_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (m *Mapping) ActionToConfigs(globalContext *githubactions.GlobalContext, us
Cmd: append([]string{s}, cmd...),
Env: env,
Mounts: mounts,
WorkingDir: m.Workspace,
})
}
}
Expand Down
5 changes: 1 addition & 4 deletions forgeactions/env_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ func SetGlobalContextFromEnvFiles(ctx context.Context, globalContext *githubacti
}

func (m *Mapping) SetGlobalContextFromEnvFiles(ctx context.Context, globalContext *githubactions.GlobalContext, step string, container forge.Container) error {
var (
_ = forge.LoggerFrom(ctx)
errs []error
)
var errs []error
globalContext = m.ConfigureGlobalContext(globalContext)

rc, err := container.CopyFrom(ctx, m.GitHubPath)
Expand Down
4 changes: 1 addition & 3 deletions githubactions/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strconv"
"strings"

"github.com/frantjc/forge"
"github.com/frantjc/forge/envconv"
xslice "github.com/frantjc/x/slice"
"github.com/go-git/go-git/v5"
Expand Down Expand Up @@ -380,9 +379,8 @@ const (
// NewGlobalContextFromEnv returns a *GlobalContext whose values
// are sourced from the git repository at the given path, the environment
// and some sensible defaults.
func NewGlobalContextFromPath(ctx context.Context, path string) (*GlobalContext, error) {
func NewGlobalContextFromPath(path string) (*GlobalContext, error) {
var (
_ = forge.LoggerFrom(ctx)
c = NewGlobalContextFromEnv()
currentBranch = DefaultBranch
currentRemote = DefaultRemote
Expand Down
2 changes: 0 additions & 2 deletions githubactions/download_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os"
"regexp"

"github.com/frantjc/forge"
xtar "github.com/frantjc/x/archive/tar"
"github.com/google/go-github/v50/github"
)
Expand All @@ -23,7 +22,6 @@ var ActionYAMLFilenames = []string{"action.yml", "action.yaml"}
// and a tarball of the GitHub Action repository.
func DownloadAction(ctx context.Context, u *Uses) (*Metadata, io.ReadCloser, error) {
var (
_ = forge.LoggerFrom(ctx)
client *github.Client
metadata *Metadata
)
Expand Down
Binary file modified internal/bin/shim_amd64
Binary file not shown.
Binary file modified internal/bin/shim_arm64
Binary file not shown.
5 changes: 1 addition & 4 deletions ore/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ type Cache struct {
}

func (o *Cache) Liquify(ctx context.Context, containerRuntime forge.ContainerRuntime, drains *forge.Drains) error {
var (
_ = forge.LoggerFrom(ctx)
cached = true
)
cached := true

d, err := digestutil.JSON(o.Ore)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions runtime/docker/build_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/frantjc/forge"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/daemon"
Expand Down Expand Up @@ -45,6 +46,14 @@ func (d *ContainerRuntime) BuildDockerfile(ctx context.Context, dir, reference s
return nil, err
}

if err := jsonmessage.DisplayJSONMessagesStream(ibr.Body, io.Discard, 0, false, nil); err != nil {
if jerr, ok := err.(*jsonmessage.JSONError); ok {
return nil, jerr
}

return nil, err
}

if _, err = io.Copy(io.Discard, ibr.Body); err != nil {
return nil, err
}
Expand Down
1 change: 0 additions & 1 deletion runtime/docker/container_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

func (c *Container) Exec(ctx context.Context, containerConfig *forge.ContainerConfig, streams *forge.Streams) (int, error) {
var (
_ = forge.LoggerFrom(ctx)
stdin io.Reader
stdout, stderr io.Writer
tty bool
Expand Down
1 change: 0 additions & 1 deletion runtime/docker/container_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

func (c *Container) Run(ctx context.Context, streams *forge.Streams) (int, error) {
var (
_ = forge.LoggerFrom(ctx)
stdin io.Reader
stdout, stderr io.Writer
detachKeys string
Expand Down
2 changes: 1 addition & 1 deletion testdata/actions/docker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ description: |
author: frantjc
runs:
using: docker
image: docker://alpine:3.15
image: docker://alpine:3.19
entrypoint: env
2 changes: 1 addition & 1 deletion testdata/actions/dockerfile/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM alpine:3.15
FROM alpine:3.19
RUN apk add curl
ENTRYPOINT ["curl"]
2 changes: 1 addition & 1 deletion testdata/actions/exit1/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ description: |
author: frantjc
runs:
using: docker
image: docker://alpine:3.15
image: docker://alpine:3.19
entrypoint: false
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
// VersionCore is the SemVer version core of forge.
// Meant to be be overridden at build time, but kept
// up-to-date sometimes to best support `go install`.
var VersionCore = "0.13.9"
var VersionCore = "0.13.10"

// SemVer returns the semantic version of forge as
// built from VersionCore and debug build info.
Expand Down

0 comments on commit bfb86cd

Please sign in to comment.