Skip to content

Commit

Permalink
try to invert --no-sock to be opt-in instead of opt-out
Browse files Browse the repository at this point in the history
  • Loading branch information
frantjc committed Dec 4, 2024
1 parent f1fffd9 commit d25d9fd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
# See https://cloud.google.com/build/docs/building/build-containers.
- name: Run forge cloudbuild docker
run: |
forge --no-sock cloudbuild gcr.io/cloud-builders/docker build testdata/actions/dockerfile
forge cloudbuild gcr.io/cloud-builders/docker build testdata/actions/dockerfile
- name: Run forge use remote
run: forge use frantjc/forge/testdata/actions/docker@${{ github.sha }}
env:
Expand Down Expand Up @@ -75,5 +75,5 @@ jobs:
run: forge put mock -v version=v0.0.0 -p version=v0.0.0
- name: Test forge.sock
run: |
forge cloudbuild gcr.io/cloud-builders/docker build testdata/actions/dockerfile
forge --use-sock cloudbuild gcr.io/cloud-builders/docker build testdata/actions/dockerfile
- run: forge cache --clean
6 changes: 3 additions & 3 deletions command/forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func NewForge() *cobra.Command {
Use: "forge",
Version: forge.SemVer(),
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
if !containerutil.NoForgeSock {
containerutil.NoForgeSock = cmd.Flag("no-dind").Changed
if !containerutil.UseForgeSock {
containerutil.UseForgeSock = !cmd.Flag("no-dind").Changed
}

return nil
Expand All @@ -30,7 +30,7 @@ func NewForge() *cobra.Command {

cmd.SetVersionTemplate("{{ .Name }}{{ .Version }} " + runtime.Version() + "\n")
cmd.PersistentFlags().CountVarP(&verbosity, "verbose", "V", "verbosity for forge")
cmd.PersistentFlags().BoolVar(&containerutil.NoForgeSock, "no-sock", false, "disable use of forge.sock")
cmd.PersistentFlags().BoolVar(&containerutil.UseForgeSock, "use-sock", false, "enable use of forge.sock")
cmd.PersistentFlags().Bool("no-dind", false, "disable Docker in Docker")
cmd.AddCommand(NewUse(), NewGet(), NewPut(), NewCheck(), NewTask(), NewCloudBuild(), NewCache())

Expand Down
10 changes: 5 additions & 5 deletions internal/containerutil/create_sleeping_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/frantjc/forge/internal/hooks"
)

var NoForgeSock bool
var UseForgeSock bool

type SleepingShimContainer struct {
forge.Container
Expand All @@ -21,10 +21,10 @@ func (c *SleepingShimContainer) Exec(ctx context.Context, cc *forge.ContainerCon
ccc := new(forge.ContainerConfig)
*ccc = *cc

if NoForgeSock {
ccc.Entrypoint = append([]string{bin.ShimPath, "exec", "--"}, ccc.Entrypoint...)
} else {
if UseForgeSock {
ccc.Entrypoint = append([]string{bin.ShimPath, "exec", fmt.Sprintf("--sock=%s", containerfs.ForgeSock), "--"}, ccc.Entrypoint...)
} else {
ccc.Entrypoint = append([]string{bin.ShimPath, "exec", "--"}, ccc.Entrypoint...)
}

return c.Container.Exec(ctx, ccc, s)
Expand All @@ -33,7 +33,7 @@ func (c *SleepingShimContainer) Exec(ctx context.Context, cc *forge.ContainerCon
func CreateSleepingContainer(ctx context.Context, containerRuntime forge.ContainerRuntime, image forge.Image, containerConfig *forge.ContainerConfig) (forge.Container, error) {
entrypoint := []string{bin.ShimPath, "sleep"}

if !NoForgeSock {
if UseForgeSock {
entrypoint = append(entrypoint,
fmt.Sprintf("--sock=%s", containerfs.ForgeSock),
)
Expand Down

0 comments on commit d25d9fd

Please sign in to comment.