Skip to content

Commit

Permalink
env variable to use the host wireguard tunnel for remote builds
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldwan committed Jun 3, 2021
1 parent 601b987 commit bc585e6
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions internal/build/imgsrc/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,29 +185,36 @@ func newRemoteDockerClient(ctx context.Context, apiClient *api.Client, appName s
clientCh := make(chan *dockerclient.Client, 1)

eg.Go(func() error {
app, err := apiClient.GetApp(appName)
if err != nil {
return errors.Wrap(err, "error fetching target app")
opts := []dockerclient.Opt{
dockerclient.WithAPIVersionNegotiation(),
dockerclient.WithHost(host),
}

terminal.Debug("creating wireguard config for org ", app.Organization.Slug)
state, err := wireguard.StateForOrg(apiClient, &app.Organization, "", "")
if err != nil {
return errors.Wrap(err, "error creating wireguard config")
}
if os.Getenv("FLY_REMOTE_BUILDER_HOST_WG") == "" {
app, err := apiClient.GetApp(appName)
if err != nil {
return errors.Wrap(err, "error fetching target app")
}

terminal.Debugf("Establishing WireGuard connection (%s)\n", state.Name)
terminal.Debug("creating wireguard config for org ", app.Organization.Slug)
state, err := wireguard.StateForOrg(apiClient, &app.Organization, "", "")
if err != nil {
return errors.Wrap(err, "error creating wireguard config")
}

tunnel, err := wg.Connect(*state.TunnelConfig())
if err != nil {
return fmt.Errorf("connect wireguard: %w", err)
terminal.Debugf("Establishing WireGuard connection (%s)\n", state.Name)

tunnel, err := wg.Connect(*state.TunnelConfig())
if err != nil {
return fmt.Errorf("connect wireguard: %w", err)
}

opts = append(opts, dockerclient.WithDialContext(tunnel.DialContext))
} else {
terminal.Debug("connecting to remote docker daemon over host wireguard tunnel")
}

client, err := dockerclient.NewClientWithOpts(
dockerclient.WithDialContext(tunnel.DialContext),
dockerclient.WithAPIVersionNegotiation(),
dockerclient.WithHost(host),
)
client, err := dockerclient.NewClientWithOpts(opts...)
if err != nil {
return errors.Wrap(err, "Error creating docker client")
}
Expand Down

0 comments on commit bc585e6

Please sign in to comment.