Closed lukekarrys closed 8 years ago
This makes a lot of sense, thanks for all the details! Is --token
the most likely name you’d expect for the flag? Also, if you don’t mind me asking, what CI services would you anticipate using this with, just so we can look into any possible nuances?
--token
is what I'd expect, but that's mostly based on using divshot-cli
for similar things in the past and that's the name it uses.
I'm using Codeship currently for CI/CD. They allow for setting environment variables and then using them in deploy scripts like this:
Also will there need to be commands to create tokens and deauth existing tokens? Or would they just need to be grabbed from the existing .netrc
file?
Yes I also need this, CI/CD is so important in a workflow today! I personally use Wercker which uses a wercker.yml file. In the Wercker UI, I can set an environment variable and use it in the deploy script, just like @lukekarrys, this way:
box: wercker/nodejs
build:
steps:
- npm-install
- npm-test
- script:
name: build
code: npm run build
- script:
name: copy build to the to-be-deployed directory
code: cp -a ./dist/. $WERCKER_OUTPUT_DIR
deploy:
steps:
- script:
name: push to surge
code: surge ./ mydomain.com --token $SURGE_TOKEN
:+1:
:+1:
Yes, this would be hugely beneficial! I primarily use Travis CI - you encrypt your environment variables locally using github_username/reponame
as a key and add them to your .travis.yml
file as secure
(example) or via their UI.
--token
seems as good a name as any.
I'm also using Travis CI, --token
seems as reasonable as any name. This would be the killer feature for me, and would automate my entire workflow from git commit through to deployed.
I'm in agreement on this. I'll try to get this in one of the next iterations. Hopefully shortly. On Mar 14, 2015 3:04 PM, "Lewis Cowper" notifications@github.com wrote:
I'm also using Travis CI, --token seems as reasonable as any name. This would be the killer feature for me, and would automate my entire workflow from git commit through to deployed.
— Reply to this email directly or view it on GitHub https://github.com/sintaxi/surge/issues/63#issuecomment-80740751.
@kennethormandy didn't see this one, thanks. Seems like most CI providers allow you to privatise environment variables to enable this. I've been looking into Travis and Circle CI.
Relevant: https://circleci.com/docs/language-nodejs#npm-authentication
surge token
to generate a token, SURGE_TOKEN=mytoken surge
to use it.
An example Circle CI config:
deployment:
production:
branch: production
commands:
- NODE_ENV=production npm run build
- surge example.com
staging:
branch: master
commands:
- NODE_ENV=staging npm run build
- surge staging.example.com
Where SURGE_TOKEN
is set on Circle CI's website.
The process would need to exit 1 when that variable is present but invalid. It would result in an ugly timeout on the CI server otherwise.
Deploying to S3 with Travis: http://docs.travis-ci.com/user/deployment/s3/
Hey everyone!
Thanks to your feedback, you can now use environment variables and display your token ✨
🎓Update to the latest version of the Surge CLI by running:
npm install -g surge
surge token
We’ve also put together a guide on how to publish using Travis CI, I’d love to get your feedback on that. There’s also a companion example repository.
This kind of setup should also work with other CI services too, but we’ll be writing more guides soon.
:+1:
:ship: How to integrate Codeship is now live. There’s an example companion repo for that as well.
I’ll probably write Wercker and CircleCI guides as well since they’ve been mentioned. Let us know if there’s anything others you’d like to see how to use surge token
with.
Thanks @kennethormandy! This is really great.
I don't think it's necessary to deploy from the test commands in codeship, since it is already getting deployed through the deployment pipeline. I opened a PR on the repo in case it is a mistake https://github.com/surge-sh/example-codeship/pull/1
just tried this today, and got bash: line 1: surge: command not found
on circleCI
quite sure I have surge
in my package.json though…
changed the path to ./node_modules/.bin/surge
fixed it… hmm, odd that it's not available on CircleCI machine PATH
@constantx Interesting, I didn’t have to do that in the example I made, but it’s possible something about the environment is different? Does that project happen to be open source? I can see if I can reproduce the problem.
just standard environment as far as I can tell. The circle.yml
file is below:
deployment:
production:
branch: master
commands:
- grunt presurge
- surge --project ./dist --domain mydomain.com
what's odd is grunt
bin is in the PATH, but not surge
:)
@constantx I’ll investigate more, we might not be taking advantage of the bin
listing in the package.json
properly or something.
In the meantime, you could also make add the second command as an npm run script:
"deploy": "surge --project ./dist --domain mydomain.com"
…and update your circle.yml
file to this:
deployment:
production:
branch: master
commands:
- grunt presurge
- npm run deploy
Another alternative, since you’re already using Grunt, would be to use grunt-surge directly.
Thanks for reporting that!
:+1: thanks @kennethormandy
surge token does not exist in surge -h - should it?
@marvinroger @kennethormandy to get Wercker working I had to add an environment variables for $SURGE_LOGIN to my Wercker project settings. Here's my wercker.yml
for my Jekyll site:
# our build should run within a Ruby box
build:
box: phusion/passenger-ruby22
steps:
# Run a smart version of bundle install
# which improves build execution time of
# future builds
- bundle-install
# A custom script step
# that actually builds the jekyll site
- script:
name: generate site
code: bundle exec jekyll build --trace
- script:
name: copy build to the to-be-deployed directory
code: cp -a ./. $WERCKER_OUTPUT_DIR
deploy:
box: nodesource/trusty
steps:
- script:
name: NPM install
code: npm install -g surge
- npm-test
- script:
name: push to Surge.sh
code: surge _site/ <MYSITE>.surge.sh --token $SURGE_TOKEN
Works like a champ!
What should I do if it asks to login even after passing the token during call, and setting SURGE_LOGIN and SURGE_TOKEN in travis ?
Feature Request
I'd like the ability to run commands like
surge --project ./build
without being logged in. Other CLIs do this with some sort of token parameter so the command ends up beingsurge --project ./build --token ABC123
.This would be helpful when trying to deploy from CI/CD services where you'd want to use your token as an environment variable, and not have to deal with the multistep login process.