»

Custom Composer Repositories

Coding, Log — Tags: , — Posted by Starck on April 12, 2014

Define a composer repository

composer.json:

Require a custom repository

composer.json:

p.s. Composer 讀取版本的依據是 Repository 上的 Tag

Disable Packagist repository source

You can disable the default Packagist repository by adding this to your composer.json:

Git Deployment Solution

Coding, Log — Tags: , , , , — Posted by Starck on April 2, 2013

Why we need a Git Deployment Solution ?

In our past website develop workflow, we may often update files to production server by FTP, but it maybe causes some problems due to human factors, and it can’t be controlled and tracked for file version. As we increasingly need to maintain our projects by Git, if we are able to update server files while we do Git push, it sounds like a good idea, right? so we dont need to check which files want to upload any more. even we can push our project to development server and production server according to our needs.

在以往網站建置的工作流程中, 我們可能常常是用 FTP 的方式來更新 production server 的檔案. 這之中, 常會發生一些人為因素的失誤造成混亂, 而且也沒有一個紀錄來追蹤檔案的版本情況. 現在的工作愈來愈需要 Git 來維護專案, 而如果我們在每次 Git push 的時候, 也更動 server 的檔案, 似乎是個不錯的 idea? (我們不再需要用 FTP 自已判斷要上傳哪些有被異動過的檔案了!) 甚至我們可以先在本機測完, Git push 到 development server, 沒問題後, 再正式發佈到 production server 上線.

聽起來好像不錯? 那該怎麼作?

需要的工具

  • Git
  • 一台已經設好 SSH-Server 的主機 ex: production.com

設定流程

假設我們現在是這個情況:

  • 伺服器的 domain name 叫 production.com
  • 伺服器網站的根目錄設在 /var/www/production.com
本機端 (local)
mkdir "your project folder"
cd "your project folder"
# 建立 git 檔案庫
git init
# create release branch
git branch master
git checkout master
git remote add prod-server [email protected]:/var/www/production.com
伺服器端 (production server)
cd /var/www/production.com
git init
git config receive.denyCurrentBranch ignore
git branch master
git checkout master

我們需要用到 Git post-receive hook 來實現當收到 push 資料之後更新到最後版本:

vim .git/hooks/post-receive

將以下 script 內容加上去

別忘了讓 post-receive 是可被執行的:

chmod +x .git/hooks/post-receive

實作流程

本機端 (local)

我們先建立一個 README.md, 然後用 Git push 看看是否伺服器上也會同步:

Git 會用 SSH 的方式連線, 所以請先確認是否能用該 user 連線登入 production server.

如果想要之後只打 git push 就佈署到主機, 請加上 -u 參數 git push -u prod-server master

伺服器端 (production server)

確認 README.md 存在, 成功!

現在, 我們現在有一個比 FTP 上傳更聰明的佈署方式了.

2013-04-03 update: 今天在找資料的時候發現 Stack Overflow 有人在討論這個方式.

Stack Overflow: Deploying a Project using Git Push

.

(c) 2024 Starck Lin | powered by WordPress