Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip #1

Merged
merged 27 commits into from
Nov 11, 2023
Prev Previous commit
Next Next commit
Fix composerize
  • Loading branch information
louislam committed Nov 11, 2023
commit 83d58cd363011e01069e44b64faff314bdcae00a
22 changes: 22 additions & 0 deletions backend/socket-handlers/docker-socket-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { DockgeServer } from "../dockge-server";
import { callbackError, checkLogin, DockgeSocket, ValidationError } from "../util-server";
import { Stack } from "../stack";

// @ts-ignore
import composerize from "composerize";

export class DockerSocketHandler extends SocketHandler {
create(socket : DockgeSocket, server : DockgeServer) {

Expand Down Expand Up @@ -217,6 +220,25 @@ export class DockerSocketHandler extends SocketHandler {
callbackError(e, callback);
}
});

// composerize
socket.on("composerize", async (dockerRunCommand : unknown, callback) => {
try {
checkLogin(socket);

if (typeof(dockerRunCommand) !== "string") {
throw new ValidationError("dockerRunCommand must be a string");
}

const composeTemplate = composerize(dockerRunCommand);
callback({
ok: true,
composeTemplate,
});
} catch (e) {
callbackError(e, callback);
}
});
}

saveStack(socket : DockgeSocket, server : DockgeServer, name : unknown, composeYAML : unknown, isAdd : unknown) : Stack {
Expand Down
22 changes: 13 additions & 9 deletions frontend/src/pages/DashboardHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
</template>

<script>
import * as convertDockerRunToCompose from "composerize";
import { statusNameShort } from "../../../backend/util-common";

export default {
Expand Down Expand Up @@ -112,15 +111,20 @@ export default {
},

convertDockerRun() {
try {
if (this.dockerRunCommand.trim() === "docker run") {
throw new Error("Please enter a docker run command");
}
this.$root.composeTemplate = convertDockerRunToCompose(this.dockerRunCommand);
this.$router.push("/compose");
} catch (e) {
this.$root.toastError(e.message);
if (this.dockerRunCommand.trim() === "docker run") {
throw new Error("Please enter a docker run command");
}

// composerize is working in dev, but after "vite build", it is not working
// So pass to backend to do the conversion
this.$root.getSocket().emit("composerize", this.dockerRunCommand, (res) => {
if (res.ok) {
this.$root.composeTemplate = res.composeTemplate;
this.$router.push("/compose");
} else {
this.$root.toastRes(res);
}
});
},

/**
Expand Down