Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deploy #15

Merged
merged 1 commit into from
Sep 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ jobs:
key: v1-dependencies-{{ .Branch }}-{{ checksum "yarn.lock" }}
- deploy:
command: |
npm run deploy -- -e SENTRY_DSN=$SENTRY_DSN --token=$NOW_TOKEN &>/dev/null
npm run deployment:pop
./node_modules/.bin/now --public -e NODE_ENV=production -e SENTRY_DSN=$SENTRY_DSN -n moci --no-clipboard --token=$NOW_TOKEN
if [ "${CIRCLE_BRANCH}" == "master" ]; then
npm run alias -- --token=$NOW_TOKEN &>/dev/null
npm run delete
npm run deployment:delete
DATA=\{\"text\":\"mo\ has\ been\ updated\ \<https://moci.now.sh/\>\"\}; curl -XPOST -d $DATA $SLACK_WEBHOOK_URL
fi
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"dev": "node server",
"prebuild": "npm run clean:build",
"build": "next build",
"deploy": "now --public -e NODE_ENV=production -n moci --no-clipboard",
"deployment:pop": "node ./scripts/deployment-pop",
"deployment:delete": "node ./scripts/deployment-delete",
"alias": "now alias --no-clipboard",
"delete": "node ./scripts/deployment-delete",
"start": "node ./server"
},
"repository": {
Expand Down
1 change: 1 addition & 0 deletions scripts/deployment-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const main = async () => {
console.log(`Success!

${targets.map(t => `Deployment ${t.uid} removed`).join('\n')}

`)
return
}
Expand Down
22 changes: 22 additions & 0 deletions scripts/deployment-pop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const NowClient = require('now-client')

const now = new NowClient(process.env.NOW_TOKEN)

const main = async () => {
const deployments = await now.getDeployments()
if (deployments.length >= 3) { // upper limit for free plan
const aliases = await now.getAliases()
const mociId = (aliases.find(a => a.alias === 'moci.now.sh') || {}).deploymentId
const target = deployments.filter(d => d.uid !== mociId).pop()
await now.deleteDeployment(target.uid)
console.log(`Success!

Deployment ${target.uid} removed

`)
} else {
console.log('Does not require delete.')
}
}

main()