Skip to content

Commit 003f338

Browse files
ready for stage 1 deploy
1 parent 7cf96da commit 003f338

File tree

8 files changed

+590
-439
lines changed

8 files changed

+590
-439
lines changed

.github/workflows/deploy.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ jobs:
3939
push: true
4040
tags: anujakalahara99/ws-server:latest
4141

42+
- name: Build & Push Version Engine Producer
43+
uses: docker/build-push-action@v5
44+
with:
45+
context: ./Version_Engine/producer
46+
push: true
47+
tags: anujakalahara99/version-engine-producer:latest
48+
49+
- name: Build & Push Version Engine Worker
50+
uses: docker/build-push-action@v5
51+
with:
52+
context: ./Version_Engine/worker-git
53+
push: true
54+
tags: anujakalahara99/version-engine-worker:latest
55+
4256
deploy:
4357
runs-on: ubuntu-latest
4458
needs: build
@@ -54,3 +68,25 @@ jobs:
5468
cd /home/${{ secrets.SERVER_USER }}/app
5569
sudo docker compose pull
5670
sudo docker compose up -d --remove-orphans
71+
72+
deploy-version-engine:
73+
runs-on: ubuntu-latest
74+
needs: build
75+
76+
steps:
77+
- name: Checkout code for compose file
78+
uses: actions/checkout@v4
79+
with:
80+
sparse-checkout: |
81+
app/compose.yaml
82+
83+
- name: Start Version Engine services
84+
uses: appleboy/ssh-action@v1.0.0
85+
with:
86+
host: ${{ secrets.VERSION_ENGINE_HOST }}
87+
username: ${{ secrets.VERSION_ENGINE_USER }}
88+
key: ${{ secrets.VERSION_ENGINE_SSH_KEY }}
89+
script: |
90+
cd /home/${{ secrets.VERSION_ENGINE_USER }}/app
91+
sudo docker compose pull
92+
sudo docker compose up -d --remove-orphans

API_Gateway/src/routes.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,25 @@ const ROUTES = [
7373
},
7474
},
7575
},
76+
{
77+
url: "/versioning",
78+
auth: true,
79+
creditCheck: false,
80+
rateLimit: {
81+
windowMs: 60 * 1000,
82+
limit: 1000,
83+
},
84+
proxy: {
85+
target:
86+
process.env.NODE_ENV === "production"
87+
? "http://144.24.150.8:6000/versioning"
88+
: "http://192.168.56.82:6000/versioning",
89+
changeOrigin: true,
90+
pathRewrite: {
91+
[`^/versioning`]: "",
92+
},
93+
},
94+
},
7695
];
7796

7897
export default ROUTES;

Frontend/src/App/CodeEditor/GitPanel/CommitForm.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { useState } from "react";
22
import { useTheme } from "../../../Contexts/ThemeProvider";
3-
import { Send } from "lucide-react";
3+
import { Send, Loader2 } from "lucide-react";
4+
import { useEditorCollaboration } from "../../../Contexts/EditorContext";
45

5-
interface CommitFormProps {
6-
onCommit: (message: string) => void;
7-
}
8-
9-
const CommitForm = ({ onCommit }: CommitFormProps) => {
6+
const CommitForm = () => {
107
const { theme } = useTheme();
8+
const { commitChanges, gitOperationLoading } = useEditorCollaboration();
119
const [message, setMessage] = useState("");
1210

13-
const handleSubmit = (e: React.FormEvent) => {
11+
const handleSubmit = async (e: React.FormEvent) => {
1412
e.preventDefault();
1513
if (message.trim()) {
16-
onCommit(message);
17-
setMessage("");
14+
const success = await commitChanges(message);
15+
if (success) {
16+
setMessage("");
17+
}
1818
}
1919
};
2020

@@ -27,14 +27,19 @@ const CommitForm = ({ onCommit }: CommitFormProps) => {
2727
placeholder="Commit message..."
2828
className={`w-full px-3 py-2 text-sm ${theme.surface} ${theme.border} border ${theme.text} focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none min-h-[60px] mb-2`}
2929
required
30+
disabled={gitOperationLoading}
3031
/>
3132
<button
3233
type="submit"
33-
disabled={!message.trim()}
34+
disabled={!message.trim() || gitOperationLoading}
3435
className={`flex items-center justify-center px-4 py-2 text-sm font-medium text-white bg-blue-500 rounded-md hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors disabled:opacity-50 disabled:cursor-not-allowed`}
3536
>
36-
<Send className="w-4 h-4 mr-2" />
37-
Commit Changes
37+
{gitOperationLoading ? (
38+
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
39+
) : (
40+
<Send className="w-4 h-4 mr-2" />
41+
)}
42+
{gitOperationLoading ? "Committing..." : "Commit Changes"}
3843
</button>
3944
</form>
4045
</div>

Frontend/src/App/CodeEditor/GitPanel/CommitHistory.tsx

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import { useEditorCollaboration } from "../../../Contexts/EditorContext";
21
import { useTheme } from "../../../Contexts/ThemeProvider";
3-
import { RotateCcw, GitCommit, Clock } from "lucide-react";
2+
import { RotateCcw, GitCommit, Clock, Loader2 } from "lucide-react";
43
import type { Commit } from "../../Dashboard/codespace.types";
54
import { formatDateTime } from "../../../utility/utility";
5+
import { useEditorCollaboration } from "../../../Contexts/EditorContext";
66

77
const CommitHistory = () => {
88
const { theme } = useTheme();
9-
const { codespace, activeSessionIndex } = useEditorCollaboration();
9+
const {
10+
codespace,
11+
activeSessionIndex,
12+
rollbackToCommit,
13+
gitOperationLoading,
14+
} = useEditorCollaboration();
1015
const commits = codespace?.sessions?.[activeSessionIndex]?.commits || [];
1116

1217
if (commits.length === 0) {
@@ -17,19 +22,37 @@ const CommitHistory = () => {
1722
);
1823
}
1924

20-
const onRollback = (commitId: string) => {
21-
// Implement rollback logic here
22-
console.log("Rollback to commit:", commitId);
25+
const handleRollback = async (commitHash: string) => {
26+
if (gitOperationLoading) return; // Prevent multiple operations
27+
28+
const success = await rollbackToCommit(commitHash);
29+
if (success) {
30+
console.log("Successfully rolled back to commit:", commitHash);
31+
// You might want to refresh the UI or show a success message
32+
}
2333
};
2434

2535
return (
2636
<div className="flex-grow overflow-auto">
2737
<h3 className={`text-sm font-medium mb-2 ${theme.text}`}>
2838
Commit History
2939
</h3>
40+
{gitOperationLoading && (
41+
<div
42+
className={`flex items-center justify-center p-2 text-xs ${theme.textMuted}`}
43+
>
44+
<Loader2 className="w-3 h-3 mr-2 animate-spin" />
45+
Operation in progress...
46+
</div>
47+
)}
3048
<ul className={`space-y-2`}>
3149
{commits.map((commit) => (
32-
<CommitItem key={commit.id} commit={commit} onRollback={onRollback} />
50+
<CommitItem
51+
key={commit.id}
52+
commit={commit}
53+
onRollback={handleRollback}
54+
isLoading={gitOperationLoading}
55+
/>
3356
))}
3457
</ul>
3558
</div>
@@ -38,28 +61,16 @@ const CommitHistory = () => {
3861

3962
interface CommitItemProps {
4063
commit: Commit;
41-
onRollback: (commitId: string) => void;
64+
onRollback: (commitHash: string) => void;
65+
isLoading: boolean;
4266
}
4367

44-
const CommitItem = ({ commit, onRollback }: CommitItemProps) => {
68+
const CommitItem = ({ commit, onRollback, isLoading }: CommitItemProps) => {
4569
const { theme } = useTheme();
4670

47-
// Format date to a more readable format
48-
// const formattedDate = new Date(commit.createdAt).toLocaleDateString(
49-
// undefined,
50-
// {
51-
// day: "2-digit",
52-
// month: "short",
53-
// year: "numeric",
54-
// hour: "2-digit",
55-
// minute: "2-digit",
56-
// }
57-
// );
58-
5971
return (
6072
<li
6173
className={`relative p-2 rounded-md ${
62-
// commit.isCurrent
6374
commit.id === "current"
6475
? `${theme.active} border-l-4 border-blue-500`
6576
: `${theme.surface} ${theme.hover}`
@@ -84,14 +95,24 @@ const CommitItem = ({ commit, onRollback }: CommitItemProps) => {
8495
</span>
8596
</div>
8697

87-
{/* Rollback button - only show for past commits */}
8898
{
8999
<button
90-
onClick={() => onRollback(commit.id)}
91-
className={`absolute top-2 right-2 p-1 rounded-full ${theme.hover} text-gray-500 hover:text-blue-500`}
92-
title="Rollback to this commit"
100+
onClick={() => onRollback(commit.commitHash)}
101+
disabled={isLoading}
102+
className={`absolute top-2 right-2 p-1 rounded-full ${theme.hover} ${
103+
isLoading
104+
? "opacity-50 cursor-not-allowed"
105+
: "text-gray-500 hover:text-blue-500"
106+
}`}
107+
title={
108+
isLoading ? "Operation in progress" : "Rollback to this commit"
109+
}
93110
>
94-
<RotateCcw className="w-4 h-4" />
111+
{isLoading ? (
112+
<Loader2 className="w-4 h-4 animate-spin" />
113+
) : (
114+
<RotateCcw className="w-4 h-4" />
115+
)}
95116
</button>
96117
}
97118
</li>

Frontend/src/App/CodeEditor/GitPanel/GitPanel.tsx

Lines changed: 20 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@ import { useState, useEffect } from "react";
22
import { useTheme } from "../../../Contexts/ThemeProvider";
33
import BranchSelector from "./BranchSelector";
44
import CommitHistory from "./CommitHistory";
5-
import CommitTree from "./CommitTree";
5+
// import CommitTree from "./CommitTree";
66
import CommitForm from "./CommitForm";
77
import type { GitState } from "./GitTypes";
8-
import {
9-
fetchBranches,
10-
fetchCommits,
11-
switchBranch,
12-
createCommit,
13-
rollbackToCommit,
14-
} from "./gitOperations";
8+
import { fetchBranches, fetchCommits } from "./gitOperations";
159

1610
const GitPanel = () => {
1711
const { theme } = useTheme();
@@ -64,74 +58,21 @@ const GitPanel = () => {
6458
}, []);
6559

6660
// Handle branch selection
67-
const handleBranchSelect = async (branchName: string) => {
68-
try {
69-
setIsLoading(true);
70-
setError(null);
71-
72-
// Switch branch and get updated state
73-
const updatedState = await switchBranch(branchName);
74-
setGitState(updatedState);
75-
} catch (err) {
76-
setError(`Failed to switch to branch: ${branchName}`);
77-
console.error(err);
78-
} finally {
79-
setIsLoading(false);
80-
}
81-
};
82-
83-
// Handle commit creation
84-
const handleCommit = async (message: string) => {
85-
try {
86-
setIsLoading(true);
87-
setError(null);
88-
89-
// Create new commit
90-
const newCommit = await createCommit(message);
91-
92-
// Update commits - mark current as not current
93-
const updatedCommits = gitState.commits.map((commit) => ({
94-
...commit,
95-
isCurrent: false,
96-
}));
97-
98-
// Add new commit
99-
updatedCommits.push(newCommit);
100-
101-
// Update state
102-
setGitState({
103-
...gitState,
104-
commits: updatedCommits,
105-
});
106-
} catch (err) {
107-
setError("Failed to create commit");
108-
console.error(err);
109-
} finally {
110-
setIsLoading(false);
111-
}
112-
};
113-
114-
// Handle rollback to a specific commit
115-
const handleRollback = async (commitId: string) => {
116-
try {
117-
setIsLoading(true);
118-
setError(null);
119-
120-
// Rollback to commit
121-
const updatedCommits = await rollbackToCommit(commitId);
122-
123-
// Update state
124-
setGitState({
125-
...gitState,
126-
commits: updatedCommits,
127-
});
128-
} catch (err) {
129-
setError(`Failed to rollback to commit: ${commitId}`);
130-
console.error(err);
131-
} finally {
132-
setIsLoading(false);
133-
}
134-
};
61+
// const handleBranchSelect = async (branchName: string) => {
62+
// try {
63+
// setIsLoading(true);
64+
// setError(null);
65+
66+
// // Switch branch and get updated state
67+
// const updatedState = await switchBranch(branchName);
68+
// setGitState(updatedState);
69+
// } catch (err) {
70+
// setError(`Failed to switch to branch: ${branchName}`);
71+
// console.error(err);
72+
// } finally {
73+
// setIsLoading(false);
74+
// }
75+
// };
13576

13677
return (
13778
<div className={`h-full flex flex-col ${theme.surface} ${theme.text}`}>
@@ -183,15 +124,15 @@ const GitPanel = () => {
183124
{!isLoading && gitState.commits.length > 0 && (
184125
<>
185126
<CommitHistory
186-
commits={gitState.commits}
187-
onRollback={handleRollback}
127+
// commits={gitState.commits}
128+
// onRollback={handleRollback}
188129
/>
189130
</>
190131
)}
191132
</div>
192133

193134
<div className="p-4">
194-
<CommitForm onCommit={handleCommit} />
135+
<CommitForm />
195136
</div>
196137
</div>
197138
);

0 commit comments

Comments
 (0)