Pergunta

Estou criando um serviço da web e quero armazenar a fonte no Github e executar o aplicativo no Heroku. Eu não vi meu cenário exato abordado em qualquer lugar da rede até agora, então vou perguntar aqui:

Eu quero ter a seguinte estrutura de diretório:

/project
  .git
  README <-- project readme file
  TODO.otl <-- project outline
  ... <-- other project-related stuff
  /my_rails_app
     app
     config
     ...
     README <-- rails' readme file 

No exposto, o projeto corresponde a http://github.com/myuser/project, e my_rails_app é o código que deve ser empurrado para o Heroku. Preciso de uma filial separada para o aplicativo Rails ou existe uma maneira mais simples que estou perdendo?

Eu acho que meus arquivos não relacionados a projetos poderiam viver em my_rails_app, mas o Rails Readme já vive lá e parece inconsistente substituir isso. No entanto, se eu deixar, minha página do Github para o aplicativo Rails conterá o Rails Readme, o que não faz sentido.

Além disso ... tentei apenas configurá -lo como descrito acima e executando

git push heroku

Na pasta principal do projeto. Claro, Heroku não sabe que eu quero implantar a subpasta:

-----> Heroku receiving push
 !     Heroku push rejected, no Rails or Rack app detected.
Foi útil?

Solução

Here's a simple solution that may or may not work for you.

  • Create two projects on GitHub. One project should be just the Rails app (i.e. everything inside the Rails app directory). The other project should be everything outside the Rails app directory.

  • Add the Rails app project as a git-submodule within the "container" project.

  • Now you can add Heroku as a remote on the Rails app repository separately and push it to heroku. Heroku will accept the push because it is just a Rails app with the expected directories and files.

Outras dicas

A solution for the Heroku situation (not the README file):

If you're using the new Heroku Cedar (I believe it wasn't available when you first asked your question) then your processes (like the rails server process) start up using Foreman. Thus, you can place a Procfile in the root github directory that looks like this:

web:     my_rails_app/script/runserver.sh

And then my_rails_app/script/runserver.sh could be a simple

#!/bin/sh

cd my_rails_app
bundle exec rails server -p $PORT

Locally, you should also create a file called .env (note the . at the beginning), which contains

PORT=3000

This file is read by foreman and used to set environment variables so that the port is set when you execute foreman start on your machine (from the root github directory, where the Procfile lies). The Heroku server takes care of the .env file on your dyno. The big advantage is you can set up multiple processes on the dyno that way!

Just overwrite Rails' default README file. There's no reason to keep it around. Put your other project-management-related stuff in the doc directory. While you certainly have valid reasons for wanting to set it up the way you did, you're just creating a headache for yourself by going against convention, and it's probably not worth the benefit.

I would add everything underneath /my_rails_app to the Heroku git repository. Then add GitHub as a remote and add everything underneath /project to the GitHub repository. Then you can push the Rails application to Heroku (from /my_rails_app) and push the full project to GitHub (from /project).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top