Skip to content

Commit

Permalink
fix: docker database
Browse files Browse the repository at this point in the history
  • Loading branch information
Crispy-rw committed Jun 7, 2023
1 parent 40e7e01 commit 085705e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,4 @@ tags
.ipython/
.envs/*
!.envs/.local/
.db_data
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,23 @@ Start the Docker containers using Docker Compose:
docker-compose up
```

#### 4. Setup the initial database:

```sh
# You can run this from a 2nd terminal. It will create a production database
docker-compose exec backend flask db reset
```

This will start the backend, frontend, and database services defined in the `docker-compose.yml` file.

### 4. Access the Application
### 5. Access the Application

Once the containers are up and running, you can access the application in your web browser:

- Backend API: `http://localhost:5000/`
- Frontend: `http://localhost:5173/`

### 5. Stop the Containers
### 6. Stop the Containers

To stop the Docker containers, press `Ctrl + C` in the terminal where the containers are running.

Expand Down
3 changes: 2 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ RUN pip install --upgrade pip && pip install -r requirements.txt

COPY . /app

CMD /wait && flask db reset && flask run --host=0.0.0.0
# CMD /wait && flask db reset && flask run --host=0.0.0.0
CMD /wait && flask run --host=0.0.0.0
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ services:
image: mysql:5.7.22
container_name: database
restart: unless-stopped
volumes:
- .db_data:/var/lib/mysql
environment:
MYSQL_DATABASE: energize_swap_db
MYSQL_USER: root
Expand All @@ -48,3 +50,6 @@ services:
networks:
net1:
driver: bridge

volumes:
.db_data:
4 changes: 2 additions & 2 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ FROM node:16-alpine

WORKDIR /usr/src/app

COPY ./package.json ./
COPY ./yarn.lock ./
COPY ./package.json .
COPY ./yarn.lock .

RUN yarn install

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function App() {
return (
<BrowserRouter>
<Routes>
{userData() == null && <Route path="/login" element={<LoginPage />} />}
<Route path="/login" element={<LoginPage />} />
<Route path="/" element={<MainLayout role={userData()?.role} />}>
{routes}
</Route>
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/pages/Login/LoginPage.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect } from "react";
import Box from "@mui/material/Box";
import Tabs from "@mui/material/Tabs";
import Tab from "@mui/material/Tab";
Expand All @@ -8,6 +8,7 @@ import { toast } from "react-toastify"

import "./login.css";
import { BASE_URL } from "../../configs";
import userData from '../../configs/helpers'

function TabPanel(props) {
const { children, value, index, ...other } = props;
Expand Down Expand Up @@ -58,6 +59,12 @@ function LoginPage() {
const [value, setTab] = React.useState(0);
const [stations, setStations] = React.useState([]);

useEffect(()=>{
if(userData() != null){
window.location.replace("/");
}
},[])

const {
register,
handleSubmit,
Expand Down
1 change: 0 additions & 1 deletion frontend/src/routes/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const generateRoute = (routes) => {

const ProtectedRoute = ({ role, redirectPath = "/unauthorized", children }) => {
const userInfo = userData()
console.log("========", userInfo)
if (userInfo == null || role !== userInfo?.role) {
return <Navigate to={redirectPath} replace />;
}
Expand Down

0 comments on commit 085705e

Please sign in to comment.