ã¯ããã«
æè¿ catnose99 ããã® ããŒã åã 人ã®ããã¯ããã°ã RSS ã§éçŽãããµã€ããäœã£ãïŒNext.jsïŒ ãå©çšãããŠããã ã圢㧠äŒç€Ÿã®ããã¯ããã° ãæ§ç¯ããŸããã
Team Blog Hub ã Next.js ã§éçºãããŠããã®ã§ããããã€å 㯠Vercel ã«æ±ºããŸããããã®éã«èšäºãèªåçã«æŽæ°ããããã«ãGitHub Actions ã§å®æçã«ãã«ããåãããã«ããŸããããŸããç¬èªãã¡ã€ã³ã®èšå®ãè¡ããŸããã
æ¬èšäºã§ã¯ãVercel ãããžã§ã¯ãã GitHub Actions ã§ãã«ãããŠãããã€ããããã®æé ã«ã€ããŠãŸãšããŠãããŸãããŸãããŸããšããŠãVercel ã§ã®ç¬èªãã¡ã€ã³ã®èšå®æ¹æ³ãåã³åŒç€Ÿã® Team Blog Hub ã®éçšæ¹éã«ã€ããŠãæžããŠãããŸãã
ãªããèšäºã¯äžèšã®åæã§æžããŠãããŸãã®ã§ã泚æãã ãããŸãã
- Vercel ã§ãµã€ã³ã¢ããæžã¿
- ãµã€ã³ã¢ããæžã¿ã§ãªãæ¹ã¯ãã¡ããããµã€ã³ã¢ããå¯èœã§ã
- Vercel ã§ãããžã§ã¯ãäœææžã¿
- ãããžã§ã¯ãæªäœæã®æ¹ã¯ãã¡ãããäœæå¯èœã§ã
- Vercel ã® GitHub é£æºã§ãããžã§ã¯ããžã®ãªããžããªã®çŽä»ãæžã¿
åäœç°å¢
- Node.js v15.6.0
- Vercel CLI 21.1.0
GitHub Actions 㧠Vercel ãžãããã€ããæºåãè¡ã
ãŸã㯠GitHub Actions 㧠Vercel ãžã®ãã«ã & ãããã€ãè¡ãããã®ç°å¢ãæŽããå¿ èŠããããŸãããã®ããã«ã¯ãåçš®å¿ èŠãšãªãæ å ±ãäºã Vercel ããååŸããŠããå¿ èŠããããŸãã
Vercel ãããã€æã«å¿ èŠãšãªãããŒã¯ã³ãååŸãã
Vercel ã«ãã°ã€ã³åŸããããããŒãžå³äžã®ã¢ã€ã³ã³ããããŒã¯ã³ãçºè¡ç»é¢ã«é·ç§»ããŸãã
ãããããŒãžå³äžã®ã¢ã€ã³ã³ãã Settings ã¡ãã¥ãŒãã¯ãªãã¯ãã
ããŒã¯ã³ãçºè¡ããŠããã®å 容ãæ§ãã (GitHub Actions ã§ã® Vercel ãããã€æã«å¿ èŠãšãªã)
çºè¡ããããŒã¯ã³ã¯ GitHub Actions ã§ã®ãããã€æã«å©çšããŸãã
Vercel ãããã€æã«å¿ èŠãšãªãæ å ±ãååŸãã
Verce ã«ã¯å ¬åŒãæäŸããŠãã CLI ãååšããã®ã§ããŸãã¯ãã¡ããã€ã³ã¹ããŒã«ããŸãã ã€ã³ã¹ããŒã«ã³ãã³ãã¯äžèšã«ãªããŸãã
# npm ã®å Žå
npm i -g vercel
# yarn ã®å Žå
yarn global add vercel
ãã®åŸãVercel ãããžã§ã¯ãã«çŽä»ãã GitHub ãªããžããªã®ã«ãŒã㧠vercel
ã³ãã³ããå®è¡ããŠãæé ã«åŸã£ãŠ Vercel ãããžã§ã¯ããšã®çŽä»ããè¡ããŸããã³ãã³ãã®å®è¡ã«æåãããš .vercel/project.json
ãšãããã¡ã€ã«ã®çæã確èªã§ããã¯ãã§ãã
.vercel/project.json
ã«ã¯ GitHub Actions çµç±ã§ã®ãããã€æã«å¿
èŠãšãªã vercel-project-id ãš vercel-org-id ã®å
容ãèšèŒãããŠããŸãã
{ "projectId": "<vercel-project-id ã®å
容>", "orgId": "<vercel-org-id ã®å
容>" }
äžèšã®å 容ã GitHub ãªããžããªã® Secrets ã«ç»é²ããŠãããŸãã
GitHub Actions ã§å®æçã« Vercel ãžãããã€ãã
GitHub ãªããžããªã® Secrets ã« .vercel/project.json
ã®å
容ãç»é²ããŸããä»å㯠ORG_ID
PROJECT_ID
VERCEL_TOKEN
ã Secrets ã«ç»é²ããŸãã
ã㌠| å€ |
---|---|
ORG_ID | .vercel/project.json ã® orgId |
PROJECT_ID | .vercel/project.json ã® projectId |
VERCEL_TOKEN | Vercel ã§çºè¡ããããŒã¯ã³ |
GitHub Actions çµç±ã§ Vercel ãžãããã€ããã®ã«å¿ èŠãªå€ã Secrets ã«ç»é²ããŠãã
ã·ãŒã¯ã¬ãããžå¿ èŠãªæ å ±ãç»é²ã§ããããGitHub Actions ã®ã¯ãŒã¯ãããŒãã¡ã€ã«ãäœæããŸããä»åã¯æå¿ã§éçºãããŠãã Vercel Action ãå©çšããŸãã
# deploy_website.yml
name: deploy website
on:
# äžå¿å確ã®ããã«æå㧠GitHub Actions ãå®è¡å¯èœã«ãã
# ãã®éã®åŒæ°ãšã㊠checkout æã® ref ãæž¡ããŠãã
# default éšåã¯ãªããžããªã«èšå®ãããŠããããã©ã«ããã©ã³ããæå®ãã
workflow_dispatch:
inputs:
ref:
description: branch|tag|SHA to checkout
default: "main"
required: true
# æ¯æ¥æ¥æ¬æéã® 11æ ã« GitHub Actions ãå®è¡ããã (cron ã®æå»ã¯ UST)
# å®è¡ã®éã«åç
§ããããã©ã³ãã¯äžèšã® default ã§æå®ãããã®ã䜿çšããã
schedule:
- cron: "0 2 * * *"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.ref }}
- uses: actions/setup-node@v2
with:
node-version: "15"
# æçš¿å
容ãæŽæ°ããããã« npm run build:posts ãèµ°ããã
- name: Recreate all posts
shell: bash
run: |
npm install
npm run build:posts
- uses: amondnet/vercel-action@v20
with:
# GitHub Actions ã® Secrets ã§äœæããå€ãåç
§ãã圢ã§
# Vercel ãããã€æã«å¿
èŠãšãªãåçš®ãã©ã¡ã¿ãèšå®ãã
vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required
vercel-args: "--prod" # Optional
vercel-org-id: ${{ secrets.ORG_ID}} #Required
vercel-project-id: ${{ secrets.PROJECT_ID}} #Required
working-directory: ./
äžèšãã¡ã€ã«ãäœæ次第ãGitHub ãªããžããªã®ããã©ã«ããã©ã³ãã«ã³ãããããŠãGitHub Actions ã®ã¯ãŒã¯ãããŒãæåå®è¡ããŠã¿ãŠæ£åžžã«ãããã€ã§ãããã確èªããŠãããŸãã
GitHub ãªããžããªã®ããŒãžã«é·ç§»åŸãå®éã« GitHub Actions ã®ã¯ãŒã¯ãããŒãå®è¡ããŠã¿ã
GitHub Actions ã®ã¯ãŒã¯ãããŒãå®è¡ãããŠãããã確èªãã
GitHub Actions ã®ã¯ãŒã¯ãããŒãæ£åžžã«å®è¡å®äºããŠããããšã確èªãã
GitHub Actions ãæ£åžžã«å®è¡ãããŠããããªããšã確èªã§ããããVercel åŽã§æ£åžžã«ãããã€ãå®äºããŠããããã確èªããŸããVercel ã®ãããããŒãžã«é·ç§»åŸã該åœãããããžã§ã¯ãããŒãžã«é·ç§»ããŠã Deployments
ã¿ããããããã€å±¥æŽã確èªããŸãã
Vercel ã§è©²åœãããããžã§ã¯ãããŒãžã«é·ç§»ããŠããããã€å±¥æŽã確èªãã
ããã§äžéãã®äœæ¥ã¯çµäºã§ãããç²ãããŸã§ããã
(ããŸã) ç¬èªãã¡ã€ã³ãçŽä»ãã
Vercel ã«ã¯ Custom Domains ãšããç¬èªãã¡ã€ã³ãçŽä»ããããã®æ©èœãåãã£ãŠããŸãããã¡ããå©çšãããšç¬èªãã¡ã€ã³çµç±ã§ Vercel ãããžã§ã¯ãã«ã¢ã¯ã»ã¹ãããããšãå¯èœã«ãªããŸãã
ã«ãŒããã¡ã€ã³ã®å Žå㯠A ã¬ã³ãŒããããµããã¡ã€ã³ã®å Žå㯠CNAME ã¬ã³ãŒããç¬èªãã¡ã€ã³ã® DNS ã¬ã³ãŒãèšå®ã«è¿œå ããã ãã§ãç¬èªãã¡ã€ã³çµç±ã§ HTTPS ã¢ã¯ã»ã¹å¯èœã«ãªããŸãã
Custom Domains ãèšå®ããŠç¬èªãã¡ã€ã³çµç±ã§ã¢ã¯ã»ã¹ã§ããããã«ãã (ãµããã¡ã€ã³èšå®æã®å Žåã®èšå®æ¹æ³)
Custom Domains ã®ç¶æ
ã Valid Configuration
ã«ãªã次第ãèšå®ããç¬èªãã¡ã€ã³ãžã¢ã¯ã»ã¹ãããšãã« Vercel ãããã€ããããŒãžã衚瀺ãããã確èªããã
(ããŸã) Team Blog Hub ã®å®éã®éçš
瀟å
ã§è©±ãåã£ãçµæãmaster
ãã©ã³ãã¯ãªãªãžãã«ãªããžããªã®ææ°å
容ãåæ ããå ŽæãšããŠãrelease
ãã©ã³ãã¯å®éã®ãããã€ã«å©çšãããã©ã³ããšããŠéçšããããšã«ããŸããã
master
ãã©ã³ããšåé¢ããŠãèªåãã¡ã®äŒç€Ÿã®ç¬èªæ¹ä¿®ã«ã€ããŠã¯ release
ãã©ã³ãã«åã蟌ãããšã§ãæ¬å®¶ãªããžããªã« PR ãåºãããããšããå©ç¹ããããŸãããŸããèªåãã¡ã®ããŒã¹ã§æ¬å®¶ãªããžããªã®ææ°ã® master
ãã©ã³ãã®åã蟌ã¿äœæ¥ãã§ãããšããå©ç¹ããããŸãã
ãã©ã³ããåé¢ããŠããã ãã§ãææ°ã®æ¬å®¶ãªããžããªã®æ°æ©èœã®åã蟌ã¿ã楜ã«ãªãæ©æµãåããããããã«ãªãããã€èªç€Ÿã®ç¬èªæ¹ä¿®ã®å
容ã«ã€ããŠãå®å¿ã㊠release
ãã©ã³ããžã³ãããã§ããããã«ãªããããªã¹ã¹ã¡ã§ãã
ãããã«
Team Blog Hub ãçšããããšã§ãç°¡åã«ã«ãã³ãããã¶ã€ã³ã§äŒç€Ÿã®ããã¯ããã°ãæ§ç¯ã§ããŸãããOSS ãšããŠå ¬éããŠãã ãã£ãŠãã catnose ããã«ã¯æ¬åœã«æè¬ã§ã ðð»
ç¡çãªãç¶ç¶æŽæ°ããç¶ããèªç€Ÿããã¯ããã°ãšããŠãããããã Team Blog Hug ã掻çšãããŠããã ãã€ã€ãPR ãã£ã³ã¹ãããã°ç©æ¥µçã«çã£ãŠãããããšèããŠããŸã ð«