<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by st.nann on Medium]]></title>
        <description><![CDATA[Stories by st.nann on Medium]]></description>
        <link>https://medium.com/@st.nann?source=rss-15377a775571------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dMyn8YLH4Cn7_FNe2hyEZQ.png</url>
            <title>Stories by st.nann on Medium</title>
            <link>https://medium.com/@st.nann?source=rss-15377a775571------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 19:15:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@st.nann/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[วิธีสร้าง LINE OA (สำหรับร้านค้าเบื้องต้น)]]></title>
            <link>https://medium.com/@st.nann/%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87-line-oa-%E0%B8%AA%E0%B8%B3%E0%B8%AB%E0%B8%A3%E0%B8%B1%E0%B8%9A%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%99%E0%B8%84%E0%B9%89%E0%B8%B2%E0%B9%80%E0%B8%9A%E0%B8%B7%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%95%E0%B9%89%E0%B8%99-9558de2bd766?source=rss-15377a775571------2</link>
            <guid isPermaLink="false">https://medium.com/p/9558de2bd766</guid>
            <dc:creator><![CDATA[st.nann]]></dc:creator>
            <pubDate>Wed, 08 Apr 2026 11:22:07 GMT</pubDate>
            <atom:updated>2026-04-08T15:26:56.987Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oqhv4ovEbtlYmY_QQ5opbw.jpeg" /></figure><p><strong>สิ่งที่ต้องเตรียม</strong><br>1. สมัคร LINE OA (<a href="https://lineforbusiness.com/th/service/line-oa-features"><em>https://lineforbusiness.com/th/service/line-oa-features</em></a>)<br>2. สมัคร LINE Developers Console (<a href="https://developers.line.biz/en/"><em>https://developers.line.biz/en/</em></a>)<br>3. สมัคร Firebase (<a href="https://firebase.google.com/"><em>https://firebase.google.com/</em></a>)<br>4. สมัคร GitHub (<a href="https://github.com/"><em>https://github.com/</em></a>)<br>5. (ถ้าไม่มี) Download VS Code</p><p><strong>ขั้นตอนการทำ</strong></p><ol><li>เปิด VS Code → Terminal เพื่อสร้าง folder project (ตั้งชื่ออะไรก็ได้) และเข้าไปที่ path folder ที่สร้าง</li></ol><pre>$ mkdir &lt;FOLDER_NAME&gt;</pre><p>ex.<br>$ mkdir line-tarot-app<br>$ cd line-tarot-app</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*Y00dEo7UfFQCKvz8nofsrg.png" /><figcaption>Initial Project</figcaption></figure><p>2. Install Firebase</p><pre>$ curl -sL https://firebase.tools | bash</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AZ2_Ir7qPtUlpTb3bmlCiQ.png" /><figcaption>Install Firebase</figcaption></figure><p>3. Login firebase</p><pre>$ firebase login</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wZ9R-G1Fn2Xu8dRTGEzbDQ.png" /><figcaption>Login firebase</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mSk2YWYQMP6kD_SaJMOuEw.png" /><figcaption>Login firebase (success)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mcV99f5IadXrwWrtPxmWJA.png" /><figcaption>Login GitHub firebase (success)</figcaption></figure><p>4. สร้าง Repository ใน GitHub</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wM4UGs76l46Hf9N4MBbl1w.png" /><figcaption>Repository GitHub</figcaption></figure><p>5. สร้าง project firebase</p><pre>$ firebase init</pre><p><em>feature:</em> select<br>- <strong><em>Firestone</em></strong><em> ( Database </em>สำหรับ<em> </em>เก็บข้อมูล<em>)<br>- </em><strong><em>Functions</em></strong><em> ( Backend API)<br>- </em><strong><em>Hosting</em></strong><em> (deploy)</em></p><blockquote>✔ <em>Please select an option:</em> Create a new project<br> ✔ <em>Please specify a unique project id (warning: cannot be modified afterward) [6–30 characters]:</em> line-tarot-app (ตั้งชื่อ project)<em><br> </em>✔<em> Please select the location of your Firestore database: </em>asia-south1<em><br> </em>✔<em> What file should be used for Firestore Rules? </em>firestore.rules<em><br> </em>✔<em> What file should be used for Firestore indexes?</em> firestore.indexes.json<br><em> </em>✔<em> What language would you like to use to write Cloud Functions? </em>JavaScript<em><br> </em>✔<em> Do you want to use ESLint to catch probable bugs and enforce style? </em>Yes<em><br> </em>✔<em> Do you want to install dependencies with npm now? </em>Yes<em><br> </em>✔<em> What do you want to use as your public directory? </em>public<em><br> </em>✔<em> Configure as a single-page app (rewrite all urls to /index.html)? </em>Yes<em><br> </em>✔<em> Set up automatic builds and deploys with GitHub? </em>Yes<em><br> </em>✔<em> For which GitHub repository would you like to set up a GitHub workflow? (format: user/repository) </em>st-nann/line-tarot-app (ชื่อตาม repository ใน GitHub)<em><br> </em>✔<em> </em>S<em>et up the workflow to run a build script before every deploy? </em>Yes<em><br> </em>✔<em> What script should be run before every deploy? </em>npm ci &amp;&amp; npm run build<em><br> </em>✔ <em>Set up automatic deployment to your site’s live channel when a PR is merged? </em>Yes<em><br> </em>✔ <em>What is the name of the GitHub branch associated with your site’s live channel? </em>main<em><br> </em>✔<em> Would you like to install agent skills for Firebase? </em>Yes</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LnzMEuH6M8j7yY13ZHHatg.png" /><figcaption>firebase init</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UPYy0owS3pRidvP5wIQ31A.png" /><figcaption>firebase init</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wHqMCVxQuw_c22e1AqdFmg.png" /><figcaption>firebase init</figcaption></figure><p>6. สร้าง<em> </em>file<em> </em><strong><em>style.css</em></strong> และ <strong><em>app.js</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*Uj7Otf8UZK9uhAooZ8kBTQ.png" /><figcaption>structure file</figcaption></figure><p>7. แก้ไข functions/index.js (Function การทำงาน สำหรับสร้าง function API)</p><pre>const functions = require(&quot;firebase-functions&quot;);<br>const admin = require(&quot;firebase-admin&quot;);<br>const fetch = require(&quot;node-fetch&quot;);<br><br>admin.initializeApp();<br>const db = admin.firestore();<br><br>// REGISTER<br>exports.register = functions.https.onRequest(async (req, res) =&gt; {<br>  res.set(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);<br>  res.set(&quot;Access-Control-Allow-Methods&quot;, &quot;GET, POST, OPTIONS&quot;);<br>  res.set(&quot;Access-Control-Allow-Headers&quot;, &quot;Content-Type&quot;);<br>  if (req.method === &quot;OPTIONS&quot;) return res.status(204).send(&quot;&quot;);<br><br>  try {<br>    const { userId, name, birthdate, invoice } = req.body;<br>    if (!userId || !invoice) return res.status(400).send({ error: &quot;missing data&quot; });<br><br>    const invoiceRef = db.collection(&quot;invoices&quot;).doc(invoice);<br>    const invoiceDoc = await invoiceRef.get();<br>    if (invoiceDoc.exists) return res.send({ error: &quot;invoice used&quot; });<br><br>    await invoiceRef.set({ used: true });<br><br>    const userRef = db.collection(&quot;users&quot;).doc(userId);<br>    const userDoc = await userRef.get();<br>    let points = 1;<br>    if (userDoc.exists) points = (userDoc.data().points || 0) + 1;<br><br>    await userRef.set({ name, birthdate, points }, { merge: true });<br>    return res.send({ success: true, points });<br><br>  } catch (err) {<br>    console.error(err);<br>    return res.status(500).send({ error: &quot;server error&quot; });<br>  }<br>});<br><br>// DRAW CARD<br>exports.drawCard = functions.https.onRequest(async (req, res) =&gt; {<br>  res.set(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);<br>  res.set(&quot;Access-Control-Allow-Methods&quot;, &quot;GET, POST, OPTIONS&quot;);<br>  res.set(&quot;Access-Control-Allow-Headers&quot;, &quot;Content-Type&quot;);<br>  if (req.method === &quot;OPTIONS&quot;) return res.status(204).send(&quot;&quot;);<br><br>  try {<br>    const { userId } = req.body;<br>    if (!userId) return res.status(400).send({ error: &quot;missing userId&quot; });<br><br>    const userRef = db.collection(&quot;users&quot;).doc(userId);<br>    const userDoc = await userRef.get();<br>    const userData = userDoc.data() || {};<br><br>    const todayUTC = new Date().toISOString().slice(0, 10);<br>    if (userData.lastDraw === todayUTC) return res.send({ error: &quot;วันนี้เปิดไพ่แล้ว&quot; });<br><br>    // history<br>    const historySnapshot = await db.collection(&quot;history&quot;).where(&quot;userId&quot;, &quot;==&quot;, userId).get();<br>    const drawnCards = historySnapshot.docs.map(d =&gt; d.data().card);<br><br>    // all cards<br>    const apiRes = await fetch(&quot;https://tarotapi.dev/api/v1/cards&quot;);<br>    const allCards = await apiRes.json(); // allCards.cards = array<br>    const remainingCards = allCards.cards.filter(c =&gt; !drawnCards.includes(c.name));<br>    if (remainingCards.length === 0) return res.send({ error: &quot;เปิดครบทุกใบแล้ว&quot; });<br><br>    // random pick<br>    const card = remainingCards[Math.floor(Math.random() * remainingCards.length)];<br><br>    // save draw<br>    await userRef.set({ lastDraw: todayUTC }, { merge: true });<br>    await db.collection(&quot;history&quot;).add({ userId, card: card.name, date: new Date() });<br><br>    return res.send({<br>      name: card.name,<br>      meaning: card.meaning_up,<br>      image: card.image,<br>      drawnCards,<br>      allCards: allCards.cards.map(c =&gt; ({ name: c.name, image: c.image }))<br>    });<br><br>  } catch (err) {<br>    console.error(err);<br>    return res.status(500).send({ error: &quot;server error&quot; });<br>  }<br>});<br><br>// GET POINTS<br>exports.getPoints = functions.https.onRequest(async (req, res) =&gt; {<br>  res.set(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);<br>  res.set(&quot;Access-Control-Allow-Methods&quot;, &quot;GET, POST, OPTIONS&quot;);<br>  res.set(&quot;Access-Control-Allow-Headers&quot;, &quot;Content-Type&quot;);<br>  if (req.method === &quot;OPTIONS&quot;) return res.status(204).send(&quot;&quot;);<br><br>  try {<br>    const userId = req.query.userId;<br>    if (!userId) return res.status(400).send({ error: &quot;missing userId&quot; });<br><br>    const doc = await db.collection(&quot;users&quot;).doc(userId).get();<br>    return res.send(doc.data() || { points: 0 });<br><br>  } catch (err) {<br>    console.error(err);<br>    return res.status(500).send({ error: &quot;server error&quot; });<br>  }<br>});</pre><p>8. แก้ไข public/index.html (Frontend UI)</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;meta charset=&quot;UTF-8&quot;&gt;<br>  &lt;title&gt;Tarot App&lt;/title&gt;<br>  &lt;script src=&quot;https://static.line-scdn.net/liff/edge/2/sdk.js&quot;&gt;&lt;/script&gt;<br>  &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css?v=11&quot;&gt;<br>&lt;/head&gt;<br><br>&lt;body&gt;<br><br>&lt;h2&gt;🔮 ดูดวง&lt;/h2&gt;<br><br>&lt;div class=&quot;card&quot; id=&quot;card&quot;&gt;<br>  &lt;div class=&quot;card-inner&quot;&gt;<br>    &lt;div class=&quot;card-front&quot;&gt;TAROT&lt;/div&gt;<br>    &lt;div class=&quot;card-back&quot; id=&quot;cardResult&quot;&gt;&lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/div&gt;<br><br>&lt;div class=&quot;progress-container&quot;&gt;<br>  &lt;div class=&quot;progress-bar&quot; id=&quot;progress&quot;&gt;&lt;/div&gt;<br>&lt;/div&gt;<br><br>&lt;p id=&quot;pointsText&quot;&gt;&lt;/p&gt;<br><br>&lt;input id=&quot;name&quot; placeholder=&quot;ชื่อ&quot;&gt;&lt;br&gt;<br>&lt;input id=&quot;birthdate&quot; placeholder=&quot;วันเกิด&quot;&gt;&lt;br&gt;<br>&lt;input id=&quot;invoice&quot; placeholder=&quot;Invoice&quot;&gt;&lt;br&gt;<br><br>&lt;button onclick=&quot;register()&quot;&gt;รับแต้ม&lt;/button&gt;<br>&lt;button onclick=&quot;draw()&quot;&gt;สุ่มไพ่&lt;/button&gt;<br><br>&lt;div id=&quot;cardGallery&quot;&gt;&lt;/div&gt;<br><br>&lt;script src=&quot;app.js?v=11&quot;&gt;&lt;/script&gt;<br><br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>9. แก้ไข public/style.css (Frontend style)</p><pre>body {<br>  font-family: -apple-system, BlinkMacSystemFont, sans-serif;<br>  background: #f6f3ee;<br>  text-align: center;<br>  padding: 20px;<br>  color: #3b3b3b;<br>}<br><br>h2 {<br>  color: #5c7c5a;<br>}<br><br>/* input */<br>input {<br>  margin: 6px;<br>  padding: 10px;<br>  width: 220px;<br>  border-radius: 10px;<br>  border: 1px solid #ddd;<br>}<br><br>/* button */<br>button {<br>  margin: 10px;<br>  padding: 10px 20px;<br>  border-radius: 20px;<br>  border: none;<br>  background: #5c7c5a;<br>  color: white;<br>}<br><br>/* progress */<br>.progress-container {<br>  width: 80%;<br>  background: #ddd;<br>  border-radius: 20px;<br>  margin: 20px auto;<br>}<br><br>.progress-bar {<br>  height: 10px;<br>  background: #5c7c5a;<br>  border-radius: 20px;<br>  width: 0%;<br>}<br><br>/* =========================<br>   CARD<br>========================= */<br><br>.card {<br>  width: 160px;<br>  height: 240px;<br>  margin: 20px auto;<br>  perspective: 1000px;<br>}<br><br>/* inner */<br>.card-inner {<br>  position: relative;<br>  width: 100%;<br>  height: 100%;<br><br>  transition: transform 0.6s;<br>  transform-style: preserve-3d;<br>}<br><br>.card.flip .card-inner {<br>  transform: rotateY(180deg);<br>}<br><br>/* front + back */<br>.card-front,<br>.card-back {<br>  position: absolute;<br>  width: 100%;<br>  height: 100%;<br>  border-radius: 15px;<br>  backface-visibility: hidden;<br>  transform-style: preserve-3d;<br>}<br><br>/* FRONT */<br>.card-front {<br>  background: linear-gradient(145deg, #5c7c5a, #3f5e3e);<br>  border: 2px solid #e6e2d3;<br>  box-shadow: 0 10px 20px rgba(0,0,0,0.15);<br>  display: flex;<br>  align-items: center;<br>  justify-content: center;<br>  color: #f6f3ee;<br>  font-size: 28px;<br>  letter-spacing: 2px;<br>  transform: translateZ(0);<br>}<br><br>/* BACK */<br>.card-back {<br>  background: white;<br>  transform: rotateY(180deg);<br>  padding: 10px;<br>}<br><br>/* ไพ่ */<br>.card-img {<br>  width: 100%;<br>  border-radius: 10px;<br>}<br><br>/* gallery */<br>#cardGallery {<br>  display: flex;<br>  flex-wrap: wrap;<br>  justify-content: center;<br>  margin-top: 20px;<br>  flex-direction: row;<br>}<br>#cardGallery img {<br>  border-radius: 5px;<br>  transition: filter 0.3s;<br>  width: 80px;<br>  margin: 5px;<br>}<br>#cardGallery div {<br>  text-align: center;<br>  font-size: 10px;<br>}</pre><p>10. แก้ไข public/app.js (File main และ call API)</p><pre>let userId = &quot;&quot;;<br><br>const API = {<br>  draw: &quot;https://drawcard-7tyc53ozea-uc.a.run.app&quot;,<br>  register: &quot;https://register-7tyc53ozea-uc.a.run.app&quot;,<br>  points: &quot;https://getpoints-7tyc53ozea-uc.a.run.app&quot;<br>};<br><br>// INIT<br>async function init() {<br>  try {<br>    await liff.init({ liffId: &quot;2009742183-h8SI5AjI&quot; });<br>    if (!liff.isLoggedIn()) {<br>      liff.login();<br>      return;<br>    }<br>    const profile = await liff.getProfile();<br>    userId = profile.userId;<br>    loadPoints();<br>  } catch (err) { console.error(err); }<br>}<br>init();<br><br>// โหลดแต้ม<br>async function loadPoints() {<br>  const res = await fetch(`${API.points}?userId=${userId}`);<br>  const data = await res.json();<br>  updateProgress(data.points || 0);<br>}<br><br>function updateProgress(points) {<br>  const percent = (points / 24) * 100;<br>  document.getElementById(&quot;progress&quot;).style.width = percent + &quot;%&quot;;<br>  document.getElementById(&quot;pointsText&quot;).innerText = points + &quot; / 24 แต้ม&quot;;<br>}<br><br>// REGISTER<br>async function register() {<br>  const res = await fetch(API.register, {<br>    method: &quot;POST&quot;,<br>    headers: { &quot;Content-Type&quot;: &quot;application/json&quot; },<br>    body: JSON.stringify({<br>      userId,<br>      name: document.getElementById(&quot;name&quot;).value,<br>      birthdate: document.getElementById(&quot;birthdate&quot;).value,<br>      invoice: document.getElementById(&quot;invoice&quot;).value<br>    })<br>  });<br>  const data = await res.json();<br>  if (data.error) { alert(data.error); return; }<br>  updateProgress(data.points);<br>}<br><br>// DRAW + FLIP<br>async function draw() {<br>  const res = await fetch(API.draw, {<br>    method: &quot;POST&quot;,<br>    headers: { &quot;Content-Type&quot;: &quot;application/json&quot; },<br>    body: JSON.stringify({ userId })<br>  });<br><br>  const data = await res.json();<br>  if (data.error) { alert(data.error); return; }<br><br>  // แสดงไพ่ใบที่สุ่ม<br>  // document.getElementById(&quot;cardResult&quot;).innerHTML = `<br>  //   &lt;img src=&quot;${data.image}&quot; class=&quot;card-img&quot;/&gt;<br>  //   &lt;h4&gt;${data.name}&lt;/h4&gt;<br>  //   &lt;p&gt;${data.meaning}&lt;/p&gt;<br>  // `;<br>  document.getElementById(&quot;cardResult&quot;).innerHTML = `<br>    &lt;h4&gt;${data.name}&lt;/h4&gt;<br>    &lt;p&gt;${data.meaning}&lt;/p&gt;<br>  `;<br><br>  // flip card animation<br>  const card = document.getElementById(&quot;card&quot;);<br>  card.classList.remove(&quot;flip&quot;);<br>  setTimeout(() =&gt; card.classList.add(&quot;flip&quot;), 50);<br><br>  // แสดง gallery: ไพ่ที่มีสี / ไพ่ที่ยังไม่สุ่มเป็นขาวดำ<br>  document.getElementById(&quot;cardGallery&quot;).innerHTML =<br>    data.allCards.map(c =&gt; {<br>      const drawn = data.drawnCards.includes(c.name);<br>      return `<br>        &lt;div style=&quot;margin: 0 10px;&quot;&gt;<br>          &lt;div class=&quot;card-text&quot; style=&quot;<br>              width: 150px;<br>              height: 200px;<br>              border-radius: 15px;<br>              background: ${drawn ? &#39;#5c7c5a&#39; : &#39;#ddd&#39;};<br>              color: ${drawn ? &#39;#f6f3ee&#39; : &#39;#888&#39;};<br>              display: flex;<br>              align-items: center;<br>              justify-content: center;<br>              font-size: 24px;<br>              font-weight: bold;<br>              margin-bottom: 10px;<br>          &quot;&gt;<br>            Tarot<br>          &lt;/div&gt;<br>          &lt;h3&gt;${c.name}&lt;/h3&gt;<br>        &lt;/div&gt;<br>      `;<br>    }).join(&quot;&quot;);<br>}</pre><p>11. Install cors เพื่อให้ call API ได้</p><pre>// เข้า folder functions<br>$ cd functions<br><br>// install package<br>$ npm install cors<br><br>// ลบไฟล์ package.json เพื่อเคลียร์ cache<br>$ rm -rf node_modules package-lock.json<br><br>// install package (ทั้งหมด)<br>$ npm install<br><br>// ออกจาก folder functions<br>$ cd ..<br><br>// deploy<br>$ firebase deploy</pre><p>12. Deploy firebase</p><pre>$ firebase deploy</pre><p>ใช้ในกรณี debug</p><pre>firebase deploy --only hosting</pre><p>ใช้ดู Domain API (domain จะแสดงเมื่อมีการ update file <em>functions/index.js</em>)</p><pre>firebase deploy --only functions</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DtAIpyBnKV5v1ctTA5fCXw.png" /><figcaption>domain (update)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*phmeoETlVS1Trd5u5kFeJg.png" /><figcaption>domain (not update)</figcaption></figure><p>ตัวอย่าง domain</p><pre>https://us-central1-line-tarot-app.cloudfunctions.net</pre><p>domain ประกอบด้วย</p><ul><li>us-central1 = <em>region default ของ Firebase</em></li><li>line-tarot-app = <em>ชื่อ project ของคุณ</em></li><li>cloudfunctions.net = <em>domain ของ Firebase</em></li></ul><blockquote>✔ <em>How many days do you want to keep container images before they’re deleted?</em> 365</blockquote><p>ถ้ามีการแก้ file functions/index.js จะต้องทำการ install package และ deploy ใหม่</p><pre><br>// เข้า folder functions<br>$ cd functions<br><br>// ลบไฟล์ package.json เพื่อเคลียร์ cache<br>$ rm -rf node_modules package-lock.json<br><br>// install package (ทั้งหมด)<br>$ npm install<br><br>// ออกจาก folder functions<br>$ cd ..<br><br>// deploy<br>firebase deploy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mcLybKngF6iOIh74M_j9WQ.png" /><figcaption>firebase deploy (success)</figcaption></figure><p>จะได้</p><pre>Project Console: https://console.firebase.google.com/project/line-tarot-app/overview<br>Hosting URL: https://line-tarot-app.web.app</pre><p><em>ถ้ามีการ update code ให้ deploy ให้ deploy ใหม่ แล้ว hard refresh (Mac: Command + Shift + R) ที่ browser (เพื่อ clear cache)</em></p><p><strong><em>Note</em></strong></p><ol><li>ถ้า error ดังรูป ให้ลบ predeploy ใน file <em>firebase.json</em> ออก</li></ol><pre>&quot;predeploy&quot;: [<br>  &quot;npm --prefix \&quot;$RESOURCE_DIR\&quot; run lint&quot;<br>]<br><br>หรือ<br><br>&quot;functions&quot;: {<br>  &quot;predeploy&quot;: [<br>    &quot;npm --prefix \&quot;$RESOURCE_DIR\&quot; run lint&quot;<br>  ]<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*erUGL1P57222m9M4J7ELZA.png" /><figcaption>error — predeploy</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jHeRD0LMSWu7Jm77FKJJ6A.png" /><figcaption><em>firebase.json</em></figcaption></figure><p>2. ถ้าเจอ Error ต้อง upgrade firebase เป็น Blaze เพื่อใช้ Functions (สามารถทดลองใช้งาน credit free $300 ได้ [<a href="https://firebase.blog/posts/2024/11/claim-300-to-get-started">https://firebase.blog/posts/2024/11/claim-300-to-get-started</a>])</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AZZeoXookZ9fp2qfWdbB2A.png" /><figcaption>error —Can not use Functions</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*157x0Wq0TuqCG4Rc-_8USw.png" /><figcaption>Select Plan (Blaze)</figcaption></figure><p>3. ถ้าเจอ <em>Couldn’t find firebase-functions package และ npm error `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.</em></p><pre>// เข้า folder functions<br>$ cd functions<br><br>// install packge<br>$ npm install firebase-functions firebase-admin<br><br>// ลบไฟล์ package.json เพื่อเคลียร์ cache<br>$ rm -rf node_modules package-lock.json<br><br>// install package (ทั้งหมด)<br>$ npm install<br><br>// ออกจาก folder functions<br>$ cd ..</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r-TLcR5HzR8tOdwwt22ahg.png" /><figcaption>error — Couldn’t find firebase-functions package</figcaption></figure><h4><strong>LINE Developers Console</strong></h4><p>13. ไปที่ <strong>LINE Developers Console</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TXTUeaIfz8msE5NU9bf9iA.png" /><figcaption>LINE Developers Console</figcaption></figure><p>14. สร้าง Providers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WkDANfnp4CmvcuZUYbZBEA.png" /><figcaption>สร้าง Providers</figcaption></figure><p>15. Create a LINE Login channel</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uL7mGo0dcVlEJqoDGhOYDA.png" /><figcaption>Create a new channel</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wZRK0vD6afypROoJPPTHWg.png" /><figcaption>Create a new channel form</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8shJPZnkX7ddhwAdmiMeew.png" /><figcaption>Create a new channel (success)</figcaption></figure><p>16. เลือก Tab <strong>Liff </strong>→ Add</p><blockquote><strong>LIFF name</strong>: ตั้งชื่ออะไรก็ได้ (เช่น Tarot App)<br> <strong>Size</strong>: Full<br> <strong>Endpoint URL</strong>: ใส่ Hosting URL ที่ได้ตอน firebase deploy = <a href="https://your-project.web.app/">https://your-project.web.app</a> (ex. <strong>Hosting URL:</strong> <a href="https://line-tarot-app.web.app/">https://line-tarot-app.web.app</a>)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1I6KuMwEiCKsPXFyXpkJPA.png" /><figcaption>Create Liff</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wa2g4MGRz9DebPydXgTnaA.png" /><figcaption>Liff form</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kWgnZFGAAL0WkVFPXokSbA.png" /><figcaption>Create Liff (Liff ID)</figcaption></figure><p><strong><em>Note</em></strong></p><p>วิธีทดสอบ Liff</p><pre>https://liff.line.me/&lt;LIFF_ID&gt;</pre><p>17. นำ <strong>Liff ID </strong>ที่สร้างไปใส่ที่ file <strong><em>public/app.js</em></strong><em> ตรง</em></p><pre>await liff.init({ liffId: &quot;YOUR_LIFF_ID&quot; });</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J34J7UShZRrNZWqU-yHP0g.png" /></figure><h4><strong>LINE OA</strong></h4><p>18. ไปที่ <strong>LINE OA</strong> เพื่อนำ <strong>Liff ID</strong> ไปใช้ใน <strong><em>Rich Menu</em></strong> โดยเลือก Rich Menus ในแถบเมนูด้านซ้าย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q5RzNkkHTvcH70gMQE0PYA.png" /><figcaption>LINE OA</figcaption></figure><p>19. Create Rich Menu → คลิก Template → ปรับแต่ง design ตามต้องการ และนำ Liff link วาง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-VBX1aV8rTzkn-EpKO8RVg.png" /><figcaption>Rich Menu</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gGnM9tAZRDt1Q1s1tKo2Ig.png" /><figcaption>Create Rich Menu (success)</figcaption></figure><p><strong>วิธีตรวจสอบ function deploy</strong></p><pre>$ firebase functions:list</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dAb4QZ5sWoRB1zEIOCDlsA.png" /><figcaption>result</figcaption></figure><p>หรือ</p><p>หน้า Web<strong> </strong>แถบด้านซ้าย <strong>Hosting &amp; Serverless</strong> → <strong>Functions</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6SrrDglZkc0VI_D7dX0-Mw.png" /></figure><p>หากต้องการจัดการข้อมูล สามารถเข้าไปที่ Firebase Console → เมนูด้านซ้าย Databases &amp; Storage</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gc7F3KG78G9wdn_KJuzEzA.png" /><figcaption>Firestore</figcaption></figure><p>ถ้า Call API แล้วติด <strong>403 Forbidden</strong> ต้องเปิด API = public ก่อน</p><p><strong>วิธีแก้</strong></p><ol><li>เข้า <strong>Google Cloud Console</strong> (<a href="https://cloud.google.com/cloud-console?utm_source=google&amp;utm_medium=cpc&amp;utm_campaign=Cloud-SS-DR-GCP-1713664-GCP-DR-APAC-TH-th-Google-BKWS-MIX-GenericCloud&amp;utm_content=c-Hybrid+%7C+BKWS+-+BRO+%7C+Txt+-+Generic+Cloud-Console-Cloud+Console-TH_en-296393718382&amp;utm_term=google+cloud+console&amp;gclsrc=aw.ds&amp;gad_source=1&amp;gad_campaignid=12372110337&amp;gclid=CjwKCAjw-dfOBhAjEiwAq0RwI8z92YxNNPFNCpJulClb3esMFdSwEHjkrMs5R3q5P2y64JVE1g-7JRoCzKcQAvD_BwE&amp;authuser=1&amp;pageId=none">https://cloud.google.com/cloud-console</a>)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SPrQrNobodw_pzNOJiUP6w.png" /><figcaption>Google Cloud Console</figcaption></figure><p>2. Go to my console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kUSPmC4NWOoNjDRHq_Fksw.png" /><figcaption>console</figcaption></figure><p>3. เมนูด้านซ้าย → <strong>Cloud Run</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*4Y30k8HGYTG6DTVKVrxMmg.png" /><figcaption>Cloud Run</figcaption></figure><p>4. เมนูด้านซ้าย → <strong>Service</strong> จะเห็น service 3 service</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xysl9v70hKqAyVAa2DeEsg.png" /><figcaption>services</figcaption></figure><p>5. เลือกdrawcard และ register</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qqkmDyrZz1hN6NFy0k-pNw.png" /><figcaption>select services</figcaption></figure><p>6. กดปุ่ม <strong>Permissions</strong> ที่เมนูด้านบน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WD5KqSJdfz7ZVtU2r-3DHw.png" /><figcaption>Permissions</figcaption></figure><p>7. Add participal → Save</p><blockquote><strong><em>New principals:</em></strong> allUsers<br><strong><em>Role</em></strong><em>:</em> Cloud Run Invoker</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ltRalfK8D4B1ADuy4_k93Q.png" /><figcaption>Add participal</figcaption></figure><p>8. Allow Public Access</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iTkvx1R6zNjOZzhf9NxSsg.png" /><figcaption>Allow Public Access</figcaption></figure><p>9. ทดสอบ cUrl</p><pre>curl -X POST https://drawcard-7tyc53ozea-uc.a.run.app \<br>  -H &quot;Content-Type: application/json&quot; \<br>  -d &#39;{&quot;userId&quot;:&quot;test123&quot;}&#39;</pre><p>ถ้าได้ reponse json = ใช้งานได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1ZDPo79gS917o_Isu82Vng.png" /><figcaption>reponse json</figcaption></figure><p>10. ทดลองเล่น LINE OA อีกครั้ง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jslXHCa2po68J6DU2ep0Zg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oYdk7jmK-GYZrTr-6Bn_Qg.png" /><figcaption>LINE OA (ซ้าย: LINE OA / ขวา: หน้า Liff)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fG5cQTsoK_LLGe9FWGhHHA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m-_8b_bLSN9TTTq2aI6SDw.jpeg" /><figcaption>LINE OA (ซ้าย: สุ่มไพ่ แสดงไพ่ที่ได้ และไพ่ทั้งหมด / ขวา: รับแต้ม)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jdqas86i5YEz6gu98sYyig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r4duWgCx3YoY_B5QDmbHkg.png" /><figcaption>LINE OA (ซ้าย: สุ่มไพ่ในวันซ้ำ / ขวา: รับแต้มในวันซ้ำ)</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9558de2bd766" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[How to] AWS Secret Manager]]></title>
            <link>https://medium.com/@st.nann/how-to-aws-secret-manager-9c00d609a6d5?source=rss-15377a775571------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c00d609a6d5</guid>
            <dc:creator><![CDATA[st.nann]]></dc:creator>
            <pubDate>Sat, 18 Feb 2023 14:30:25 GMT</pubDate>
            <atom:updated>2025-01-07T03:16:36.285Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PodPx_hraN4h4Jh2wnRstQ.png" /></figure><p>เคยมั้ยที่สร้าง Service มา แล้วจะต้องเก็บ secret key ต่างๆไว้ในไฟล์ .env ซึ่งบางทีรู้สึกว่าไม่ปลอดภัย….วันนี้เลยจะมาแนะนำ product ตัวนึงของ AWS นั่นก็คือ <strong>Secret Manager</strong> เพื่อใช้ในการเก็บ key นั้นๆ แล้วโหลดมาใช้ก็ service ของเรา (โดยในบทความนี้จะแบ่งเป็น 2 ส่วนคือ ฝั่งของทาง DevOps และฝั่งของทาง Developer แต่จะเน้นไปที่การเรียกใช้งาน Secret Manager ของทางฝั่ง Developer และในส่วนของบทความนี้จะใช้กับ service golang เท่านั้น)</p><blockquote>คำเตือน: เนื้อหาบางส่วนจะเป็นส่วนที่ปรับใช้กับ service ของทางผู้เขียนเอง</blockquote><h4>DevOps</h4><ol><li>สร้าง Store สำหรับเก็บค่า <strong>Secret value</strong> ของ Env โดยจะมีข้อมูลบางส่วนเข้ารหัสด้วย base64 (ข้อมูลจะถูกเก็บ by user โดยแต่ละ user จะมีสิทธิในการเข้า database ไม่เหมือนกัน)</li><li>Setup ค่า <strong>Secret value </strong>(ไม่เก็บค่า Database Name)</li><li>สร้าง Permission ให้เข้าถึง <strong>Secret</strong> <strong>value</strong></li></ol><p><strong>Note</strong>: Store มี Secret Type ตาม Database Type และที่ไม่ใช่ Database Type (Other) ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*naXAwDK2_VLy_cSydy18HA.png" /></figure><ul><li><strong>RDS Database / DocumentDB Database / Redshift Cluster / Other Database</strong>: จะมีการ sync ค่า config ต่างๆมาจาก Database ที่ใช้ปัจจุบัน ซึ่งจะทำให้สามารถทำ Rotation ของ Database ได้ด้วย</li><li><strong>Other</strong>: Secret Customize</li></ul><h4>ขั้นตอนการเข้า AWS Secret Manager</h4><ol><li>Login AWS (<a href="https://becicorp.awsapps.com/start#/">https://becicorp.awsapps.com/start#/</a> )</li><li>คลิก AWS Account</li><li>เลือก Service</li><li>คลิก Management Console</li><li>Search “<strong>Secrets Manager</strong>”</li><li>Search “<strong>Secret Name</strong>” (ex. alpha)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G5EJvOzncERo0Sqo8cyU7Q.png" /><figcaption>REMARK::ในรูปของ sensor ชื่อ secret name ไว้</figcaption></figure><p>7. เลือก Secret Name ที่ต้องการ</p><p>8. แสดงข้อมูล Secret ต่างๆ เช่น <strong>Secret ARN</strong>, <strong>Secret Name</strong>, <strong>Secret value </strong>(คลิก Retrieve secret value), <strong>SDK Code</strong> เป็นต้น</p><h4>ขั้นตอนการ Implement</h4><p>0. ถ้าเป็น Service ที่ต้องรันใน docker ให้ เพิ่ม command install aws cli ก่อนใน <strong>Dcokerfile</strong></p><pre>RUN apt-get update &amp;&amp; apt-get install -y unzip<br>RUN curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot;<br>RUN echo &quot;A&quot; | unzip awscliv2.zip<br>RUN ./aws/install<br>RUN rm awscliv2.zip<br>RUN rm -R aws</pre><p>หลังจากเพิ่ม และ Run docker-compose up -d --build เรียบร้อยแล้วให้เข้า terminal ของ docker เพื่อรัน install sdk (ข้อ 1) และ config credential (ข้อ 2) แล้ว restart docker service</p><p><strong>ตัวอย่างไฟล์แบบเต็ม</strong></p><pre>FROM --platform=linux/amd64 golang:1.20<br>WORKDIR /go/src/<br>ENV GO111MODULE=on<br># RUN go version<br>RUN go install github.com/cespare/reflex@v0.3.1<br>COPY . .<br>RUN apt-get update &amp;&amp; apt-get install -y unzip<br>RUN curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot;<br>RUN echo &quot;A&quot; | unzip awscliv2.zip<br>RUN ./aws/install<br>RUN rm awscliv2.zip<br>RUN rm -R aws<br>ENV CGO_ENABLED=0 GOOS=linux<br>ENV MICRO_CLIENT=grpc MICRO_SERVER=grpc<br>EXPOSE 8888<br>CMD [ &quot;reflex&quot;, &quot;-r &#39;\.go&#39;&quot;, &quot;-s&quot;, &quot;--&quot;, &quot;sh&quot;, &quot;-c&quot;, &quot;go run .&quot; ]</pre><p><strong>Note: </strong>หากเจอ Error ตามภาพ ให้ตรวจสอบ ว่าใน Dockerfile ใช้ platform ไหน ในการ pull image หากไม่ใช่ AMD ให้เปลี่ยนเป็น AMD โดยการเพิ่ม --platform=linux/amd64 หลัง FROM หน้า IMAGE</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wIsUWj_6DVviCkqrpBRzgg.png" /></figure><p><strong>Reference</strong>:</p><p><a href="https://stackoverflow.com/questions/71040681/qemu-x86-64-could-not-open-lib64-ld-linux-x86-64-so-2-no-such-file-or-direc">qemu-x86_64: Could not open &#39;/lib64/ld-linux-x86-64.so.2&#39;: No such file or directory</a></p><ol><li>Install <strong>aws-sdk</strong></li></ol><p><strong>Go Service (aws-sdk-go)</strong></p><pre>$ go get github.com/aws/aws-sdk-go-v2/aws<br>$ go get github.com/aws/aws-sdk-go-v2/config<br>$ go get github.com/aws/aws-sdk-go-v2/service/secretsmanager</pre><blockquote>Note: หาก Install aws-sdk แล้วติดปัญหาดังรูป</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*HM6DBR2r0NZkeW2Wx5GVag.png" /></figure><p>ให้ใส่ required version package ที่ go.mod ดังนี้</p><pre>go 1.14<br><br>replace github.com/aws/aws-sdk-go-v2 =&gt; github.com/aws/aws-sdk-go-v2 v1.18.0<br>replace github.com/aws/aws-sdk-go-v2/config =&gt; github.com/aws/aws-sdk-go-v2/config v1.18.25<br>replace github.com/aws/aws-sdk-go-v2/service/secretsmanager =&gt; github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.19.8<br><br>require (<br> github.com/aws/aws-sdk-go-v2 v1.18.0 // indirect<br> github.com/aws/aws-sdk-go-v2/config v1.18.25 // indirect<br> github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.19.8 // indirect<br>)</pre><p>และ install ด้วย command</p><pre>$ go get github.com/aws/aws-sdk-go-v2@v1.18.0<br>$ go get github.com/aws/aws-sdk-go-v2/config@v1.18.25<br>$ go get github.com/aws/aws-sdk-go-v2/service/secretsmanager@v1.19.8</pre><p><strong>Node.js (aws-sdk)</strong></p><pre>$ yarn add @aws-sdk/client-secrets-manager<br>หรือ<br>$ npm install @aws-sdk/client-secrets-manager</pre><p>2. Login เข้า AWS โดยพิมพ์ command ใน terminal (<strong>local only</strong>)</p><pre>$ aws configure</pre><p>3. กรอกข้อมูล Credential เพื่อ Access เข้า AWS Database ได้ (<strong>local only</strong>) เช่น <strong>User name, Access Key ID, Secret access key</strong></p><p><strong>Note: </strong>ถ้ารันแล้ว Access Denined (ตามรูป)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hObR8czcGX7PrZw3lh9zEA.png" /></figure><p><strong>วิธีแก้</strong></p><ul><li>ตรวจสอบว่ามี <strong>AWS_ACCESS_KEY_ID</strong> และ <strong>AWS_SECRET_ACCESS_KEY</strong> อยู่ใน <strong>.env</strong> หรือไม่ ถ้ามีสามารถลบออกได้เลยใน env <strong>alpha</strong>, <strong>staging</strong>, <strong>preprod</strong>, <strong>prod</strong> ไม่จำเป็นต้องใช้ แต่ใน <strong>local</strong> ยังจำเป็นต้องใช้อยู่ โดยให้เรีก env ใน Secret Manager ก่อน แล้วค่อย assign key ทั้ง 2 key อีกที (ใน code) แล้วลองรันใหม่ (เนื่องจากตอนแรกถ้ามีใน .env ตอน access เข้า secret manager เพื่อ GetSecretValue จะใช้ AWS_ACCESS_KEY_ID และ AWS_SECRET_ACCESS_KEY ของ user ตาม .env ทำให้ไม่มีสิทธิในการอ่านได้)</li><li>ถ้าใน code มี เรียกใช้ AWS_ACCESS_KEY_ID และ AWS_SECRET_ACCESS_KEY ให้ comment credentail ทั้ง 2 ตัว ออกด้วย</li></ul><p><strong>Go Service</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jjOS9hiZhPQ7op4QPLDEqQ.png" /></figure><p><strong>Node.js</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*j3IZapbWY-M2Sa3BE4ttUQ.png" /></figure><p>4. Implement Code ตามไฟล์ ดังนี้</p><h4>file: .env (local only)</h4><ol><li>เพิ่ม config ในไฟล์ .env</li></ol><pre>APP_ENV=local<br>APP_DEBUG=true<br>AWS_SECRET_ARN=&lt;SECRET_ARN&gt;<br>AWS_SECRET_ARN2=&lt;SECRET_ARN2&gt;<br>AWS_REGION_AP_SOUTHEAST_1=&lt;REGION&gt;<br>AWS_SECRET_KEYS=password<br><br>NAMEDB_DATABASE=dbname<br>NAME2DB_DATABASE=db2name<br>NAME3DB_DATABASE=db3name</pre><ul><li><strong>APP_ENV</strong> คือ App Environment</li><li><strong>AWS_SECRET_ARN หรือ AWS_SECRET_ARN2 </strong>คือ Secret Name ที่ได้จากการสร้าง Store สามารถ copy ใน store ได้ใน AWS ในที่นี้ของใส่เป็นตัวแปรไว้ ตั้งชื่ออิงตาม</li></ul><blockquote>arn:aws:secretsmanger:&lt;REGION&gt;:&lt;USER_ID&gt;:secret:&lt;SECRET_NAME&gt;/&lt;USERNAME_DATABASE&gt;-&lt;HASH_ID&gt;: arn:aws:secretsmanager:&lt;SECRE_NAME&gt;/&lt;USERNAME&gt;-&lt;HASH&gt;</blockquote><blockquote>username ที่มีสิทธิเข้าถึง: /username ถ้าเป็น /admin จะมีสิทธิในการเข้าถึง database ทั้งหมดของแต่ละ database type ดูได้จาก Secret Manager (การใช้งานขึ้นอยู่กับ Service นั้นๆ และ role ของ user ขึ้นอยู่กับการให้สิทธิของ DevOps)</blockquote><ul><li><strong>AWS_REGION</strong> คือ Region ที่สร้าง Store ใน AWS</li><li><strong>AWS_SECRET_KEYS</strong> คือ key ของ env ที่ต้องการทำการ decode value เช่น password,… เป็นต้น<br><strong>Note:</strong> format จะเป็น key1,key2,key3,….</li><li><strong>&lt;DATABASE_NAME&gt;DB_DATABASE</strong> จะระบุชื่อ Database ที่ Service นั้นๆใช้งาน เนื่องจากการ config ของ user database ที่ผู้เขียนเจอใน service จะเป็น 1 username สามารถเข้าใช้งานได้หลาย Database (1:n) ดังรูป Diagram ทำให้ต้องระบุ Database Name ที่จะใช้ใน .env (แต่โดยทั่วไปควรเป็น 1:1)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*trotpEM08LGbtq2ou-A6Jg.png" /><figcaption>1 Secret Manager มี 1 Store และ 1 Store มีหลาย ​Database ที่สามารถเข้าใช้งานได้</figcaption></figure><ul><li><strong>env</strong> อื่นๆ ที่ไม่มี Secret Key จะไม่เก็บใน Secret Manager ให้ใส่ไว้ตามเดิม</li></ul><p><strong>Note</strong>: ในกรณีที่ต้องการ Cutomize env (เฉพาะตอน dev) สามารถใส่ในไฟล์ .env ได้ โดยให้ชื่อ Key ตรงกันกันกับ env เดิม เช่น NAMEDB_HOST=host เป็นต้น แต่ถ้ามี env ที่เป็นชื่อใหม่ สามารถเพิ่มใน .env แล้วลองเทสใช้งานใน local ได้เลย</p><h4>file: task-definition-{env}.json (สำหรับทำ CI/CD Jenkins)</h4><ol><li>ระบุค่า “<strong>taskRoleArn</strong>” ซึ่งจะเป็นการระบุว่า Role นั้นๆสามารถ Access Service ใดได้บ้าง</li></ol><pre>{<br>  &quot;taskRoleArn&quot;: &quot;ARN_TASK_ROLE&quot;<br>}</pre><ul><li><strong>taskRoleArn</strong> คือการระบุสิทธิในการเข้าถึง aws service ต่างๆ (DevOps กำหนด)</li></ul><p>2. เพิ่มค่าเหมือนในไฟล์ env ตาม environment ในส่วนของ <strong>“environment”</strong></p><pre>{<br>  &quot;containerDefinitions&quot;: [<br>    &quot;environment&quot;: [<br>        {<br>          &quot;name&quot;: &quot;APP_ENV&quot;,<br>          &quot;value&quot;: &quot;alpha&quot;<br>        },<br>        {<br>          &quot;name&quot;: &quot;APP_DEBUG&quot;,<br>          &quot;value&quot;: &quot;true&quot;<br>        },<br>        {<br>          &quot;name&quot;: &quot;AWS_SECRET_ARN&quot;,<br>          &quot;value&quot;: &quot;SECRET_ARN&quot;<br>        },<br>        {<br>          &quot;name&quot;: &quot;AWS_SECRET_ARN2&quot;,<br>          &quot;value&quot;: &quot;SECRET_ARN2&quot;<br>        },<br>        {<br>          &quot;name&quot;: &quot;AWS_REGION&quot;,<br>          &quot;value&quot;: &quot;REGION&quot;<br>        },<br>        {<br>          &quot;name&quot;: &quot;AWS_SECRET_KEYS&quot;,<br>          &quot;value&quot;: &quot;password&quot;<br>        },<br>        {<br>          &quot;name&quot;: &quot;NAMEDB_DATABASE&quot;,<br>          &quot;value&quot;: &quot;dbname&quot;<br>        },<br>        {<br>          &quot;name&quot;: &quot;NAME2DB_DATABASE&quot;,<br>          &quot;value&quot;: &quot;db2name&quot;<br>        },<br>        {<br>          &quot;name&quot;: &quot;NAME3DB_DATABASE&quot;,<br>          &quot;value&quot;: &quot;db3name&quot;<br>        }<br>      ]<br>    }<br>  ]<br>}</pre><p><strong>Note</strong>: ปรับค่า container_env ใน .jenkinsfile &gt; {env}.Jenkinsfile ด้วย / env ไหนที่ไม่ได้ใช้แล้วลบออกด้วย</p><p>3. ลบค่า Secret Env และค่าที่ไม่ได้ใช้ใน env ต่างๆออกจาก <strong>“environment”</strong> ใน <strong>task-definition-{env}.json</strong></p><h4>file: utils &gt; aws.go หรือ lib &gt; aws.js</h4><p>สร้าง file aws.go เพื่อทำการ Get Secret Env จาก AWS Secret Manager จากนั้น Decode ค่า Secret Env ตามที่ระบุ และ Set ค่า Env ให้กับ Service โดยเพิ่ม code ดังนี้</p><ol><li>กำหนด database ของ service นั้น โดยมีข้อมูลของ<br>- <strong>prefix: </strong>ชื่อ Prefix key ของ database ที่จะเเสดงใน env<br>- <strong>secretARN: </strong>Secret ARN จาก env (ขึ้นอยู่กับ database แต่ละประเภท)<br>- <strong>region: </strong>Region จาก env<br><strong>Note: </strong>เนื่องจากวิธีการเก็บค่าของ env ระหว่างฝั่ง DevOps (เก็บ by Database user มีการกำหนดสิทธิ) กับฝั่ง Dev (เก็บ by service) ไม่เหมือนกัน จึงทำให้ต้องมีการ define ค่าต่างๆตามที่ระบุใน Prefix ด้านบน เพื่อ set ค่าให้กับ env เพื่อใช้งานได้ตาม code เดิม</li></ol><pre>func InitSecretManager() {<br> // Load default .env<br> myconfig.LoadConfig()<br><br> var prefix string<br> var secretARN string<br> var region string<br> var exceptEnv []string<br> appEnv := os.Getenv(&quot;APP_ENV&quot;)<br> <br> // [Optional] Unset S3 Bucket Key<br> os.Unsetenv(&quot;AWS_ACCESS_KEY_ID&quot;)<br> os.Unsetenv(&quot;AWS_SECRET_ACCESS_KEY&quot;)<br> // Name database<br> prefix = &quot;NAMEDB_&quot;<br> secretARN = os.Getenv(&quot;AWS_SECRET_ARN&quot;)<br> exceptEnv = []string{&quot;local&quot;, &quot;alpha&quot;, &quot;staging&quot;}<br> if contains(exceptEnv, appEnv) {<br>  secretARN = os.Getenv(&quot;AWS_SECRET_ARN2&quot;)<br> }<br> region = os.Getenv(&quot;AWS_REGION&quot;)<br> GetEnvFromSecretsManager(prefix, secretARN, region)<br> // Name2 database<br> prefix = &quot;NAM2EDB_&quot;<br> secretARN = os.Getenv(&quot;AWS_SECRET_ARN&quot;)<br> exceptEnv = []string{&quot;local&quot;, &quot;alpha&quot;, &quot;staging&quot;}<br> if contains(exceptEnv, appEnv) {<br>  secretARN = os.Getenv(&quot;AWS_SECRET_ARN2&quot;)<br> }<br> region = os.Getenv(&quot;AWS_REGION&quot;)<br> GetEnvFromSecretsManager(prefix, secretARN, region)<br> // Name3 database<br> prefix = &quot;NAM3EDB_&quot;<br> secretARN = os.Getenv(&quot;AWS_SECRET_ARN&quot;)<br> exceptEnv = []string{&quot;local&quot;, &quot;alpha&quot;, &quot;staging&quot;, &quot;preprod&quot;}<br> if contains(exceptEnv, appEnv) {<br>  secretARN = os.Getenv(&quot;AWS_SECRET_ARN2&quot;)<br> }<br> region = os.Getenv(&quot;AWS_REGION&quot;)<br> GetEnvFromSecretsManager(prefix, secretARN, region)<br>}</pre><pre>async function InitSecretManager() {<br>  delete process.env.AWS_ACCESS_KEY_ID<br>  delete process.env.AWS_SECRET_ACCESS_KEY<br>  let prefix = &#39;&#39;<br>  let secretARN = &#39;&#39;<br>  let region = &#39;&#39;<br>  let exceptEnv = &#39;&#39;<br>  const appEnv = process.env.APP_ENV<br>  // Key - non encoded base64<br> prefix = &#39;&#39;<br> secretARN = process.env.AWS_SECRET_ARN_KEY<br> region = process.env.AWS_REGION_AP_SOUTHEAST_1<br> await GetEnvFromSecretsManager(prefix, secretARN, region)<br>}</pre><p><strong>Remark: </strong>exceptEnv และ appEnv ใช้ในกรณีที่ Database User แต่ละ Environment ใช้ไม่เหมือนกัน</p><p>2. สร้าง Connection ในการ Connect secret manager store</p><pre>func GetEnvFromSecretsManager(prefix string, secretName string, region string) {<br> config, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region))<br> if err != nil {<br>  log.Fatal(err.Error())<br> }<br><br> // Create Secrets Manager client<br> svc := secretsmanager.NewFromConfig(config)<br> input := &amp;secretsmanager.GetSecretValueInput{<br>  SecretId:     aws.String(secretARN),<br>  VersionStage: aws.String(&quot;AWSCURRENT&quot;),<br> }<br> result, err := svc.GetSecretValue(context.TODO(), input)<br> if err != nil {<br>  log.Fatal(err.Error())<br> }<br> SetEnv(prefix, result)<br>}</pre><pre>async function GetEnvFromSecretsManager(prefix, secretARN, region) {<br>  const client = new SecretsManagerClient({ region }) // Create a Secrets Manager client<br>  let result // Retrieve the secret value<br>  try {<br>    result = await <br>    client.send(<br>      new GetSecretValueCommand({<br>        SecretId: secretARN,<br>        VersionStage: &quot;AWSCURRENT&quot;<br>      })<br>    )<br>  } catch (error) {<br>    console.log(`[SECRET MANAGER] Error connect AWS secret manager: ${error}`)<br>    throw error<br>  }<br>  SetEnv(prefix, result)<br>}</pre><p>3. รับค่า Secret Env ที่ได้จาก Secret Manager เพื่อทำการ Decode Value โดยเทียบ Key กับค่าที่ set ไว้ในไฟล์ .env (<strong>AWS_SECRET_KEYS</strong>) และใช้ Prefix ในการ set ค่าให้กับ key ใน env<br><strong>Note</strong>: เนื่องจากค่า Value ที่ Get มาจาก Secret Manager มี \n มาด้วย จึงต้องทำการ Replace ออก</p><pre>func SetEnv(result *secretsmanager.GetSecretValueOutput) {<br> var env map[string]interface{}<br> if result.SecretString != nil {<br>  secretString := *result.SecretString<br>  json.Unmarshal([]byte(secretString), &amp;env)<br><br>  secretKeyName := []string{}<br>  awsSecretKey := os.Getenv(&quot;AWS_SECRET_KEYS&quot;)<br>  if awsSecretKey != &quot;&quot; {<br>   secretKeyName = strings.Split(awsSecretKey, &quot;,&quot;)<br>  }<br>  for key, _ := range env {<br>   secretValue := fmt.Sprintf(&quot;%v&quot;, env[key])<br>   isSecret := contains(secretKeyName, key)<br>   if isSecret {<br>    secretValue = DecryptSecretKey(key, secretValue)<br>   }<br>   key = prefix + strings.ToUpper(key)<br>   secretValue = strings.Replace(secretValue, &quot;\n&quot;, &quot;&quot;, -1)<br>   // for custom .env file<br>   customEnv := os.Getenv(key)<br>   if customEnv != &quot;&quot; {<br>    secretValue = customEnv<br>   }<br>   os.Setenv(key, secretValue)<br>  }<br> }<br>}</pre><pre>function SetEnv(prefix, result) {<br>  let env = {}<br>  if (result.SecretString !== null) {<br>    env = Object.assign(env, JSON.parse(result.SecretString))<br>    let secretKeyName = []<br>    const awsSecretKey = process.env.AWS_SECRET_KEYS<br>    if (awsSecretKey != &#39;&#39;) {<br>      secretKeyName = awsSecretKey.split(&#39;,&#39;)<br>    }<br>    const keys = Object.keys(env)<br>    keys.forEach(key =&gt; {<br>      let secretValue = env[key]<br>      const isSecret = secretKeyName.includes(key)<br>      if (isSecret) {<br>        secretValue = DecryptSecretKey(key, secretValue)<br>      }<br>      key = prefix + key.toUpperCase()<br>      // for custom .env file<br>      const customEnv = process.env[key]<br>      if (customEnv) {<br>        secretValue = customEnv<br>      }<br>      process.env[key] = secretValue<br>    })<br>  }<br>  // console.log(&#39;process.env: &#39;, process.env)<br>}</pre><p>4. Decode ค่า Secret Value ด้วย base64 (เฉพาะค่าที่มีการ encode ไว้ใน Secret Manager)</p><pre>func DecryptSecretKey(key string, secretValue string) string {<br> decodeValue, err := base64.StdEncoding.DecodeString(secretValue)<br> if err != nil {<br>  fmt.Println(&quot;Base64 Decode Error:&quot;, err)<br>  return &quot;&quot;<br> }<br> value := fmt.Sprintf(&quot;%s&quot;, decodeValue)<br> return value<br>}</pre><pre>function DecryptSecretKey(key, secretValue) {<br>  try {<br>    const decodeValue = atob(secretValue)<br>    return decodeValue<br>  } catch (error) {<br>    console.log(`[SECRET MANAGER] Error decode base64: ${error}`)<br>    throw error<br>  }<br>}</pre><p><strong>file: utils &gt; aws.go (แบบเต็ม)</strong></p><pre>package utils<br><br>import (<br> &quot;context&quot;<br> &quot;encoding/base64&quot;<br> &quot;encoding/json&quot;<br> &quot;fmt&quot;<br> &quot;log&quot;<br> &quot;os&quot;<br> &quot;strings&quot;<br> &quot;github.com/aws/aws-sdk-go-v2/aws&quot;<br> &quot;github.com/aws/aws-sdk-go-v2/config&quot;<br> &quot;github.com/aws/aws-sdk-go-v2/service/secretsmanager&quot;<br> myconfig &quot;repository.com/api/config&quot;<br>)<br>func contains(s []string, str string) bool {<br> for _, v := range s {<br>  if v == str {<br>   return true<br>  }<br> }<br> return false<br>}<br>func InitSecretManager() {<br> // Load default .env<br> myconfig.LoadConfig()<br> var prefix string<br> var secretARN string<br> var region string<br> var exceptEnv []string<br> appEnv := os.Getenv(&quot;APP_ENV&quot;)<br> <br> // Unset S3 Bucket Key<br> os.Unsetenv(&quot;AWS_ACCESS_KEY_ID&quot;)<br> os.Unsetenv(&quot;AWS_SECRET_ACCESS_KEY&quot;)<br> // Name database<br> prefix = &quot;NAMEDB_&quot;<br> secretARN = os.Getenv(&quot;AWS_SECRET_ARN&quot;)<br> exceptEnv = []string{&quot;local&quot;, &quot;alpha&quot;, &quot;staging&quot;}<br> if contains(exceptEnv, appEnv) {<br>  secretARN = os.Getenv(&quot;AWS_SECRET_ARN2&quot;)<br> }<br> region = os.Getenv(&quot;AWS_REGION&quot;)<br> GetEnvFromSecretsManager(prefix, secretARN, region)<br> // Name2 database<br> prefix = &quot;NAM2EDB_&quot;<br> secretARN = os.Getenv(&quot;AWS_SECRET_ARN&quot;)<br> exceptEnv = []string{&quot;local&quot;, &quot;alpha&quot;, &quot;staging&quot;}<br> if contains(exceptEnv, appEnv) {<br>  secretARN = os.Getenv(&quot;AWS_SECRET_ARN2&quot;)<br> }<br> region = os.Getenv(&quot;AWS_REGION&quot;)<br> GetEnvFromSecretsManager(prefix, secretARN, region)<br> // Name3 database<br> prefix = &quot;NAM3EDB_&quot;<br> secretARN = os.Getenv(&quot;AWS_SECRET_ARN&quot;)<br> exceptEnv = []string{&quot;local&quot;, &quot;alpha&quot;, &quot;staging&quot;, &quot;preprod&quot;}<br> if contains(exceptEnv, appEnv) {<br>  secretARN = os.Getenv(&quot;AWS_SECRET_ARN2&quot;)<br> }<br> region = os.Getenv(&quot;AWS_REGION&quot;)<br> GetEnvFromSecretsManager(prefix, secretARN, region)<br>}<br>func GetEnvFromSecretsManager(prefix string, secretARN string, region string) {<br> config, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region))<br> if err != nil {<br>  log.Fatal(err.Error())<br> }<br> // Create Secrets Manager client<br> svc := secretsmanager.NewFromConfig(config)<br> input := &amp;secretsmanager.GetSecretValueInput{<br>  SecretId:     aws.String(secretARN),<br>  VersionStage: aws.String(&quot;AWSCURRENT&quot;),<br> }<br> result, err := svc.GetSecretValue(context.TODO(), input)<br> if err != nil {<br>  log.Fatal(err.Error())<br> }<br> SetEnv(prefix, result)<br>}<br>func SetEnv(prefix string, result *secretsmanager.GetSecretValueOutput) {<br> var env map[string]interface{}<br> if result.SecretString != nil {<br>  secretString := *result.SecretString<br>  json.Unmarshal([]byte(secretString), &amp;env)<br>  secretKeyName := []string{}<br>  awsSecretKey := os.Getenv(&quot;AWS_SECRET_KEYS&quot;)<br>  if awsSecretKey != &quot;&quot; {<br>   secretKeyName = strings.Split(awsSecretKey, &quot;,&quot;)<br>  }<br>  for key, _ := range env {<br>   secretValue := fmt.Sprintf(&quot;%v&quot;, env[key])<br>   isSecret := contains(secretKeyName, key)<br>   if isSecret {<br>    secretValue = DecryptSecretKey(key, secretValue)<br>   }<br>   key = prefix + strings.ToUpper(key)<br>   secretValue = strings.Replace(secretValue, &quot;\n&quot;, &quot;&quot;, -1)<br>   // for custom .env file<br>   customEnv := os.Getenv(key)<br>   if customEnv != &quot;&quot; {<br>    secretValue = customEnv<br>   }<br>   os.Setenv(key, secretValue)<br>  }<br>  // fmt.Println(&quot;env: &quot;, os.Environ())<br> }<br>}<br>func DecryptSecretKey(key string, secretValue string) string {<br> decodeValue, err := base64.StdEncoding.DecodeString(secretValue)<br> if err != nil {<br>  fmt.Println(&quot;Base64 Decode Error:&quot;, err)<br>  return &quot;&quot;<br> }<br> value := fmt.Sprintf(&quot;%s&quot;, decodeValue)<br> return value<br>}</pre><p><strong>file: lib &gt; aws.js (แบบเต็ม)</strong></p><pre>const { SecretsManagerClient, GetSecretValueCommand } = require(&#39;@aws-sdk/client-secrets-manager&#39;)<br>async function InitSecretManager() {<br>  delete process.env.AWS_ACCESS_KEY_ID<br>  delete process.env.AWS_SECRET_ACCESS_KEY<br>  let prefix = &#39;&#39;<br>  let secretARN = &#39;&#39;<br>  let region = &#39;&#39;<br>  let exceptEnv = &#39;&#39;<br>  const appEnv = process.env.APP_ENV<br>  // Key - non encoded base64<br> prefix = &#39;&#39;<br> secretARN = process.env.AWS_SECRET_ARN_KEY<br> region = process.env.AWS_REGION_AP_SOUTHEAST_1<br> await GetEnvFromSecretsManager(prefix, secretARN, region)<br>}<br>async function GetEnvFromSecretsManager(prefix, secretARN, region) {<br>  const client = new SecretsManagerClient({ region }) // Create a Secrets Manager client<br>  let result // Retrieve the secret value<br>  try {<br>    result = await <br>    client.send(<br>      new GetSecretValueCommand({<br>        SecretId: secretARN,<br>        VersionStage: &quot;AWSCURRENT&quot;<br>      })<br>    )<br>  } catch (error) {<br>    console.log(`[SECRET MANAGER] Error connect AWS secret manager: ${error}`)<br>    throw error<br>  }<br>  SetEnv(prefix, result)<br>}<br>function SetEnv(prefix, result) {<br>  let env = {}<br>  if (result.SecretString !== null) {<br>    env = Object.assign(env, JSON.parse(result.SecretString))<br>    let secretKeyName = []<br>    const awsSecretKey = process.env.AWS_SECRET_KEYS<br>    if (awsSecretKey != &#39;&#39;) {<br>      secretKeyName = awsSecretKey.split(&#39;,&#39;)<br>    }<br>    const keys = Object.keys(env)<br>    keys.forEach(key =&gt; {<br>      let secretValue = env[key]<br>      const isSecret = secretKeyName.includes(key)<br>      if (isSecret) {<br>        secretValue = DecryptSecretKey(key, secretValue)<br>      }<br>      key = prefix + key.toUpperCase()<br>      // for custom .env file<br>      const customEnv = process.env[key]<br>      if (customEnv) {<br>        secretValue = customEnv<br>      }<br>      process.env[key] = secretValue<br>    })<br>  }<br>  // console.log(&#39;process.env: &#39;, process.env)<br>}<br>function DecryptSecretKey(key, secretValue) {<br>  try {<br>    const decodeValue = atob(secretValue)<br>    return decodeValue<br>  } catch (error) {<br>    console.log(`[SECRET MANAGER] Error decode base64: ${error}`)<br>    throw error<br>  }<br>}<br>module.exports = {<br>  InitSecretManager<br>}</pre><h4>file: main.go</h4><p>เพิ่ม function ภายใต้ main() ก่อนเริ่ม connect database และเริ่ม process ต่างๆ เพื่อทำการ Get Secret Env จาก AWS Secret Manager จากนั้น Decode ค่า Secret Env ตามที่ระบุ และ Set ค่า Env ให้กับ Service</p><ul><li>สำหรับ Service ที่<em>ไม่มี</em> S3 bucket key ใน .env</li></ul><p><strong>Go Service</strong></p><pre>// Import utils file<br>&quot;repository.ch3plus.com/sso/user-service/utils&quot;<br><br>// Get AWS Secret Env (all service)<br>utils.InitSecretManager()</pre><p><strong>Node.js</strong></p><pre>// Load .env<br>require(&#39;dotenv&#39;).config()<br><br>const express = require(&#39;express&#39;)<br>const app = express()<br><br>// Import lib file<br>const { InitSecretManager } = require(&#39;./lib/aws&#39;)<br><br>// [optional] For service have s3 buckey only<br>const appEnv = process.env.APP_ENV || &#39;local&#39;<br>const awsAccessKeyID = process.env.AWS_ACCESS_KEY_ID<br>const awsSecretAccessKey = process.env.AWS_SECRET_ACCESS_KEY<br><br>// Get AWS Secret Env (all service)<br>InitSecretManager().then(() =&gt; {<br><br>    // [optional] For service have s3 bucket only<br>    if (appEnv == &#39;local&#39;) {<br>        process.env.AWS_ACCESS_KEY_ID = awsAccessKeyID<br>        process.env.AWS_SECRET_ACCESS_KEY = awsSecretAccessKey<br>    }<br><br>    // Code อื่นๆที่ใช้ในการเรียก route ต่างๆ<br>    const cors = require(&#39;cors&#39;)<br>    const otherRouter = require(&#39;./routes/other&#39;)<br>    app.use(logger(&#39;dev&#39;, {<br>        skip: (req, res) =&gt; {<br>            const routes = [&#39;/health&#39;] // route lists for ignore debug log <br>            let isDisable = false<br>            routes.forEach(v =&gt; {<br>                if (v === req.url) {<br>                    isDisable = true<br>                }<br>            })<br>            return isDisable<br>        }<br>    }))<br><br>    app.use(cors({origin: &#39;*&#39;}))<br><br>    app.get(&#39;/health&#39;, (req, res) =&gt; {<br>        res.status(200).send(&#39;Ok&#39;)<br>    });<br><br>    app.get(&#39;/res/all&#39;, async (req, res) =&gt; {<br>      res.sendStatus(200)<br>    })<br><br>    app.use(&#39;/other&#39;, otherRouter)<br>})<br><br>module.exports = app</pre><ul><li>สำหรับ Service ที่<em>มี</em> S3 bucket key ใน .env</li></ul><p><strong>Go Service</strong></p><pre>// Import utils file<br>&quot;repository/service/utils&quot;<br>// [optional] For service have s3 buckey only<br>appEnv := os.Getenv(&quot;APP_ENV&quot;)<br>awsAccessKeyID := os.Getenv(&quot;AWS_ACCESS_KEY_ID&quot;)<br>awsSecretAccessKey := os.Getenv(&quot;AWS_SECRET_ACCESS_KEY&quot;)<br>// Get AWS Secret Env (all service)<br>utils.InitSecretManager()<br>// [optional] For service have s3 buckey only<br>if appEnv == &quot;local&quot; {<br> os.Setenv(&quot;AWS_ACCESS_KEY_ID&quot;, awsAccessKeyID)<br> os.Setenv(&quot;AWS_SECRET_ACCESS_KEY&quot;, awsSecretAccessKey)<br> bootstrap.InitOAuth(conf)<br>}</pre><p><strong>Node.js</strong></p><pre>// Import lib file<br>const { InitSecretManager } = require(&#39;./lib/aws&#39;)<br>// [optional] For service have s3 buckey only<br>const appEnv = process.env.APP_ENV || &#39;local&#39;<br>const awsAccessKeyID = process.env.AWS_ACCESS_KEY_ID<br>const awsSecretAccessKey = process.env.AWS_SECRET_ACCESS_KEY<br>// Get AWS Secret Env (all service)<br>InitSecretManager().then(() =&gt; {<br>    // [optional] For service have s3 bucket only<br>    if (appEnv == &#39;local&#39;) {<br>        process.env.AWS_ACCESS_KEY_ID = awsAccessKeyID<br>        process.env.AWS_SECRET_ACCESS_KEY = awsSecretAccessKey<br>    }<br>})<br>// [optional] For service have s3 buckey only<br>if (appEnv == &#39;local&#39;) {<br>    process.env.AWS_ACCESS_KEY_ID = awsAccessKeyID<br>    process.env.AWS_SECRET_ACCESS_KEY = awsSecretAccessKey<br>}</pre><h4>ขั้นตอนการตรวจสอบว่า Code ทำงานได้</h4><ol><li>Login AWS (<a href="https://becicorp.awsapps.com/start#/">https://becicorp.awsapps.com/start#/</a> )</li><li>คลิก AWS Account</li><li>เลือก Service</li><li>คลิก Management Console</li><li>Search “<strong>ECS</strong>”</li><li>เลือก Cluster ตาม environment ของ Service (เช่น service: api จะอยู่ใน cluster: coreapi-alpha)</li><li>เลือก Service ที่ต้องการ (เช่น api-alpha)</li><li>ตรวจสอบ status ในการ build pipeline บน jenkins (ต้องไม่ failed)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7joR0-cxRxskcav8RefJeQ.png" /></figure><p><strong>Note: </strong>ถ้าหน้า UI แสดงไม่เหมือนในรูปให้ enable “<strong>New ECS Experience”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*HALuzds-jsLPx3EIbUlY7g.png" /></figure><p>9. คลิก tab “<strong>Logs</strong>” เพื่อตรวจสอบการทำงาน จะต้อง connect database และ service อื่นๆ ได้ตามปกติตาม config ใน env</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1qrin3EcZ9SjPT0toMDolQ.png" /></figure><blockquote>สำหรับภาษาอื่นๆ สามารถดูใน Sample Code ของหน้า Secret Manager &gt; Secret Arn ของแต่ละ Secret Arn ได้</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ZeexzFmYnPFKEYTt9ClWg.png" /></figure><blockquote><strong>Note:</strong> หากต้องการ disable log health check (route: /health) ใน service node.js สามารถทำได้โดย</blockquote><ol><li>Install morgan</li></ol><pre>$ yarn add morgan<br>หรือ<br>$ npm install morgan</pre><p>2. เพิ่ม code ในหน้า app.js</p><pre>app.use(logger(&#39;dev&#39;, {<br>    skip: (req, res) =&gt; {<br>        const routes = [&#39;/health&#39;]<br>        let isDisable = false<br>        routes.forEach(v =&gt; {<br>            if (v === req.url) {<br>                isDisable = true<br>            }<br>        })<br>        return isDisable<br>    }<br>}))</pre><p><strong>Reference:</strong></p><ul><li><a href="https://arshadzackeriya.medium.com/use-aws-secret-manager-with-a-simple-golang-ecs-task-f858d90f5d77">Use AWS Secret Manager with a simple Golang ECS Task.</a></li><li><a href="https://medium.com/yemeksepeti-teknoloji/can-you-keep-a-secret-using-aws-secrets-manager-with-golang-647185280fb6">Can You Keep a Secret? — Using AWS Secrets Manager with Golang</a></li><li><a href="https://medium.com/@nd1292/aws-configure-for-docker-containers-with-or-without-jenkins-b4c1443a15c9">AWS configure for Docker Containers with Jenkins Pipeline.</a></li><li><a href="https://xd04.medium.com/aws-secrets-manager-nodejs-8ff19bc13e3b">AWS Secrets Manager + Nodejs</a></li><li><a href="https://github.com/expressjs/morgan/issues/119">Ignoring specific HTTP endpoint (like health check endpoints) · Issue #119 · expressjs/morgan</a></li><li><a href="https://github.com/expressjs/morgan#skip">GitHub - expressjs/morgan: HTTP request logger middleware for node.js</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c00d609a6d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[How to] การทำ Tuning Performance SQL Queries (Basic)]]></title>
            <link>https://medium.com/@st.nann/how-to-%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%97%E0%B8%B3-tuning-performance-sql-queries-basic-2afea3fa4029?source=rss-15377a775571------2</link>
            <guid isPermaLink="false">https://medium.com/p/2afea3fa4029</guid>
            <category><![CDATA[phpmyadmin]]></category>
            <category><![CDATA[tuning]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[st.nann]]></dc:creator>
            <pubDate>Sat, 02 Oct 2021 02:05:06 GMT</pubDate>
            <atom:updated>2021-10-02T02:05:06.479Z</atom:updated>
            <content:encoded><![CDATA[<p>ก่อนอื่นต้องบอกก่อนว่าในบทความนี้ จะใช้ tool PHP MyAdmin ในการ monitor ถ้าไม่มีสามารถใช้ tool อื่นๆแทนได้ ตามความถนัด</p><p>มีใครเคยเจอปัญหาการใช้งาน query SQL ต่างๆ แล้วทำให้ performance ของระบบไม่ได้ประสิทธิที่ภาพที่ดี ช้าลงบ้างมั้ย ?</p><p>ถ้าเคยในบทความนี้จะมีวิธีในการ tuning performance เบื้องต้น มาให้ลองทำกัน โดยมีวิธี ดังนี้</p><h4>Solution 1</h4><p>การทำ <strong>Index</strong> ให้กับ field ข้อมูลที่ใช้การ query ด้วยเงื่อนไข where โดยหากมีการทำ index จะทำให้ query ทำการค้นหาได้ไวขึ้น ซึ่งปกติจะต้องทำการค้นหาทั้งหมด ถ้าทำ index ก็จะหาถึงแค่ข้อมูลที่เจอ โดยคำสั่ง SQL ที่ใช้ในการตรวจสอบคือ</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3edc30c04f27b663e2d4f43995a6bb9b/href">https://medium.com/media/3edc30c04f27b663e2d4f43995a6bb9b/href</a></iframe><p><em>หมายเหตุ: หากมีเงื่อนไขเพิ่มเติมสามารถ ใส่เพิ่มได้เลย</em></p><p><strong>ผลลัพธ์</strong></p><p>เมื่อทำการ query โดยใส่ EXPLAIN หน้า query ข้อมูลจะแสดงตามภาพด้านล่าง โดยสามารถดูความเปลี่ยนแปลงได้จาก</p><ul><li><em>possible_keys / key</em>: sql จะแสดงให้เห็นว่ามีการทำ index หรือไม่ แล้วค้นหาผ่าน query ไหนบ้าง</li><li><em>key_len</em>: หากมีค่าเป็น NULL แสดงว่า query ทำการหาจากข้อมูลทั้งหมด</li><li><em>rows</em>: จำนวน record ที่ query ทำการค้นหา ซึ่งจากผลลัพธ์ด้านล่างจะเห็นว่า ก่อนทำ กับหลังทำ index ต่างกันพอสมควร</li></ul><p><strong>ก่อนทำ index</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lxYDuU3Ht7Dho0113-CuOQ.png" /></figure><p><strong>หลังทำ index</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pvXYmw6HBVIw-z5L1lnmsg.png" /></figure><p><em>หมายเหตุ: เนื่องจาก SQL เป็นข้อมูลจริง จึงทำการปิด query บางส่วนไว้</em></p><p>หากต้องการทำ index เพิ่มเติมสามารถดูวิธีการทำได้ตามด้านล่าง</p><p><strong>วิธีการทำ Index</strong></p><p>ให้รันคำสั่ง SQL ดังนี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72a729a948b934ebf9a6a097d0adf2a9/href">https://medium.com/media/72a729a948b934ebf9a6a097d0adf2a9/href</a></iframe><p><strong>Solution 2</strong></p><p>การดูข้อมูลของ slow_query โดยสามารถดูได้จาก</p><p><strong>Database</strong>: mysql<br><strong>Table</strong>: slow_log</p><p>แต่ก่อนอ่นต้องการทำ Enable การเก็บ log ก่อน โดย</p><ol><li>คลิกที่รูป <strong>บ้าน (Dashboard)</strong> ของหน้า PHP MyAdmin</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*G4kFFbMDr4qT2EQXNDwsiA.png" /></figure><p>2. คลิกที่แถบเมนู <strong>Status</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mXvu8bPn1t3-QZKAyWcQ5g.png" /></figure><p>3. คลิก Monitor</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jSIOeajDtIsCAMjJw-KapQ.png" /></figure><p>4. คลิก Instructions/Setup</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*X45PlKJPWSBGjEmiCnzyFg.png" /></figure><p>5. ระบบจะแสดง popup ตามด้านล่าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pkdeaf1avyZZiUOH3feFog.png" /></figure><p>6. จากนั้นทำการ Enable log ทั้งหมด โดย</p><ul><li>คลิก Set log_output to TABLE: ตั้งค่าการเก็บ log ที่ตาราง log_output</li><li>คลิก Enable general_log: เปิดการเก็บ log การ query ปกติ</li><li>คลิก Enable slow_query_log: เปิดการเก็บ log ที่ทำให้ slow query</li><li>คลิก Set long_query_time to 1 seconds: ตั้งค่า long_query_time เป็น 1 วินาที</li></ul><p>เมื่อคลิกเรียบร้อยแล้วจะแสดง ดังรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V-qxdEoOXgAAKe9KBl3Kcw.png" /></figure><p>7. จากนั้นทำการทำ query ปกติตามต้องการ แล้วสังเกตผลลัพธได้ที่<br><strong>Database</strong>: mysql<br><strong>Table</strong>: slow_log</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zeh99vIamzZaxzH1B4uU4A.png" /></figure><p>จะเห็นว่า log แสดงให้เห็นว่า query ไหนที่ทำให้ช้า performance ตกบ้าง จากนั้นให้ทำการแก้ไข และตรวจสอบดูอีกครั้งหนึ่ง หาก ไม่มี query ไหนที่ทำให้ performance ตกแล้ว log จะไม่ทำการ insert log เพิ่มเติม</p><p><strong>Solution 3</strong></p><p>นอกจากจะทำการ <strong>tuning performance</strong> ตามขั้นตอนข้างบนแล้ว ก็จำเป็นต้องตรวจสอบ SQL ที่เขียนด้วยว่ามีความจำเป็น หรือมีส่วนไหนที่ปรับให้มาทำใน code แทนการ SQLได้หรือไม่ หากทำได้ควรปรับเพิ่มเติม แต่ถ้าหากไม่สามารถปรับไปเขียนใน code ได้ ก็สามารถตรวจสอบที่ SQL ได้ว่ามีคำสั่งไหนที่ปรับได้บ้าง เช่น</p><ul><li>หากใช้ <em>UNION ALL</em> หากไม่จำเป็นต้องใช้ สามารถใช้ <em>UNION</em> แทนได้ เพราะ union จะทำการ query ข้อมูลออกมาแค่ส่วนที่เหมือนกันจริงๆ ไม่เอาตัวที่ซ้ำกันออกมา</li><li>ควรใช้ <em>WHERE</em> หรืแ <em>INNER JOIN</em> แล้วทำ index แทนการทำ JOIN อื่นๆ และ HAVING</li><li><em>SELECT</em> เฉพาะ field ที่จำเป็น แทนการ <em>SELECT *</em></li><li>ลดการใช้ <em>wildcard</em> ในการค้นหา โดน wildcard คือ การใช้ % ในการค้นหาแบบ like</li></ul><p>ตัวอย่างอื่นๆ เพิ่มเติม สามารถดูได้ที่</p><ul><li><a href="https://mode.com/sql-tutorial/sql-performance-tuning/">Performance Tuning SQL Queries | Advanced SQL - Mode</a></li><li><a href="https://www.sisense.com/blog/8-ways-fine-tune-sql-queries-production-databases/">8 Ways to Fine-Tune Your SQL Queries (for Production Databases) | Sisense</a></li><li><a href="https://www.sqlshack.com/query-optimization-techniques-in-sql-server-tips-and-tricks/">Query optimization techniques in SQL Server: tips and tricks</a></li></ul><p>หากทำการ Tuning Performance เรียบร้อยแล้ว สามารถดู Graph Monitor ใน PHP MyAdmin ได้ดังนี้</p><ol><li>คลิกที่รูป <strong>บ้าน (Dashboard)</strong> ของหน้า PHP MyAdmin</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*G4kFFbMDr4qT2EQXNDwsiA.png" /></figure><p>2. คลิกที่แถบเมนู <strong>Status</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mXvu8bPn1t3-QZKAyWcQ5g.png" /></figure><p>3. คลิก Monitor</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jSIOeajDtIsCAMjJw-KapQ.png" /></figure><p>4. ตรวจสอบกราฟ Performance โดยมีรายละเอียด ดังนี้</p><ul><li><em>Questions</em>: Performance การ Query</li><li><em>Connections</em>: Performance การ Connection</li><li><em>Traffic</em>: จำนวนข้อมูลของการค้นหา</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5-6QSEDsQj-IKQKQ8PLMmQ.png" /></figure><p>นอกจาก Graph ที่แสดงข้าง สามารถตั้งค่า Graph ที่จะให้แสดงเพิ่มเติมได้โดย สามารถคลิก <strong>Settings</strong> &gt; <strong>Add chart</strong> &gt; <strong>เลือก Graph ได้ที่ Preset chart</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*LCToLP5-m1sEjPUqQQnf4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*hueEUPcscovJv_oQT9h_Yw.png" /></figure><p>และ Add chart โดย Graph อื่นๆ ก็จะมี</p><ul><li>Query cache efficiency: ประสิทธิภาพการค้นหาโดยใช้ cache</li><li>Query cache usage: การค้นหาโดยใช้ cache</li><li>System CPU usage: ประสิทธิภาพการใช้ CPU</li><li>System memory: ประสิทธิภาพการใช้ RAM</li><li>System swap: ประสิทธิภาพการใช้ swap</li></ul><p>เมื่อเพิ่มแล้วจะแสดง ดังรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_OeOcW3KZrQRhp1kJTHqyQ.png" /></figure><p>ขั้นตอนด้านบนเป็เพียงการ Tuning Performance เบื้องต้นเท่านั้น ซึ่งยังมีวิธีการอื่นๆอีกมากมายสำหรับการ Tuning Performance</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2afea3fa4029" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[How to] ทำ Pipeline CI Mirror Repository จาก Gitlab ไปยัง GitHub และ Bitbucket]]></title>
            <link>https://medium.com/@st.nann/how-to-%E0%B8%97%E0%B8%B3-pipeline-ci-mirror-repository-%E0%B8%88%E0%B8%B2%E0%B8%81-gitlab-%E0%B9%84%E0%B8%9B%E0%B8%A2%E0%B8%B1%E0%B8%87-github-1545617516f1?source=rss-15377a775571------2</link>
            <guid isPermaLink="false">https://medium.com/p/1545617516f1</guid>
            <category><![CDATA[repositories]]></category>
            <category><![CDATA[mirror]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[pipeline]]></category>
            <dc:creator><![CDATA[st.nann]]></dc:creator>
            <pubDate>Sat, 25 Sep 2021 04:01:58 GMT</pubDate>
            <atom:updated>2021-10-01T14:52:08.561Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*79rG3f81AqTu3oAox675Gg.jpeg" /><figcaption>reference: <a href="https://www.slideshare.net/AmazonWebServices/scale-cicd-configuration-management-pipelines-with-git-amazon-efs-sqs-stg330-aws-reinvent-2018">https://www.slideshare.net/AmazonWebServices/scale-cicd-configuration-management-pipelines-with-git-amazon-efs-sqs-stg330-aws-reinvent-2018</a></figcaption></figure><p>หลังจากได้ลองทำ <strong>Mirror Repository</strong> แบบ <strong>manual</strong> โดยใช้ Gitlab ไปแล้วจากบทความนี้</p><p><a href="https://medium.com/@st.nann/how-to-%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87-mirror-repository-%E0%B8%A3%E0%B8%B0%E0%B8%AB%E0%B8%A7%E0%B9%88%E0%B8%B2%E0%B8%87-gitlab-%E0%B8%81%E0%B8%B1%E0%B8%9A-github-%E0%B9%81%E0%B8%A5%E0%B8%B0-gitlab-%E0%B8%81%E0%B8%B1%E0%B8%9A-bitbucket-a1da93bfe6c9">[How to] สร้าง Mirror Repository ระหว่าง GitLab กับ GitHub และ GitLab กับ BitBucket</a></p><p>และสร้าง <strong>pipeline CI/CD</strong> โดยใช้ <strong>Gitlab CI</strong> ไปแล้วจากบทความนี้</p><p><a href="https://medium.com/@st.nann/how-to-%E0%B8%97%E0%B8%B3-pipeline-ci-cd-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-gitlab-1c4bee6e42e7">[How to] ทำ Pipeline CI/CD ด้วย Gitlab</a></p><p>ที่นี้จะลองมาทำ <strong>pipeline</strong> ในการ <strong>build mirror repository</strong> แบบ<strong>อัตโนมัติ</strong> กันดู โดยมีขั้นตอน ดังนี้</p><ol><li>ภายใน source code ที่ต้องการทำ pipeline ให้สร้างไฟล์ชื่อ <strong>.gitlab-ci.yml</strong> ซึ่งเมื่อทำการ push และ merge code ขึ้น Gitlab แล้ว ทาง Gitlab จะทำการอ่านไฟล์นี้โดยอัตโนมัติ</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*_zVKlpgWnoFPEvLGKrvPnA.png" /></figure><p>2. ภายในไฟล์ .gitlab-ci.yml ให้พิมพ์คำสั่งในการทำ Mirror Repository โดยมีรายละเอียด ดังนี้ (สามารถเพิ่มขั้นตอน หรือ script อื่นๆได้ตามต้องการ)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fdea62184c3b2fb3085982976da8714/href">https://medium.com/media/3fdea62184c3b2fb3085982976da8714/href</a></iframe><ul><li><strong>github-push</strong><em>: </em>จะเป็นส่วนที่อยู่ในส่วนของ <strong>CI</strong> มีขั้นตอนการทำงาน ดังนี้ (ขั้นตอนขึ้นอยู่กับแต่ละ project)<br>- <em>stage</em>: ชื่อของขั้นตอนที่แสดงใน pipeline จะเป็นชื่อตามขั้นตอนใน stages<br>- <em>only</em>: branch ที่ต้องการให้ทำ pipeline<br>- <em>​script</em>: คำสั่งที่ต้องการให้ทำใน stage นี้ทั้งหมด ซึ่งในที่น้ี ให้ทำการ Mirror Repository ไปยัง GitHub และ Bitbucket</li></ul><p>โดยมีขั้นตอน <strong>script</strong> ดังนี้</p><ul><li><em>git clone — bare …</em> : ทำการ clone repository จาก Gitlab โดนการ clone แบบ bare จะเป็นการ clone ให้อยู่ใน directory .git</li><li><em>cd &lt;ชื่อ REPOSITORY&gt;</em>: เข้าไปยัง folder &lt;ชื่อ REPOSITORY&gt;</li><li><em>git config — global user.email …</em> : ตั้งค่า Email ที่ใช้ในการเข้าถึงในการทำ Mirror Repository โดยในคำสั่งนี้จะมีการใช้ตัวแปรของ Gitlab ด้วย คือ <em>$GITHUB_PRIVATE_EMAIL (ขั้นตอนการสร้างจะแสดงให้ดูในหัวข้อ “การสร้างตัวแปร (variable) Gitlab”)</em></li><li><em>git reset — soft HEAD~1: </em>จะนำสิ่งที่เคย commit กลับมายังสถานะ staged เหมือนก่อน commit แต่ add ไปหมดแล้ว โดยในคำสั่งนี้จะมีการใช้ตัวแปรของ Gitlab ด้วย คือ <em>$GITHUB_ACCESS_TOKEN, $BITBUCKET_ACCESS_TOKEN </em>และ <em>$MIRROR_USERNAME (ขั้นตอนการสร้าง variable สามารถดูได้ในหัวข้อ “การสร้างตัวแปร (variable) Gitlab” และขั้นตอนการสร้าง $BITBUCKET_ACCESS_TOKEN สามารถดูได้ในหัวข้อ “การสร้าง Bitbucket Access Token” ด้านล่าง)</em></li><li><em>git push — mirror …</em> : การ push mirror repository ขึ้น GitHub และ Bitbucket</li><li><em>cd ..</em> : เข้าไปที่ folder root</li><li><em>rm -rf &lt;ชื่อ REPOSITORY&gt;</em>: ลบไฟล์ &lt;ชื่อ REPOSITORY&gt;</li></ul><p>3. หลังจากนั้นทำการ push code ขึ้น Gitlab และทำการ merge เข้า master จากนั้น pipeline จะทำการรัน และทำการ sync Mirror Repository เข้า GitHub และ Bitbucket ตามลำดับ</p><p>โดยวิธีการตรวจสอบ pipeline สามารถดูได้ที่</p><p><a href="https://medium.com/@st.nann/how-to-%E0%B8%97%E0%B8%B3-pipeline-ci-cd-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-gitlab-1c4bee6e42e7">[How to] ทำ Pipeline CI/CD ด้วย Gitlab</a></p><p>และวิธีการตรวจสอบ Mirror Repository สามารถดูได้ที่</p><p><a href="https://medium.com/@st.nann/how-to-%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87-mirror-repository-%E0%B8%A3%E0%B8%B0%E0%B8%AB%E0%B8%A7%E0%B9%88%E0%B8%B2%E0%B8%87-gitlab-%E0%B8%81%E0%B8%B1%E0%B8%9A-github-%E0%B9%81%E0%B8%A5%E0%B8%B0-gitlab-%E0%B8%81%E0%B8%B1%E0%B8%9A-bitbucket-a1da93bfe6c9">[How to] สร้าง Mirror Repository ระหว่าง GitLab กับ GitHub และ GitLab กับ BitBucket</a></p><h4>ไฟล์ .gitlab-ci.yml แบบสมบูรณ์</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c859e7ae65e765ad6235aa29efd275b/href">https://medium.com/media/2c859e7ae65e765ad6235aa29efd275b/href</a></iframe><h4><em>การสร้างตัวแปร (variable) Gitlab</em></h4><ol><li>เข้า website ของ GitLab โดยไปที่ Project ที่ต้องการสร้าง</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FNSzGb2pPdHxooSvQD5AcQ.png" /></figure><p>2. คลิกที่ <strong>Settings &gt; CI/CD</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*89s_d5mxUHH6KD5Vw6egkQ.png" /></figure><p>3. ในหัวข้อ <strong>variable</strong> ให้คลิก <strong>Expand</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LbxBVUlrTZXj9wWqUhlHKA.png" /></figure><p>4. ทำการเพิ่มตัวแปรที่ต้องการ โดยคลิก <strong>Add variable</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GyXnza05jZBN9pHN-BlwFw.png" /></figure><p>5. จากนั้นให้กรอกรายละเอียด variable โดยมีรายละเอียด ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fVM3jrLe4eXZQpzH9RBGuQ.png" /></figure><ul><li><strong>Key</strong>: ชื่อ variable</li><li><strong>Value</strong>: ค่าของ variable</li><li><strong>Type</strong>: เลือก Variable</li><li><strong>Environment scope</strong>: Environment ที่ต้องการใช้ variable</li><li><strong>Flags:<br></strong><em> — Protect variable: </em>Export variable ได้เฉพาะ branch กับ tag ที่เป็น protected เท่านั้น<em><br> — Mask variable: </em>หากเลือก Gitlab จะทำการซ่อนค่าที่แสดงใน logs ตอนรัน job เพื่อความปลอดภัยของ variable เช่น password, token, key ต่างๆ</li></ul><p>6. จากนั้นคลิก <strong>Add variable ก็</strong>จะแสดงตามตารางด้านล่าง ซึ่งสามารถนำไปใช้ในไฟล์<strong> .gitlab-ci.yml </strong>ได้ โดยใส่<strong> $ </strong>ด้านหน้า</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lm0R16sbrX4tQwUdEXEG6g.png" /></figure><h4><em>การสร้าง Bitbucket Access Token</em></h4><ol><li>คลิกที่รูป Profile ที่แถบ sidebar ด้านล่าง</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*SMVwOc6o7pxNH47fYUCaDA.png" /></figure><p>2. คลิก <strong>Personal settings</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*KjAQhgGaYofwc7GpVIZ2aQ.png" /></figure><p>3. เมื่อแสดงหน้า Personal Settings แล้ว ให้เลือกเมนู <strong>App passwords</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*5qbG3BKzn1qEZ0qnABC7nA.png" /></figure><p>4. จากนั้นคลิก <strong>Create app password</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AD-xZFSdr6J6j29j1HcYXw.png" /></figure><p>5. จากนั้นกรอกรายละเอียดระบุชื่อที่สื่อถึง Token ในช่อง <strong>Label</strong> และ assign <strong>Permissions</strong> สำหรับการเข้าถึงของ Token ที่สร้าง (สำหรับ Mirror Repository ให้เลือก Repositories — Read, Write)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0EzlEdEG-vWIrTeGfYbzNw.png" /></figure><p>6. จากนั้นคลิก <strong>Create</strong> เมื่อคลิกแล้วระบบจะแสดง popup ตามภาพ จากนั้น <strong>copy Access Token</strong> ที่ได้ เพื่อนำไปใช้งานได้ตามต้องการ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*e9hKCDJJVqVQ6TeGEQX6gQ.png" /></figure><p>7. ในตารางจะแสดงข้อมูล ดังรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7UXDWXoLsXtPb41bD-xfeQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1545617516f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[How to] ทำ Pipeline CI/CD ด้วย Gitlab]]></title>
            <link>https://medium.com/@st.nann/how-to-%E0%B8%97%E0%B8%B3-pipeline-ci-cd-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-gitlab-1c4bee6e42e7?source=rss-15377a775571------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c4bee6e42e7</guid>
            <category><![CDATA[gitlab-ci]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[pipeline]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[gitlab]]></category>
            <dc:creator><![CDATA[st.nann]]></dc:creator>
            <pubDate>Sat, 25 Sep 2021 03:13:43 GMT</pubDate>
            <atom:updated>2021-10-01T14:28:49.207Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E3qDqLvpfAjbE0EA1SvV5Q.jpeg" /><figcaption>reference: <a href="https://lizard.global/blog/lizard-globals-guide-for-deploying-firebase-with-gitlab-cicd">https://lizard.global/blog/lizard-globals-guide-for-deploying-firebase-with-gitlab-cicd</a></figcaption></figure><p>ก่อนอื่นมาทำความรู้จักกันก่อนว่า CI/CD นั้นคืออะไร…</p><p><strong>CI (Continuous Integration) </strong>คือ กระบวนการที่จัดการ source code ของเราให้ผ่านกระบวนการการ testing, building เพื่อให้แน่ใจว่า source code สามารถใช้งานได้จริง ไม่มีข้อผิดพลาด</p><p><strong>CD (Continuous Delivery และ Continuous Deployment)</strong> กระบวนการที่ช่วยเหลือให้สามารถ Deploy Software ได้อย่างมีประสิทธิภาพ โดยการนำ source code ที่ผ่านการ build และ testing มาแล้ว ซึ่งอาจอยู่ในรูปแบบที่แตกต่างกัน เช่น JAR file, static file หรือแม้กระทั่ง container image ให้จัดการ deploy ขึ้นไปอยู่บน server ตามต้องการ และสามารถใช้งานได้อย่างถูกต้อง กระบวนการ CD มี 2 ประเภท ดังนี้<br>- <strong><em>Continuous Delivery </em></strong>คือ การส่งมอบ software ที่ใช้วิธีการ manual ในการ Deploy หลังจากผ่านขั้นตอน CI มาเรียบร้อยแล้ว โดยจะต้องมีการอนุมัติจากผู้รับรอง ซึ่งในที่นี้อาจหมายถึง manager เพื่อทำการตรวจสอบก่อน deploy ขึ้นสู่ server<strong><br>- <em>Continuous Deployment</em> </strong>คือ การส่งมอบ software ในรูปแบบ automate หลังจากผ่านขั้นตอน CI มาเรียบร้อยแล้ว จะทำการ deploy ขึ้นสู่ server ทันที ไม่ต้องรอการอนุมัติใด ๆ</p><blockquote><strong>reference:</strong> <br><a href="https://cloud-ace.co.th/blog/w0w7e1-ci-cd-services-google-cloud">https://cloud-ace.co.th/blog/w0w7e1-ci-cd-services-google-cloud</a><br><a href="https://www.somkiat.cc/better-ci-cd/">https://www.somkiat.cc/better-ci-cd/</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Gm1SIHw529yd62ESqokvvQ.jpeg" /><figcaption>reference: <a href="https://dev.to/mustafakhaled/devops-understanding-and-applying-ci-cd-pipeline-for-android-developers-part-2-486p">https://dev.to/mustafakhaled/devops-understanding-and-applying-ci-cd-pipeline-for-android-developers-part-2-486p</a></figcaption></figure><p>หลังจากทำความรู้จักกับ CI/CD แล้ว ก็มีเริ่มทำ pipeline ใน GitLab กันได้เลย โดยมีขั้นตอน ดังนี้</p><ol><li>ภายใน source code ที่ต้องการทำ pipeline ให้สร้างไฟล์ชื่อ <strong>.gitlab-ci.yml</strong> ซึ่งเมื่อทำการ push และ merge code ขึ้น Gitlab แล้ว ทาง Gitlab จะทำการอ่านไฟล์นี้โดยอัตโนมัติ</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*_zVKlpgWnoFPEvLGKrvPnA.png" /></figure><p>2. ภายในไฟล์ .gitlab-ci.yml ให้พิมพ์คำสั่ง โดยมีรายละเอียด ดังนี้ (สามารถเพิ่มขั้นตอน หรือ script อื่นๆได้ตามต้องการ)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8e80eac8263da0878f815255a218dd9/href">https://medium.com/media/f8e80eac8263da0878f815255a218dd9/href</a></iframe><ul><li><strong>image</strong>: docker image ที่มี dependencies รองรับของ project นั้นๆในที่นี้ใช้ node เวอร์ชันล่าสุด (latest)</li><li><strong>cache</strong>: การใช้ cache file ในการทำ pipeline โดยใช้ได้เฉพาะ project นั้นๆ ไม่สามารถใช้ข้าม project ได้</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ce52f04bc6cb3a2f76d87435d260b0b/href">https://medium.com/media/7ce52f04bc6cb3a2f76d87435d260b0b/href</a></iframe><ul><li><strong>stages</strong>: ขั้นตอนของการทำ pipeline โดยสามารถปรับแต่งได้ตามต้องการ</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fdea62184c3b2fb3085982976da8714/href">https://medium.com/media/3fdea62184c3b2fb3085982976da8714/href</a></iframe><ul><li><strong>github-push</strong><em>: </em>จะเป็นส่วนที่อยู่ในส่วนของ <strong>CI</strong> มีขั้นตอนการทำงาน ดังนี้ (ขั้นตอนขึ้นอยู่กับแต่ละ project)<br>- <em>stage</em>: ชื่อของขั้นตอนที่แสดงใน pipeline จะเป็นชื่อตามขั้นตอนใน stages<br>- <em>only</em>: branch ที่ต้องการให้ทำ pipeline<br>- <em>​script</em>: คำสั่งที่ต้องการให้ทำใน stage นี้ทั้งหมด ซึ่งในที่น้ี ให้ทำการ Mirror Repository ไปยัง GitHub โดยในคำสั่งนี้จะมีการใช้ตัวแปรของ Gitlab ด้วย คือ <em>$GITHUB_PRIVATE_EMAIL, $GITHUB_ACCESS_TOKEN, $BITBUCKET_ACCESS_TOKEN </em>และ <em>$MIRROR_USERNAME </em>(โดยสามารถดูวิธีสร้างตัวแปรได้ใน <em>“[How to] ทำ Pipeline CI Mirror Repository จาก Gitlab ไปยัง GitHub”</em> ตามลิงค์ด้านล่าง)<br><em>หมายเหตุ: สามารถดูรายละเอียดเพิ่มเติมของการทำ Mirror Repository ได้ตามลิงค์ด้านล่าง</em></li></ul><ul><li><a href="https://medium.com/@st.nann/how-to-%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87-mirror-repository-%E0%B8%A3%E0%B8%B0%E0%B8%AB%E0%B8%A7%E0%B9%88%E0%B8%B2%E0%B8%87-gitlab-%E0%B8%81%E0%B8%B1%E0%B8%9A-github-%E0%B9%81%E0%B8%A5%E0%B8%B0-gitlab-%E0%B8%81%E0%B8%B1%E0%B8%9A-bitbucket-a1da93bfe6c9">[How to] สร้าง Mirror Repository ระหว่าง GitLab กับ GitHub และ GitLab กับ BitBucket</a></li><li><a href="https://medium.com/@st.nann/how-to-%E0%B8%97%E0%B8%B3-pipeline-ci-mirror-repository-%E0%B8%88%E0%B8%B2%E0%B8%81-gitlab-%E0%B9%84%E0%B8%9B%E0%B8%A2%E0%B8%B1%E0%B8%87-github-1545617516f1">[How to] ทำ Pipeline CI Mirror Repository จาก Gitlab ไปยัง GitHub</a></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b826f7172753a037027b770bc6c27fb/href">https://medium.com/media/6b826f7172753a037027b770bc6c27fb/href</a></iframe><ul><li><strong>install</strong>:<strong> </strong>จะเป็นส่วนที่อยู่ในส่วนของ <strong>CI</strong> มีขั้นตอนการทำงาน ดังนี้ (ขั้นตอนขึ้นอยู่กับแต่ละ project)<br>- <em>stage</em>: ชื่อของขั้นตอนที่แสดงใน pipeline จะเป็นชื่อตามขั้นตอนใน stages<br>- <em>only</em>: branch ที่ต้องการให้ทำ pipeline<br>- <em>​script</em>: คำสั่งที่ต้องการให้ทำใน stage นี้ทั้งหมด ซึ่งในที่น้ี ให้ทำการ install yarn<br>- <em>artifacts</em>:<br> — <em>paths</em>: location ที่ต้องการให้เก็บไฟล์หลังจากการทำคำสั่งใน script เรียบร้อยแล้ว เพื่อนำไปใช้ในขั้นตอนถัดไป</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1109d6c80a4a937c30614aa608e07a23/href">https://medium.com/media/1109d6c80a4a937c30614aa608e07a23/href</a></iframe><ul><li><strong>build</strong>: จะเป็นส่วนที่อยู่ในส่วนของ <strong>CI</strong> มีขั้นตอนการทำงาน ดังนี้ (ขั้นตอนขึ้นอยู่กับแต่ละ project)<br>- <em>stage</em>: ชื่อของขั้นตอนที่แสดงใน pipeline จะเป็นชื่อตามขั้นตอนใน stages<em><br></em>- stage: ชื่อของขั้นตอนที่แสดงใน pipeline<br>- only: branch ที่ต้องการให้ทำ pipeline<br>- ​script: คำสั่งที่ต้องการให้ทำใน stage นี้ทั้งหมด ซึ่งในที่น้ี ให้ทำการ build code ขึ้น production<br>- <em>dependencies</em>: เป็นการบอกว่า ก่อนจะทำ stage นี้จะต้องผ่าน stage ไหนมาก่อน<br>- <em>artifacts</em>:<br> — <em>paths</em>: location ที่ต้องการให้เก็บไฟล์หลังจากการทำคำสั่งใน script เรียบร้อยแล้ว เพื่อนำไปใช้ในขั้นตอนถัดไป</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/355ce7cc07bb5569bad30f08a17f15c6/href">https://medium.com/media/355ce7cc07bb5569bad30f08a17f15c6/href</a></iframe><ul><li><strong>deploy</strong>: จะเป็นส่วนที่อยู่ในส่วนของ <strong>CD</strong> มีขั้นตอนการทำงาน ดังนี้ (ขั้นตอนขึ้นอยู๋กับแต่ละ project)<br>- <em>stage</em>: ชื่อของขั้นตอนที่แสดงใน pipeline จะเป็นชื่อตามขั้นตอนใน stages<br>- only: branch ที่ต้องการให้ทำ pipeline<br>- ​script: คำสั่งที่ต้องการให้ทำใน stage นี้ทั้งหมด ซึ่งในที่น้ี ให้ทำการ deploy code ขึ้น production โดยใช้ firebase hosting โดยในคำสั่งนี้จะมีการใช้ตัวแปรของ Gitlab ด้วย คือ <em>$CI_PIPELINE_ID และ $CI_BUILD_ID </em>(โดยสามารถดูวิธีสร้างตัวแปรได้ใน <em>“[How to] ทำ Pipeline CI Mirror Repository จาก Gitlab ไปยัง GitHub และ Bitbucket”</em> ตามลิงค์ด้านล่าง<br>- <em>dependencies</em>: เป็นการบอกว่า ก่อนจะทำ stage นี้จะต้องผ่าน stage ไหนมาก่อน<br><em>หมายเหตุ: สามารถดูรายละเอียดเพิ่มเติมของการทำ Deploy ขึ้น Hosting Firebase ได้ตามลิงค์ด้านล่าง</em></li></ul><ul><li><a href="https://medium.com/st-sanyanee/how-to-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5-deploy-website-%E0%B8%82%E0%B8%B6%E0%B9%89%E0%B8%99-web-hosting-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-firebase-%E0%B8%9F%E0%B8%A3%E0%B8%B5-113c11cc7455">[How to] วิธี deploy website ขึ้น web hosting ด้วย Firebase ฟรี !</a></li><li><a href="https://medium.com/@st.nann/how-to-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5%E0%B8%97%E0%B8%B3-ci-cd-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-travis-ci-%E0%B8%88%E0%B8%B2%E0%B8%81-github-%E0%B9%80%E0%B8%9E%E0%B8%B7%E0%B9%88%E0%B8%AD-deploy-%E0%B9%84%E0%B8%9B%E0%B8%A2%E0%B8%B1%E0%B8%87-firebase-424b5a30c842">[How to] วิธีทำ CI/CD ด้วย Travis-ci จาก GitHub เพื่อ deploy ไปยัง Firebase</a></li><li><a href="https://medium.com/@st.nann/how-to-%E0%B8%97%E0%B8%B3-pipeline-ci-mirror-repository-%E0%B8%88%E0%B8%B2%E0%B8%81-gitlab-%E0%B9%84%E0%B8%9B%E0%B8%A2%E0%B8%B1%E0%B8%87-github-1545617516f1">[How to] ทำ Pipeline CI Mirror Repository จาก Gitlab ไปยัง GitHub</a></li></ul><h4>ไฟล์ .gitlab-ci.yml แบบสมบูรณ์</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c859e7ae65e765ad6235aa29efd275b/href">https://medium.com/media/2c859e7ae65e765ad6235aa29efd275b/href</a></iframe><p><em>ข้อมูลคำสั่งไฟล์ .yml เพิ่มเติม</em></p><ul><li><a href="https://www.perforce.com/manuals/gitswarm-ee/ci/yaml/README.html">GitSwarm-EE 2017.2-1 Documentation</a></li><li><a href="https://docs.gitlab.com/ee/ci/caching/#cache">Caching in GitLab CI/CD | GitLab</a></li><li><a href="https://docs.gitlab.com/ee/ci/pipelines/">CI/CD pipelines | GitLab</a></li></ul><p>3. เมื่อสร้างไฟล์ เรียบร้อยแล้ว ให้ทำการ push ไฟล์ พร้อม code ที่มีการแก้ไขขึ้น Gitlab และทำการ merge code เข้า branch master หลังจากนั้นให้เข้าไปที่ <strong>CI/CD &gt; Pipeline</strong> ทางเมนู sidebar</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*WNZZ6w2W6v1I5uh_F7MHmA.png" /></figure><p>4. หลังจากเข้ามาที่หน้า pipeline จะเห็นว่า pipeline CI/CD เริ่มทำงานตาม stages ที่เขียนไว้ในไฟล์ gitlab-ci.yml แล้ว</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*li4VhQzz6n7h5VVUvDGnqw.png" /></figure><p>หากคลิกเข้าไปที่ <strong>running</strong> จะเห็นว่า pipeline ทำถึงขั้นตอนไหนบ้างแล้วตามกราฟขั้นตอน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XssTVsvh6omgyRLa7Oe4Kw.png" /></figure><p>และเมื่อคลิกเข้าไปที่แต่ละ <strong>stage</strong> ก็จะเห็น <strong>log</strong> การรัน pipeline ดังรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vPNNkoBcLq5cy0yKwRbkJQ.png" /></figure><p>5. รอจน pipeline ทำงานเสร็จเรียบร้อย (<strong>success</strong>) จะแสดงดังรูปด้านล่าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*caeqT-cYp8JOD9ZSqcqJ2w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R4qW4bfKyoC1WrBgcJYyHg.png" /></figure><p>หาก <strong>failed</strong> จะแสดง ดังรูป ซึ่งสามารถ คลิกที่ fail เข้าไปดูได้ว่า ติด error อะไร</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mcxSO8CTt4_kIc27jN5wnQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cv9WU1nHBi62Guj98dtE5A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*svP7PVXRNXt94UH1hJJ2nw.png" /></figure><p>และหากเมื่อ pipeline ทำการ build ไปแล้ว แต่ต้องการจะยกเลิกการทำ pipeline สามารถทำได้โดยคลิกที่ ปุ่ม cancel ด้านหลัง เพื่อ stop pipeline</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7esjCObh3ISV9uplud-w_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SNJ4hkegU8H-PhLaUSWRpg.png" /></figure><p>หาก pipeline failed หรือ cancel แล้วต้องการจะ rebuild pipeline ใหม่ สามารถทำได้โดยคลิกปุ่ม retry ด้านหลัง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SNJ4hkegU8H-PhLaUSWRpg.png" /></figure><p><em>ข้อมูลเพิ่มเติม สำหรับการตรวจสอบ syntax และขั้นตอนการทำงานของไฟล์ </em><strong><em>.gitlab-ci.yml </em></strong><em>สามารถเข้าไปตรวจสอบได้ที่</em></p><p><a href="https://gitlab.com/my-portfolio-exprerience/my-portfolio-v3/-/ci/lint">https://gitlab.com/my-portfolio-exprerience/my-portfolio-v3/-/ci/lint</a></p><p><em>โดยถ้าหากคำสั่งที่เขียนในไฟล์ </em><strong><em>.gitlab-ci.yml</em></strong><em> ถูกต้อง </em><strong><em>validate ผ่าน</em></strong><em> จะแสดง ดังรูป</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jksfPap_meSzuX4ALOr9Gg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-6Bq4wSJ03vAQN5PdI9Fag.png" /></figure><p><em>แต่ถ้าหากมีการเขียนผิด </em><strong><em>validate ไม่ผ่าน </em></strong><em>จะแสดง ดังรูป</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j2UlF0dh9mIZBDqfbWe1ag.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c4bee6e42e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[How to] สร้าง Mirror Repository ระหว่าง GitLab กับ GitHub และ GitLab กับ BitBucket]]></title>
            <link>https://medium.com/@st.nann/how-to-%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87-mirror-repository-%E0%B8%A3%E0%B8%B0%E0%B8%AB%E0%B8%A7%E0%B9%88%E0%B8%B2%E0%B8%87-gitlab-%E0%B8%81%E0%B8%B1%E0%B8%9A-github-%E0%B9%81%E0%B8%A5%E0%B8%B0-gitlab-%E0%B8%81%E0%B8%B1%E0%B8%9A-bitbucket-a1da93bfe6c9?source=rss-15377a775571------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1da93bfe6c9</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[bitbucket]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[mirroring]]></category>
            <dc:creator><![CDATA[st.nann]]></dc:creator>
            <pubDate>Sun, 19 Sep 2021 05:22:36 GMT</pubDate>
            <atom:updated>2021-10-01T14:38:56.285Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0tjfpboXOM29gRYY3DpRQ.png" /></figure><pre>หมายเหตุ: ก่อนที่จะทำตามขั้นตอนด้านล่าง จำเป็นจะต้องมี code ทั้งใน GitLab, GitHub, BitBucket หรือ Version Control เจ้าอื่นๆก่อน</pre><p>มีใครเคยประสบปัญหาที่มี repository หลายๆ repository แต่อยู่บน git คนละเจ้า แล้วเวลา push code ขึ้นต้องทำ mannual ในการ push ขึ้นทีละส่วน แล้วค่อยมากด merge request แต่ละที่หรือไม่ เช่น มี code project A แต่ต้องการ push code ขึ้นที่ GitHub และ GitLab โดยปกติถ้าทำ mannual จะต้องใช้ git remote add ทั้ง GitHub และ GitLab แล้วค่อย push code ขึ้น จากนั้นกด merge ทั้งที่ GitHub และ GitLab เป็นต้น จากที่เล่ามาจะเห็นว่ามีขั้นตอนค่อนข้างหลายขั้นตอนอยู่ อาจจะทำให้ลืมบ้าง ไม่ลืมบ้าง แต่วันนี้มีวิธีที่สะดวก สบาย push code ขึ้นที่เดียวแล้วทางระบบจะทำการ push เข้าอีกที่ให้อัตโนมัติ มานำเสนอ โดยสามารถดูขั้นตอนได้ตามด้านล่าง ดังนี้</p><p><strong>Mirror Repository จาก GitLab ไปยัง GitHub</strong></p><ol><li>เข้าหน้า website GitLab โดยเข้าไปที่ repository ที่ต้องการทำ mirror แล้วคลิก <strong>Settings &gt; Repository</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*0xxaWQsrhbTC_hLDz0nyag.png" /></figure><p>2. เมื่อเข้ามาในหน้า Repository แล้วให้เลื่อนมาที่ส่วนของ <strong>Mirroring Repositories</strong> แล้วคลิก <strong>Expand</strong> จะเห็นเเสดงเนื้อหา ดังรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LXAKI1T2euQlNmhFAPcANQ.png" /></figure><p>3. จากนั้นให้ไปที่ GitHub เพื่อสร้าง access token ในการเปิด permission ให้ Gitlab เข้าถึง repository โดยเข้าที่ <strong>Settings</strong></p><pre>หมายเหตุ: สาเหตุที่ต้องใช้ access token เพราะทาง GitHub หยุดการสนับสนุน การเข้าถึงโดยใช้ password แล้วตั้งแต่ 13 สิงหาคม 2021</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*ysSFKYtwZrtZ6QNQwmupQw.png" /></figure><p>4. เลือกที่หัวข้อ <strong>Developer settings</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*OBgSKb1FhIHvz0SKeA3jAA.png" /></figure><p>5. จากนั้นเลือก <strong>Personal access tokens</strong> เพื่อทำการสร้าง access token ใช้ในการเปิด permission ให้ GitLab เข้ามาทำ action ใน GitHub ได้ เช่น pull, push, … เป็นต้น</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*Vx2ufzOTYUbmvzzsRdFRqg.png" /></figure><p>6. เมื่อเข้ามาที่หน้า Personal access tokens แล้วให้คลิกที่ <strong>Generate new token</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nFgP24kNmHXnmOWlGcgT7Q.png" /></figure><p>7. ถ้าให้กรอก password ให้กรอก password ที่ใช้ในการเข้า GitHub ก่อน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*cuAnwRNX-pyVn_4DlhE07g.png" /></figure><p>8. จากนั้นระบบจะเข้าที่หน้า <strong>New personal access tokens</strong> โดยมีรายละเอียดให้กรอก ดังนี้</p><ul><li><em>Note</em>: ให้กรอกข้อความที่ระบุได้ว่า token นี้จะเอาไปทำอะไร</li><li><em>Expiration</em>: กำหนดวันหมดอายุ token (โดยสามารถระบุให้ใช้ได้ตลอดก็ได้ โดยเลือก No expriration)</li><li><em>Select scopes</em>: เลือก Permission ที่ต้องการเปิดสิทธิให้ทำอะไรได้บ้าง (โดยถ้าทำ mirror repository จำเป็นต้องเปิด <strong>public_repo</strong>)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bLeuDiKOQwrq5nWrgQMuhQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iroUK7TocDkcvFA_gE1U-Q.png" /></figure><p>เมื่อกรอกเรียบร้อยแล้ว ให้คลิก <strong>Generate token</strong></p><p>9. หลังจากนั้นจะได้ token มา ให้คลิก <strong>copy</strong> เก็บไว้ก่อน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_6QtM5jj3qGiLUPHT82e7w.png" /></figure><p>10. จากนั้นไปที่ repository ที่ต้องการทำ mirror ใน <strong>GitHub</strong> ให้คลิก <strong>code &gt; เลือก HTTPS &gt; คลิก copy web url</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P7K-0n-GyetGlRSOOfLn3w.png" /></figure><p>11. กลับมาที่หน้า <strong>Gitlab</strong> website แล้วนำ <strong>token</strong> และ <strong>web url</strong> มาวางที่ช่อง <strong>Git repository URL</strong> โดยมี format คือ</p><pre><a href="https://github.com/st-nann/my-portfolio-v3.git">https://&lt;ACCESS_TOKEN&gt;github.com/&lt;REPOSITORY_GROUP&gt;/</a><a href="https://github.com/st-nann/my-portfolio-v3.git">&lt;REPOSITORY_NAME&gt;</a><a href="https://github.com/st-nann/my-portfolio-v3.git">.git</a></pre><p>โดย REPOSITORY_GROUP และ REPOSITORY_NAME จะมีอยู่แล้วใน web url ที่ copy มา ส่วน token ให้ copy จากที่ได้ตอน generate token</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5nMuK2SKANrgmQoWq102bQ.png" /></figure><p>12. หลังจากนั้น กรอกข้อมูล ดังนี้</p><ul><li><strong>Mirror direction</strong>: Push</li><li><strong>Password</strong>: ให้กรอก access token ที่ได้จาก GitHub</li><li><strong>Keep divergent refs</strong>: เลือกหรือไม่เลือกก็ได้ แต่ถ้าเลือกจะเป็นการ force push แม้จะมีปัญหาส่วนใดก็ตาม (โดยสามารถแก้ไขได้ทีหลัง แต่ต้องทำจาก API)</li></ul><p>เมื่อกรอกข้อมูลเรียบร้อยแล้วให้คลิก <strong>Mirror repository</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nlkfOl7cK9hdgDrlDZq3rA.png" /></figure><p>13. เมื่อสร้างเรียบร้อย จะมี record แสดงใน table ด้านล่าง โดยจะมีวันที่ และเวลาล่าสุด ในการทำ action และทำ action success หาก error จะมี message แสดงให้เห็นด้วย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*va-rhN4bmie8D_ENeByJPw.png" /></figure><blockquote>ข้อมูลเพิ่มเติม: <a href="https://docs.gitlab.com/ee/user/project/repository/repository_mirroring.html">https://docs.gitlab.com/ee/user/project/repository/repository_mirroring.html</a></blockquote><p><strong>Mirror Repository จาก GitLab ไปยัง BitBucket</strong></p><ol><li>เข้าหน้า website GitLab โดยเข้าไปที่ repository ที่ต้องการทำ mirror แล้วคลิก <strong>Settings &gt; Repository</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*0xxaWQsrhbTC_hLDz0nyag.png" /></figure><p>2. เมื่อเข้ามาในหน้า Repository แล้วให้เลื่อนมาที่ส่วนของ <strong>Mirroring Repositories</strong> แล้วคลิก <strong>Expand</strong> จะเห็นเเสดงเนื้อหา ดังรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LXAKI1T2euQlNmhFAPcANQ.png" /></figure><p>3. จากนั้นให้ไปที่ <strong>BitBucket</strong> และเข้าเข้าที่ repository ที่ต้องการทำ mirror</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IsoRKpkWPNyLdMrKLi4lrw.png" /></figure><p>4. คลิก <strong>clone</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5LO6XmbppVaOEKrTRzMYrg.png" /></figure><p>5. เลือก <strong>HTTPS</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FeX3e4YY8Tzsgh4dIUiHlw.png" /></figure><p>6. คลิก <strong>copy</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_PpGRI6j7XHQYkShSPVYJQ.png" /></figure><p>7. กลับมาที่หน้า <strong>Gitlab</strong> website แล้ววาง <strong>repository url</strong> ที่ช่อง <strong>Git repository URL</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P5JvVdGumwmwhSoxJLKNrQ.png" /></figure><p>8. หลังจากนั้น กรอกข้อมูล ดังนี้</p><ul><li><strong>Mirror direction</strong>: Push</li><li><strong>Password</strong>: ใช้ในการ Login เข้า BitBucket</li><li><strong>Keep divergent refs</strong>: เลือกหรือไม่เลือกก็ได้ แต่ถ้าเลือกจะเป็นการ force push แม้จะมีปัญหาส่วนใดก็ตาม (โดยสามารถแก้ไขได้ทีหลัง แต่ต้องทำจาก API)</li></ul><p>เมื่อกรอกข้อมูลเรียบร้อยแล้วให้คลิก <strong>Mirror repository</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nlkfOl7cK9hdgDrlDZq3rA.png" /></figure><p>9. เมื่อสร้างเรียบร้อย จะมี record แสดงใน table ด้านล่าง โดยจะมีวันที่ และเวลาล่าสุด ในการทำ action และทำ action success หาก error จะมี message แสดงให้เห็นด้วย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gYROquTuE67FYmJQZJprVQ.png" /></figure><p>จากนั้นลอง push code ขึ้น Gitlab ก็จะเห็นว่า GitHub และ BitBucket ก็จะมีการเปลี่ยนแปลงตาม GitLab ด้วย</p><p><strong>Gitlab</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lQwD_uBJ4YvjG5ubODZw2A.png" /></figure><p><strong>GitHub</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5xsW9FPKP0S833Z6rfPFPQ.png" /></figure><p><strong>BitBucket</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Di0ITxUOWeFkN9A87fzrPA.png" /></figure><pre>หมายเหตุ: เวลาอาจจะคลาดเคลื่อนเล็กน้อย ช่วงระหว่าง push และ merge branch </pre><p>และในส่วนของ <strong>Mirroring Repositories</strong> ก็มีการ Update วันที่ และเวลาด้วย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rUMujG2tvBcFW9HljzNU8w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1da93bfe6c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[How to] วิธีทำ CI/CD ด้วย Travis-ci จาก GitHub เพื่อ deploy ไปยัง Firebase]]></title>
            <link>https://medium.com/@st.nann/how-to-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5%E0%B8%97%E0%B8%B3-ci-cd-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-travis-ci-%E0%B8%88%E0%B8%B2%E0%B8%81-github-%E0%B9%80%E0%B8%9E%E0%B8%B7%E0%B9%88%E0%B8%AD-deploy-%E0%B9%84%E0%B8%9B%E0%B8%A2%E0%B8%B1%E0%B8%87-firebase-424b5a30c842?source=rss-15377a775571------2</link>
            <guid isPermaLink="false">https://medium.com/p/424b5a30c842</guid>
            <category><![CDATA[travis-ci]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[st.nann]]></dc:creator>
            <pubDate>Sat, 18 Sep 2021 02:48:57 GMT</pubDate>
            <atom:updated>2021-09-18T03:03:38.355Z</atom:updated>
            <content:encoded><![CDATA[<p>ก่อนที่จะไปทำ CI/CD เรามาทำความรู้จักกันก่อนว่า CI/CD คืออะไร</p><blockquote><a href="https://www.spicydog.org/blog/gitlab-ci-cd-1-introduction/">https://www.spicydog.org/blog/gitlab-ci-cd-1-introduction/</a></blockquote><p>หลังจากทำความรู้จักแล้ว จะต้องมีการ Configuration ค่าต่างๆของ Firebase ภายใน Repository หรือ Project ต่างๆก่อน โดยหากใครยังไม่ได้ทำ สามารถเข้าไปดูขั้นตอนต่างๆได้ที่นี่ (ทำถึงแค่ขั้นตอนที่ 13)</p><blockquote><a href="https://medium.com/st-sanyanee/how-to-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5-deploy-website-%E0%B8%82%E0%B8%B6%E0%B9%89%E0%B8%99-web-hosting-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-firebase-%E0%B8%9F%E0%B8%A3%E0%B8%B5-113c11cc7455">https://medium.com/st-sanyanee/how-to-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5-deploy-website-%E0%B8%82%E0%B8%B6%E0%B9%89%E0%B8%99-web-hosting-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-firebase-%E0%B8%9F%E0%B8%A3%E0%B8%B5-113c11cc7455</a></blockquote><p>เมื่อทำการ Configuration เเละเขียน code เรียบร้อยแล้ว ทุกคนก็คงอยากจะนำ code deploy ขึ้น hosting เพื่อให้คนอื่นสามารถดู website ได้ วันนี้เลยมีวิธีทำง่ายๆ สะดวก และทำได้รวดเร็ว มาให้ลองใช้กันคือ <strong><em>การทำ CI/CD ด้วย Travis-ci จาก GitHub เพื่อ deploy ไปยัง Firebase </em></strong>ซึ่งมีขึ้นตอน ดังนี้</p><h3>Auto Build จาก GitHub (CI)</h3><ol><li>เข้า Website ของ Travis CIโดยเข้าไปที่<br><a href="https://www.travis-ci.com/">https://www.travis-ci.com/</a></li></ol><figure><img alt="Travis CI" src="https://cdn-images-1.medium.com/max/1024/1*Yck0Q8lbaq0xPvsQyIz1cA.png" /></figure><p>2. ทำการ Sign in โดยใช้ Account ของ GitHub (จากรูปจะเห็นว่ามี Website ของ Git Version Control ของหลายเจ้า ซึ่งตอนนี้ Travis ทำการทดสอบอยู่ ในอนาคตอาจจะได้ใช้กันตามสะดวก)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XIQe2V5lz8pf4tHYXpCR9Q.png" /></figure><p>3. หลังจากที่ Sign in เข้ามาแล้ว ภายในหน้า Dashboard จะแสดงรายชื่อ Repository ทั้งหมด ที่เรามีภายใน GitHub ขึ้นมาดังรูป (สังเกตว่าจะมีทั้ง Public และ Private Repository)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FAOQsFZVW--rHQRbht3QIg.png" /></figure><p>ซึ่งสามารถระบุได้ว่า ต้องการให้แสดงทุก Repository หรือไม่โดยเข้าไปที่ <strong>Settings &gt; Manage repositories on GitHub</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*ccG2CLxADjRDrtgQnEK9sg.png" /><figcaption>Settings</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mc4dbcDakSodRj9kiUUYHg.png" /><figcaption>Manage repositories on GitHub</figcaption></figure><p>จากนั้นระบบจะ Redirect ไปที่หน้า Website ของ GitHub (หากของใครแสดงหน้ากรอก Password ให้กรอก Password) จากนั้นให้เลื่อนลงมาที่ <strong>Repository access</strong> เพื่อจัดการกับ Repository จากนั้นคลิก Save</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cv2czenzsNiNohSJtm7VjA.png" /></figure><h3>Auto Deploy ไปยัง Firebase (CD)</h3><p>หลังจากที่ Manage Repository ที่ต้องการ Build เรียบร้อยแล้ว ให้กลับมาต่อกันที่ Travis เพื่อทำขั้นตอนต่อไป ดังนี้</p><ol><li>ให้คลิกที่ <strong>Settings</strong> ของ Repository ที่ต้องการทำ Auto Deploy</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MsYSYJ6IenT28RwWlNw8lg.png" /></figure><p>2. เมื่อคลิก Settings เข้ามาแล้ว Website จะแสดงดังรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UUukYhCN-vCDZ6PUB5PZNA.png" /><figcaption>หน้า Setting ของ Travis CI</figcaption></figure><p>โดยมีรายละเอียดแต่ละส่วน ดังนี้</p><ul><li>Tab ด้านซ้ายมือ จะเป็น History ที่เคยทำการ Build แต่ละ Repository ไป</li><li>ส่วนตรงกลางจะเป็นส่วน Settings ค่าต่างๆที่ต้องการ Build ของ Repositoty นั้นๆ</li></ul><p>6. จากนั้นให้เลื่อนลงมาที่ส่วนของ <strong>Environment Variables</strong> เพื่อกำหนดค่า Deploy ไปยัง Firebase โดยมี 2 variable คือ <strong>FIREBASE_TOKEN</strong> และ <strong>PROJECT_ID </strong>(หากมี variable อื่นๆอีกให้กรอกที่ช่องด้านล่าง และคลิก Add)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_AeqCNpVFkGA5g52PWO3Kg.png" /></figure><ul><li>FIREBASE_TOKEN: จะได้มาจากการ Log in ใน Repository โดยต้องพิมพ์ Command ตามขั้นตอนด้านล่าง</li><li>PROJECT_ID: จะได้มาจากหน้า Website ของ Firebase</li></ul><h4>ขั้นตอนการขอ FIREBASE_TOKEN</h4><p>6.1.1 ให้เข้าไปที่ Repository ด้วย Editor ต่างๆ ซึ่งโดยในที่นี้จะเข้าด้วย VSCode แล้วรัน Command</p><blockquote>$ Firebase login:ci</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*UG96dKGIXmgxx6m1_8bmoQ.png" /></figure><p>6.1.2 เมื่อรัน Command แล้ว จะทำการ Redirect เพื่อเข้าหน้า Website Google เพื่อให้ทำการ Login</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j1G2wp6fKNliBajQda-5Vw.png" /></figure><p>6.1.3 Allow Permission ให้ Firebase CLI เข้าถึงได้ โดยคลิก <strong>อนุญาต</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*1NwTpwCVNk9fCrR8DYusoQ.png" /></figure><p>6.1.4 เมื่อคลิก อนุญาต แล้ว หน้า website จะแสดง ดังรูป เป็นการ Login สำเร็จ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*KqzHb2h5_KtlgegRmYoYeQ.png" /></figure><p>6.1.5 จากนั้นให้กลับมาที่หน้า Editor ให้สังเกตที่ terminal จะเห็นว่ามี Token แสดงอยู่ให้ Copy มาใส่ที่ Travis-ci ได้เลย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*thCVJMK5Y8z0dx_arr2FDg.png" /></figure><h4>ขั้นตอนการขอ PROJECT_ID</h4><p>6.2.1 เข้าไปที่หน้า Website ของ Firebase</p><p><a href="https://firebase.google.com/">Firebase | Google&#39;s Mobile and Web App Development Platform</a></p><p>6.2.2 คลิกที่ Console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3-DtkK4bi9MTVIoI6AWKXA.png" /></figure><p>6.2.3 หน้า website จะแสดง project ทั้งหมดที่มี ให้คลิกเข้า project ที่ต้องการทำ Auto deploy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rjy1IdgHdfcPswtNwolLUg.png" /></figure><p>6.2.4 หลังจากที่เข้า project แล้ว ให้คลิกที่ icon <strong>Setting &gt; Project Settings</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*uyJAWuvgDFG90_ZjCFldBQ.png" /></figure><p>6.2.5 จากนั้น Copy Project ID ไปใส่ที่ Travis-ci</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qvx3FrfDMcE9YMj74q-w4w.png" /></figure><p>7. หลังจาก Setting ค่าใน Travis-ci เรียบร้อยแล้ว ให้ทำการสร้าง file <strong>.travis.yml </strong>ใน Repository</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*dGpiljZB393zHLOBqiD6iw.png" /></figure><p>8. จากนั้นทำการเขียน file .yml เพื่อให้ GitHub อ่าน เพื่อไปทำ Auto deploy ดังนี้</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9690a708a0ed515b3adbd7203ea5fa9c/href">https://medium.com/media/9690a708a0ed515b3adbd7203ea5fa9c/href</a></iframe><p>โดยมีรายละเอียด คือ<br>- language: ภาษาที่ใช้ในการรัน (ในที่นี้ใช้ nodejs)<br>- node_js: version ของ node_js (ขึ้นกับ language)<br>- branches: branch ที่ต้องการให้ทำ Auto Build/Deploy<br>- install: command รันเพื่อ install module ต่างๆ<br>- script: ขั้นตอน command ที่ต้องการรันกับ project<br>- after_success: ขั้นตอนที่ให้ทำหลังจากการ build (ในที่นี้จะเป็นการ deploy ไปยัง firebase)</p><p>9. เมื่อ Configuration ค่าต่างๆเรียบร้อยแล้ว ให้ทำการ commit และ push code ขึ้น GitHub หลังจากนั้นให้ทำการ merge code ให้เรียบร้อย และสังเกตที่หน้า website Travis-ci จะเห็นว่าระบบทำการ Auto Build และ Deploy ให้เรียบร้อยแล้ว (ซึ่งสามารถ Cancel Build ได้ หากมีปัญหาใดๆ)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Utm5YJzzXF4OYrttJVAkTw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1QUQBwNmudxhzMRrQk16Yw.png" /></figure><p>10. หลังจากนั้น ให้รอจนกว่าระบบจะทำการ deploy เรียบร้อย</p><p>ถ้า Passed จะแสดง status เป็นสีเขียว</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w1J9xeS-Ie7fIX5sdlEyag.png" /><figcaption>Travis-ci</figcaption></figure><p>ถ้า Errored แสดงเป็นสีแดง (สามารถเข้าไปดู log ได้ว่า error ส่วนไหน)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6tllnpGyIG_v34qSYKWkeQ.png" /></figure><p>11. ทำการตรวจสอบการ deploy ที่ Firebase หากสำเร็จจะแสดง วันที่/เวลา deploy ตามที่ทำ และหน้า website ที่นำ code ขึ้น จะแสดงตามต้องการ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_V_JfeALsLsKDz3pZicYjw.png" /><figcaption>Firebase</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j02i5EVF-4Dw_X4iQUYqtA.png" /><figcaption>My Portfolio</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=424b5a30c842" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[How to] วิธี deploy website ขึ้น web hosting ด้วย Firebase ฟรี !]]></title>
            <link>https://medium.com/st-sanyanee/how-to-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5-deploy-website-%E0%B8%82%E0%B8%B6%E0%B9%89%E0%B8%99-web-hosting-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-firebase-%E0%B8%9F%E0%B8%A3%E0%B8%B5-113c11cc7455?source=rss-15377a775571------2</link>
            <guid isPermaLink="false">https://medium.com/p/113c11cc7455</guid>
            <category><![CDATA[web-hosting]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[st.nann]]></dc:creator>
            <pubDate>Sat, 19 Aug 2017 08:34:31 GMT</pubDate>
            <atom:updated>2017-08-19T08:34:31.211Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qkTKmvomK6oYgUxXJt4Yuw.png" /></figure><p><em>เมื่อเราเขียน website แล้ว หลายคนก็อยากที่จะ deploy website ขึ้นไปยัง web hosting เพื่อให้คนอื่นสามารถเข้าถึง website ได้ วันนี้เราเลยจะมาแนะนำให้รู้จักกับ </em><strong><em>Firebase</em></strong><em> ซึ่ง Firebase นั้นมี feature ให้ชาว Dev ทั้งหลาย ได้ deploy website ขึ้นไปยัง web hosting กันแบบ</em><strong><em>ฟรีๆ</em></strong><em> แต่ก่อนที่เราจะไปถึงขั้นตอนนั้น เรามาทำความรู้จักกับ Firebase ก่อนดีกว่า ว่ามีสามารถทำอะไรบ้าง</em></p><blockquote><strong><em>Firebase</em></strong> เป็นบริการใหม่จาก Google ซึ่งจะมี tools ต่างๆมากมาย เพื่อให้ชาว developer ได้ใช้งานกัน (แต่ในที่นี้จะขอพูดถึงแต่ hosting เท่านั้น) ซึ่งตัว hosting นี้จะเหมาะกับ Front-end Developer เนื่องจาก website ที่จะสามารถ deploy ขึ้น web hosting ได้นั้น จะต้องเป็น website แบบ static (HTML, Java script, CSS) ไม่สามารถนำ website ที่เป็นฝั่ง server (php, script, …) ขึ้นไปใช้งานได้</blockquote><blockquote><strong><em>Web Hosting</em></strong> <em>คือผู้ให้บริการในส่วนของการเช่าพื้นที่บน server ในการฝาก website ซึ่งจะ online ตลอด 24 ชม. เพื่อให ้end user เข้าชม website online ได้ตลอดเวลา</em></blockquote><h3>ขั้นตอนการ deploy website ขึ้น web hosting ด้วย Firebase</h3><ol><li><strong>สมัคร</strong> Account ของ Google ด้วย E-mail “…@gmail.com” (<a href="https://accounts.google.com/SignUp?hl=en"><strong>https://accounts.google.com/SignUp?hl=en</strong></a>)</li><li>เมื่อสมัครเรียบร้อยแล้วให้ทำการ <strong>Login</strong> เข้าสู่ระบบ</li><li>เข้าหน้า Website ของ <strong>Firebase</strong> (<a href="https://firebase.google.com/"><strong>https://firebase.google.com/</strong></a>) คลิก <strong>GET STARTED</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tDGy9BpIpWfWdhX-8m2LQQ.png" /></figure><p>4. คลิก <strong>Add Project</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sV9szEBeDPAqq1l3H8CkNA.png" /></figure><p>5. ทำการ<strong> Create Project</strong> โดยกรอกชื่อ Project และประเทศของผู้ใช้งาน แล้วคลิก <strong>CREATE PROJECT</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lfbvgz65-3im4lMBljAm4A.png" /></figure><p>6. จะเข้ามาสู่หน้า <strong>Overview</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W2cCo8pls791-dTMhgSTUQ.png" /></figure><p>7. เลือก <strong>Hosting</strong> ทาง tab ด้านซ้าย แล้วคลิก <strong>GET STARTED</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qMv9SGay_RumosTqy3BzMA.png" /></figure><p>8. จะแสดงหน้า Command ในการ <strong>Setup hosting</strong> ขึ้นมา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sXAnP7TcBg_mQOvVCz-FLg.png" /></figure><p>9. พิมพ์ Command ที่แสดงบน website firebase เพื่อ<strong>ติดตั้ง tool firebase</strong> ใน project ของเรา</p><blockquote>$ npm install -g firebase-tools</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*MOFEjxzaj09sAqdq4avh1w.jpeg" /></figure><p>10. ทำการ<strong> build project</strong> โดยพิมพ์ Command ด้านล่าง เมื่อ build เมื่อ build เรียบร้อยแล้วจาะมี <strong>folder dist</strong> เพิ่มขึ้นมาใน Project</p><blockquote>$ npm run build</blockquote><p>หรือ</p><blockquote>$ yarn build</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*-D5hp4KRBDkc3R7QHIuLHQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*qIiatvsZd26ML3STPwaqyA.jpeg" /></figure><p>11. หลังจากลง firebase tool และ build แล้ว ให้คลิก <strong>CONTINUE </strong>ที่หน้า website firebase</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VXklf2OlliPJw0HEPLT4pw.png" /></figure><p>12. ทำการ <strong>Login Google Account</strong> ใน Project โดยพิมพ์ Command ตามที่แสดงบน website firebase</p><blockquote>$ firebase login</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*m-lXlqQBhP631CqpAK_X5A.jpeg" /></figure><p>พิมพ์ <strong>Y </strong>แล้วกด <strong>Enter</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ea-8_n3oqZ6qHQBe5XIigw.jpeg" /></figure><p>จะแสดงหน้า <strong>website</strong> ให้ login</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bKRU0ntVcteM4SvEt-XJbA.png" /></figure><p>หลังจาก Login เรียบร้อยแล้ว จะแสดง ui ให้คลิก<strong> ALLOW</strong> firebase</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QdzQrkgMfYCIeDZtnfzWOA.png" /></figure><p>ถ้าแสดงหน้า website ตามรูปด้านล่าง แสดงว่า Login ได้สำเร็จ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RxLlLbp51QZblxeEsWl_bA.png" /></figure><p>และ Command ใน project แสดงตามรูปด้านล่าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y0eTRG6HoWG3nB7obN9zWA.jpeg" /></figure><p>13. หลังจากนั้น ให้ทำการสร้าง <strong>project init firebase</strong> ใน Project โดยพิมพ์ Command</p><blockquote>$ firebase init</blockquote><p>เลือก <strong>Hosting: Configure and deploy Firebase Hosting site</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*VHAafD9my-gref7GO-pO-g.jpeg" /></figure><p>เลือก<strong>ชื่อ Project</strong> ตามที่ได้สร้างไว้ในข้อ 5 ในที่นี้คือ my-portfolio</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*NeRKbkvXz9BM-iBS3GJudg.jpeg" /></figure><p>จากนั้นรอ ให้ firebase สร้าง file เมื่อเสร็จเรียบร้อยแล้วจะได้มา 2 file คือ <strong>firebase.json </strong>และ <strong>.firebaserc</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AZqT5-qOQKsm7NSPXg_kqw.jpeg" /></figure><p>14. Double click <strong>firebase.json</strong> file เพื่อแก้ไข configuration ในการ deploy ตามด้านล่าง</p><pre>{<br>  &quot;hosting&quot;: {<br>    &quot;public&quot;: &quot;./dist&quot;,<br>    &quot;ignore&quot;: [<br>      &quot;firebase.json&quot;,<br>      &quot;**/.*&quot;,<br>      &quot;**/node_modules/**&quot;<br>    ],<br>    &quot;rewrites&quot;: [ {<br>      &quot;source&quot;: &quot;**&quot;,<br>      &quot;destination&quot;: &quot;/index.html&quot;<br>    } ]<br>  }<br>}</pre><p>โดย</p><blockquote><strong><em>public</em></strong> คือ path folder ที่ต้องการ deploy (ในที่นี้คือ folder dist ที่ได้จากการ build Project)</blockquote><blockquote><strong><em>ignore</em></strong> คือ ไฟล์ที่ไม่ต้องการนำขึ้นไปัง server</blockquote><blockquote><strong><em>rewrites</em></strong> คือ ส่วนที่ใช้ในการ config หน้า website 404 (Page not found)</blockquote><p>14. หลังจากนั้น ทำการ deploy project ขึ้น website โดยใช้ command</p><blockquote>$ firebase deploy</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*bmgCPFaExeLMiiSkd-hSQg.jpeg" /></figure><p>15. หาก deploy สำเร็จ ให้ตรวจสอบที่หน้า website จะมี <strong>link project</strong> ที่ deploy ขึ้นไป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2-dmv3QJ1kdRB-ICfjfniw.png" /></figure><p>16. คลิกที่ <strong>link Domain</strong> จะแสดงหน้า website ของเรา เป็นอันเสร็จเรียบร้อย เช่น <a href="https://my-portfolio-ef29f.firebaseapp.com/"><strong>https://my-portfolio-ef29f.firebaseapp.com/</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TAFfSRCHlDfcjcvhl0A9Vw.jpeg" /></figure><p><strong>Note</strong>: วิธี <strong>logout</strong> Google Account ให้พิมพ์ Command</p><blockquote>$ firebase logout</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*jyHYkeApOuYGY_Rixxm39Q.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=113c11cc7455" width="1" height="1" alt=""><hr><p><a href="https://medium.com/st-sanyanee/how-to-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5-deploy-website-%E0%B8%82%E0%B8%B6%E0%B9%89%E0%B8%99-web-hosting-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-firebase-%E0%B8%9F%E0%B8%A3%E0%B8%B5-113c11cc7455">[How to] วิธี deploy website ขึ้น web hosting ด้วย Firebase ฟรี !</a> was originally published in <a href="https://medium.com/st-sanyanee">st-sanyanee</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[How to] วิธีการใช้งาน Vue.js ร่วมกับ Vuetify]]></title>
            <link>https://medium.com/st-sanyanee/how-to-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-vue-js-%E0%B8%A3%E0%B9%88%E0%B8%A7%E0%B8%A1%E0%B8%81%E0%B8%B1%E0%B8%9A-vuetify-318e41071ca0?source=rss-15377a775571------2</link>
            <guid isPermaLink="false">https://medium.com/p/318e41071ca0</guid>
            <category><![CDATA[framework]]></category>
            <category><![CDATA[user-interface-design]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[frontend-developer]]></category>
            <category><![CDATA[vuetify]]></category>
            <dc:creator><![CDATA[st.nann]]></dc:creator>
            <pubDate>Mon, 14 Aug 2017 04:53:04 GMT</pubDate>
            <atom:updated>2017-10-05T14:35:47.999Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dA0K8ZQ4yQn1Ld4JQBG4ug.png" /></figure><p><em>ก่อนที่เราจะรู้วิธีการใช้งาน เรามาทำความรู้จักกับ VueJs และ Vuetify กันก่อนดีกว่าค่ะ (หากใครรู้แล้วข้ามส่วนนี้ได้เลยนะคะ)</em></p><blockquote><strong><em>VueJs หรือ Vue.js</em></strong> เป็น Javascript Framework สำหรับ Front-end ที่ใช้ในการเขียน User Interface (UI) เพื่อแสดงผลให้กับผู้ใช้งาน สามารถเขียนโดยแบ่งเ็น component แต่ละส่วนได้</blockquote><blockquote><strong><em>Vuetify</em></strong><em> </em>เป็น Material Design Component Framework สำหรับ Vue.js เพื่อใช้ในการปรับแต่งหน้า User Interface (UI) ให้สวยงาม</blockquote><p>หลังจากเราได้รู้จักกับ Framework ทั้ง 2 Framework ไปแล้ว เรามาเริ่มพูดถึงวิธีการใช้งานดีกว่าค่ะ</p><h3><strong>Installation VueJs</strong></h3><ol><li>Install <strong>vue-cli</strong> ของ Vue.js ซึ่งเป็นตัวช่วยสร้าง Project</li></ol><blockquote>$ npm install -g vue-cli</blockquote><p>2. Install <strong>Webpack</strong> ของ Vue.js ซึ่งเป็น Template ในการสร้าง Project โดยการ install webpack จะรวมการ install ส่วนต่างๆเอาไว้ ทำให้ไม่ต้องไป install ทีละตัว เช่น Webpack, vue-loader, ESLint, Unit test, end-to-end Test, SASS และอื่นๆอีกมากมาย ในที่นี้เลือก <strong>webpack-simple-2.0</strong> เนื่องจาก webpack-simple-2.0 <strong>สนับสนุน Vue.js 2.0</strong></p><blockquote>$ vue init webpack</blockquote><p><strong>หมายเหตุ</strong>: ในส่วนของ ESLint สามารถดูรายละเอียดเพิ่มเติมได้จาก<br><a href="https://stories.sellsuki.co.th/javascript-standard-style-%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%80%E0%B8%96%E0%B8%AD%E0%B8%B0%E0%B8%84%E0%B8%A3%E0%B8%B1%E0%B8%9A-%E0%B8%88%E0%B8%B0%E0%B9%84%E0%B8%94%E0%B9%89%E0%B9%84%E0%B8%A1%E0%B9%88%E0%B8%95%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99%E0%B8%A0%E0%B8%B2%E0%B8%A3%E0%B8%B0%E0%B8%82%E0%B8%AD%E0%B8%87%E0%B8%84%E0%B8%99%E0%B8%AD%E0%B8%B7%E0%B9%88%E0%B8%99-a2622578631d">https://stories.sellsuki.co.th/javascript-standard-style-%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%80%E0%B8%96%E0%B8%AD%E0%B8%B0%E0%B8%84%E0%B8%A3%E0%B8%B1%E0%B8%9A-%E0%B8%88%E0%B8%B0%E0%B9%84%E0%B8%94%E0%B9%89%E0%B9%84%E0%B8%A1%E0%B9%88%E0%B8%95%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99%E0%B8%A0%E0%B8%B2%E0%B8%A3%E0%B8%B0%E0%B8%82%E0%B8%AD%E0%B8%87%E0%B8%84%E0%B8%99%E0%B8%AD%E0%B8%B7%E0%B9%88%E0%B8%99-a2622578631d</a></p><p>ถึงขั้นตอนนี้ให้ทำการ run หน้า website เพื่อทดสอบการติดตั้ง Vue.js โดยใช้คำสั่ง</p><blockquote>$ npm install และ</blockquote><blockquote>$ npm run dev หรือ</blockquote><blockquote>$ yarn dev (หากทำการ install yarn แล้ว)</blockquote><p>ซึ่งจะแสดงหน้า website <a href="http://localhost:8080/">http://localhost:8080</a> ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XkXNPKqaNXGh7vqPPv1unQ.png" /></figure><h3>Installation Vuetify และ Style</h3><ol><li>Install <strong>vuetify</strong> โดยทำการ save ลง dependencies</li></ol><blockquote>$ npm install vuetify --save หรือ</blockquote><blockquote>$ yarn add vuetify --dev (หากทำการ install yarn แล้ว)</blockquote><p>2. Install <strong>Stylus, CSS</strong> เพื่อให้ใช้งาน style component ต่างๆของ vuetify ได้</p><blockquote>$ npm i stylus stylus-loader style-loader css-loader --save-dev</blockquote><p><strong>Note</strong>: <em>หากใครต้องการใช้งาน SASS ให้ทำการ Install ตามคำสั่ง ด้านล่าง</em></p><blockquote>$ npm install sass-loader node-sass webpack --save-dev</blockquote><p><strong>Problem</strong>: <em>หากใครพบปัญหาว่า หา babel-preset-env ไม่พบ ให้ทำการ install ตามคำสั่งด้านล่าง (ถ้าใครไม่พบปัญา สามารถข้ามขั้นตอนนี้ได้เลยค่ะ)</em></p><blockquote>$ npm install babel-preset-env --save-dev หรือ</blockquote><blockquote>$ yarn add babel-preset-env --save-dev (หากทำการ instal้l yarn แล้ว)</blockquote><h3>Import Vuetify</h3><ol><li>ทำการ import vuetify โดยเพิ่ม code ใน <strong>src &gt; main.js</strong> เพื่อกำหนด style ตามด้านล่าง</li></ol><pre><strong>import </strong>Vuetify <strong>from </strong>&#39;vuetify&#39;</pre><pre>Vue.<em>use</em>(Vuetify)</pre><h3>Import Style</h3><p>1. ทำการสร้างไฟล์ <strong>main.styl</strong> ใน Project โดยสร้างใน <strong>src &gt; styles &gt; main.styl</strong> เพื่อกำหนด style component ต่างๆ และพิมพ์ code ตามด้านล่าง</p><pre>@import &#39;../../node_modules/vuetify/src/stylus/settings/_colors&#39;<br><br>$theme := {<br>  primary: $red.darken-2<br>  accent: $red.accent-2<br>  secondary: $grey.lighten-1<br>  info: $blue.lighten-1<br>  warning: $amber.darken-2<br>  error: $red.accent-4<br>  success: $green.lighten-2<br>}<br><br>@import &#39;../../node_modules/vuetify/src/stylus/main&#39;</pre><p>2.ทำการ import style ในไฟล์ <strong>App.vue</strong></p><pre>&lt;style lang=&quot;stylus&quot;&gt;<br>  @import &#39;./styles/main&#39;<br>&lt;/style&gt;</pre><p>3. ไปที่ Folder <strong>build &gt; webpack.base.conf.js</strong> เพื่อทำการ config ให้ใช้ style ได้ โดยภายในไฟล์จะมี code ดังนี้</p><pre><strong>var </strong>path = require(&#39;path&#39;)<br><strong>var </strong>utils = require(&#39;./utils&#39;)<br><strong>var </strong>config = require(&#39;../config&#39;)<br><strong>var </strong>vueLoaderConfig = require(&#39;./vue-loader.conf&#39;)<br><br><strong>function </strong>resolve (dir) {<br>  <strong>return </strong>path.join(__dirname, &#39;..&#39;, dir)<br>}<br><br>module.exports = {<br>  entry: {<br>    app: &#39;./src/main.js&#39;<br>  },<br>  output: {<br>    path: config.build.assetsRoot,<br>    filename: &#39;[name].js&#39;,<br>    publicPath: process.env.NODE_ENV === &#39;production&#39;<br>      ? config.build.assetsPublicPath<br>      : config.dev.assetsPublicPath<br>  },<br>  resolve: {<br>    extensions: [&#39;.js&#39;, &#39;.vue&#39;, &#39;.json&#39;],<br>    alias: {<br>      &#39;vue$&#39;: &#39;vue/dist/vue.esm.js&#39;,<br>      &#39;@&#39;: resolve(&#39;src&#39;)<br>    }<br>  },<br>  module: {<br>    rules: [<br>      {<br>        test: /\.(js|vue)$/,<br>        loader: &#39;eslint-loader&#39;,<br>        enforce: &#39;pre&#39;,<br>        include: [resolve(&#39;src&#39;), resolve(&#39;test&#39;)],<br>        options: {<br>          formatter: require(&#39;eslint-friendly-formatter&#39;)<br>        }<br>      },<br>      {<br>        test: /\.vue$/,<br>        loader: &#39;vue-loader&#39;,<br>        options: vueLoaderConfig<br>      },<br>      {<br>        test: /\.js$/,<br>        loader: &#39;babel-loader&#39;,<br>        include: [resolve(&#39;src&#39;), resolve(&#39;test&#39;)]<br>      },<br>      {<br>        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,<br>        loader: &#39;url-loader&#39;,<br>        options: {<br>          limit: 10000,<br>          name: utils.assetsPath(&#39;img/[name].[hash:7].[ext]&#39;)<br>        }<br>      },<br>      {<br>        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,<br>        loader: &#39;url-loader&#39;,<br>        options: {<br>          limit: 10000,<br>          name: utils.assetsPath(&#39;fonts/[name].[hash:7].[ext]&#39;)<br>        }<br>      },<br>      {<br>        test: /\.styl$/,<br>        loader: [&#39;style&#39;, &#39;css&#39;, &#39;stylus&#39;]<br>      }<br>    ]<br>  }<br>}</pre><p>เมื่อทำถึงขั้นตอนนี้ จะสามารถใช้งาน component ต่างๆของ vuetify ได้แล้ว เช่น button, dialog, select และอื่นๆเป็นต้น แต่หากลองทำ icon material หรือ font awesome มาใช้งานจะยังไม่สามารถใช้งานได้ จึงต้งทำการสร้างไฟล์ และ import ก่อน</p><h3>Import front style</h3><p>1. ทำการสร้างไฟล์ <strong>font.scss</strong> ใน Project โดยสร้างใน <strong>src &gt; styles &gt; font.scss</strong> เพื่อกำหนด font หรือ icon style ต่างๆ และพิมพ์ code ตามด้านล่าง</p><pre><em>/* fallback */<br></em>@font-face {<br>  font-family: &#39;Material Icons&#39;;<br>  font-style: normal;<br>  font-weight: 400;<br>  src: local(&#39;/static/fonts/Material Icons&#39;), url(https://medium.com/&#39;/static/fonts/MaterialIcons-Regular.woff2&#39;) format(&#39;woff2&#39;);<br>}<br>.material-icons {<br>  font-family: &#39;Material Icons&#39;;<br>  font-weight: normal;<br>  font-style: normal;<br>  font-size: 22px;<br>  line-height: 1;<br>  letter-spacing: normal;<br>  text-transform: none;<br>  display: inline-block;<br>  white-space: nowrap;<br>  word-wrap: normal;<br>  direction: ltr;<br>  -webkit-font-feature-settings: &#39;liga&#39;;<br>  -webkit-font-smoothing: antialiased;<br>}</pre><p>2. ทำการ import font style ในไฟล์ <strong>App.vue</strong></p><pre>&lt;style lang=&quot;scss&quot;&gt;<br>  @import &#39;./styles/font.scss&#39;;<br>&lt;/style&gt;</pre><p>3. Download file <strong>font-awesome.min.css</strong> มาวางใน Folder <strong>static &gt; css</strong></p><blockquote>Link: <a href="http://fontawesome.io/get-started/">http://fontawesome.io/get-started/</a></blockquote><p>4. เรียกใช้งาน font awesome ใน file <strong>index.html</strong></p><pre>&lt;link rel=&quot;stylesheet&quot; href=&quot;/static/css/font-awesome.min.css&quot;&gt;</pre><h3><strong>ตัวอย่างหน้า Website</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wN8Y7uALmmSdT-6CjaAjGQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DQgxWLXVgds0iyJoAUbu-Q.png" /></figure><h3>Reference:</h3><p>## Vue.js (<a href="https://vuejs.org/">https://vuejs.org/</a>)</p><p>## Vuetify (<a href="https://vuetifyjs.com/">https://vuetifyjs.com/</a>)</p><p>## SASS (<a href="https://github.com/webpack-contrib/sass-loader">https://github.com/webpack-contrib/sass-loader</a>)</p><p>## BABEL-PRESET-ENV (<a href="https://github.com/babel/babel-preset-env">https://github.com/babel/babel-preset-env</a>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=318e41071ca0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/st-sanyanee/how-to-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-vue-js-%E0%B8%A3%E0%B9%88%E0%B8%A7%E0%B8%A1%E0%B8%81%E0%B8%B1%E0%B8%9A-vuetify-318e41071ca0">[How to] วิธีการใช้งาน Vue.js ร่วมกับ Vuetify</a> was originally published in <a href="https://medium.com/st-sanyanee">st-sanyanee</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[How to] วิธีใช้ Git กับ PhpStorm]]></title>
            <link>https://medium.com/st-sanyanee/how-to-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5%E0%B9%83%E0%B8%8A%E0%B9%89-git-%E0%B8%81%E0%B8%B1%E0%B8%9A-phpstorm-b6c89390cac2?source=rss-15377a775571------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6c89390cac2</guid>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[phpstorm]]></category>
            <dc:creator><![CDATA[st.nann]]></dc:creator>
            <pubDate>Sat, 12 Aug 2017 04:10:03 GMT</pubDate>
            <atom:updated>2017-08-13T03:07:38.681Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*x6reJHM9emdxcjDkpTOKsw.png" /></figure><p><em>ก่อนอื่นต้องขอบอกก่อนว่า Blog นี้เป็น Blog แรกที่เขียน ถ้าผิดพลาดอะไรติชมกันได้เลยนะคะ……</em></p><p><em>วันนี้เราจะมาพูดถึง วิธีการใช้ Git กับ PhpStorm นะคะ แต่ก่อนที่จะพูดถึงวิธีการใช้ จะขออธิบายก่อนว่า Git กับ Phpstorm คืออะไร (สำหรับใครที่ยังไม่รู้นะคะ ใครรู้แล้วข้ามได้เลยค่ะ :)*)</em></p><blockquote><strong>Git </strong>คือ Version Control ซึ่งทำหน้าที่ในการจัดการ backup version ต่างๆ ให้กับโปรเจค เมื่อมีการ commit ไฟล์ โดยจะสามารถ restoreโปรเจคกลับไปได้ ณ จุดเวลาที่เราต้องการ และหากมีการ upload โปรเจค ขึ้นไปบน Git ก็สามารถแชร์โปรเจคนั้นๆ ให้กับคนในทีมได้ โดยหากคนในทีมมีการแก้ไขโปรเจค ก็จะสามารถขอ merge request เพื่อที่จะให้ผู้ที่มีสิทธิ์ merge code เข้าด้วยการได้</blockquote><blockquote>PhpStorm คือ Editor ที่ใช้สำหรับในการเขียน Code</blockquote><p>ต่อไปจะเป็นการอธิบายขั้นตอน<em>วิธีการใช้ Git กับ PhpStorm นะคะ โดยมีขั้นตอน ดังนี้</em></p><ol><li>สมัครสมาชิก Git โดย Git ที่สมัครจะเป็นอะไรก็ เช่น GitLab, GitHub หรืออื่นๆเป็นต้น<br><a href="https://github.com/"><strong><em>https://github.com/</em></strong></a><br><a href="https://about.gitlab.com/"><strong><em>https://about.gitlab.com/</em></strong></a></li><li>Download Git จาก <a href="https://git-scm.com/download"><strong><em>https://git-scm.com/download</em></strong></a><strong><em> และทำการ Install</em></strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J7lv6AnBmFEZFPXporrqvw.png" /></figure><p>3. Download Phpstorm จาก <a href="https://www.jetbrains.com/phpstorm/download/#section=windows"><strong><em>https://www.jetbrains.com/phpstorm/download/#section=windows</em></strong></a> และทำการ Install</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q-YLYC5cvHbCXYY39ETFKQ.png" /></figure><h3>กรณี ใช้ GitLab</h3><p>4.1 จากนั้นเข้า PhpStorm Click <strong>Configure &gt; Setting &gt; Git</strong> แล้วกรอก Path to Git Executable โดย Path จะเป็นที่อยู่ไฟล์ที่เราทำการ install Git</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yrd4ixWcb44_RVj94WhZmg.jpeg" /></figure><h3>กรณี ใช้ GitHub</h3><p>4.2 จากนั้นเข้า PhpStorm Click <strong>Configure &gt; Setting &gt; GitHub</strong> แล้วกรอกรายละเอียด ดังนี้<br><strong><em>Host:</em></strong><em> Website ของ GitHub<br></em><strong><em>Login:</em></strong><em> username ที่ใช้เข้า GitHub<br></em><strong><em>Password:</em></strong><em> password ที่ใช้เข้า GitHub</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AAxksToPM4hgtyENggXGxA.jpeg" /></figure><p>5. หลังจากนั้น ให้ทำการทดลองสร้าง Project ในหน้า Website ของ Git</p><p>6. เมื่อทำการสร้างแล้ว ให้กลับมาที่ PhpStorm เพื่อที่จะเชื่อมต่อไปยัง Git server โดยจะทำการเชื่อมต่อ โดย</p><blockquote><em>$ git remote -vvv</em></blockquote><p>7. ทำการ Remote ไปยัง Git โดย</p><blockquote><em>$ git remote add origin [Path url ssh Git ที่ต้องการเชื่อมต่อ]</em></blockquote><p><strong>Note</strong>: Path SSH สามารถหาได้จาก Website Git ในโปรเจคที่เราสมัคร ตัวอย่าง path git@gitlab.nipa.cloud:st.nann/Git-Test.git</p><p>8. เมื่อ Remote แล้วให้ทำการตรวจสอบว่า Remote สำเร็จหรือไม่ โดยการพิมพ์ Command</p><blockquote>$ git remote -vvv</blockquote><p>Note: หากสำเร็จจะแสดง ดังนี้<br><em>origin git@gitlab.nipa.cloud:st.nann/Git-Test.git (fetch)<br>origin git@gitlab.nipa.cloud:st.nann/Git-Test.git (push)</em></p><p>9. หลังจากนั้น ให้ทำการทำ <strong>Authentication</strong> เพื่อใช้ในการเข้าใช้งาน Git โดยทั่วไปแล้วจะมี 2 วิธี คือ<br>- ใช้ Username และ Password<br>- ใช้ Generate Key (นิยมกว่า)</p><p>10. ในส่วนนี้จะขอยกตัวอย่างการใช้ Generate Key เนื่องจาก วิธีการใช้ Username และ Password ได้แสดงในข้อ 4.2 แล้ว เราจะทำการใช้ Generate Key โดยเข้าไปที่โปรแกรม git.exe ที่ Download มาในข้อ 2 แล้วพิมพ์ Command</p><blockquote>$ ssh-keygen.exe</blockquote><p>11. ทำการกด Enter ไปเรื่อยๆจนสิ้นสุด ดังรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*YKt2RrkUXAQsNlgTQvKf7A.png" /></figure><p>12. Copy path <strong>public key</strong> ตั้งแต่หลัง in ถึงคำว่า pub <strong>(ไม่เอาจุด)</strong> แล้วพิมพ์ Command</p><blockquote>$ cat [Path Public Key ที่ได้]</blockquote><p>13. ขั้นตอนสุดท้าย จะได้ key ที่ถูก Generate มา เพื่อนำไปกรอกในหน้า Website Git (ในที่นี้จะขอยกตัวอย่างรูปภาพของ GitLab นะคะ) ให้เข้าไปที่ <strong>Profile setting &gt; SSH</strong> แล้ว<strong> paste public Key</strong> ที่ copy มา พร้อมตั้งชื่อ key นั้นๆ โดยจะเป็นชื่ออะไรก็ได้ เพื่อบ่งบอกให้เรารู้ว่าเป็น key ของอะไร แล้วทำการกด <strong>Add key</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*e-2K-boOtU8t_WJ78XgwCQ.png" /></figure><p><em>เพียงเท่านี้ก็สามารถใช้ Git โปรเจคต่างๆได้แล้วนะคะ สำหรับบางคนอาจจะสงสัยว่า แล้วจะใช้งาน Git อย่างไร หากมีการแก้ไขไฟล์ต่างๆ ซึ่งก็ไม่ยากเลยค่ะ มีขั้นตอน ดังนี้ ค่ะ</em></p><ol><li>ให้ตรวจสอบดูสีของไฟล์ก่อนว่า ไฟล์นั้นๆเป็นสีอะไร หากเป็น<strong>สีแดง</strong> แสดงว่าไฟล์นั้นยังไม่ถูก add เข้า repository (ส่วนเก็บไฟล์) ของ Git ให้ <strong>click ขวา &gt; add &gt; git</strong> เพื่อ add เข้า repository ก่อน</li><li>เมื่อไฟล์เป็น<strong>สีเขียว</strong>แล้ว ให้ทำการ <strong>Create new branch</strong> โดยจะสร้าง branch ใหม่สำหรับการ commit ไฟล์ เพื่อไม่ให้ข้อมูลไปทับกับไฟล์เดิม โดยการ <strong>click ที่มุมขวาล่างที่มีคำว่า Git: master &gt; New Branch</strong></li><li>เมื่อสร้าง branch ใหม่แล้ว <strong>Click ขวา</strong> ไฟล์ที่ต้องการเก็บ version ณ จุดเวลานั้นๆให้ทำการ <strong>Commit</strong> ไฟล์</li><li>จะแสดงหน้าต่างขึ้นมาให้ทำการ <strong>push</strong> ไฟล์ขึ้นไปยัง server โดยต้อง<strong>กรอกรายละเอียด comment</strong> ก่อน ซึ่งอาจจะเป็นรายละเอียดของการทำงานไฟล์ก็ได้</li><li>เมื่อ push ไฟล์ไปยัง server แล้ว ให้ไปที่<strong>หน้า website </strong>เพื่อทำการ<strong>ขอ merge request</strong> ไปยังผู้ที่มีสิทธิ์รวมไฟล์ โดยการ <strong>click create new merge request</strong></li><li>หลังจากนั้น <strong>ผู้ที่มีสิทธิ์</strong>จะทำการรวมข้อมูลในไฟล์ โดยการ <strong>merge</strong> ไฟล์นั้นๆ โดยอาจจะลบ branch ที่ merge ไปแล้วทิ้ง ให้เหลือเเต่ branch master ซึ่งเป็น branch หลักก็ได้</li><li>หากต้องการให้<strong>ข้อมูล</strong>ในโปรเจคใน PhpStorm เป็น<strong>ปัจจุบัน</strong> ก็สามารถที่จะ pull ลงมาได้ ซึ่งอาจจะทำการ <strong>fetch</strong> ข้อมูลก่อน เพื่อให้ข้อมูลเป็นปัจจุบัน โดยการ <strong>click VCS &gt; Git &gt; Fetch</strong></li><li>เมื่อ fetch แล้ว ให้ทำการ <strong>pull</strong> โดยการ <strong>click VCS &gt; Git &gt;Pull</strong></li></ol><p><strong>Problem</strong>: หากมีการ <em>conflict</em> ซึ่งเกิดจากการแก้ไขไฟล์เดียวกันของคนในทีม ให้ทำการแก้ไขไฟล์นั้น หรือ <em>revert</em> ไฟล์กลับไปก่อน แล้วทำการ <em>pull ใหม่</em></p><p><strong>Note:</strong> หากต้องการ<strong>แชร์</strong>ให้คนอื่น มาแก้ไขงานในโปรเจคของเราให้ทำการ <strong>clone</strong> โปรเจคมา โดย <strong>click VCS &gt; Git &gt; Clone </strong>แล้ว<strong> copy SSH Path Repository </strong>มาใส่ในช่อง <strong>Git Repository url </strong>เช่น<strong> </strong><a href="/service/mailto:git@github.com">git@github.com</a>:st-nann/my-portfolio.git</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6c89390cac2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/st-sanyanee/how-to-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5%E0%B9%83%E0%B8%8A%E0%B9%89-git-%E0%B8%81%E0%B8%B1%E0%B8%9A-phpstorm-b6c89390cac2">[How to] วิธีใช้ Git กับ PhpStorm</a> was originally published in <a href="https://medium.com/st-sanyanee">st-sanyanee</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>