File tree Expand file tree Collapse file tree 15 files changed +188
-19
lines changed Expand file tree Collapse file tree 15 files changed +188
-19
lines changed Original file line number Diff line number Diff line change @@ -28,3 +28,20 @@ MaximumメンバーがWeb研究部の活動として、Twitterのようなマイ
28
28
3 . ` cp .env.example .env ` で.envファイルを作成
29
29
4 . ` .env ` ファイルを自分の好きな名前やパスワードに書き換え
30
30
5 . ` ./scripts/setup.sh ` でビルドしてコンテナを起動する
31
+
32
+ ### 停止
33
+
34
+ ` ./scripts/stop.sh ` でコンテナを停止する
35
+
36
+ ### 再開
37
+
38
+ ` ./scripts/start.sh ` でコンテナを再開する
39
+
40
+ ### DBデータの削除
41
+
42
+ ` ./scripts/reset-db.sh ` でDBデータを削除する
43
+
44
+ ### デプロイ
45
+
46
+ ` ./scripts/deploy.sh ` で本番環境にデプロイする
47
+ (マイグレーションなど特別なオペレーションが必要な場合もある)
Original file line number Diff line number Diff line change @@ -18,7 +18,8 @@ type Handler struct {
18
18
}
19
19
20
20
var (
21
- SQL_PATH = "./sql"
21
+ SQL_PATH = "./sql"
22
+ IMAGES_DIR = "./public/images"
22
23
)
23
24
24
25
func getEnv (key , fallback string ) string {
@@ -98,7 +99,7 @@ type Post struct {
98
99
99
100
func (h * Handler ) GetPosts (c echo.Context ) error {
100
101
posts := []Post {}
101
- err := h .DB .Select (& posts , "SELECT * FROM posts" )
102
+ err := h .DB .Select (& posts , "SELECT * FROM posts ORDER BY created_at DESC LIMIT 20 " )
102
103
if err != nil {
103
104
h .Logger .Error (err )
104
105
return c .JSON (500 , err )
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ services:
7
7
volumes :
8
8
- ./etc/nginx/prod/conf.d:/etc/nginx/conf.d
9
9
- ./frontend/dist:/var/www/html
10
+ - ./backend/public:/var/www/public
10
11
depends_on :
11
12
- backend
12
13
@@ -36,6 +37,8 @@ services:
36
37
- MYSQL_DATABASE=${MYSQL_DATABASE}
37
38
- MYSQL_USER=${MYSQL_USER}
38
39
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
40
+ volumes :
41
+ - ./backend/public:/app/public
39
42
depends_on :
40
43
database :
41
44
condition : service_healthy
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ services:
6
6
- 80:80
7
7
volumes :
8
8
- ./etc/nginx/dev/conf.d:/etc/nginx/conf.d
9
+ - ./backend/public:/var/www/public
9
10
depends_on :
10
11
- backend
11
12
- frontend
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ server {
10
10
proxy_set_header Host $host;
11
11
}
12
12
13
+ location /images {
14
+ alias /var/www/public/images;
15
+ }
16
+
13
17
location /api {
14
18
proxy_pass http://backend:8000;
15
19
proxy_http_version 1.1;
Original file line number Diff line number Diff line change @@ -8,6 +8,10 @@ server {
8
8
try_files $uri $uri/ /index.html;
9
9
}
10
10
11
+ location /images {
12
+ alias /var/www/public/images;
13
+ }
14
+
11
15
location /api {
12
16
proxy_pass http://backend:8000;
13
17
proxy_http_version 1.1;
Original file line number Diff line number Diff line change 1
- import { Container } from "@mui/material" ;
1
+ import { Container , CssBaseline } from "@mui/material" ;
2
2
import { GlobalStyles } from "@mui/material" ;
3
3
import { Form } from "./components/Form" ;
4
4
import { Timeline } from "./components/Timeline" ;
5
5
import { useEffect , useState } from "react" ;
6
+ import { ColorModeProvider } from "./components/theme/ColorModeProvider.jsx" ;
7
+ import { ToggleTheme } from "./components/theme/ToggleTheme.jsx" ;
6
8
7
9
function App ( ) {
8
10
const [ posts , setPosts ] = useState ( [ ] ) ;
@@ -29,22 +31,30 @@ function App() {
29
31
30
32
return (
31
33
< >
32
- < GlobalStyles
33
- styles = { {
34
- body : {
35
- margin : 0 ,
36
- } ,
37
- } }
38
- />
39
- < Container
40
- maxWidth = "md"
41
- sx = { {
42
- py : 3 ,
43
- } }
44
- >
45
- < Form onSubmitted = { onSubmitted } />
46
- < Timeline posts = { posts } isLoading = { isLoading } fetchPosts = { fetchPosts } />
47
- </ Container >
34
+ < ColorModeProvider >
35
+ < CssBaseline />
36
+ < ToggleTheme />
37
+ < GlobalStyles
38
+ styles = { {
39
+ body : {
40
+ margin : 0 ,
41
+ } ,
42
+ } }
43
+ />
44
+ < Container
45
+ maxWidth = "md"
46
+ sx = { {
47
+ py : 3 ,
48
+ } }
49
+ >
50
+ < Form onSubmitted = { onSubmitted } />
51
+ < Timeline
52
+ posts = { posts }
53
+ isLoading = { isLoading }
54
+ fetchPosts = { fetchPosts }
55
+ />
56
+ </ Container >
57
+ </ ColorModeProvider >
48
58
</ >
49
59
) ;
50
60
}
Original file line number Diff line number Diff line change
1
+ import { createContext } from "react" ;
2
+
3
+ export const ColorModeContext = createContext ( { toggleColorMode : ( ) => { } } ) ;
Original file line number Diff line number Diff line change
1
+ import { ThemeProvider , createTheme } from "@mui/material/styles" ;
2
+ import { useMemo , useState , useEffect } from "react" ;
3
+ import { ColorModeContext } from "./ColorModeContext" ;
4
+
5
+ export const ColorModeProvider = ( { children } ) => {
6
+ const [ mode , setMode ] = useState ( ( ) => {
7
+ const storedMode = localStorage . getItem ( "colorMode" ) ;
8
+ return storedMode !== null ? storedMode : "light" ;
9
+ } ) ;
10
+
11
+ useEffect ( ( ) => {
12
+ localStorage . setItem ( "colorMode" , mode ) ;
13
+ } , [ mode ] ) ;
14
+
15
+ const colorMode = useMemo (
16
+ ( ) => ( {
17
+ toggleColorMode : ( ) => {
18
+ setMode ( ( prevMode ) => ( prevMode === "light" ? "dark" : "light" ) ) ;
19
+ } ,
20
+ } ) ,
21
+ [ ]
22
+ ) ;
23
+
24
+ const theme = useMemo (
25
+ ( ) =>
26
+ createTheme ( {
27
+ palette : {
28
+ mode,
29
+ } ,
30
+ } ) ,
31
+ [ mode ]
32
+ ) ;
33
+
34
+ return (
35
+ < ThemeProvider theme = { theme } >
36
+ < ColorModeContext . Provider value = { colorMode } >
37
+ { children }
38
+ </ ColorModeContext . Provider >
39
+ </ ThemeProvider >
40
+ ) ;
41
+ } ;
Original file line number Diff line number Diff line change
1
+ import { useContext } from "react" ;
2
+ import { ColorModeContext } from "./ColorModeContext" ;
3
+ import { useTheme } from "@emotion/react" ;
4
+ import { Box } from "@mui/system" ;
5
+ import { IconButton } from "@mui/material" ;
6
+ import { Brightness4 , Brightness7 } from "@mui/icons-material" ;
7
+
8
+ export const ToggleTheme = ( ) => {
9
+ const theme = useTheme ( ) ;
10
+ const colorMode = useContext ( ColorModeContext ) ;
11
+ const icon =
12
+ theme . palette . mode === "dark" ? < Brightness7 /> : < Brightness4 /> ;
13
+ return (
14
+ < Box sx = { { ml : 1 } } >
15
+ < IconButton onClick = { colorMode . toggleColorMode } color = "inherit" >
16
+ { icon }
17
+ </ IconButton >
18
+ </ Box >
19
+ ) ;
20
+ } ;
Original file line number Diff line number Diff line change @@ -10,4 +10,5 @@ if [ ! -f "${ENV_FILE}" ]; then
10
10
exit 1
11
11
fi
12
12
13
+ docker compose -f docker-compose.prod.yml down
13
14
docker compose -f docker-compose.prod.yml up -d --build
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ THIS_FILE_DIR=" $( cd " $( dirname " $0 " ) " && pwd) "
4
+ PROJECT_DIR=" $( cd " ${THIS_FILE_DIR} /.." && pwd) "
5
+ FRONT_DIR=" ${PROJECT_DIR} /frontend"
6
+ BACK_DIR=" ${PROJECT_DIR} /backend"
7
+ DB_DATA_DIR=" ${PROJECT_DIR} /etc/mysql/dbdata"
8
+ ENV_FILE=" ${PROJECT_DIR} /.env"
9
+
10
+ echo " DBデータを削除してもよろしいですか?"
11
+ echo " 削除する場合は y を入力してください。"
12
+ echo " 削除しない場合は n を入力してください。"
13
+
14
+ read -p " y/n: " yn
15
+
16
+ case " $yn " in [yY]* ) ;; * )
17
+ echo " 削除せずに終了します..."
18
+ exit
19
+ ;;
20
+ esac
21
+
22
+ echo " Dockerを停止します..."
23
+
24
+ docker compose down
25
+
26
+ echo " Dockerを停止しました!"
27
+
28
+ echo " DBデータを削除します..."
29
+
30
+ sudo rm -rf " ${DB_DATA_DIR} "
31
+
32
+ echo " DBデータを削除しました!"
33
+
34
+ echo " Dockerを立ち上げます..."
35
+
36
+ docker compose up -d --build
37
+
38
+ echo " Dockerを立ち上げました!"
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ THIS_FILE_DIR=" $( cd " $( dirname " $0 " ) " && pwd) "
4
+ PROJECT_DIR=" $( cd " ${THIS_FILE_DIR} /.." && pwd) "
5
+ FRONT_DIR=" ${PROJECT_DIR} /frontend"
6
+ BACK_DIR=" ${PROJECT_DIR} /backend"
7
+ ENV_FILE=" ${PROJECT_DIR} /.env"
8
+
9
+ echo " Dockerを立ち上げます..."
10
+
11
+ docker compose up -d --build
12
+
13
+ echo " Dockerを立ち上げました!"
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ THIS_FILE_DIR=" $( cd " $( dirname " $0 " ) " && pwd) "
4
+ PROJECT_DIR=" $( cd " ${THIS_FILE_DIR} /.." && pwd) "
5
+ FRONT_DIR=" ${PROJECT_DIR} /frontend"
6
+ BACK_DIR=" ${PROJECT_DIR} /backend"
7
+ ENV_FILE=" ${PROJECT_DIR} /.env"
8
+
9
+ echo " Dockerを終了します..."
10
+
11
+ docker compose down
12
+
13
+ echo " Dockerを終了しました!"
You can’t perform that action at this time.
0 commit comments