Archived Support Site

This support site is archived. You can view the old support discussions but you cannot post new discussions.

Pushing same site to separate environments

Normally the way I do my sites, I have a "dev" site and then the "production" site. This takes the form of:

http://d.foo.com/ (Dev)
http://foo.com/

I usually secure the dev site to only allow me access, I do this through Basic auth... in MVC it's hard to say, "restrict everything except the account controller," or at least I haven't found an easy way to do it, that's why I like the catch all authorization at the IIS level.

Can I do anything similar with AppHarbor? I definitely like the workflow but I also like to test my apps before I deploy them for all to see.

The only way I could do it right now (I think) is creating a new application, associating it with the relevant sub-domain (d.*), and adding that as an extra remote push. But I would then need some way of figuring out I am in dev and securing the site.

  1. There's an open request for this feature.

    In the meantime, using two AppHarbor applications is probably a good idea. You can discriminate between by development and production checking the host-header. You could also use AppHarbor AppSettings configuration-variable-replacement. You can configure these in the application interface.

    You could add an attribute to your controllers that determines whether requests are for the development site and require basic http auth if that is the case.

    Let us know if this works for you.

  2. Thanks, this approach seems to work albeit it does require some extra plumbing:

    1. Create second application (YourApp-Dev)
    2. Add a new remote to your repository: git remote add appharbor-d {your dev url}
    3. Associated it with a sub-domain or leave it as is
    4. In Configuration Variables, add RuntimeEnvironment and the value of D or some value indicating this is the staging environment.
    5. In your project, add the appSetting with the same key but a different value (e.g. L) to denote a localhost.
    6. Create a new derived Authorize attribute and attach it to your BaseController or a controller you'd like to be protected in dev:

      public class AuthorizeLocalAttribute : AuthorizeAttribute {
      private const string LOCAL = "L";
      private const string DEVELOPMENT = "D";
      private const string PRODUCTION = "P";
      
      protected override bool AuthorizeCore(HttpContextBase httpContext) {
          // Ignore all Account controller calls (Anonymous)
          if (httpContext.Request.RequestContext.RouteData.Values["controller"].ToSafeString() == "Account")
              return true;
      
          // Get runtime environment
          string runtimeEnvironment = ConfigurationManager.AppSettings["RuntimeEnvironment"];
      
          if (runtimeEnvironment == DEVELOPMENT) {
              return base.AuthorizeCore(httpContext);
          }
          else {
              return true;
          }
      }
      }
      

    Change it according to your needs. I might refactor into an Enum. In my main app, I set the variable to "P" to denote production... but I don't use it yet.

    To push to dev: git push appharbor-d master and to prod: git push appharbor master.

    I also added a line to skip authorization for the Account controller. This was important for me because otherwise my OpenID redirection didn't work (it still has an issue with the port numbers but that's for a different discussion).

    Hope this helps other people. I'd love to this baked into AppHarbor so I don't need to require code but this works and is fairly lightweight.

  3. PS. ToSafeString() is a simple extension: return value == null ? String.Empty : value.ToString().

    Use the attribute like:

    [AuthorizeLocal(Users = "My Admin ID")]
    public abstract class BaseController : Controller { }
    
  4. Cool, thanks for sharing. Is this something you would be interested in writing up for a blog post, either for your own blog or as a guest post on the AppHarbor blog?

  5. I just made one:

    http://kamranicus.com/Blog/Posts/2/befriending-appharbor-and-making...

    Hope that helps some people out!

  6. Perfect!, thanks.

  7. friism closed this discussion on 06 Apr, 2011 04:37 PM.

Discussions are closed to public comments.
If you need help with AppHarbor please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac