Skip to content

Commit d8c4794

Browse files
authored
Merge pull request #950 from NUTFes/feat/nose/fix-prod-Dockerfile
Dockerfileを修正
2 parents c0d63b5 + 7e70a2c commit d8c4794

File tree

116 files changed

+273
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+273
-163
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ build:
55
docker compose build
66
docker compose run --rm view npm install
77

8+
9+
build-stg:
10+
docker compose -f compose.stg.yml build
11+
12+
813
# アプリコンテナの起動
914
run:
1015
docker compose up -d
@@ -97,3 +102,7 @@ run-all:
97102

98103
gen-er:
99104
docker run -v "./er:/output" --net="host" schemaspy/schemaspy:snapshot -t mysql -host localhost:3306 -db finansu_db -u root -p root -connprops allowPublicKeyRetrieval\\=false -s finansu_db
105+
106+
107+
108+

api/drivers/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func RunServer(router router.Router) *echo.Echo {
2727

2828
// CORS対策
2929
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
30-
AllowOrigins: []string{"http://localhost:3000", "127.0.0.1:3000", "http://localhost:3001", "127.0.0.1:3001", "http://localhost:8000", "127.0.0.1:8000", "https://finansu.nutfes.net"}, // ドメイン
30+
AllowOrigins: []string{"http://localhost:3000", "127.0.0.1:3000", "http://localhost:3001", "127.0.0.1:3001", "http://localhost:8000", "127.0.0.1:8000", "https://finansu.nutfes.net", "https://stg-finansu.nutfes.net"}, // ドメイン
3131
AllowMethods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete},
3232
}))
3333

api/prod.Dockerfile

Lines changed: 0 additions & 16 deletions
This file was deleted.

compose.prod.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ services:
77

88
view:
99
build:
10-
context: ./view
11-
dockerfile: prod.Dockerfile
10+
context: ./
11+
dockerfile: prod.view.Dockerfile
1212
container_name: "nutfes-finansu-view"
13-
command: "npm run start"
1413
ports: ["3000:3000"]
1514
depends_on: ["api"]
1615

1716
api:
1817
build:
19-
context: ./api
20-
dockerfile: prod.Dockerfile
18+
context: ./
19+
dockerfile: prod.api.Dockerfile
2120
container_name: "nutfes-finansu-api"
2221
env_file: ["./finansu.env"]
2322
ports: ["1323:1323"]

compose.stg.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ services:
77

88
view:
99
build:
10-
context: ./view
11-
dockerfile: prod.Dockerfile
10+
context: ./
11+
dockerfile: prod.view.Dockerfile
12+
args:
13+
NEXT_PUBLIC_APP_ENV: "stg"
1214
container_name: "nutfes-finansu-view"
13-
command: "npm run start"
1415
ports: ["3000:3000"]
1516
depends_on: ["api"]
1617

1718
api:
1819
build:
19-
context: ./api
20-
dockerfile: prod.Dockerfile
20+
context: ./
21+
dockerfile: prod.api.Dockerfile
2122
container_name: "nutfes-finansu-api"
2223
env_file: ["./finansu.env"]
2324
ports: ["1323:1323"]

prod.view.Dockerfile

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
# Build用 コンテナ
2-
FROM node:20.14 AS builder
3-
WORKDIR /app/next-project
4-
COPY ./view/next-project /app/next-project
5-
RUN npm install
2+
FROM node:20-alpine AS base
3+
4+
FROM base AS builder
5+
6+
# build時に必要な環境変数
7+
ARG NEXT_PUBLIC_APP_ENV=production
8+
ENV NEXT_PUBLIC_APP_ENV=${NEXT_PUBLIC_APP_ENV}
9+
10+
WORKDIR /app
11+
12+
COPY ./view/next-project/package*.json ./
13+
RUN npm ci
14+
15+
COPY ./view/next-project/ ./
616
RUN npm run build
717

8-
# 本番用 軽量 nodejs20.14
9-
FROM node:20.14-slim
18+
# Create runner image
19+
FROM gcr.io/distroless/nodejs20-debian12:nonroot AS runner
20+
1021
WORKDIR /app
1122
LABEL org.opencontainers.image.source="https://github.com/NUTFes/FinanSu"
12-
ENV NODE_ENV production
13-
ENV NEXT_PUBLIC_APP_ENV "production"
14-
15-
COPY --from=builder /app/next-project/next.config.js ./
16-
COPY --from=builder /app/next-project/public ./public
17-
COPY --from=builder --chown=nonroot:nonroot /app/next-project/.next ./.next
18-
COPY --from=builder /app/next-project/node_modules ./node_modules
19-
COPY --from=builder /app/next-project/package.json ./package.json
20-
21-
USER nonroot
22-
EXPOSE 3000
23-
CMD ["node_modules/.bin/next", "start"]
23+
ENV NODE_ENV=production
24+
25+
COPY --from=builder --chown=65532:65532 /app/.next/standalone /app/
26+
COPY --from=builder --chown=65532:65532 /app/.next/static /app/.next/static
27+
COPY --from=builder --chown=65532:65532 /app/public /app/public
28+
29+
ARG PORT=3000
30+
ENV HOSTNAME=0.0.0.0
31+
ENV PORT=${PORT}
32+
EXPOSE ${PORT}
33+
34+
ENTRYPOINT [ "/nodejs/bin/node", "server.js" ]

view/next-project/next.config.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @type {import('next').NextConfig} */
22
const isProd = process.env.NEXT_PUBLIC_APP_ENV === 'production';
3+
const isStg = process.env.NEXT_PUBLIC_APP_ENV === 'stg';
34

45
module.exports = {
56
reactStrictMode: true,
@@ -9,7 +10,16 @@ module.exports = {
910
// SSR_API_URI: isProd ? 'http://nutfes-finansu-api:1323' : 'http://nutfes-finansu-api:1323',
1011
// CSR_API_URI: isProd ? 'http://localhost:1323' : 'http://localhost:1323',
1112

12-
SSR_API_URI: isProd ? 'https://finansu-api.nutfes.net' : 'http://nutfes-finansu-api:1323',
13-
CSR_API_URI: isProd ? 'https://finansu-api.nutfes.net' : 'http://localhost:1323',
13+
SSR_API_URI: isProd
14+
? 'https://finansu-api.nutfes.net'
15+
: isStg
16+
? 'https://stg-finansu-api.nutfes.net'
17+
: 'http://nutfes-finansu-api:1323',
18+
CSR_API_URI: isProd
19+
? 'https://finansu-api.nutfes.net'
20+
: isStg
21+
? 'https://stg-finansu-api.nutfes.net'
22+
: 'http://localhost:1323',
1423
},
24+
output: 'standalone',
1525
};

view/next-project/package-lock.json

Lines changed: 105 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

view/next-project/src/stories/FinanSuButton.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Meta } from '@storybook/react';
1+
import type { Meta } from '@storybook/react';
22
import FinanSuButton from '@components/common/FinanSuButton';
33

44
const meta: Meta<typeof FinanSuButton> = {

view/next-project/src/stories/OpenDeleteModalButton.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Meta } from '@storybook/react';
1+
import type { Meta } from '@storybook/react';
22
import { OpenAddModalButton } from '@components/fund_information';
33

44
const meta: Meta<typeof OpenAddModalButton> = {

0 commit comments

Comments
 (0)