Skip to content

Commit

Permalink
Merge pull request #186 from fyne-io/features/no-network
Browse files Browse the repository at this point in the history
Add ability to disable network in the container while building.
  • Loading branch information
Bluebugs committed Apr 15, 2023
2 parents 4fbae90 + ae38391 commit 7070259
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/command/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Context struct {
Pull bool // Pull if true attempts to pull a newer version of the docker image
NoProjectUpload bool // NoProjectUpload if true, the build will be done with the artifact already stored on S3
NoResultDownload bool // NoResultDownload if true, the result of the build will be left on S3 and not downloaded locally
NoNetwork bool // NoNetwork if true, the build will be done without network access

//Build context
BuildMode string // The -buildmode argument to pass to go build
Expand Down Expand Up @@ -142,6 +143,7 @@ func makeDefaultContext(flags *CommonFlags, args []string) (Context, error) {
Name: flags.Name,
StripDebug: !flags.NoStripDebug,
Debug: flags.Debug,
NoNetwork: flags.NoNetwork,
Volume: vol,
Pull: flags.Pull,
Release: flags.Release,
Expand Down
6 changes: 6 additions & 0 deletions internal/command/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type localContainerEngine struct {

pull bool
cacheEnabled bool
noNetwork bool
}

func newLocalContainerEngine(context Context) (containerEngine, error) {
Expand All @@ -39,6 +40,7 @@ func newLocalContainerEngine(context Context) (containerEngine, error) {
engine: &context.Engine,
pull: context.Pull,
cacheEnabled: context.CacheEnabled,
noNetwork: context.NoNetwork,
}, nil
}

Expand Down Expand Up @@ -151,6 +153,10 @@ func (i *localContainerImage) cmd(vol volume.Volume, opts options, cmdArgs []str
"-e", fmt.Sprintf("GOCACHE=%s", vol.GoCacheDirContainer()), // mount GOCACHE to reuse cache between builds
)

if i.runner.noNetwork {
args = append(args, "--network=none")
}

// add custom env variables
args = AppendEnv(args, i.runner.env, i.env["GOOS"] != freebsdOS)
args = AppendEnv(args, i.env, i.env["GOOS"] != freebsdOS)
Expand Down
3 changes: 3 additions & 0 deletions internal/command/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type CommonFlags struct {
NoResultDownload bool
// NoStripDebug if true will not strip debug information from binaries
NoStripDebug bool
// NoNetwork if true will not setup network inside the container
NoNetwork bool
// Name represents the application name
Name string
// Release represents if the package should be prepared for release (disable debug etc)
Expand Down Expand Up @@ -133,6 +135,7 @@ func newCommonFlags() (*CommonFlags, error) {
flagSet.BoolVar(&flags.Debug, "debug", false, "Debug mode")
flagSet.BoolVar(&flags.Pull, "pull", false, "Attempt to pull a newer version of the docker image")
flagSet.StringVar(&flags.DockerRegistry, "docker-registry", "docker.io", "The docker registry to be used instead of dockerhub (only used with defualt docker images)")
flagSet.BoolVar(&flags.NoNetwork, "no-network", false, "If set, the build will be done without network access")
return flags, nil
}

Expand Down

0 comments on commit 7070259

Please sign in to comment.