2014-11-06 145 views
1

如何爲共享目錄中的Web應用程序創建單獨的Git存儲庫,以便通過GitHub將每個應用程序部署到生產環境? Web應用程序設置是常見的慣例,所以如果沒有辦法實現這一點,我感到很驚訝。通過GitHub將Web應用程序部署到生產

對於每個應用程序,索引文件和資產居住在各自的public_html目錄:

/home/user/public_html/app1 
/home/user/public_html/app2 
/home/user/public_html/app3 

每個網站的應用程序文件住在他們各自的上層目錄:

/home/user/app1 
/home/user/app2 
/home/user/app3 

那麼,運行git init有每個應用程序的回購?這裏是挑戰:

  1. git init"user"目錄將創建一個單一的回購爲 所有應用
  2. "/home/user/public_html/app1"git init不會 包括在"/home/user/app1""/home/user/app1"
  3. git init應用程序文件將不包括 指數和資產在"/home/user/public_html/app1"

注意:此問題被大量編輯爲使用非IIS術語,希望能更好地傳達問題。

+0

試試capistrano進行部署。 – 2014-11-28 10:14:19

回答

-1

所以從我得到的映射的想法是,它是這樣的:
一些fodlder
|
- > wwwroot文件
        |
        - >指數
           資產
|
- >的Inetpub

這樣的wwwroot和的Inetpub在同一個主文件夾
如果是這種情況,那麼你需要開始你的git的init在你的主文件夾(標記上方爲「某些文件夾」),如果有是你的「主文件夾」中的其他文件和文件夾,那麼你必須手動添加文件到你的提交,在這種情況下,如果你選擇做'git add wwwroot/assets/somepicture.png'(如果你選擇了「offcourse」 git add --all在這個建議的情況下,你會將主文件夾中的所有文件添加到你的提交中,所以這不會是最好的實踐。

0

我建議在/home/user/app1級別爲每個應用程序創建一個git存儲庫。然後在每個目錄中創建一個assets目錄。然後,您可以將符號鏈接/home/user/public_html/app1設置爲/home/user/app1/assets

+---home 
    +---user 
     +---app1 (git repo) 
     | +---assets 
     +---app2 (git repo) 
     | +---assets 
     +---public_html 
      +---app1 -> /home/user/app1/assets 
      +---app2 -> /home/user/app2/assets 

git存儲庫將包含您的應用程序和資產文件,但Web服務器仍然能夠訪問資產文件。

或者,您可以重新配置您的Web服務器以直接訪問assets目錄。

1

我認爲有3種方法可以做到這一點。第一個將使用git submodule。基本上,你在你的目錄/home/user中創建一個主存儲庫,這恰好是所有其他存儲庫等子模塊。在這種情況下,每個應用程序需要2個存儲庫,一個用於app_n,另一個用於public_html/app_n。檢查下面的示例說明2個應用:

#Create the repositories etc 
cd test && mkdir repositories && cd repositories 
mkdir app1 app2 public_html_app1 public_html_app2 
cd app1/ && git init && touch file && git add . && git commit -m "msg" && cd .. 
cd app2/ && git init && touch file && git add . && git commit -m "msg" && cd .. 
cd public_html_app1/ && git init && touch file && git add . && git commit -m "msg" && cd .. 
cd public_html_app2/ && git init && touch file && git add . && git commit -m "msg" && cd .. 

#Create the master repo and add submodules 
cd .. && mkdir deployment && cd deployment 
git init && mkdir public_html 
git submodule add ../repositories/app1 app1 
git submodule add ../repositories/app2 app2 
git submodule add ../repositories/public_html_app1 public_html/app1 
git submodule add ../repositories/public_html_app2 public_html/app2 
git commit -m "creating repo structure" 

在上面,部署目錄類似於你/home/user/目錄。

第二種方法是在app_n目錄中創建public_html目錄,並從那裏爲靜態資產等提供服務。這應該可以通過apache或運行的任何Web服務器輕鬆配置。第三種方法將使用symlinks。由於您使用的是IIS,因此無法爲您工作(您需要在Windows上瀏覽虛擬目錄)。基本上,您可以在public_html目錄中創建符號鏈接。您的public_html文件將僅用應用程序進行跟蹤,但是,您可以在public_html目錄中創建符號鏈接。檢查下面的步驟以重現2應用場景的相同情況

mkdir -p app1/public_html app2/public_html public_html 
ln -sf app1/public_html/ public_html/app1 
ln -sf app2/public_html/ public_html/app2 
+0

沒有必要維護一個單獨的子模塊來拆分git repo。請參閱http://stackoverflow.com/a/13738951/4231110 – 2014-11-24 15:34:14

+0

@justinhoward我不認爲這適用於此。我們可以維護一個單一的回購,但是OP明確地提出了這樣一個問題:'如何爲Web應用程序創建單獨的Git存儲庫...' – 2014-11-25 03:19:34

+0

第二個選項聽起來很有希望。是否有.htaccess示例或資源您知道,您可以顯示如何完成從Web根上方提供靜態文件? – suncoastkid 2015-01-14 13:27:01

相關問題