Skip to content

Commit 53a1e20

Browse files
committed
fix: Dockerfile & deploy.yaml for Next.js of SSG&SSR
1 parent 85d5073 commit 53a1e20

File tree

3 files changed

+26
-34
lines changed

3 files changed

+26
-34
lines changed

.github/workflows/deploy.yaml

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Build and Push Docker Image
33
on:
44
push:
55
branches:
6-
- main # メインブランチへのプッシュ時にトリガー
6+
- main # メインブランチへのプッシュ時に実行
77
workflow_dispatch: # 手動でトリガー可能
88

99
jobs:
@@ -22,38 +22,21 @@ jobs:
2222
node-version: 22
2323
cache: "yarn"
2424

25-
# 3. Yarn を使ってプロジェクトをインストール
26-
- name: Install Dependencies Using Yarn
27-
run: yarn install
28-
29-
# 4. Next.js をビルド(SSG ページの生成)
30-
- name: Build Next.js App
31-
run: yarn build
32-
33-
# 5. ユーザー名とリポジトリ名をフォーマットする
34-
- name: Format Username and Repository Name
35-
id: format
36-
run: |
37-
FORMATTED_USERNAME=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
38-
FORMATTED_REPO_NAME=$(echo "${{ github.event.repository.name }}" | sed -E 's/([a-z])([A-Z])/\1-\2/g' | tr '[:upper:]' '[:lower:]')
39-
40-
echo "FORMATTED_USERNAME=${FORMATTED_USERNAME}" >> $GITHUB_ENV
41-
echo "FORMATTED_REPO_NAME=${FORMATTED_REPO_NAME}" >> $GITHUB_ENV
42-
43-
# 6. Docker にログイン(GitHub Container Registry)
25+
# 3. Docker にログイン(GitHub Container Registry)
4426
- name: Log in to GitHub Container Registry
45-
uses: docker/login-action@v2
27+
uses: docker/login-action@v3.3.0
4628
with:
4729
registry: ghcr.io
48-
username: ${{ env.FORMATTED_USERNAME }}
49-
password: ${{ secrets.GITHUB_TOKEN }} # GitHub Actions が自動提供するトークン
30+
username: ${{ secrets.GITHUB_ACTOR }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
5032

51-
# 7. Docker イメージをビルド
33+
# 4. Docker イメージをビルド
5234
- name: Build Docker Image
5335
run: |
54-
docker build -f infra/docker/Dockerfile . -t ghcr.io/${{ env.FORMATTED_USERNAME }}/${{ env.FORMATTED_REPO_NAME }}:latest
36+
docker build -f infra/docker/Dockerfile . \
37+
-t ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:latest
5538
56-
# 8. Docker イメージをプッシュ
39+
# 5. Docker イメージをプッシュ
5740
- name: Push Docker Image
5841
run: |
59-
docker push ghcr.io/${{ env.FORMATTED_USERNAME }}/${{ env.FORMATTED_REPO_NAME }}:latest
42+
docker push ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:latest

infra/docker/Dockerfile

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ビルドステージ
12
FROM node:22-alpine AS builder
23

34
# 作業ディレクトリの設定
@@ -7,13 +8,21 @@ WORKDIR /app
78
COPY package.json yarn.lock ./
89
RUN yarn install --frozen-lockfile
910

10-
# アプリケーションをビルド(SSG 対応)
11+
# アプリケーションのビルド
1112
COPY . .
1213
RUN yarn build
1314

14-
# 実行用イメージを準備
15-
FROM nginx:alpine
16-
COPY --from=builder /app/out /usr/share/nginx/html
15+
# 実行ステージ
16+
FROM node:22-alpine
1717

18-
# ポート 80 の公開(Nginx サーバー)
19-
EXPOSE 80
18+
# 作業ディレクトリの設定
19+
WORKDIR /app
20+
21+
# ビルド成果物をコピー
22+
COPY --from=builder /app ./
23+
24+
# 必要なポートを公開
25+
EXPOSE 3000
26+
27+
# Next.jsのビルトインサーバーを起動
28+
CMD ["yarn", "start"]

infra/k8s/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ source:
55
targetRevision: main
66
container:
77
image: ghcr.io/y-ryuzu/react-portfolio:latest
8-
port: 80
8+
port: 3000
99
resources:
1010
limits:
1111
cpu: "500m"

0 commit comments

Comments
 (0)