22 มีนาคม 2562

kubenates training note (21-22 Mar 2019)

related repositories
https://github.com/up1/course-kubernetes-in-practice
https://github.com/up1/workshop-kubernetes-microservices

========================= day1=========================
gcloud sdk => https://cloud.google.com/sdk/docs/quickstart-macos

slide => https://github.com/up1/course-kubernetes-in-practice

cloud native landspace => https://landscape.cncf.io/

container design principal
- image immutible: 1 image run anywhere

- high observability principle
  -- health
    --- readiness: workable (can connect db, redis, external)
    --- liveness: call, get 200 (but don't know workable or not)

  -- metrics
    --- tracing
    --- logging

- single responsibility
  -- 1 container -> 1 process

- support graceful shutdown
  -- handle sigterm

- self containment principle
  -- no configuratin in container
  -- no storage is related to container (change disk, not affect app)

kubernetes world is a service layer, everything is a service

standard k8s
- 4 machines
- design to run eveywhere
- master & slaves
- เวลาเรา manage, manage ผ่าน master
- เวลาใช้งาน เข้า slaves ตรงๆ ไม่ผ่าน master

$ kubectl get nodes // get nodes

k8s master components
- API server => mapping, updating etds, access etcd, authen, authorize
- scheduler => เลือกว่าจะดีพลอยเครื่องไหน, resource utilization
- controller => maintain number of pods (up or down)
- etcd => discovery


k8s slaves (node) components:
- kubelet: get command from master, จงสร้างแอพ 1, เป็น agent
- docker
- kube-proxy: รับ request จากภายนอก(คนใช้งาน), เก็บ iptables
- fluend

tracing
tool: jeager, istio

workshop 01-hello
$ kubectl run hello --image=somkiat/hello:latest --port=8080 --generator=run/v1
--generator=run/v1 => คือให้มันสร้าง replicationcontroller ให้
replicationcontroller/hello created

pod คือ หน่วยที่เล็กที่สุด
scaling => scale ระดับ pod
ใน pod มีได้หลาย container แต่ควรมีแค่ container เดียว

$ kubectl get pod // get pods
$ kubectl describe pod/hello-6ln72 // get pod details

2 containers ถ้าอยู่ใน pod เดียวกัน คุยผ่าน localhost ได้

$ kubectl get pod/hello-6ln72 -o json // get json format, or -o yaml

$ kubectl get rc // get replicationcontroller or "kubectl get replicationcontroller"

$ kubectl scale rc hello --replicas=3 // scale to 3

$ kubectl get pod -w // watching

$ kubectl delete pod/hello-6ln72 // delete pod

* replicationcontroller ปัจจุบันไม่ได้ใช้แล้วนะ

$ kubectl get pod -o wide // ดูว่าแต่ละ pod รันบนเครื่องไหน

$ kubectl get pod,rc // view pod & rc

$ kubectl delete rc/hello // delete rc

$ kubectl --namespace=kube-system get pod // ดู pod system

logging (เป็น udp มีโอกาสหาย สำหรับ application log)
1. app log to syslog server
2. fluend set source to syslog (monitor syslog)
audit log ห้ามหาย ห้ามใช้

ของ gcp, fluend จะอ่าน log แล้วโยนเข้า stack driver ให้

เราจะไม่ expose pod, expose ผ่าน service layer เอา

$ kubectl get service // or "kubectl get svc", can see clusterIP

3 types of services
1. clusterIP:
  - private
  - clusterIP is ip of the service
2. node port
3. load balance
  - default => dynamic ip
  - static ip => pay money
  - access LB ที่เดียว
4. ingress controller (built-in k8s)
  - map /a => go to service A
  - map /b => go to service B

$ kubectl expose rc hello --type=LoadBalancer --name hello-http // expose LB
$ kubectl get svc -w
$ kubectl get svc/hello-http -o yaml

workshop 02 - single pod

selector เดียวกันคือ cluster เดียวกัน

$ kubectl get all

$ kubectl delete all --all

1. cd /Users/apple/Desktop/myProjects/k8s-training/course-kubernetes-in-practice/workshop/02-pod-service/single-pod
2. kubectl create -f .
    or kubectl create -f https://xxxxx.yaml
    or kubectl create -f pod.yaml
3. kubectl delete -f . // delete all

allow firewall on gcpcloud
$ gcloud compute firewall-rules create xxx123 --allow tcp:32346

$ kubectl get node -o wide // node is machine

replicaSet
- we don't use replicationcontroller anymore, use replicaSet (rs)

view all resources => kubectl api-resources

deployment stretagy
- re-create
- ramp -> default k8s
- blue green
- ab
- canary
- shadow

$ kubectl describe po/hello-5bbb55ffb-cg7kk // can see namespace of this pod
$ kubectl get ns // get name space

service expose pod (in selector -> selector pod)
deployment -> replicaSet -> pod

$ kubectl get deploy // get deployment

owasp
- web
- mobile
- docker

slide: SCK-DOCKER-KUBERNETES-IN-PRACTICE.pdf

config map: reference configuration
secret: xxxxx (config ที่เป็นความลับ, e.g., password)
super secret should use 3rd party, e.g., vault

kompose -> convert docker-compose to k8s (https://github.com/kubernetes/kompose)





========================= day2=========================
monitor docker
- cAdvisor: monitor docker (https://github.com/google/cadvisor)
- prometheus:
  -- set docker daemon json to point to prometheus server
  -- enable localhost:1337
  -- advance=> {
    "metrics-addr": "0.0.0.0:1337",
    "experimental: true,
    "debug": true
  }
  -- http://localhost:1337/metrics

$ docker system events // watch docker event


hpa (horizontal pod autoscaler)
hpa
- auto scale based on cpu by default, we can auto scale by custom matric
- มันจะค่อยๆ สเกล  ถ้าทราฟฟิคพีคสูงมากๆ ไมเวิร์ต ต้อง manual scale

components in autoscaling
- cAdvisor (in kubelet) will monitor pod data
- heapster (metrics-server for new version) collect metrics from cAdvisors
- hpa will get metrics from heapster
- hpa work with deployment, will increase or decrease number of replicas

heapster is deprecated (use metrics-server instead)

metrics-server: need to install by ourselves for on-premise case


$kubectl create -f https://raw.githubusercontent.com/up1/course-kubernetes-in-practice/master/working-with-java/02-web-app/k8s/mongodb/mongo-controller.yaml
$kubectl create -f https://raw.githubusercontent.com/up1/course-kubernetes-in-practice/master/working-with-java/02-web-app/k8s/mongodb/mongo-service.yaml

$kubectl create -f https://raw.githubusercontent.com/up1/course-kubernetes-in-practice/master/working-with-java/03-hpa/boot-deployment.yaml
$kubectl create -f https://raw.githubusercontent.com/up1/course-kubernetes-in-practice/master/working-with-java/03-hpa/boot-service.yaml

$ gcloud compute firewall-rules create xxx124 --allow tcp:32500 // open firewall
$ kubectl get node -o wide // get external ip of machine
$ curl http://35.224.26.179:32500/user

$kubectl autoscale deployment/spring-boot-service-deployment --min=1 --max=5 --cpu-percent=5
$kubectl get hpa
$kubectl describe hpa

secret and configuration management
$ kubectl get configmap
$ kubectl get secret

configmap 2 modes
- env -> need to re-deploy deployment
- volumn -> don't need to re-deploy deployment

$ spring-boot-service-deployment-567f8d58bc-lc85k // exec pod

$ kubectl apply -f config.yaml // apply config map after updating
$ kubectl apply -f . // apply configuration change

stateful with k8s

sample: https://codelabs.developers.google.com/codelabs/cloud-mongodb-statefulset/index.html#0

stateful with k8s
- volumn
- statefulset

volumes
- EmptyDir:
  -- เหมือน tmp ข้อมูลจะออโต้ลบเอง
  -- e.g., log
  -- 1 pod 2 containers: main & fluentd (shift log)
- hostPath
- gitRepo
- NFS
- icePersistentDisk
- flocker: cloud storage
- Persistent Volume Claim (PVC)

storage class:
- dynamic claim
- class, e.g., gold, platinum

Persistent Volume:
- static claim: ต้องบอกว่าจะเคลมกี่ G
- cannot bind 2 pvc to the same pv

$ cd workshop/05-volume/persistent_volume

$ kubectl get pv -w // get pv
$ kubectl get pvc -w  // get pvc
$ kubectl get po,pv,pvc


http://www.somkiat.cc/hello-cotton-for-api-testing/ // automate test

workshop >> https://github.com/up1/workshop-kubernetes-microservices

online play docker >> https://labs.play-with-docker.com/


port
- nodeport: port of nodeport
- port: port of service
- targetPort: port of pod



12 กุมภาพันธ์ 2562

บริจาคเงินง่ายๆ ผ่านแอพ AirPay

แอพ AirPay ซึ่งเป็น mobile wallet application (มีทั้งสำหรับ iOS และ Android) นั้น มีช่องทางให้เราบริจาคเงินให้กับมูลนิธิต่างๆ ได้หลากหลาย โดยการตัดบัตรเครดิต ซึ่งค่อนข้างสะดวกสำหรับคนที่ชอบทำบุญ

วิธีการบริจาคเงิน สามารถทำได้ง่ายๆ โดยล็อคอินเข้าระบบ และเลือกเมนูบริจาค



หลังจากนั้นแอพจะแสดงรายชื่อมูลนิธิ องค์กร ต่างๆ พร้อมรายละเอียดให้เราดูว่า แต่ละมูลนิธิ หรือองค์กรนั้นๆ เอาเงินเราไปทำอะไรบ้าง ซึ่งมีให้เลือกค่อนข้างหลากหลาย








หลังจากนั้นให้เราเลือกมูลนิธิหรือองค์กรที่เราต้องการจะบริจาคเงิน และกดปุ่ม "บริจาควันนี้"


เลือกจำนวนเงินที่ต้องการจะบริจาค และกดปุ่ม "ถัดไป" เพื่อเลือกช่องทางการชำระเงิน ซึ่งเราสามารถชำระผ่านบัตรเครดิตได้ด้วย


จากรูปด้านล่างเป็นตัวอย่างหน้า Transaction ของตัวเอง


28 มกราคม 2562

10 คำสอนตรงๆ ง่ายๆ ของ “หลวงพ่อคูณ” ที่จะคงอยู่ในใจตลอดไป

รวบรวม 10 โอวาทธรรม หรือคำสอนของ พระเทพวิทยาคม (หลวงพ่อคูณ ปริสุทฺโธ) พระเกจิอาจารย์ชื่อดังแห่งวัดบ้านไร่ จ.นครราชสีมา
เนื้อหาบางส่วนจากหนังสืออาจาริยานุสรณ์ พระเทพวิทยาคม (หลวงพ่อคูณ ปริสุทฺโธ) (เล่มใหญ่) จัดทำโดยมหาวิทยาลัยขอนแก่น ได้เผยแพร่โอวาทธรรมคำสอนของหลวงพ่อคูณที่จะคงอยู่ในใจตลอดไป “หลวงพ่อเทศนาเป็นคำพูดตรงๆ แทรกธรรมง่ายๆ ที่ประชาชนทั่วไปฟังแล้วเข้าใจได้ ในที่นี้ไม่สามารถสาธยายได้หมด จึงขอยกตัวอย่างมาเพียงบางส่วนเท่านั้น”


ก่อนสอนคนอื่นต้องสอนตัวเองก่อน

“มันต้องสอนตัวเองก่อน จะแนะนำอะไรเขา ตัวเองทำให้เขาดูตัวอย่างก่อน เช่น สอนให้เขาบริจาคทาน ตัวเองต้องบริจาคเสียก่อนด้วยจึงจะถูก ใครมันจะไปเชื่อ เชื่อไม่ได้ ต้องทำให้เขาดูก่อน สอนตัวเองก่อน ถึงค่อยไปสอนคนอื่น จะทำอะไรทุกอย่างมันต้องทำให้เขาดูก่อน เขาจึงจะเชื่อ… อย่างพระสงฆ์ อย่าดีแต่ไปสอนคนอื่น สอนตัวเองบ้างเถอะน่า สอนคนอื่นอย่างน้ำไหลไฟดับ แต่ตัวเองไม่สอน บอกให้เขาบริจาคเท่านั้นเท่านี้ แต่ตัวเองไม่ทำให้เขาดูก่อน หรือจะเป็นครูอะไรก็ตาม..เป็นครูนาฏศิลป์ก็ต้องรำเป็น หรือเป็นครูอะไรๆ ก็ต้องทำเป็นก่อนทั้งนั้น พระพุทธองค์ก็เหมือนกัน สอนตัวเองได้แล้วท่านเอาชนะตัวเองได้แล้ว จึงได้เสด็จออกไปเทศนาโปรดปัญจวัคคีย์และเวไนยสัตว์”





ความประมาทเป็นบ่อเกิดแห่งความตาย

หลวงพ่อมักจะให้ข้อคิดกับคนที่เอารถมาให้ท่านเจิมว่า “การขับรถอย่างระมัดระวังไม่ประมาท สำคัญกว่าการเจิม อย่างโบราณท่านว่า วิ่งไม่ดูตาม้าตาเรือก็ชนกันตาย การขับรถจะต้องดูทาง ถ้ามันคดโค้งจะต้องระมัดระวัง” “ถ้าประมาทเมื่อใดก็ตายเมื่อนั้น เพราะฉะนั้นทำอะไรทุกอย่าง ทำให้ดี อย่าได้ประมาท อย่าผัดผ่อน ถ้าประมาทแล้วนึกได้ทีหลังจะเสียใจ”



ละทำชั่ว ทำดี มีศีลธรรมประจำใจ

ละทำชั่ว ทำดี มีศีลธรรมประจำใจ ถือเป็นหัวใจของพระพุทธศาสนา ท่านมักกล่าวอยู่เสมอว่า “อยากให้บ้านเราเจริญนะ ไม่ยากหรอก ตั้งอยู่ในองค์ปัญจะทั้ง 5 คือ รักษาศีล 5 ให้บริสุทธิ์ ไม่ให้ขาด อย่าให้ด่างพร้อย เป็นมนุษย์สุดประเสริฐ หรือใครก็ตาม แม้แต่พระ เราก็ต้องรักษาศีล 5 ถ้าไม่มีศีล 5 ประจำใจ ไม่ว่าพระรูปใดรูปหนึ่งก็เป็นพระไม่ได้เหมือนกัน”


“กูให้มึงรู่จั๊กพอ”

ในวัตรปฏิบัติของหลวงพ่อคูณหลายประการที่เป็นการสอนธรรมโดยอ้อม เช่น การรับเงินจากญาติโยมที่มาบริจาคให้ท่านนำไปสร้างสาธารณกุศล ท่านจะหยิบเพียงใบเดียวและเป็นใบที่มีค่าน้อยที่สุด หลวงพ่อบอกว่าที่ทำเช่นนี้เพราะ…
“กูให้มึงรู่จั๊กพอเพราะผู้คนหาเงินมาด้วยความยากลำบาก ยิปทั่งหม๊ดจะเป็นการเอาเปรียบหยาดเหงื่อแรงงานของญาติโยม เราต้องมีเมตตาแก่เพื่อนมนุษย์ เกิด แก่ เจ๊บ ตาย เขาให่เท่าไหร่ก็เอาเท่านั้น มันเป็นไปไม่ได้ อย่าเอามากหลาย หลานเอ๊ย โลภของคนเรา ร่อยล้าน พันล่าน ก็ไม่พอให่รู้จักว่าพอกันซักทีซิ พูดว่า “พอ” กันซักที การรับบริจาคเพียงส่วนหนึ่งของกูนี่ เป็นการเตือนสติและสอนพุทธศาสนิกชนทั่งหลายว่าให่รู่จักพอ อย่าโลภมากหรือให่ลดความโลภ ความอยากได้ของคนอื่น อย่าเบียดเบียนเอารัดเอาเปรียบซึ่งกันและกัน”



“เราต้องให่เขาก่อน แล่วเขาก็จะให่เราทีหลัง”

ด้วยบารมีของหลวงพ่อคูณ เมื่อตั้งใจจะสร้างอะไร สิ่งนั้นย่อมสำเร็จ คือจะมีผู้บริจาคสมทบอย่างมากมาย เคยมีผู้สอบถามเรื่องนี้ หลวงพ่อหัวเราะพร้อมบอกว่า … “เราต้องให่เขาก่อน แล่วเขาก็จะให่เราทีหลัง และเมื่อเราได้รับการบริจาคมาแล้ว เราควรที่จะทำตัวให่เป็นประโยชน์ต่อสังคม ไม่ใช่หวังเก๊บหวังรวยแต่อย่างเดียว มันไม่ใช่วิสัยของเพศสมณะ เมื่อเขาเห็นเรานำไปทำประโยชน์ เขาก็ยิ่งแต่จะมาช่วยเรา ถ้าเราไม่นำไปทำบุญให่เขาต่อ เขาจะได้บุญอะไร”



การด่าลูกเป็นอัปมงคล พูดกับลูกๆ แต่สิ่งดีๆ มันจะได้เป็นมงคล

หลวงพ่อคูณให้พรเนื่องในโอกาสวันเด็กแห่งชาติ พ.ศ. 2540
“กูเองก็ขอให้เด็กไทยทุกคนจงประพฤติตัวให้เหมาะสมกับที่เราเป็นชาติไทย พวกลูกๆ หลานๆ ก็ขอให้ตั้งใจเล่าเรียนศึกษาหาความรู้ใส่ตัวเองเอาไว้ เมื่อเติบโตขึ้นเป็นผู้ใหญ่ก็จะมีวิชาหากินกับเขา อย่าได้เป็นเด็กเกเร ให้รู้จักรักพ่อแม่ เขาสั่งสอนบอกอะไรก็ให้เชื่อฟัง…”
“ทางพวกพ่อแม่ก็สั่งสอนให้ลูกๆ ถ้าจะเอ่ยคำสอนไหน ก็อย่าไปพูดว่า ลูกคนนี้ดื้อ ลูกคนนี้มึน ลูกคนนี้ซน ลูกคนนี้บอกยากสอนยาก เพราะมึงไปว่ามันมาแต่เล็กๆ มันเป็นอัปมงคล และจะส่งเสริมให้ลูกของมึงดื้อจริงๆ พวกมึงต้องพูดคำว่า เป็นคนดี บอกง่าย สอนง่าย ไม่เคยเกเร ให้พูดกับลูกๆ แต่สิ่งดีๆ มันจะได้เป็นมงคลและมันก็จะได้จดจำเอาไว้ มึงทำตามกูบอกเด้อลูกหลายเอ๊ย”



อย่าไปงมงายเอาเงินไปซื้อเลขหวย

“พวกมึงมาขอโชคพร กูก็ให้พรและเคาะหัว แต่เรื่องเลขเด็ดไม่มีให้ใครด๊อก อย่าไปงมงายเอาเงินไปซื้อเลขหวยกันเลย เก็บเงินไว้ซื้อกับข้าวดีกว่า”  (เดลินิวส์ 25 กันยายน 2541 ) กรณีข่าวเลขเด็ดอายุของหลวงพ่อคูณที่สร้างความสนใจให้กับนักเสี่ยงโชคทั่วประเทศ ทำให้ผู้สื่อข่าวพยายามติดต่อขอสัมภาษณ์หลวงพ่อตลอดวัน แต่หลวงพ่อไม่ว่าง เพราะรับแขกไม่ขาดสายจนไม่ได้พักผ่อน หลวงพ่อคูณได้พูดเตือนสติไปถึงนักเสี่ยงโชคสั้นๆ ว่า “กูไม่อยากพูดอะไรทั้งนั้น ไม่อยากให้ลูกหลานมันงมงายเกินเหตุ ใครจะโชคดีแล้วแต่โชควาสนา”  (เดลินิวส์ 31 สิงหาคม 2542)



พ่อแม่ที่อยู่บนบ้านต้องทำบุญทุกวัน คือต้องรู้จักตอบแทนบุญคุณ อย่ามัวแต่รอไปทำบุญ 100 วัน ซึ่งจะได้บุญน้อยกว่า

หลวงพ่อคูณแนะนำสั่งสอนให้รู้จักบุญคุณ และตอบแทนบุญคุณต่อผู้มีพระคุณ พ่อแม่ ครูอาจารย์ แผ่นดินหรือประเทศชาติอันเป็นที่กำเนิด เป็นที่อยู่อาศัย และพระเจ้าแผ่นดินที่เป็นศูนย์รวมจิตใจของคนทั้งชาติ หลวงพ่อบอกว่า ผู้เป็นลูกต้องรู้จักตอบแทนบุญคุณพ่อแม่



ยิ่งเอามันยิ่งอด ยิ่งสละให้หมด มันยิ่งได้

หลวงพ่อคูณ เป็นตัวอย่างที่ดีในเรื่องของการบริจาคทาน หรือการเสียสละเพื่อให้พุทธศาสนิกชนปฏิบัติตาม ท่านได้ดำเนินชีวิตบำเพ็ญทานบารมีอย่างจริงจังมาโดยตลอดตามแนวของพระมหาเวสสันดร



อย่าลอดคันนาก็แล้วกัน

ญาติโยมถามหลวงพ่อคูณว่า เมื่อให้วัตถุมงคลหรือฝังตะกรุดผู้ใดแล้ว หลวงพ่อได้ตั้งกฎเกณฑ์ในการปฏิบัติหรือต้อง “กรำ” ของอย่างไร ซึ่งก็หมายถึงข้อห้ามที่จะทำมิได้ ในขณะที่มีวัตถุมงคลอยู่ในครอบครอง เพราะเชื่อว่า ของขลังเหล่านั้นจะเสื่อมและไม่มีความศักดิ์สิทธิ์อีกต่อไป ท่านตอบแบบติดตลกว่า “กูไม่ได้ตั้งกฎอะไรด๊อก ลอดอะไรก็ได้ แต่อย่าลอดหัวคันนาก็แล้วกัน”
ที่หลวงพ่อพูดเช่นนี้ มีความหมายว่า ผู้ที่มีวัตถุมงคลนั้นจะลอดอะไรก็ได้ วัตถุมงคลนั้นไม่เสื่อม ยังทรงพุทธานุภาพและเป็นสิริมงคลเสมอตราบเท่าที่ผู้นั้นประพฤติตนเป็นคนดี มีศีลธรรม ไม่ประพฤติชั่วออกนอกลู่นอกทาง เหมือนการลอดคันนาที่ไม่มีผู้ใดกระทำ เพราะคันนามีไว้สำหรับเดิน ไม่ใช่ลอด ผู้ที่มีวัตถุมงคลและปฏิบัติตามจึงเกิดสิริมงคลกับชีวิตตลอดไป


ที่มา https://www.sanook.com/news/7659378/


15 มกราคม 2562

Creating sequence diagram from code

A sequence diagram is really useful for representing system workflow between each entity inside the system.

https://www.websequencediagrams.com is an online tool for generating a sequence diagram from source code easily and you can manage each diagram inside this tool or just copy source code to your own git repository.

We just manage the code like this.

 The tool will generate this sequence diagram automatically. We can also export the diagram to pdf, svg, png format.


16 ธันวาคม 2561

Android utility app for Pokemon Go user

If you play Pokemon Go game. I would like to suggest the utility app for you. The "go app" on Android play store (https://play.google.com/store/apps/details?id=draood.pokeapp2).


You can search for each your favorite pokemons by filtering the type, pokemon name and sort by your prefered criteria.

When you open the app, you will see the result like this in the 1st time.



In the pokemon type dropdown, you can filter the type that you want to filter.


In the sort drop down, you can perform sorting by the condition that you want.


In the example below, I will filter pokemon type to "water" and sort by "cp", the result will look like this image.



In the example below, I will filter the pokemon name that contain "poli" only.


You can see pokemon detail by clicking each pokemon card. The example below, I click poliwag.
I can see basic information including the shiny form image.


I can see the pokemon move list like this.



I can also see the type counter for this pokemon and see the evolution forms of this pokemon.

This app is free to use on Android Play store (https://play.google.com/store/apps/details?id=draood.goapp)

If you like it, please review the app for me and provide feed back.

05 ธันวาคม 2561

create swift framework and include some dependency using swift package manager

in the example, i gonna create swift framework and use library https://github.com/vapor/jwt

1. create new folder, e.g., testJwt
$ mkdir testJwt

2. goto the folder
$ cd testJwt

3. init package
$ swift package init

4. update Package.swift
$ vi Package.swift

update file like this

dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(url: "https://github.com/vapor/jwt.git", from: "3.0.0")
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "testJwt",
            dependencies: ["JWT"]),
        .testTarget(
            name: "testJwtTests",
            dependencies: ["testJwt"]),

    ]


5. install package dependencies
$ swift package update

6. generate xcode project
$ swift package generate-xcodeproj

7. build project
$ swift build

8. then you can call JWT from your framework code by adding import JWT at the top of the swift file


Note:

if you found the error like error: 'openssl/conf.h' file not found

try to install commands below

$ brew install openssl
$ brew upgrade openssl
$ brew install libressl

12 กรกฎาคม 2561

build android apk release file using cordova


  • goto the cordova root path
  • generate key file using command >> keytool -genkey -v -keystore YOUR_FILE.jks -keyalg RSA -keysize 2048 -validity 10000 -alias YOUR_ALIAS (example ==> keytool -genkey -v -keystore sample.jks -keyalg RSA -keysize 2048 -validity 10000 -alias sample)
  • move the key file to FILE_NAME.jks path platforms/android/
  • create file platforms/android/release-signing.properties with the following content

storeFile=FILE_NAME.jks
storeType=jks
keyAlias=YOUR_ALIAS
keyPassword=YOUR_PASSWORD
storePassword=YOUR_PASSWORD

  • goto the cordova root path and run >>> cordova build --release


09 กรกฎาคม 2561

convert create-react-app to android/ios mobile application using cordova

steps

  • install jdk 1.8
  • install android studio
  • install gradle by running brew install gradle
  • accept android license by running ~/Library/Android/sdk/tools/bin/sdkmanager --licenses
  • install cordova by running sudo npm install -g cordova
  • create cordova app by running cordova create mycordova
  • goto mycordova cd mycordova
  • create react application inside mycordova by running create-react-app myweb
  • modify myweb/public/index.html like this

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src * data: content:;">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<title>React App</title>
</head>
<body>
<div id="root"></div>
<script type="text/javascript" src="cordova.js"></script>
</body>
</html>



  • modify myweb/package.json like this
{
"name": "sample-app",
"version": "0.1.0",
"private": true,
"homepage": "./", // <- add="" span="">
"dependencies": {
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-scripts": "1.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build && cp -a ./build/. ../www/", // <- add="" span="">
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}

  • inside myweb run npm run build
  • goback to mycordova folder and then run cordova build to generate .apk file or run cordova run andriod to build and run app