Skip to content

Website build on commit #58

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

Closed
rvagg opened this issue Feb 22, 2015 · 29 comments
Closed

Website build on commit #58

rvagg opened this issue Feb 22, 2015 · 29 comments

Comments

@rvagg
Copy link
Member

rvagg commented Feb 22, 2015

cc @iojs/website

Currently we are using github-webhook with the following configuration on the server:

{
  "port": 9999,
  "path": "/webhook",
  "secret": "orly?",
  "log": "/home/iojs/github-webhook.log",
  "rules": [{
    "event": "push",
    "match": "ref == \"refs/heads/master\" && repository.full_name == \"iojs/website\"",
    "exec": "cd /home/iojs/website.github/ && git reset --hard && git clean -fdx && git fetch origin && git checkout origin/master && rsync -avz --delete --exclude .git /home/iojs/website.github/public/ /home/iojs/www/"
  }]
}

i.e. the "build" process is:

  1. in the existing clone of iojs/website, do a reset and clean
  2. fetch from origin
  3. checkout origin/master
  4. rsync the ./public/ directory of the repo into the live site directory

What I want to suggest we add is a build step in between 3 and 4 here, but it needs to be done inside a container so we don't give free reign for code in the website repo to run on the server.

Something like this:

docker pull iojs:latest && \
docker run \
  --rm \
  -v /home/iojs/website.github/:/website/ \
  -v /home/iojs/.npm:/npm/ \
  iojs:latest \
  bash -c " \
    adduser iojs --gecos iojs --disabled-password && \
    su iojs -c ' \
      npm config set loglevel http && \
      npm config set cache /npm/ && \
      cd /website/ && \
      npm install && \
      node_modules/.bin/gulp build \
    ' \
  "

I've just run this and it seems to work fine and I could enable it right now if that's suitable to the website team.

Note for build team (@kenperkins in particular) our Ansible script for the website needs an initial git clone of iojs/website to /home/iojs/website.github/, I don't think we are doing that currently. The above command will also need /home/iojs/.npm/ to be made and owned by iojs.

@kenperkins
Copy link

@Fishrock123
Copy link
Contributor

Would we have access to the releases.json from inside the gulp build with this? (I assume not.) We might need to have it sync the json into the build container before build.

@rvagg
Copy link
Member Author

rvagg commented Feb 23, 2015

Yep, can do, how about we copy it in to the root of the project directory and name it releases.json, would that do? Of course you could just pull it from the website during build too and that way the build is portable.

@therebelrobot
Copy link

+1 to that @rvagg. That would make it simplistic to pull into gulp build. @Fishrock123 so long as the releases.json is up to date, that would work for dynamic linking to the latest, shouldn't it?

@snostorm
Copy link
Contributor

+1 to just pulling it down via HTTP (with a local fallback, perhaps), although if we do "inject it" I'd prefer to overwrite it at source/releases.json before the build runs.

This way this publish script can also be triggered when new versions hit the web.

How long would this take to switch over? I'm all for the change happening any time.

@rvagg
Copy link
Member Author

rvagg commented Mar 13, 2015

What I might do is put the above script into a stand-alone file so it can be run by the webhook and also as a result of an update to index.json, so the site gets rebuilt when you push new stuff and when there's new stuff available to it.

How about I set up a test version of this so you can play with it first and then we can go live later. Will try and do it this weekend.

@snostorm
Copy link
Contributor

I'll try to prep a proof-of-concept of using https://iojs.org/dist/index.json for version numbers, download links, etc. when I get a chance. I have an unrelated PR in queue which should make this pretty easy to switch over.

Tracking on nodejs/iojs.org#284

@rvagg
Copy link
Member Author

rvagg commented Mar 13, 2015

let's use a test branch on iojs/website, maybe actually call it "test" and we can webhook/pull from that instead of master for testing purposes

@snostorm
Copy link
Contributor

Sure. Should we wait for the "new stuff" or just test randomly as-is without the new .json hooks?

Edit: I guess we can do "both". Start with the current master, then push the new stuff when ready, and see if it all works as expected :)

@rvagg
Copy link
Member Author

rvagg commented Mar 13, 2015

yes, both!

@snostorm
Copy link
Contributor

Looks like I need to destroy an old "test" branch first, ha. Edit: done. Master === Test

@snostorm
Copy link
Contributor

nodejs/iojs.org#287 is now sitting on https://github.com/iojs/website/tree/test

It'll generate a releases.html from the latest https://iojs.org/dist/index.json as well as using it to power the version info seen throughout the site.

@snostorm
Copy link
Contributor

Is there going to be a domain where we can see the site running from the test branch?

nodejs/iojs.org#291 is now the latest PR for this work.

@rvagg
Copy link
Member Author

rvagg commented Mar 22, 2015

/cc @kenperkins

/etc/github-webhook.json now contains a line for the test branch of the website:

      "event": "push",
      "match": "ref == \"refs/heads/test\" && repository.full_name == \"iojs/website\"",
      "exec": "/home/iojs/build-site.sh"

and /home/iojs/build-site.sh looks like this:

#!/bin/bash

set -e

pidof -s -o '%PPID' -x $(basename $0) > /dev/null 2>&1 && \
  echo "$(basename $0) already running" && \
  exit 1

cd /home/iojs/website.github.test
git reset --hard
git clean -fdx
git fetch origin
git checkout origin/test

docker pull iojs:latest
docker run \
  --rm \
  -v /home/iojs/website.github.test/:/website/ \
  -v /home/iojs/.npm:/npm/ \
  iojs:latest \
  bash -c " \
    addgroup iojs --gid 1000 && \
    adduser iojs --uid 1000 --gid 1000 --gecos iojs --disabled-password && \
    su iojs -c ' \
      npm config set loglevel http && \
      npm config set cache /npm/ && \
      cd /website/ && \
      npm install && \
      node_modules/.bin/gulp build \
    ' \
  "

rsync -avz --delete --exclude .git /home/iojs/website.github.test/public/ /home/iojs/www.test/

There is also a new line in /etc/crontab:

*  *    * * *   iojs    /home/iojs/check-build-site.sh

And /home/iojs/check-build-site.sh is:

#!/bin/bash

indexjson=/home/dist/public/release/index.json
indexhtml=/home/iojs/www.test/en/index.html
buildsite=/home/iojs/build-site.sh

[ $indexjson -nt $indexhtml ] && $buildsite

(Note the hardwiring of en/index.html, this is a little unfortunate and brittle.)

There's also an nginx site setup for test.iojs.org on the same host that uses /home/iojs/www.test/ as the docroot so stick this in your /etc/hosts and you'll pick it up:

104.236.136.193 test.iojs.org

i.e. pushing to the test branch on the website repo or creating a new release will now check out website/test and run the full npm install and gulp build process. You just need to be patient because the dep tree is nontrivial and takes a while to install, so give it a minute or so.

@snostorm you can give it a go now if you want to push any changes to test to see if they build properly.

@snostorm
Copy link
Contributor

Thanks @rvagg, everything sounds great. I have a push (hopefully) generating right now. Minor change where I lined up some out of date content (i18n mostly) between test..master.

I'll try to sneak in a build change which adds a copy of the en/index.html to /index.html. Awkward indeed.

@snostorm
Copy link
Contributor

so give it a minute or so

How long should we expect? Like 10+ minutes?. If so, things might be working as expected (it has been about that long.) If shorter, then it was a no-go on the auto push working.

Sanity checks:

I'll check back later myself to see if it finished.

@rvagg
Copy link
Member Author

rvagg commented Mar 23, 2015

@snostorm you pushed to the test branch?

@rvagg
Copy link
Member Author

rvagg commented Mar 23, 2015

should only be ~1 min, the time it takes to npm install and grunt blahblah, pretty fast but the dep list is massive (typical node app, sheesh!)

@snostorm
Copy link
Contributor

Hmm. https://github.com/iojs/website/blob/test/public/es/index.html#L29 is confirming the changes I'm looking for but not showing on the test subdomain. I can try a 2nd push.

@snostorm
Copy link
Contributor

"Test" is now at nodejs/iojs.org@8750053 ... verifiable by view source and seeing if <!DOCTYPE html> is lowercase. Still waiting as before.

@rvagg
Copy link
Member Author

rvagg commented Mar 24, 2015

@snostorm it looks correct to me .. can you double-check for me and maybe test some more? It could also be that I promoted the armv6l build of 1.6.2 which should have triggered a build too.

I'll leave it to you to make a call on whether this is solid enough to move to the next step and do master

@snostorm
Copy link
Contributor

No go still. I did a test ~14 hours ago, just remembered to check on it. Looks like the Github hook isn't quite working.

@snostorm
Copy link
Contributor

Any luck confirming the lack of build-on-push? FYI the build code of test is also in master now. Maybe we should try our luck targeting iojs/website#master vs #test?

@rvagg
Copy link
Member Author

rvagg commented Mar 31, 2015

figured it out -- github-webhook uses exec() and it was spewing way too much data to buffer and blowing the maxBuffer, so I've switched to spawn() and am streaming stdout and stderr to the log file now. the test branch appears to be working on commit now at least!

@snostorm
Copy link
Contributor

Great. I saw on the 1.6.3 release this is now live for master as well? Hurray for less "published public" type commits.

@Fishrock123
Copy link
Contributor

So where is iojs.org currently coming from? The test branch?

@rvagg
Copy link
Member Author

rvagg commented Mar 31, 2015

master, I turned off the test stuff completely, you can delete that branch in fact

@rvagg rvagg closed this as completed Mar 31, 2015
@Fishrock123
Copy link
Contributor

hmmm, the website isn't updating after the 1.6.4 release..

@rvagg
Copy link
Member Author

rvagg commented Apr 6, 2015

a previous build was blocking it, I had to manually kill it but it was paused somewhere in the build process -- perhaps in the gulp build? I'm manually running the build again now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants