Skip to content

Commit

Permalink
Alternative dev workflow based on Docker.
Browse files Browse the repository at this point in the history
Merge this as soon as we publish google/webfundamentals-dev Docker
image.
  • Loading branch information
x1ddos committed Mar 20, 2015
1 parent 4cfb13c commit a162d31
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 4 deletions.
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.git
.sass-cache
.editorconfig
.gitignore
.ruby-version
.travis.yml
node_modules
tools
src
appengine/build
Dockerfile
LICENSE
Makefile
*.md
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
16 changes: 14 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -74,6 +75,7 @@ module.exports = function(grunt) {
}
},

/*jshint camelcase: false */
gae: {
options: {
path: 'appengine',
Expand All @@ -88,14 +90,17 @@ module.exports = function(grunt) {
async: true,
asyncOutput: true,
args: {
port: config.port
host: SERVER_HOST,
port: config.port,
skip_sdk_update_check: true
}
}
},
stop: {
action: 'kill'
}
},
/*jshint camelcase: true */

htmlmin: {
all: {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============================

Expand Down
2 changes: 1 addition & 1 deletion src/_plugins/include_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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+")
Expand Down
2 changes: 1 addition & 1 deletion src/_plugins/sample_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!(/<!-- \/\/ \[(?:(?:START)|(?:END)) [^\]]+\] -->\s*\n?/m, "\n")
contents.gsub!(/\/\* \/\/ \[(?:(?:START)|(?:END)) [^\]]+\] \*\/\s*\n?/m, "\n")
contents.gsub!(/<!-- \/\/ \[TEMPLATE ([^\]]+)\] -->\s*\n/m) { |matches|
Expand Down
25 changes: 25 additions & 0 deletions tools/docker.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a162d31

Please sign in to comment.