diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d8ceb11c..4c8e338b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,7 +3,7 @@ name: CI on: push: branches: - - 'master' + - 'main' pull_request: jobs: @@ -16,7 +16,9 @@ jobs: with: node-version-file: .node-version cache: npm - - run: SKIP_GENAPI=1 npm ci + - run: npm ci + env: + SKIP_GENAPI: 1 genApi: name: Generate APIs runs-on: ubuntu-latest @@ -34,14 +36,18 @@ jobs: build: name: Build runs-on: ubuntu-latest - needs: [packages, genApi] + needs: + - packages + - genApi steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version-file: .node-version cache: npm - - run: SKIP_GENAPI=1 npm ci + - run: npm ci + env: + SKIP_GENAPI: 1 - uses: actions/download-artifact@v4 with: name: apis @@ -52,14 +58,18 @@ jobs: lint: name: Lint runs-on: ubuntu-latest - needs: [packages, genApi] + needs: + - packages + - genApi steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version-file: .node-version cache: npm - - run: SKIP_GENAPI=1 npm ci + - run: npm ci + env: + SKIP_GENAPI: 1 - uses: actions/download-artifact@v4 with: name: apis @@ -68,14 +78,18 @@ jobs: format: name: Format runs-on: ubuntu-latest - needs: [packages, genApi] + needs: + - packages + - genApi steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version-file: .node-version cache: npm - - run: SKIP_GENAPI=1 npm ci + - run: npm ci + env: + SKIP_GENAPI: 1 - uses: actions/download-artifact@v4 with: name: apis @@ -84,14 +98,18 @@ jobs: typeCheck: name: Type Check runs-on: ubuntu-latest - needs: [packages, genApi] + needs: + - packages + - genApi steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version-file: .node-version cache: npm - - run: SKIP_GENAPI=1 npm ci + - run: npm ci + env: + SKIP_GENAPI: 1 - uses: actions/download-artifact@v4 with: name: apis @@ -100,7 +118,9 @@ jobs: test: name: Test runs-on: ubuntu-latest - needs: [packages, genApi] + needs: + - packages + - genApi steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 91241c80..1b5b19ee 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -12,9 +12,27 @@ env: IMAGE_NAME: traportfolio-dashboard jobs: + # API生成部分をDockerのビルド部分から分離 + genApi: + name: Generate APIs + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version-file: .node-version + cache: npm + - run: npm ci + - uses: actions/upload-artifact@v4 + with: + name: apis + path: ./src/lib/apis/generated + # GitHubリリース機能で自動リリース make-dist: runs-on: ubuntu-latest + needs: + - genApi steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -23,6 +41,10 @@ jobs: cache: npm - name: Node package install run: npm ci + - uses: actions/download-artifact@v4 + with: + name: apis + path: ./src/lib/apis/generated - name: Vite build run: npm run build env: @@ -40,6 +62,9 @@ jobs: # ghcrにビルド済みイメージをアップロード image: name: Build Docker Image + needs: + - genApi + - make-dist runs-on: ubuntu-latest steps: - name: Set IMAGE_TAG env @@ -61,6 +86,11 @@ jobs: username: traptitech password: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/download-artifact@v4 + with: + name: apis + path: ./src/lib/apis/generated + - name: Build and push uses: docker/build-push-action@v5 with: diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 2e330f5d..e81d10c3 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -10,11 +10,27 @@ env: IMAGE_TAG: main jobs: + genApi: + name: Generate APIs + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version-file: .node-version + cache: npm + - run: npm ci + - uses: actions/upload-artifact@v4 + with: + name: apis + path: ./src/lib/apis/generated image: permissions: contents: read packages: write runs-on: ubuntu-latest + needs: + - genApi steps: - name: Login to GitHub Container Registry uses: docker/login-action@v3 @@ -23,6 +39,10 @@ jobs: username: traptitech password: ${{ secrets.GITHUB_TOKEN }} - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: apis + path: ./src/lib/apis/generated - name: Build and push uses: docker/build-push-action@v5 with: @@ -33,7 +53,8 @@ jobs: deploy-staging: name: Deploy staging runs-on: ubuntu-latest - needs: [image] + needs: + - image steps: - name: Install SSH key uses: shimataro/ssh-key-action@v2 diff --git a/Dockerfile b/Dockerfile index 5f7397e4..8384073d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,15 @@ -FROM --platform=$BUILDPLATFORM node:20.8.0-alpine as build +FROM --platform=$BUILDPLATFORM node:20.11.1-alpine as build WORKDIR /app -RUN apk update \ - && apk --no-cache add openjdk11 \ - && rm -rf /var/cache/apk/* +RUN apk update + +ENV NODE_ENV=production SKIP_GENAPI=1 COPY package.json package-lock.json ./ COPY scripts/ ./scripts/ RUN npm ci COPY . . -RUN NODE_ENV=production npm run build +RUN npm run build # 本番環境 FROM caddy:2.4.6-alpine