Skip to content

Commit

Permalink
Migrate "now" to "vercel" (#210) (modified)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadorequest committed Nov 21, 2020
1 parent 5e32b83 commit 7388ea4
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 91 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# XXX Tips: When is this file being used?
# This file is used only when building the Next.js app locally (localhost), whether it's for running `next dev` or `next build`.
# For staging/production stages, the app relies on "now.{NEXT_PUBLIC_CUSTOMER_REF}.{NEXT_PUBLIC_APP_STAGE}.yml:build.env".
# For staging/production stages, the app relies on "vercel.{NEXT_PUBLIC_CUSTOMER_REF}.{NEXT_PUBLIC_APP_STAGE}.yml:build.env".

# XXX Tips: What's the difference between env vars starting with "NEXT_PUBLIC_" and the others?
# All env variables that DON'T start with "NEXT_PUBLIC_" MUST be manually exposed by ./next.config.js for the project to work locally
Expand All @@ -18,7 +18,7 @@

# The stage is "how" the application is running.
# It can be either "development", "staging" or "production".
# This value is also set in each "now.*.json" files, so that other stages use their own value.
# This value is also set in each "vercel.*.json" files, so that other stages use their own value.
# Tip: This value must not be changed.
# Tip: You may override it from ".env.local" if you want to simulate another stage, locally.
NEXT_PUBLIC_APP_STAGE=development
Expand Down
2 changes: 1 addition & 1 deletion .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# XXX Tips: When is this file being used?
# This file is used only when building the Next.js app locally (localhost), whether it's for running `next dev` or `next build`.
# For staging/production stages, the app relies on "now.{NEXT_PUBLIC_CUSTOMER_REF}.{NEXT_PUBLIC_APP_STAGE}.yml:build.env".
# For staging/production stages, the app relies on "vercel.{NEXT_PUBLIC_CUSTOMER_REF}.{NEXT_PUBLIC_APP_STAGE}.yml:build.env".

# XXX Tips: What's the difference between env vars starting with "NEXT_PUBLIC_" and the others?
# All env variables that DON'T start with "NEXT_PUBLIC_" MUST be manually exposed by ./next.config.js for the project to work locally
Expand Down
4 changes: 2 additions & 2 deletions .github/WORKFLOW_DISPATCH.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ All inputs are available within `${{github}}` variable. Because this input has b
In order to use a **fallback** value (useful when the input isn't required, e.g: `required: false`), we can use this bash trick:

```bash
CUSTOMER_TO_DEPLOY="${MANUAL_TRIGGER_CUSTOMER:-$(cat now.json | jq -r '.build.env.NEXT_PUBLIC_CUSTOMER_REF')}"
CUSTOMER_TO_DEPLOY="${MANUAL_TRIGGER_CUSTOMER:-$(cat vercel.json | jq -r '.build.env.NEXT_PUBLIC_CUSTOMER_REF')}"
```

If `MANUAL_TRIGGER_CUSTOMER` is empty, then we'll resolve its fallback value from the `now.json` file and extract the `build.env.NEXT_PUBLIC_CUSTOMER_REF` value.
If `MANUAL_TRIGGER_CUSTOMER` is empty, then we'll resolve its fallback value from the `vercel.json` file and extract the `build.env.NEXT_PUBLIC_CUSTOMER_REF` value.

## 3. How to trigger the workflow using an external HTTP request?

Expand Down
48 changes: 24 additions & 24 deletions .github/workflows/deploy-zeit-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
node-version: '12.x' # Use the same node.js version as the one Zeit's uses (currently node12.x)

# Starts a Zeit deployment, using the production configuration file of the default institution
# The default institution is the one defined in the `now.json` file (which is a symlink to the actual file)
# The default institution is the one defined in the `vercel.json` file (which is a symlink to the actual file)
# N.B: It's Zeit that will perform the actual deployment
start-production-deployment:
name: Starts Zeit deployment (production) (Ubuntu 18.04)
Expand All @@ -45,30 +45,30 @@ jobs:
- uses: actions/checkout@v1 # Get last commit pushed - XXX See https://github.com/actions/checkout
- name: Deploying on Zeit (production)
# Workflow overview:
# - Resolve customer to deploy from github event input (falls back to resolving it from now.json file)
# - Resolve customer to deploy from github event input (falls back to resolving it from vercel.json file)
# - Deploy the customer in production
# XXX You can use https://jqplay.org/ if you want to play around with "jq" to manipulate JSON
run: |
# Print the version of the "now" CLI being used (helps debugging)
now --version
# Print the version of the "vercel" CLI being used (helps debugging)
vercel --version
# Resolving customer to deploy based on the github event input, when using manual deployment triggerer through "workflow_dispatch" event
# Falls back to the customer specified in the now.json file, which is most useful when deployment is triggered through "push" event
# Falls back to the customer specified in the vercel.json file, which is most useful when deployment is triggered through "push" event
MANUAL_TRIGGER_CUSTOMER="${{ github.event.inputs.customer}}"
echo "MANUAL_TRIGGER_CUSTOMER: " $MANUAL_TRIGGER_CUSTOMER
CUSTOMER_REF_TO_DEPLOY="${MANUAL_TRIGGER_CUSTOMER:-$(cat now.json | jq --raw-output '.build.env.NEXT_PUBLIC_CUSTOMER_REF')}"
CUSTOMER_REF_TO_DEPLOY="${MANUAL_TRIGGER_CUSTOMER:-$(cat vercel.json | jq --raw-output '.build.env.NEXT_PUBLIC_CUSTOMER_REF')}"
echo "Customer to deploy: " $CUSTOMER_REF_TO_DEPLOY
# Deploy the customer on Vercel using the customer specified in now.json
# Deploy the customer on Vercel using the customer specified in vercel.json
CUSTOMER_REF=${CUSTOMER_REF_TO_DEPLOY} yarn deploy:customer:production:simple --token $ZEIT_TOKEN
# Find all custom aliases configured in the customer deployment configuration file (now.json)
ZEIT_DEPLOYMENT_ALIASES_JSON=$(cat now.$CUSTOMER_REF_TO_DEPLOY.production.json | jq --raw-output '.alias')
# Find all custom aliases configured in the customer deployment configuration file (vercel.json)
ZEIT_DEPLOYMENT_ALIASES_JSON=$(cat vercel.$CUSTOMER_REF_TO_DEPLOY.production.json | jq --raw-output '.alias')
echo "Custom aliases: " $ZEIT_DEPLOYMENT_ALIASES_JSON
# Convert the JSON array into a bash array - See https://unix.stackexchange.com/a/615717/60329
readarray -t ZEIT_DEPLOYMENT_ALIASES < <(jq --raw-output '.alias[]' < now.$CUSTOMER_REF_TO_DEPLOY.production.json)
readarray -t ZEIT_DEPLOYMENT_ALIASES < <(jq --raw-output '.alias[]' < vercel.$CUSTOMER_REF_TO_DEPLOY.production.json)
# Count the number of element in the array, will be 0 if it's an empty array, or if the "alias" key wasn't defined
ZEIT_DEPLOYMENT_ALIASES_COUNT=${#ZEIT_DEPLOYMENT_ALIASES[@]}
Expand All @@ -80,12 +80,12 @@ jobs:
# For each alias configured, then assign it to the deployed domain
for DEPLOYMENT_ALIAS in "${ZEIT_DEPLOYMENT_ALIASES[@]}"; do
echo "npx now alias "$ZEIT_DEPLOYMENT_URL $DEPLOYMENT_ALIAS
npx now alias $ZEIT_DEPLOYMENT_URL $DEPLOYMENT_ALIAS --token $ZEIT_TOKEN || echo "Aliasing failed for '$DEPLOYMENT_ALIAS', but the build will continue regardless."
echo "npx vercel alias "$ZEIT_DEPLOYMENT_URL $DEPLOYMENT_ALIAS
npx vercel alias $ZEIT_DEPLOYMENT_URL $DEPLOYMENT_ALIAS --token $ZEIT_TOKEN || echo "Aliasing failed for '$DEPLOYMENT_ALIAS', but the build will continue regardless."
done
else
# $ZEIT_DEPLOYMENT_ALIASES is null, this happens when it was not defined in the now.json file
echo "There are no more aliases to configure. You can add more aliases from your now.json 'alias' property. See https://vercel.com/docs/configuration?query=alias%20domain#project/alias"
# $ZEIT_DEPLOYMENT_ALIASES is null, this happens when it was not defined in the vercel.json file
echo "There are no more aliases to configure. You can add more aliases from your vercel.json 'alias' property. See https://vercel.com/docs/configuration?query=alias%20domain#project/alias"
echo "$ZEIT_DEPLOYMENT_ALIASES"
fi
env:
Expand All @@ -103,9 +103,9 @@ jobs:
- uses: actions/checkout@v1 # Get last commit pushed - XXX See https://github.com/actions/checkout
- name: Resolving deployment url from Zeit
# Workflow overview:
# - Resolve customer to deploy from github event input (falls back to resolving it from now.json file)
# - Resolve customer to deploy from github event input (falls back to resolving it from vercel.json file)
# - Resolve $ZEIT_DEPLOYMENT_URL
# - Fetch all deployments data (by using the scope in `now.json`)
# - Fetch all deployments data (by using the scope in `vercel.json`)
# - Resolve the last url (from `response.deployments[0].url`)
# - Remove the `"` character to pre-format url
# We need to set env the url for next step, formatted as `https://${$ZEIT_DEPLOYMENT}`
Expand All @@ -117,17 +117,17 @@ jobs:
echo "MANUAL_TRIGGER_CUSTOMER: " $MANUAL_TRIGGER_CUSTOMER
echo "MANUAL_TRIGGER_CUSTOMER=$MANUAL_TRIGGER_CUSTOMER" >> $GITHUB_ENV
CUSTOMER_REF_TO_DEPLOY="${MANUAL_TRIGGER_CUSTOMER:-$(cat now.json | jq --raw-output '.build.env.NEXT_PUBLIC_CUSTOMER_REF')}"
CUSTOMER_REF_TO_DEPLOY="${MANUAL_TRIGGER_CUSTOMER:-$(cat vercel.json | jq --raw-output '.build.env.NEXT_PUBLIC_CUSTOMER_REF')}"
echo "Customer that was deployed: " $CUSTOMER_REF_TO_DEPLOY
echo "CUSTOMER_REF_TO_DEPLOY=$CUSTOMER_REF_TO_DEPLOY" >> $GITHUB_ENV
# Resolve Vercel team ID
VERCEL_TEAM_ID=`cat now.$CUSTOMER_REF_TO_DEPLOY.production.json | jq --raw-output '.scope'`
VERCEL_TEAM_ID=`cat vercel.$CUSTOMER_REF_TO_DEPLOY.production.json | jq --raw-output '.scope'`
echo "Vercel team ID: " $VERCEL_TEAM_ID
echo "VERCEL_TEAM_ID=$VERCEL_TEAM_ID" >> $GITHUB_ENV
# Resolve Vercel project name
VERCEL_PROJECT_NAME=`cat now.$CUSTOMER_REF_TO_DEPLOY.production.json | jq --raw-output '.name'`
VERCEL_PROJECT_NAME=`cat vercel.$CUSTOMER_REF_TO_DEPLOY.production.json | jq --raw-output '.name'`
echo "Vercel project name: " $VERCEL_PROJECT_NAME
echo "VERCEL_PROJECT_NAME=$VERCEL_PROJECT_NAME" >> $GITHUB_ENV
Expand Down Expand Up @@ -183,9 +183,9 @@ jobs:
- uses: actions/checkout@v1 # Get last commit pushed - XXX See https://github.com/actions/checkout
- name: Resolving deployment url from Zeit
# Workflow overview:
# - Resolve customer to deploy from github event input (falls back to resolving it from now.json file)
# - Resolve customer to deploy from github event input (falls back to resolving it from vercel.json file)
# - Resolve $ZEIT_DEPLOYMENT_URL
# - Fetch all deployments data (by using the scope in `now.json`)
# - Fetch all deployments data (by using the scope in `vercel.json`)
# - Resolve the last url (from `response.deployments[0].url`)
# - Remove the `"` character to pre-format url
# We need to set env the url for next step, formatted as `https://${$ZEIT_DEPLOYMENT}/en` using /en endpoint to improve perfs by avoiding the url redirect on /
Expand All @@ -197,17 +197,17 @@ jobs:
echo "MANUAL_TRIGGER_CUSTOMER: " $MANUAL_TRIGGER_CUSTOMER
echo "MANUAL_TRIGGER_CUSTOMER=$MANUAL_TRIGGER_CUSTOMER" >> $GITHUB_ENV
CUSTOMER_REF_TO_DEPLOY="${MANUAL_TRIGGER_CUSTOMER:-$(cat now.json | jq --raw-output '.build.env.NEXT_PUBLIC_CUSTOMER_REF')}"
CUSTOMER_REF_TO_DEPLOY="${MANUAL_TRIGGER_CUSTOMER:-$(cat vercel.json | jq --raw-output '.build.env.NEXT_PUBLIC_CUSTOMER_REF')}"
echo "Customer that was deployed: " $CUSTOMER_REF_TO_DEPLOY
echo "CUSTOMER_REF_TO_DEPLOY=$CUSTOMER_REF_TO_DEPLOY" >> $GITHUB_ENV
# Resolve Vercel team ID
VERCEL_TEAM_ID=`cat now.$CUSTOMER_REF_TO_DEPLOY.production.json | jq --raw-output '.scope'`
VERCEL_TEAM_ID=`cat vercel.$CUSTOMER_REF_TO_DEPLOY.production.json | jq --raw-output '.scope'`
echo "Vercel team ID: " $VERCEL_TEAM_ID
echo "VERCEL_TEAM_ID=$VERCEL_TEAM_ID" >> $GITHUB_ENV
# Resolve Vercel project name
VERCEL_PROJECT_NAME=`cat now.$CUSTOMER_REF_TO_DEPLOY.production.json | jq --raw-output '.name'`
VERCEL_PROJECT_NAME=`cat vercel.$CUSTOMER_REF_TO_DEPLOY.production.json | jq --raw-output '.name'`
echo "Vercel project name: " $VERCEL_PROJECT_NAME
echo "VERCEL_PROJECT_NAME=$VERCEL_PROJECT_NAME" >> $GITHUB_ENV
Expand Down
Loading

0 comments on commit 7388ea4

Please sign in to comment.