Skip to content

Commit deed2ed

Browse files
authored
Merge pull request #47 from saitamau-maximum/development
Release: v1.0.0
2 parents 71a82f6 + 6d0a3a4 commit deed2ed

File tree

15 files changed

+188
-19
lines changed

15 files changed

+188
-19
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,20 @@ MaximumメンバーがWeb研究部の活動として、Twitterのようなマイ
2828
3. `cp .env.example .env`で.envファイルを作成
2929
4. `.env`ファイルを自分の好きな名前やパスワードに書き換え
3030
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+
(マイグレーションなど特別なオペレーションが必要な場合もある)

backend/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ type Handler struct {
1818
}
1919

2020
var (
21-
SQL_PATH = "./sql"
21+
SQL_PATH = "./sql"
22+
IMAGES_DIR = "./public/images"
2223
)
2324

2425
func getEnv(key, fallback string) string {
@@ -98,7 +99,7 @@ type Post struct {
9899

99100
func (h *Handler) GetPosts(c echo.Context) error {
100101
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")
102103
if err != nil {
103104
h.Logger.Error(err)
104105
return c.JSON(500, err)

backend/public/images/.gitkeep

Whitespace-only changes.

docker-compose.prod.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ services:
77
volumes:
88
- ./etc/nginx/prod/conf.d:/etc/nginx/conf.d
99
- ./frontend/dist:/var/www/html
10+
- ./backend/public:/var/www/public
1011
depends_on:
1112
- backend
1213

@@ -36,6 +37,8 @@ services:
3637
- MYSQL_DATABASE=${MYSQL_DATABASE}
3738
- MYSQL_USER=${MYSQL_USER}
3839
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
40+
volumes:
41+
- ./backend/public:/app/public
3942
depends_on:
4043
database:
4144
condition: service_healthy

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
- 80:80
77
volumes:
88
- ./etc/nginx/dev/conf.d:/etc/nginx/conf.d
9+
- ./backend/public:/var/www/public
910
depends_on:
1011
- backend
1112
- frontend

etc/nginx/dev/conf.d/maxitter.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ server {
1010
proxy_set_header Host $host;
1111
}
1212

13+
location /images {
14+
alias /var/www/public/images;
15+
}
16+
1317
location /api {
1418
proxy_pass http://backend:8000;
1519
proxy_http_version 1.1;

etc/nginx/prod/conf.d/maxitter.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ server {
88
try_files $uri $uri/ /index.html;
99
}
1010

11+
location /images {
12+
alias /var/www/public/images;
13+
}
14+
1115
location /api {
1216
proxy_pass http://backend:8000;
1317
proxy_http_version 1.1;

frontend/src/App.jsx

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { Container } from "@mui/material";
1+
import { Container, CssBaseline } from "@mui/material";
22
import { GlobalStyles } from "@mui/material";
33
import { Form } from "./components/Form";
44
import { Timeline } from "./components/Timeline";
55
import { useEffect, useState } from "react";
6+
import { ColorModeProvider } from "./components/theme/ColorModeProvider.jsx";
7+
import { ToggleTheme } from "./components/theme/ToggleTheme.jsx";
68

79
function App() {
810
const [posts, setPosts] = useState([]);
@@ -29,22 +31,30 @@ function App() {
2931

3032
return (
3133
<>
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>
4858
</>
4959
);
5060
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { createContext } from "react";
2+
3+
export const ColorModeContext = createContext({ toggleColorMode: () => {} });
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
};

scripts/deploy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ if [ ! -f "${ENV_FILE}" ]; then
1010
exit 1
1111
fi
1212

13+
docker compose -f docker-compose.prod.yml down
1314
docker compose -f docker-compose.prod.yml up -d --build

scripts/reset-db.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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を立ち上げました!"

scripts/start.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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を立ち上げました!"

scripts/stop.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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を終了しました!"

0 commit comments

Comments
 (0)