DEV Community

Yuta Goto
Yuta Goto

Posted on

2

CircleCIを使用してVercelにデプロイする

Vercelにはgit pushを検知してDeployする仕組みがあるが、lintやtestしてからのデプロイはgit push検知の状態ではできないのでvercelのコマンドを使用してCDツールに組み込む。

https://vercel.com/cli

準備

vercelのgit integrationを切っておく。

vercel git repository setting

Vercelの個人設定からCircleCIで使用するTokenを生成する。

Vercel Token

Vercelで生成したTokenをCircleCIの環境変数にセットする。

CircleCI Env

実装

yarn add でvercelコマンドを準備し、Scriptを組んでおくと楽に設定できる。

yarn add -D vercel
Enter fullscreen mode Exit fullscreen mode
// package.json
{
  "scripts": {
    "deploy": "vercel --token $VERCEL_TOKEN --prod --confirm"
  }
}
Enter fullscreen mode Exit fullscreen mode

--confirm はデプロイするための質問をスキップさせることができる。

https://vercel.com/docs/cli#commands/overview/unique-options/confirm

.circleci/config.yml に設定を書く。

# .circleci/config.yml
version: 2.1

orbs:
  node: circleci/node@4.7

jobs:
  deploy:
    working_directory: ~/[ProjectName]
    docker:
      - image: circleci/node:latest
    steps:
      - checkout
      - run:
          name: install
          command: yarn install
      - run:
          name: deploy
          command: yarn deploy

workflows:
  version: 2
  main:
    jobs:
      - deploy:
          filters:
            branches:
              only:
                - main
Enter fullscreen mode Exit fullscreen mode

vercel --token $VERCEL_TOKEN --prod --confirm を実行すると現在のディレクトリがプロジェクト名として認識されデプロイされるので、 ymlファイルの working_directory:[ProjectName] の部分をきちんと設定すれば意図したプロジェクト名でデプロイすることができる。

CICD

CIの実行結果に本番用のURLが出力されるので、そこからアクセスすることも可能になっている。

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay