Allow server to run without a Dokku connection.

This commit is contained in:
James Murdza 2024-08-01 09:29:42 -07:00
parent 2eb2c4c39b
commit aac602d9db

View File

@ -114,22 +114,24 @@ io.use(async (socket, next) => {
const lockManager = new LockManager(); const lockManager = new LockManager();
if (!process.env.DOKKU_HOST) throw new Error('Environment variable DOKKU_HOST is not defined'); if (!process.env.DOKKU_HOST) console.error('Environment variable DOKKU_HOST is not defined');
if (!process.env.DOKKU_USERNAME) throw new Error('Environment variable DOKKU_USERNAME is not defined'); if (!process.env.DOKKU_USERNAME) console.error('Environment variable DOKKU_USERNAME is not defined');
if (!process.env.DOKKU_KEY) throw new Error('Environment variable DOKKU_KEY is not defined'); if (!process.env.DOKKU_KEY) console.error('Environment variable DOKKU_KEY is not defined');
const client = new DokkuClient({ const client =
host: process.env.DOKKU_HOST, process.env.DOKKU_HOST && process.env.DOKKU_KEY && process.env.DOKKU_USERNAME
username: process.env.DOKKU_USERNAME, ? new DokkuClient({
privateKey: fs.readFileSync(process.env.DOKKU_KEY), host: process.env.DOKKU_HOST,
}); username: process.env.DOKKU_USERNAME,
privateKey: fs.readFileSync(process.env.DOKKU_KEY),
})
: null;
client?.connect();
client.connect(); const git = process.env.DOKKU_KEY ? new SecureGitClient(
const git = new SecureGitClient(
"dokku@gitwit.app", "dokku@gitwit.app",
process.env.DOKKU_KEY process.env.DOKKU_KEY
) ) : null;
io.on("connection", async (socket) => { io.on("connection", async (socket) => {
try { try {
@ -280,6 +282,7 @@ io.on("connection", async (socket) => {
async (callback: (response: CallbackResponse) => void) => { async (callback: (response: CallbackResponse) => void) => {
console.log("Retrieving apps list..."); console.log("Retrieving apps list...");
try { try {
if (!client) throw Error("Failed to retrieve apps list: No Dokku client")
callback({ callback({
success: true, success: true,
apps: await client.listApps() apps: await client.listApps()
@ -299,6 +302,7 @@ io.on("connection", async (socket) => {
try { try {
// Push the project files to the Dokku server // Push the project files to the Dokku server
console.log("Deploying project ${data.sandboxId}..."); console.log("Deploying project ${data.sandboxId}...");
if (!git) throw Error("Failed to retrieve apps list: No git client")
// Remove the /project/[id]/ component of each file path: // Remove the /project/[id]/ component of each file path:
const fixedFilePaths = sandboxFiles.fileData.map((file) => { const fixedFilePaths = sandboxFiles.fileData.map((file) => {
return { return {