From a162d31d46ebf89787ffef403998ff1067886439 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 20 Mar 2015 12:04:01 +0000 Subject: [PATCH] Alternative dev workflow based on Docker. Merge this as soon as we publish google/webfundamentals-dev Docker image. --- .dockerignore | 14 ++++++++++++++ Dockerfile | 28 +++++++++++++++++++++++++++ Gruntfile.js | 16 ++++++++++++++-- README.md | 35 ++++++++++++++++++++++++++++++++++ src/_plugins/include_code.rb | 2 +- src/_plugins/sample_builder.rb | 2 +- tools/docker.sh | 25 ++++++++++++++++++++++++ 7 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 tools/docker.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000000..468e48654b2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +.git +.sass-cache +.editorconfig +.gitignore +.ruby-version +.travis.yml +node_modules +tools +src +appengine/build +Dockerfile +LICENSE +Makefile +*.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..014c486db02 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM node:0.10 + +RUN apt-get update && apt-get install -y ruby ruby-dev bundler fontforge ttfautohint + +ENV CLOUDSDK_CORE_DISABLE_PROMPTS=1 +ENV CLOUDSDK_PYTHON_SITEPACKAGES=1 + +ADD https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz / +RUN tar xzf google-cloud-sdk.tar.gz + +RUN /google-cloud-sdk/install.sh +RUN /google-cloud-sdk/bin/gcloud config set component_manager/fixed_sdk_version 0.9.48 +RUN /google-cloud-sdk/bin/gcloud components update app -q + +ADD . /wf/ +WORKDIR /wf + +RUN bundle install +RUN npm install || ( cat /wf/npm-debug.log && exit 1 ) +RUN npm install -g grunt-cli + +ENV PATH=/google-cloud-sdk/platform/google_appengine:$PATH +ENV DOCKER=1 + +VOLUME /wf/src +VOLUME /wf/appengine/build + +CMD /bin/bash diff --git a/Gruntfile.js b/Gruntfile.js index bae554b90c9..505bfd6a05e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,6 +4,7 @@ 'use strict'; var LIVERELOAD_PORT = 35729; +var SERVER_HOST = process.env.DOCKER ? '0.0.0.0' : 'localhost'; module.exports = function(grunt) { @@ -74,6 +75,7 @@ module.exports = function(grunt) { } }, + /*jshint camelcase: false */ gae: { options: { path: 'appengine', @@ -88,7 +90,9 @@ module.exports = function(grunt) { async: true, asyncOutput: true, args: { - port: config.port + host: SERVER_HOST, + port: config.port, + skip_sdk_update_check: true } } }, @@ -96,6 +100,7 @@ module.exports = function(grunt) { action: 'kill' } }, + /*jshint camelcase: true */ htmlmin: { all: { @@ -246,7 +251,7 @@ module.exports = function(grunt) { if (((release === undefined) && (err === undefined)) || (err)) { grunt.log.write('Failed to retrieve latest web-starter-kit release '); grunt.log.writeln('information - using wsk-version.json.'); - + release = grunt.file.readJSON(out, {'encoding': 'utf8'}); } else { grunt.file.write(out, JSON.stringify(release, null, 2)); @@ -341,6 +346,13 @@ module.exports = function(grunt) { 'watch' ]); + // Develop task for docker-based env + grunt.registerTask('develop-no-open', 'The default task for developers.\nRuns the tests, builds the minimum required, serves the content and watches for changes.\nDoes not open URL.', [ + 'build', // Build the site with Jekyll + 'gae:local', + 'watch' + ]); + // Devsite task grunt.registerTask('devsite', 'Runs the build steps with devsite config', [ 'clean:icons', // Clean up icon font files for regeneration diff --git a/README.md b/README.md index 2c4a07be090..f8020d4fafd 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,41 @@ On Mac, due to the number of files in the project, you will likely need to incre If you want to build a single language then run this: `grunt develop --lang=en`. +Alternative dev workflow based on Docker +======================================== + +In this configuration the only requirement is [Docker](https://docs.docker.com/installation/). + +Once you clone this repo, start building the site right away: + +```sh +tools/docker.sh grunt build +``` + +or run a local dev server: + +```sh +tools/docker.sh grunt develop +# then point your browser to http://localhost:8081/web/fundamentals +``` + +Essentially, prefix `grunt` command with `tools/docker.sh` and it will run inside a Docker container, +which includes all the dependencies needed to build the site. + +If you want to experiment with your own Docker image instead of using `google/webfundamentals-dev`, +modify `Dockerfile` in the root of this repo and build your image: + +```sh +docker build -t myimage . +``` + +Once the image is built, use it with `tools/docker.sh`: + +```sh +WF_DOCKER_IMAGE=myimage tools/docker.sh grunt develop +``` + + Using project-level meta data ============================= diff --git a/src/_plugins/include_code.rb b/src/_plugins/include_code.rb index 92a2f0f48e7..68d03e85bdb 100644 --- a/src/_plugins/include_code.rb +++ b/src/_plugins/include_code.rb @@ -96,7 +96,7 @@ def render(context) filepath.sub!("_langs/" + lang + "/", "_langs/en/") end String file = File.join(path, filepath) - contents = File.read(file) + contents = File.read(file).force_encoding('UTF-8') snippet = getmatch(contents, @lang, @section) @@comment_formats.each do |lang, parms| match = getmatcher_tag(lang, "[^\\]]+", "\\w+") diff --git a/src/_plugins/sample_builder.rb b/src/_plugins/sample_builder.rb index a860b20b3a5..facc11819e0 100644 --- a/src/_plugins/sample_builder.rb +++ b/src/_plugins/sample_builder.rb @@ -115,7 +115,7 @@ def initialize(site, sourcepath, dir, section) end def contents() - contents = File.read(@sourcepath) + contents = File.read(@sourcepath).force_encoding('UTF-8') contents.gsub!(/\s*\n?/m, "\n") contents.gsub!(/\/\* \/\/ \[(?:(?:START)|(?:END)) [^\]]+\] \*\/\s*\n?/m, "\n") contents.gsub!(/\s*\n/m) { |matches| diff --git a/tools/docker.sh b/tools/docker.sh new file mode 100755 index 00000000000..687ffffb2aa --- /dev/null +++ b/tools/docker.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +image=${WF_DOCKER_IMAGE:-google/webfundamentals-dev} +cmd=$1 +action=$2 +if [[ "$cmd" = "grunt" && "$action" = "develop" ]]; then + action="develop-no-open" +fi +# remove $cmd and $action from $@ +shift +shift + +args="-v $(pwd)/src:/wf/src -v $(pwd)/appengine/build:/wf/appengine/build" +if [[ "$action" = develop* ]]; then + args="$args -p 8081:8081 -p 35729:35729" +fi + +docker run -ti --rm $args $image $cmd $action "$@" + +# revert ownership of files generated by root within the container +if [ "$cmd" = "grunt" ]; then + owner=$(id -ru):$(id -rg) + docker run --rm $args $image chown -R $owner /wf/appengine/build /wf/src/icons +fi +