Skip to content

Commit

Permalink
FIXME: Temporary workaround to get ember dev server to pass exec thro…
Browse files Browse the repository at this point in the history
…ugh to 4646
  • Loading branch information
philrenaud committed Oct 6, 2023
1 parent 9952078 commit a1e439e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
1 change: 0 additions & 1 deletion api/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
14 changes: 13 additions & 1 deletion command/agent/alloc_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion command/agent/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13290,5 +13290,4 @@ type Action struct {
Name string
Command *string
Args []string
// Type *string
}
18 changes: 14 additions & 4 deletions ui/app/services/sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}` +
Expand Down
4 changes: 4 additions & 0 deletions ui/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a1e439e

Please sign in to comment.