Myself and two other people have been working on reimplementing a
static site in nanoc. We're currently working in a shared virtual
host on our server on several shared git workspaces.
Next we need to do some integration testing combining the nanoc output
with that of the original static site content that has not been
converted yet.
Finally, we need to compile and integrate the site for the production release.
Any suggestions on how to deal with these multiple configurations,
development/sandbox, Q&A/staging and live/production?
Right now the only solution is to put config.yaml in the .gitignore
file which is not ideal as the file is mostly he same for all our
environments. The main differences between environments is the
base_url and images_url settings.
Maybe having nanoc load a config_local.rb or config_local_yaml would
allow overriding settings in config.yaml?
If a configuration override is a Ruby file, then at least in our case,
it could automatically determine the appropriate settings based on the
current directory and hostname.
Thanks,
-Bill
I don't have a lot of experience with managing multiple environments
with nanoc. There is only a single place where I have some support for
that and that is the deployment rake task, which is described at
<http://nanoc.stoneship.org/docs/6-guides/#deploying-sites>. I have
used multiple configurations quite often for the Myst Online site;
there was a separate "staging" site to where I'd publish the site to
ensure that everything was okay before pushing it to the live server,
and to allow other people to review the site before going live.
The Myst Online site also had a base_url and an assets_url setting,
and I had to change these before compiling and publishing, depending
on where I'd be publishing to. This was indeed a bit of a pain, and it
occasionally went wrong... What you could do, is edit
@config[:base_url] and @config[:assets_url] in the preprocess block
and let those two attributes depend on the environment, e.g.
ENV['nanoc_env']. It's still not a great solution, but it should make
compilation a bit more automated.
If you have suggestions for support for multiple environments in
nanoc, be sure to let me know. Share your ideas!
Denis
> --
> You received this message because you are subscribed to the nanoc discusssion group.
>
> To post to this group, send email to na...@googlegroups.com
> To unsubscribe from this group, send email to nanoc+un...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/nanoc
>
Hi,
I don't have a lot of experience with managing multiple environments
with nanoc. There is only a single place where I have some support for
that and that is the deployment rake task, which is described at
<http://nanoc.stoneship.org/docs/6-guides/#deploying-sites>. I have
used multiple configurations quite often for the Myst Online site;
there was a separate "staging" site to where I'd publish the site to
ensure that everything was okay before pushing it to the live server,
and to allow other people to review the site before going live.
The Myst Online site also had a base_url and an assets_url setting,
and I had to change these before compiling and publishing, depending
on where I'd be publishing to. This was indeed a bit of a pain, and it
occasionally went wrong... What you could do, is edit
@config[:base_url] and @config[:assets_url] in the preprocess block
and let those two attributes depend on the environment, e.g.
ENV['nanoc_env']. It's still not a great solution, but it should make
compilation a bit more automated.
If you have suggestions for support for multiple environments in
nanoc, be sure to let me know. Share your ideas!
Looks similar to / mergeable with the deployment options, no?
--
Damien Pollet
type less, do more [ | ] http://people.untyped.org/damien.pollet
On Thu, Dec 2, 2010 at 09:29, Bill Burton <bbu...@mail.com> wrote:Looks similar to / mergeable with the deployment options, no?
> One possibility may be to support an environments option in config.yaml like
> this:
There is no proper implementation for multiple environment yet, even though I do believe it would be useful.
There are a few important complications to take into account when implementing this. The one that jumps to mind right away is that nanoc uses certain caches to store compilation information so that compilation happens faster. These caches will need to be aware of different environments: cached content from environment X should not be reused in environment Y.
In addition to that, the deploy command may need to be updated to take environments into account as well, so that you don’t accidentally deploy a site compiled as “staging” to a location marked as “production”.
One easy but ugly way to achieve multiple environments is to use a NANOC_ENV variabl, then access it using ENV['NANOC_ENV'] and do conditional stuff based on that. During compilation you’d set the env var on the commandline, e.g. `nanoc co NANOC_ENV=production`. You should remove the tmp directory before compiling your site with a different environment though, because you’ll get incorrect results otherwise.
Denis
> --
> You received this message because you are subscribed to the nanoc discusssion group.
>
> To post to this group, send email to na...@googlegroups.com
> To unsubscribe from this group, send email to
> nanoc+un...@googlegroups.com
> For more options, visit this group at
maybe you can look at https://github.com/mkempe/nanoczzle, my personal
template based on nanoc3, which have simple environment support.
Or here are the steps for simple multiple environment support:
1. Add this to your config.yaml and set the assets_url in each
environment:
environment: development
development: &defaults
assets_url: /
test:
<<: *defaults
assets_url: http://www.foobar.com/
production:
<<: *defaults
assets_url: http://www.barfoo.com/
2. Add the following method to your helper.rb:
def url_for(item)
if item
environment = @site.config[:environment].to_sym # Get current
environment as symbol
return @site.config[environment] && @site.config[environment]
[:assets_url] ? File.join(@site.config[environment][:assets_url],
item) : item
end
end
3. Use the following helper in your templates / partials:
url_for('/foo.css')
url_for('/bar.css')
4. Change the environment in your config.yaml before you compile.
Done.
This approach will work because changing the config.yaml file causes all items to be recompiled. If you instead rely on an external source to determine the environment (e.g. an environment variable) this will not work, as nanoc will believe nothing has changed. In this case, you will need to manually recompile (remove tmp/ and compile).
Cheers,
Denis
Hi Denis,
We have been using nanoc for years for a very large site and are compiling to multiple environments using an environment variable as suggested. Aside from this being not very elegant, the main problem is that the cache in the tmp directory gets invalidated each time we switch environments and so compilation is taking a long time. We have extended nanoc quite heavily with scripts that pipe output through a spell checker, an HTML5 validator, curly quote fixer and more, and a full recompile means those all need to run again.
I'm looking at improving this by symlinking the tmp directory and output directory based on the environment variable, but it would be great if we could get full support for environments by having a cache that is separate for each environment and does not need to be invalidated each time.
Thanks for considering this.
-j
You received this message because you are subscribed to the Google Groups "nanoc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nanoc+un...@googlegroups.com.
To post to this group, send email to na...@googlegroups.com.
Visit this group at http://groups.google.com/group/nanoc.
For more options, visit https://groups.google.com/d/optout.
@Bill, That's an interesting approach, I may try to replicate that, thanks for sharing. We also build to two different directories but with a bit of a hack: the nanoc Rules file allows you to write to a relative path, so it writes to something like output/../output_production/... based on the environment variable which works but does not solve the issue with invalidating the tmp directory.
It seems that by adding two thing to nanoc we would have a simple fix:
- Add a --config option to nanoc to specify a non-default config file
- Add a new configuration option in the yaml file to specify the location of the tmp directory
I took a brief look at the code and it looks well organised enough that someone familiar with the code could do that in 30 minutes, but perhaps I'm overlooking something
@Dennis would this work? is this something that would be considered for inclusion?
A more elaborate fix would be to also allow you to specify a different Rules file in the config file so that you can apply different filters (Sass compression) but that works well enough with an environment variable.