docker+githook實現goweb項目自動發包部署(1)

來源:互聯網
上載者:User

標籤:

環境:一台公司的程式開發伺服器(可以隨便裝東西~),自己的電腦

1.先在兩台機器上面安裝好git,然後在伺服器上面初始化一個空的庫,然後還有一個程式碼程式庫

cd /home/baizhi/src
git init --bare DAP_go.git
git clone [email protected]/DAP_go.git  這裡是公司的倉庫

2.然後本地代碼的關聯一下,remote是可以關聯多個遠程倉庫的,我關聯了兩個,一個自己初始化的一個公司的,這裡用自己的來配置hook

mkdir DAP_go
cd DAP_go
git init
git add remote baizhi [email protected]:/home/src/DAP_go.git

3.設定管理員上面的hooks

cd DAP_go.git/hooksmv post_receive.sample post_receivevi post_receive(內容如下)#!/bin/shunset GIT_DIRcdcd /home/baizhi/src/DAP_gogit pullexit 0

4.然後在本地的DAP_go上面修改代碼,push成功後就會觸發hooks了,我這裡比較坑爹,我得提交兩次,一次提交到公司的(例行公事,等於My Code做了兩次備份,再也不怕硬碟壞掉了:),一次提交到伺服器上自己建立的。

切換到自己本地的DAP_go下vi testhellogit add .git commitgit push(我這邊預設是到了公司的倉庫,那麼現在公司的倉庫有新代碼了)git push baizhi dev(baizhi是伺服器上遠程庫的名字,一般關聯一個的時候用的一般是origin,dev是分支) Counting objects: 3, done.Delta compression using up to 4 threads.Compressing objects: 100% (2/2), done.Writing objects: 100% (3/3), 266 bytes | 0 bytes/s, done.(到這裡是代碼寫入到伺服器上自己初始化的庫,下面是hook的指令碼執行的過程)Total 3 (delta 1), reused 0 (delta 0)remote: From ip:server/dap_goremote:    7a2f32a..d9df2ae  dev        -> origin/devremote: Updating 7a2f32a..d9df2aeremote: Fast-forwardremote:  test |    1 +remote:  1 files changed, 1 insertions(+), 0 deletions(-)To [email protected]:/home/baizhi/src/DAP_go.git   7a2f32a..d9df2ae  dev -> dev

5.然後在伺服器的DAP_go上看看是不是最新的代碼,這裡顯示了Already up-to-date,說明成功了

[[email protected] DAP_go]$ git pullAlready up-to-date.

6.上面做的這些就可以實現代碼變動的監控,下面docker要做的任務就是對代碼進行熱編譯。然後上面的post_reciver的指令碼可能還需要添加構建新的docker鏡像的命令,然後就可以在測試,或者正式環境上拉取最新的鏡像?明天弄,先下班

 

docker+githook實現goweb項目自動發包部署(1)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.