From a1e439e4a62b54cc478766a4815eea682620d3f6 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Fri, 6 Oct 2023 09:57:52 -0400 Subject: [PATCH] FIXME: Temporary workaround to get ember dev server to pass exec through to 4646 --- api/tasks.go | 1 - command/agent/alloc_endpoint.go | 14 +++++++++++++- command/agent/job_endpoint.go | 1 - nomad/structs/structs.go | 1 - ui/app/services/sockets.js | 18 ++++++++++++++---- ui/config/environment.js | 4 ++++ 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/api/tasks.go b/api/tasks.go index d3707f8b7e7..eeae3906708 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -1174,5 +1174,4 @@ type Action struct { Name string `hcl:"name,label"` Command *string `mapstructure:"command" hcl:"command"` Args []string `mapstructure:"args" hcl:"args,optional"` - // Type *string `mapstructure:"type" hcl:"type,optional"` } diff --git a/command/agent/alloc_endpoint.go b/command/agent/alloc_endpoint.go index 6660227bf8d..3fb72772136 100644 --- a/command/agent/alloc_endpoint.go +++ b/command/agent/alloc_endpoint.go @@ -504,7 +504,19 @@ func (s *HTTPServer) allocExec(allocID string, resp http.ResponseWriter, req *ht } s.parse(resp, req, &args.QueryOptions.Region, &args.QueryOptions) - conn, err := s.wsUpgrader.Upgrade(resp, req, nil) + // conn, err := s.wsUpgrader.Upgrade(resp, req, nil) + // FIXME: this is an open checkOrigin here that allows :4200 to make requests to :4646, + // freeing local ember up from not having to proxy. + // This is like three workarounds in a trenchcoat and I dno't feel good about it but it unblocks me + + var upgrader = websocket.Upgrader{ + // Allow all origins + CheckOrigin: func(r *http.Request) bool { return true }, + } + + // Then when you upgrade the connection: + conn, err := upgrader.Upgrade(resp, req, nil) + if err != nil { return nil, fmt.Errorf("failed to upgrade connection: %v", err) } diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index 095bc55e28e..51adb7f7b85 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -1398,7 +1398,6 @@ func ApiActionToStructsAction(job *structs.Job, action *api.Action, act *structs act.Name = action.Name act.Args = action.Args act.Command = action.Command - // act.Type = action.Type } func ApiResourcesToStructs(in *api.Resources) *structs.Resources { diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 722b19ccaec..9fa81bb7d3f 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -13290,5 +13290,4 @@ type Action struct { Name string Command *string Args []string - // Type *string } diff --git a/ui/app/services/sockets.js b/ui/app/services/sockets.js index 3fcdd746346..307e54970e1 100644 --- a/ui/app/services/sockets.js +++ b/ui/app/services/sockets.js @@ -3,6 +3,7 @@ * SPDX-License-Identifier: BUSL-1.1 */ +// @ts-check import Service from '@ember/service'; import config from 'nomad-ui/config/environment'; import { getOwner } from '@ember/application'; @@ -35,12 +36,21 @@ export default class SocketsService extends Service { }, }); } else { + const shouldForward = config.APP.deproxyWebsockets; + const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; - const applicationAdapter = getOwner(this).lookup('adapter:application'); - const prefix = `${ - applicationAdapter.host || window.location.host - }/${applicationAdapter.urlPrefix()}`; + + // FIXME: Temporary, local ember implementation to get around websocket proxy issues duiring development. + let prefix; const region = this.system.activeRegion; + if (!shouldForward) { + const applicationAdapter = getOwner(this).lookup('adapter:application'); + prefix = `${ + applicationAdapter.host || window.location.host + }/${applicationAdapter.urlPrefix()}`; + } else { + prefix = 'localhost:4646/v1'; + } return new WebSocket( `${protocol}//${prefix}/client/allocation/${taskState.allocation.id}` + diff --git a/ui/config/environment.js b/ui/config/environment.js index 2be2e58ac5c..26e9e2fcc72 100644 --- a/ui/config/environment.js +++ b/ui/config/environment.js @@ -55,6 +55,10 @@ module.exports = function (environment) { // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; // ENV.APP.LOG_VIEW_LOOKUPS = true; + // FIXME: Temporary, local ember implementation + // to get around websocket proxy issues duiring development. + ENV.APP.deproxyWebsockets = true; + ENV['ember-cli-mirage'] = { enabled: USE_MIRAGE, excludeFilesFromBuild: !USE_MIRAGE,