From 95cab48f089907b4fb8cae5bcc43ed9fb31e3e2f Mon Sep 17 00:00:00 2001 From: solufa Date: Thu, 6 Jun 2024 16:57:39 +0900 Subject: [PATCH] feat: add Dockerfile for releasing --- .github/workflows/deploy-client.yml | 55 ----------------------------- .github/workflows/release.yml | 26 ++++++++++++++ Dockerfile | 22 ++++++++++++ batches/writeVersion.js | 9 +++++ package.json | 4 +++ 5 files changed, 61 insertions(+), 55 deletions(-) delete mode 100644 .github/workflows/deploy-client.yml create mode 100644 .github/workflows/release.yml create mode 100644 Dockerfile create mode 100644 batches/writeVersion.js diff --git a/.github/workflows/deploy-client.yml b/.github/workflows/deploy-client.yml deleted file mode 100644 index af11b4f..0000000 --- a/.github/workflows/deploy-client.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: Deploy client - -on: - workflow_run: - workflows: ['Test'] - branches: [main] - types: - - completed - -jobs: - deploy: - name: Deploy - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} - permissions: - contents: write - steps: - - uses: actions/checkout@v3 - with: - ref: ${{ github.event.workflow_run.head_branch }} - - uses: actions/setup-node@v3 - with: - node-version: 20 - - uses: actions/cache@v2 - id: root-npm-cache - with: - path: 'node_modules' - key: root-npm-${{ hashFiles('package-lock.json') }} - - uses: actions/cache@v2 - id: client-npm-cache - with: - path: 'client/node_modules' - key: client-npm-${{ hashFiles('client/package-lock.json') }} - - uses: actions/cache@v2 - id: server-npm-cache - with: - path: 'server/node_modules' - key: server-npm-${{ hashFiles('server/package-lock.json') }} - - run: npm install - if: steps.root-npm-cache.outputs.cache-hit != 'true' - - run: npm install --prefix client - if: steps.client-npm-cache.outputs.cache-hit != 'true' - - run: npm install --prefix server - if: steps.server-npm-cache.outputs.cache-hit != 'true' - - run: npm run build --prefix client - env: - API_ORIGIN: ${{ vars.API_ORIGIN }} - NEXT_PUBLIC_COGNITO_POOL_ENDPOINT: ${{ vars.NEXT_PUBLIC_COGNITO_POOL_ENDPOINT }} - NEXT_PUBLIC_COGNITO_POOL_ID: ${{ vars.NEXT_PUBLIC_COGNITO_POOL_ID }} - NEXT_PUBLIC_COGNITO_CLIENT_ID: ${{ vars.NEXT_PUBLIC_COGNITO_CLIENT_ID }} - - run: touch ./client/out/.nojekyll - - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./client/out diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ad71afd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,26 @@ +name: Release + +on: + push: + tags: + - 'v*' + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV + - uses: docker/build-push-action@v5 + with: + push: true + build-args: | + VERSION=${{ env.VERSION }} + tags: frourio/magnito:latest,frourio/magnito:${{ env.VERSION }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..27a6382 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM node:20-alpine + +WORKDIR /usr/src/app + +COPY package.json package-lock.json . +RUN npm ci + +COPY client/package.json client/package-lock.json ./client/ +RUN npm ci --prefix client + +COPY server/package.json server/package-lock.json ./server/ +RUN npm ci --prefix server + +COPY . . +ARG VERSION + +RUN cp client/.env.example client/.env +RUN cp server/.env.example server/.env +RUN npm run batch:writeVersion -- $VERSION +RUN npm run build + +CMD npm start diff --git a/batches/writeVersion.js b/batches/writeVersion.js new file mode 100644 index 0000000..c013afd --- /dev/null +++ b/batches/writeVersion.js @@ -0,0 +1,9 @@ +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); + +const version = process.argv[2]; +const jsonPath = path.join(process.cwd(), 'package.json'); + +assert(/\d+\.\d+\.\d+/.test(version)); +fs.writeFileSync(jsonPath, JSON.stringify({ ...require(jsonPath), version }, null, 2), 'utf8'); diff --git a/package.json b/package.json index e6c40d0..3538bb7 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,13 @@ "dev": "run-p dev:*", "dev:client": "npm run dev --prefix client", "dev:server": "npm run dev --prefix server", + "build": "run-p build:*", + "build:client": "npm run build --prefix client", + "build:server": "npm run build --prefix server", "generate": "run-p generate:*", "generate:client": "npm run generate --prefix client", "generate:server": "npm run generate --prefix server", + "batch:writeVersion": "node batches/writeVersion.js", "lint": "run-p lint:*", "lint:client": "npm run lint:fix --prefix client", "lint:server": "npm run lint:fix --prefix server",