<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Deployment &#8211; Few Steps &#8211; ก้าวสั้นๆ แต่ไปเรื่อยๆ</title>
	<atom:link href="https://myifew.com/tag/deployment/feed/" rel="self" type="application/rss+xml" />
	<link>https://myifew.com</link>
	<description></description>
	<lastBuildDate>Fri, 11 Dec 2020 13:12:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://myifew.com/wp-content/uploads/2018/07/cropped-logo6-ts-32x32.png</url>
	<title>Deployment &#8211; Few Steps &#8211; ก้าวสั้นๆ แต่ไปเรื่อยๆ</title>
	<link>https://myifew.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>สร้างเว็บไซต์บน Kubernetes ง่ายๆ โดยไม่ต้องวางระบบเองด้วย DigitalOcean App Platform</title>
		<link>https://myifew.com/5748/how-to-use-kubernetes-on-digitalocean-app-platform/</link>
					<comments>https://myifew.com/5748/how-to-use-kubernetes-on-digitalocean-app-platform/#comments</comments>
		
		<dc:creator><![CDATA[iFew]]></dc:creator>
		<pubDate>Fri, 11 Dec 2020 13:05:17 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Automation Tools]]></category>
		<category><![CDATA[Continuous Deployment]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[DigitalOcean]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Git Deployment]]></category>
		<category><![CDATA[PaaS]]></category>
		<category><![CDATA[Platform as a Service]]></category>
		<guid isPermaLink="false">https://myifew.com/?p=5748</guid>

					<description><![CDATA[วันนี้เพิ่งได้เข้าไปดูบัญชี DigitalOcean ตัวเอง กะว่าจะปรับเปลี่ยนแพ็คเกจอะไรนิดหน่อย พบว่าเขามีออกบริการตัวใหม่มาตัวหนึ่ง (จริงๆ ออกมาตั้งแต่เดือนตุลาคมแล้ว กระผมรู้ช้าเอง T-T) ชื่อว่า DigitalOcean App Platform ลองอ่านคอนเซ็ปตอนแรกตื่นเต้นมากครับ นึกว่า DigitalOcean ทำ Serverless&#8230;]]></description>
										<content:encoded><![CDATA[
<p>วันนี้เพิ่งได้เข้าไปดูบัญชี <a rel="noreferrer noopener" href="https://m.do.co/c/96fec482c76f" data-type="URL" data-id="https://m.do.co/c/96fec482c76f" target="_blank"><strong>DigitalOcean</strong></a> ตัวเอง กะว่าจะปรับเปลี่ยนแพ็คเกจอะไรนิดหน่อย พบว่าเขามีออกบริการตัวใหม่มาตัวหนึ่ง (จริงๆ ออกมาตั้งแต่เดือนตุลาคมแล้ว กระผมรู้ช้าเอง T-T) ชื่อว่า <strong><a rel="noreferrer noopener" href="https://m.do.co/c/96fec482c76f" data-type="URL" data-id="https://m.do.co/c/96fec482c76f" target="_blank">DigitalOcean App Platform</a></strong> </p>



<p>ลองอ่านคอนเซ็ปตอนแรกตื่นเต้นมากครับ นึกว่า DigitalOcean ทำ Serverless ออกมาแล้ว แต่จริงๆเป็น PaaS (Platform as a Service) ตัวหนึ่ง ที่ช่วยสร้าง Infrastructure ต่างๆ ให้โดยที่เราไม่ต้องจัดการอะไรเองเลย แต่ก็ยังตื่นเต้นอยู่นะ เพราะมันทำด้วย Kubernetes ที่ Scaling ได้ และรองรับภาษาหลายตัว รวมถึง PHP ด้วยจ้า</p>



<span id="more-5748"></span>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1200" height="551" src="https://myifew.com/wp-content/uploads/2019/02/1_dAnZk19kGszKTvAgag31sQ-1200x551.jpeg" alt="" class="wp-image-5284" srcset="https://myifew.com/wp-content/uploads/2019/02/1_dAnZk19kGszKTvAgag31sQ-1200x551.jpeg 1200w, https://myifew.com/wp-content/uploads/2019/02/1_dAnZk19kGszKTvAgag31sQ-1024x470.jpeg 1024w, https://myifew.com/wp-content/uploads/2019/02/1_dAnZk19kGszKTvAgag31sQ-768x352.jpeg 768w, https://myifew.com/wp-content/uploads/2019/02/1_dAnZk19kGszKTvAgag31sQ-700x321.jpeg 700w, https://myifew.com/wp-content/uploads/2019/02/1_dAnZk19kGszKTvAgag31sQ-600x275.jpeg 600w, https://myifew.com/wp-content/uploads/2019/02/1_dAnZk19kGszKTvAgag31sQ.jpeg 1600w" sizes="(max-width: 1200px) 100vw, 1200px" /><figcaption>ภาพอธิบาย PaaS จาก:<br><a href="https://medium.com/@sdorzak/why-serverless-is-the-new-black-e4ff9e9947e0">https://medium.com/@sdorzak/why-serverless-is-the-new-black-e4ff9e9947e0</a></figcaption></figure>



<h2 class="wp-block-heading">มีอะไรน่าสนใจใน <strong>DigitalOcean App Platform</strong></h2>



<p>ก่อนจะพาดูผมทดสอบ ขอขายของให้สุดก่อน ว่าทำไมผมถึงชอบมัน และตื่นเต้นอยากลองใช้</p>



<ol class="wp-block-list"><li><strong>ราคาถูก</strong> &#8211; คนใช้ DigitalOcean อย่างผมจะรู้ว่าที่นี่ราคาถูกดี รวมถึงเจ้าระบบ App Platform ด้วย ที่เริ่มต้นเพียง 5$ ต่อเดือน (แต่ใช้ ฟรี ได้นะ ถ้าเป็น static files)</li><li><strong>รองรับหลายภาษาเขียนโปรแกรมและเฟรมเวิร์ก</strong> &#8211;  เช่น Node.js, Python, Django, Go, PHP, Laravel, React, Ruby, Ruby on Rails, Gatsby, Hugo แต่ถ้าอยากใช้นอกเหนือกว่านี้ เช่น .NET Core ก็ทำเป็น Docker Container ไปใช้ได้ รวมถึงทำไต์ง่ายๆ เป็น static sites หรือ CDN ก็ได้</li><li><strong>Scale ได้ง่าย</strong> &#8211; เพราะทำงานอยู่บน Kubernetes clusters จึงทำให้ รองรับการ Scale-out หรือ Scale-up ได้ เพียงแค่กดเปลี่ยนแพ็คเกจของ App หรือกดเพิ่มลดจำนวน App ในหน้า Dashboard ได้เลย</li><li><strong>Zero Downtime</strong> &#8211; ในขณะที่เรา Scale-out หรือ Scale-up ตัว Server เราอยู่ จะไม่กระทบกับเว็บไซต์เรา ผู้เข้าเว็บไซต์ยังทำงานได้ปกติ</li><li><strong>Automated Deployment </strong>&#8211; มันจะเชื่อมต่อกับ Github ของเรา (อนาคตจะต่อกับ Bitbucket,GitLab ได้) และเมื่อมีการ Push Code ขึ้นไป ก็จะทำการ Deploy ทันทีที่ App Platform ทำให้เราเห็นการเปลี่ยนแปลงได้ทันทีบนหน้าเว็บไซต์เรา</li></ol>



<p>ตั้งแต่ข้อ 3-5 ถ้าเราจะวางระบบ Infrastructure ให้ได้แบบนี้ คงไม่ใช่เรื่องง่ายๆเลย  (อย่างน้อยก็สำหรับผมคนหนึ่งแล้วหละ) </p>



<p>ปล. จะเรียกว่าข้อเสียไหมไม่รู้นะครับ แต่ตอนนี้ยังไม่มีบริการทางฝั่ง Asia ให้เลือก ดังนั้นอาจมีผลกับความเร็วเล็กน้อย, รวมถึงยังไม่มีฟีเจอร์ให้ใช้งานอะไรมาก จนถึงขั้นกำหนด Pipeline หรือลงรายละเอียด จนถึงขั้นเป็น CI/CD แบบใน Jenkins ได้</p>



<figure class="wp-block-image size-large"><img decoding="async" width="668" height="592" src="https://myifew.com/wp-content/uploads/2020/12/do-app-region.png" alt="" class="wp-image-5760"/></figure>



<h2 class="wp-block-heading">แนะนำให้ศึกษาเรื่องเหล่านี้ก่อน</h2>



<p>บริการนี้เรียกได้ว่าเป็น Automated Deployment ดังนั้น หากจะนำไปใช้งานจริง ควรจะเข้าใจที่มาที่ไปไว้บ้าง ว่า Best Practice ที่ควรทำเป็นอย่างไร เพราะหากอ่านแล้วและนำไปใช้จริง อาจจะเกิดความเสียหายได้ ดังนั้น ผมแนะนำให้ไปอ่านเรื่องราวนี้ก่อนครับ</p>



<ul class="wp-block-list"><li><a rel="noreferrer noopener" href="https://myifew.com/5080/the-twelve-factors/" data-type="URL" data-id="https://myifew.com/5080/the-twelve-factors/" target="_blank">สรุปแนวคิด The Twelve Factors ในภาพเดียวจบ</a></li><li><a rel="noreferrer noopener" href="https://myifew.com/4072/automation-deploy-git-bitbucket-jenkins/" data-type="URL" data-id="https://myifew.com/4072/automation-deploy-git-bitbucket-jenkins/" target="_blank">เริ่มต้นทำ CI/CD – Automation Deployment ด้วย Git และ Jenkins (3 – จบ</a><a href="https://myifew.com/4072/automation-deploy-git-bitbucket-jenkins/" data-type="URL" data-id="https://myifew.com/4072/automation-deploy-git-bitbucket-jenkins/">)</a></li><li><a rel="noreferrer noopener" href="https://myifew.com/4455/design-and-develop-code-for-testable/#more-4455" data-type="URL" data-id="https://myifew.com/4455/design-and-develop-code-for-testable/#more-4455" target="_blank">ต้องคิดอย่างไร รู้อะไร และทำอย่างไร เพื่อให้เกิด Automated Test</a></li><li><a rel="noreferrer noopener" href="https://myifew.com/4414/design-project-code-structure-for-testable/" data-type="URL" data-id="https://myifew.com/4414/design-project-code-structure-for-testable/" target="_blank">จะทำระบบให้รองรับ Automated Test ได้อย่างไร (Testable)</a> </li><li><a rel="noreferrer noopener" href="https://myifew.com/5166/understand-serverless-with-aws-lambda-for-newbie/" data-type="URL" data-id="https://myifew.com/5166/understand-serverless-with-aws-lambda-for-newbie/" target="_blank">มาทำความรู้จักกับ Serverless และ AWS Lambda ฉบับคนคิดจะใช้</a> (ไม่เกี่ยวแต่อยากนำเสนอ แหะๆ)</li></ul>



<h2 class="wp-block-heading">ทดสอบ <strong>DigitalOcean App Platform</strong> กันหน่อย</h2>



<p>ไปสร้าง Repository บน GitHub ไว้ และนำไฟล์โค้ดของเว็บไซต์เรา push ขึ้นไปรอไว้ก่อน ในที่นี้ผมใส่ index.html ไว้</p>



<figure class="wp-block-image size-large"><img decoding="async" width="2840" height="1298" src="https://myifew.com/wp-content/uploads/2020/12/do-app-first-deploy-git.png" alt="" class="wp-image-5756"/></figure>



<p>เข้า DigitalOcean และไปที่เมนู App จากนั้นกด Launch Your App (ใครยังไม่ได้สมัคร ก็ไปสมัครสมาชิก <a rel="noreferrer noopener" href="https://m.do.co/c/96fec482c76f" target="_blank"><strong>DigitalOcean</strong></a> กันก่อนนะ)</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="2880" height="1742" src="https://myifew.com/wp-content/uploads/2020/12/DigitalOcean-App-Platform.png" alt="" class="wp-image-5751"/></figure>



<p>สำหรับครั้งแรก จะเจอให้ Link Account กับ GitHub ก่อนนะครับ</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="2880" height="1432" src="https://myifew.com/wp-content/uploads/2020/12/Launch-App-DigitalOcean-App-Platform.png" alt="" class="wp-image-5770"/></figure>



<p>เมื่อ Link Account GitHub เสร็จ ก็เลือก Repository ที่เราต้องการใช้สร้าง</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="2880" height="1432" src="https://myifew.com/wp-content/uploads/2020/12/Launch-App-DigitalOcean-App-Platform-Git.png" alt="" class="wp-image-5769"/></figure>



<p>จากนั้นเลือก Region ซึ่งปัจจุบันตอนผมทดสอบ ยังมีเพียงฝั่งทวีป America และ Europe เท่านั้น, จากนั้นเราเลือก Git Branch ที่ต้องการเชื่อมโยงการ Deploy และเลือกว่าจะให้ Deploy อัตโนมัติทันทีเมื่อมีการ Push Code เข้าสู่ Branch นั้น</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="2880" height="2372" src="https://myifew.com/wp-content/uploads/2020/12/Launch-App-DigitalOcean-App-Platform-create.png" alt="" class="wp-image-5768"/></figure>



<p>มาถึงส่วนสำคัญ คือการ Config App ของเรา ว่าจะตั้งค่าอย่างไรบ้าง ดังนี้</p>



<ul class="wp-block-list"><li><strong>Type</strong> &#8211; คือประเภทของ APP ซึ่งในที่นี้ระบบมองว่าโค้ดผมเป็น HTML มันเลยเลือกให้เป็น Static Site ให้</li><li><strong>HTTP Routes</strong> &#8211; กำหนด Path ในการเข้าถึง เช่น / จะวิ่งเข้ามาที่ App นี้ หรือจะตั้งว่า /aabbcc ก็ได้ ดังนั้นใครเข้า www.web.com/aabbcc ก็จะเข้ามาที่ App นี้</li><li><strong>Environment Variables</strong> &#8211; ตัวแปรที่เก็บไว้ใช้ในระบบ เช่น เก็บ User/Password Database  ไว้ที่นี่เป็นต้น</li><li><strong>Build Command</strong> &#8211; เป็น Shell Script จะใส่อะไรก็ได้ หรือเว้นไว้ก้ได้</li><li><strong>Output Directory</strong> &#8211; ที่เก็บผลลัพธ์หลังจาก build แล้ว </li></ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="2880" height="3022" src="https://myifew.com/wp-content/uploads/2020/12/Launch-App-DigitalOcean-App-Platform-config.png" alt="" class="wp-image-5767"/></figure>



<p>ส่วนปุ่มด้านล่าง Add a Database คือการให้ App นี้อนญาตให้เชื่อมต่อกับ Database อะไรได้บ้าง หรือจะสร้างใหม่เลยก็ได้นะ</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="2840" height="1308" src="https://myifew.com/wp-content/uploads/2020/12/do-app-add-database.png" alt="" class="wp-image-5752"/></figure>



<p>ขั้นตอนสุดท้ายคือการเลือกแพ็คเกจใช้งาน ซึ่งในที่นี้เป็น Static Site เลยทำให้ใช้งานได้ฟรีครับ แต่ถ้าเราใช้กับพวก Dynamic Script อย่าง Node.js, PHP, Docker ก็จะต้องใช้เป็น Basic หรือ Pro เท่านั้น แต่ก็ถือว่าเป็นการเริ่มต้นใช้งานที่ถูกมากๆ แค่ 5$ เท่านั้น (แต่แพ็คเกจ Basic ทาง DigitalOcean แนะนำให้ใช้เป็นระบบสำหรับทดสอบ หรือ Prototype จะดีกว่านะ)</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="2880" height="3202" src="https://myifew.com/wp-content/uploads/2020/12/Launch-App-DigitalOcean-App-Platform-choose-package.png" alt="" class="wp-image-5766"/></figure>



<p>หลังจากกด Launch Starter App แล้ว รอสักครู่ มันจะสร้าง Instant และเมื่อเสร็จแล้ว ก็จะเห็น URL สำหรับการใช้งาน </p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="2518" height="512" src="https://myifew.com/wp-content/uploads/2020/12/do-app-create-success-have-url.png" alt="" class="wp-image-5754"/></figure>



<p>เมื่อทดลองเข้าไปดูตาม URL ก็จะเห็นหน้าที่ผมไว้สร้างไว้บน GitHub แล้ววว</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="2870" height="1560" src="https://myifew.com/wp-content/uploads/2020/12/do-app-first-deploy-result.png" alt="" class="wp-image-5757"/></figure>



<p>แต่หน้าตามันดูห่วยๆ เนอะ คราวนี้ผมจะสร้าง css file เพิ่ม</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="2044" height="1492" src="https://myifew.com/wp-content/uploads/2020/12/do-app-second-deploy-added-css.png" alt="" class="wp-image-5761"/></figure>



<p>และทำการ push code ขึ้นสู่ GitHub</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="914" height="424" src="https://myifew.com/wp-content/uploads/2020/12/do-app-second-deploy-added-css-push.png" alt="" class="wp-image-5764"/></figure>



<p>มีไฟล์ css เพิ่มมาใน GibHub แล้ว</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="2832" height="1416" src="https://myifew.com/wp-content/uploads/2020/12/do-app-second-deploy-added-css-github.png" alt="" class="wp-image-5762"/></figure>



<p>พอผมกลับไปดูหน้าเว็บไซต์ ว้าวว มันเป็นระเบียบสวยงามขึ้นแล้ววว </p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="2870" height="1566" src="https://myifew.com/wp-content/uploads/2020/12/do-app-second-deploy-result.png" alt="" class="wp-image-5765"/></figure>



<p>ไปดูรายการ Deployments มีการเก็บบันทึกไว้ว่ามีการ Deploy อะไรไปบ้าง</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="2488" height="588" src="https://myifew.com/wp-content/uploads/2020/12/do-app-second-deploy-added-css-log.png" alt="" class="wp-image-5763"/></figure>



<h2 class="wp-block-heading">สรุป</h2>



<p>อย่างที่ผมเกริ่นไปตอนแรก การจะวางระบบ Infrastructure ให้ได้แบบนี้ หรือเริ่มใช้ Kubernetes คงไม่ใช่เรื่องง่ายๆเลยสำหรับผู้ใช้งานทั่วไป หรือโปรแกรมเมอร์หลายๆคน รวมถึงผมด้วย ต่อให้สร้างขึ้นมาได้ แต่การดูแลรักษาเป็นเรื่องที่ปวดหัวมาก เช่น ถ้ามีผู้ใช้เข้ามาสูงมากๆ หรือถ้าโดน DDoS โจมตี เป็นต้น</p>



<p>ดังนั้นการมีบริการ PaaS ลักษณะนี้ขึ้นมา ก็ช่วยทำให้เราสะดวกมากขึ้น และทำให้โปรแกรมเมอร์อย่างเรา สามารถเป็น DevOps ได้เองอย่างไม่ยากเย็นนัก</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myifew.com/5748/how-to-use-kubernetes-on-digitalocean-app-platform/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>How To Set Up Deployment with Git</title>
		<link>https://myifew.com/3932/how-to-set-up-deployment-with-git/</link>
					<comments>https://myifew.com/3932/how-to-set-up-deployment-with-git/#respond</comments>
		
		<dc:creator><![CDATA[iFew]]></dc:creator>
		<pubDate>Tue, 21 Mar 2017 07:46:17 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Continuous Deployment]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Git Deployment]]></category>
		<guid isPermaLink="false">https://myifew.com/?p=3932</guid>

					<description><![CDATA[เวลาปรับปรุง code แล้วนำไฟล์ขึ้น server ก็คงใช้ upload ปกติทั่วไป อันนี้มาลองดูวิธีที่หล่อขึ้นมาอีกนิด คือใช้ git ทำ deployment เพื่ออำนวยความสะดวกในการทำงานร่วมกับทีม สะดวกในการ merge file, มี subversion และไม่ต้องหาไฟล์ที่แก้ไขเพื่ออัพโหลด]]></description>
										<content:encoded><![CDATA[<p>เวลาปรับปรุง code แล้วนำไฟล์ขึ้น server ก็คงใช้ upload ปกติทั่วไป อันนี้มาลองดูวิธีที่หล่อขึ้นมาอีกนิด คือใช้ git ทำ deployment เลย ซึ่งยังไม่เป็น Continuous Integration (CI) และ Continuous Deployment (CD) เพราะยังไม่ใช่ Automatic Deployment แต่แค่อำนวยความสะดวกในการทำงานร่วมกับทีม สะดวกในการ merge file, มี subversion และไม่ต้องหาไฟล์ที่แก้ไขเพื่ออัพโหลด<span id="more-3932"></span></p>
<p>บทความนี้อ้างอิงวิธีการจาก <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps" target="_blank">Digitalocean Tutorials : How To Set Up Automatic Deployment with Git with a VPS</a></p>
<blockquote><p>คำเตือน: อย่างที่บอก มันแค่อำนวยความสะดวกด้วย Git ดังนั้นก่อนจะ Deploy ขึ้น Production Server ควรผ่านการ Test ให้เสร็จเสียก่อน</p></blockquote>
<p style="text-align: center;"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3934 aligncenter" src="https://myifew.com/wp-content/uploads/2017/03/git-deployment-1.gif" alt="" width="674" height="481" />(รูปตัวอย่างของ Git Deployment ของ จาก <a href="http://www.flyingcorkmedia.com/blog/our-git-deployment-setup/" target="_blank">flyingcorkmedia.com</a>)</p>
<h2>เตรียมของ</h2>
<p>บน Production Server:</p>
<ul>
<li>Directory ที่เราใช้ Live เว็บไซต์ เช่น <em>/var/www/domain.com</em></li>
<li>Directory ที่เราใช้เก็บ Git Repo เช่น <em>/var/repo/site.git</em></li>
</ul>
<p>บน Localhost:</p>
<ul>
<li>ติดตั้ง Git</li>
<li>ทำการผูก SSH Key ระหว่างเครื่องเรา (Localhost) กับ Production Server (ถ้าไม่ผูกก็ได้ แต่จะต้องมาพิมพ์รหัสตลอดทุกครั้งที่ Commit นะ, ตัดสินใจดูเอาเอง)</li>
</ul>
<h2>เริ่มต้นทำ Git Repo บน Production Server</h2>
<p>ถ้ายังไม่ได้สร้าง /var/repo/site.git ให้ใช้คำสั่ง</p>
<p>[wc_code]mkdir /var/repo/site.git[/wc_code]</p>
<p>จากนั้น เข้าไป git init ให้มันด้วยคำสั่ง git init &#8211;bare</p>
<p>[wc_code]cd /var/repo/site.git<br />
git init &#8211;bare[/wc_code]</p>
<p>อธิบาย: git init &#8211;bare จะสร้างและเก็บค่าคอนฟิกของ Version Control เฉยๆ จะไม่มีการเก็บ Source Code</p>
<h2>ทำการ Git Hook</h2>
<p>ให้เข้าไปที่ไดเร็กทอรี่ repo ที่ได้สร้างไว้เมื่อสักครู่ จากนั้น ปรับ permission ไฟล์ hooks/post-receive เพื่ออนุญาตให้ execute file ได้ และเข้าไปแก้ไขข้อมูลในไฟล์นั้น</p>
<p>[wc_code]cd /var/repo/site.git<br />
chmod +x hooks/post-receive<br />
vi hooks/post-receive[/wc_code]</p>
<p>ในไฟล์นั้นจะไม่มีข้อมูลใดๆ จากนั้นให้เราใส่คำสั่งดังนี้</p>
<p>[wc_code]#!/bin/sh<br />
git &#8211;work-tree=/var/www/domain.com &#8211;git-dir=/var/repo/site.git checkout -f[/wc_code]</p>
<p>เป็นการบอกว่า เมื่อมีการ git push เข้ามา ให้ส่ง source code ไปยัง /var/www/domain.com</p>
<p>จากนั้นให้เราบันทึกและออกมาจากหน้า editor<br />
เป็นอันเสร็จขั้นตอนที่ต้องทำบน Production Server</p>
<h2>ทำ Git Repo บน Localhost</h2>
<p>คราวนี้เรามาจัดการบนเครื่อง Localhost เราต่อ โดยให้เราเข้าไปที่ไดเร็กทอรี่ที่เก็บ Source Code ของเรา จากนั้นเข้า Git Bash และทำการพิมพ์ git init</p>
<p>[wc_code]git init[/wc_code]</p>
<p>และพิมพ์คำสั่งทำการสร้าง remote ขึ้นมาชื่อ live</p>
<p>[wc_code]git remote add live ssh://user@mydomain.com/var/repo/site.git[/wc_code]</p>
<p>เป็นอันเสร็จขั้นตอนของ Localhost ครับ</p>
<h2>ทดลองใช้งาน</h2>
<p>ให้ลองสร้างไฟล์ขึ้นมาสักไฟล์หนึ่ง จากนั้น ทำการ commit git ตามปกติ แต่ ขั้นตอน push ให้ส่งไปที่ remote live แทน เช่น</p>
<p>[wc_code]git add .<br />
git commit -m &#8220;Test push file to production server&#8221;<br />
git push live master[/wc_code]</p>
<p>ข้อมูลบนเว็บไซต์ของเราบน Production Server จะมีการเปลี่ยนแปลงไปตามที่เราได้แก้ไขไป</p>
<h2>เพิ่มขั้นตอนทำเป็น Development Environment ก่อนก็ได้นะ</h2>
<p>การเอาขึ้น Production ด้วยคำสั่งเดียวมันดูอันตรายไปหน่อย อาจทำขั้นตอนเดียวกันนี้แต่เป็น Development Environment ก่อนก็ได้ โดยทำเหมือนเดิมทุกอย่างเลยครับ</p>
<p>โดยสมมติว่า</p>
<ul>
<li>Directory ที่เราใช้ Live Beta เว็บไซต์ เช่น /var/www/<strong>beta</strong></li>
<li>Directory ที่เราใช้เก็บ Git Repo Beta เช่น /var/repo/<strong>beta.git</strong></li>
</ul>
<p>ให้สร้าง Config Version Control</p>
<p>[wc_code]cd /var/repo/<strong>beta.git</strong><br />
git init &#8211;bare<br />
chmod +x hooks/post-receive<br />
vi hooks/post-receive[/wc_code]</p>
<p>ใส่ข้อมูลในไฟล์ hooks/post-receive ว่า</p>
<p>[wc_code]#!/bin/sh<br />
git &#8211;work-tree=/var/www/<strong>beta</strong> &#8211;git-dir=/var/repo/<strong>beta.git</strong> checkout -f[/wc_code]</p>
<p>จากนั้นมา add remote beta ใน repo localhost เราไปที่ไดเร็ดทอรี่ beta.git</p>
<p>[wc_code]git remote add <strong>beta</strong> ssh://user@mydomain.com/var/repo/<strong>beta.git</strong>[/wc_code]</p>
<p>คราวนี้ เวลาพัฒนาหรือแก้ไขปรับหรุง Source Code เสร็จ ก็ทำการนำเข้า Dvelopment Environment เพื่อทดสอบก่อน</p>
<p>[wc_code]git add .<br />
git commit -m &#8220;New version&#8221;<br />
git push beta master[/wc_code]</p>
<p>เมื่อทดสอบระบบทั้งหมดใน Development Environment  เสร็จ ก็ทำการนำเข้า Production อีกครั้ง</p>
<p>[wc_code]git push live master[/wc_code]</p>
<p>เป็นอันจบขั้นตอนทั้งหมด</p>
<p>ไว้คราวหน้าลอง CI/CD แล้วจะมาเขียนเหลาไหฟังอีกครั้ง</p>
<p>&#8212;</p>
<p>Featured Image from  <a href="http://www.flyingcorkmedia.com/blog/our-git-deployment-setup/" target="_blank">flyingcorkmedia.com</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://myifew.com/3932/how-to-set-up-deployment-with-git/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
