Category Archives: Uncategorized

Quản lý phiên bản Node.js

Mình dùng NVM để cài đặt Node.js và có thể chọn được version cần dùng.

Cài đặt

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

Show danh sách các phiên bản Node.js lts

nvm ls-remote --lts
...
       v12.21.0   (LTS: Erbium)
       v12.22.0   (LTS: Erbium)
       v12.22.1   (LTS: Erbium)
       v12.22.2   (LTS: Erbium)
       v12.22.3   (LTS: Erbium)
       v12.22.4   (LTS: Erbium)
       v12.22.5   (Latest LTS: Erbium)
       v14.15.0   (LTS: Fermium)
       v14.15.1   (LTS: Fermium)
       v14.15.2   (LTS: Fermium)
       v14.15.3   (LTS: Fermium)
       v14.15.4   (LTS: Fermium)
       v14.15.5   (LTS: Fermium)
       v14.16.0   (LTS: Fermium)
       v14.16.1   (LTS: Fermium)
       v14.17.0   (LTS: Fermium)
       v14.17.1   (LTS: Fermium)
       v14.17.2   (LTS: Fermium)
       v14.17.3   (LTS: Fermium)
       v14.17.4   (LTS: Fermium)
->     v14.17.5   (Latest LTS: Fermium)

Cài đặt Node.js. Npm sẽ đi kèm

nvm install v14.17.5

v14.17.5 is already installed.
Now using node v14.17.5 (npm v6.14.14)

Docker always pull base image when build. How to stop it.

TL;DR: Disable BuildKit

Credit: mattwelke

Context

I have docker image with repository & tag same with FROM image in Dockerfile. But when I build image, docker always pull metadata for check from docker hub and pull it.

➜  ~ docker image ls
REPOSITORY             TAG       IMAGE ID       CREATED              SIZE
confluentinc/cp-base   6.0.3     827d97cf9dd3   46 minutes ago       566MB
confluentinc/cp-base   6.0.3-1   827d97cf9dd3   46 minutes ago       566MB
confluentinc/cp-base   latest    827d97cf9dd3   46 minutes ago       566MB

Dockerfile snippet

➜  ~ cat debian/zookeeper/Dockerfile

FROM confluentinc/cp-base:latest

EXPOSE 2181 2888 3888

ARG COMMIT_ID=unknown
LABEL io.confluent.docker.git.id=$COMMIT_ID
ARG BUILD_NUMBER=-1
LABEL io.confluent.docker.build.number=$BUILD_NUMBER

MAINTAINER partner-support@confluent.io
LABEL io.confluent.docker=true

ENV COMPONENT=zookeeper

RUN echo "===> installing ${COMPONENT}..." \
...
docker build --build-arg KAFKA_VERSION=5.3.3 --build-arg CONFLUENT_PLATFORM_LABEL= --build-arg CONFLUENT_MAJOR_VERSION=6 --build-arg CONFLUENT_MINOR_VERSION=0 --build-arg CONFLUENT_PATCH_VERSION=3 --build-arg COMMIT_ID=017a760 --build-arg BUILD_NUMBER=1 -t confluentinc/cp-zookeeper:latest -f debian/zookeeper/Dockerfile debian/zookeeper
[+] Building 5.3s (5/7)
 => [internal] load build definition from Dockerfile                                                                                                            0.0s
 => => transferring dockerfile: 37B                                                                                                                             0.0s
 => [internal] load .dockerignore                                                                                                                               0.0s
 => => transferring context: 2B                                                                                                                                 0.0s
 => [internal] load metadata for docker.io/confluentinc/cp-base:latest                                                                                          1.8s
 => [internal] load build context                                                                                                                               0.0s
 => => transferring context: 662B                                                                                                                               0.0s
 => CANCELED [1/3] FROM docker.io/confluentinc/cp-base:latest@sha256:3d39ae1ee2cbd023789726997192c59571fde83a7c499c250bd1f381671c48c8                           3.4s
 => => resolve docker.io/confluentinc/cp-base:latest@sha256:3d39ae1ee2cbd023789726997192c59571fde83a7c499c250bd1f381671c48c8                                    0.0s
 => => sha256:8a45f3148b491bcd6e5276c2c87627e0837fb7a365a33d2d0042c9539ebd7c0d 1.05MB / 54.39MB                                                                 3.4s
 => => sha256:5fd1c1919136112f38da58359c6977b0e7b2bcbaecb8d54dec8c1c2e83160605 0B / 168.79MB                                                                    3.4s
 => => sha256:171a7e7c3b1354e376d6f4288780a1e9a7f38906787cb82eab66cc7c3dd02356 0B / 26.63MB

I try to change base image to confluentinc/cp-base:6.0.3 but not luck.

➜  ~ docker build --build-arg KAFKA_VERSION=5.3.3 --build-arg CONFLUENT_PLATFORM_LABEL= --build-arg CONFLUENT_MAJOR_VERSION=6 --build-arg CONFLUENT_MINOR_VERSION=0 --build-arg CONFLUENT_PATCH_VERSION=3 --build-arg COMMIT_ID=017a760 --build-arg BUILD_NUMBER=1 -t confluentinc/cp-zookeeper:latest -f debian/zookeeper/Dockerfile debian/zookeeper
[+] Building 1.9s (3/3) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                            0.0s
 => => transferring dockerfile: 1.77kB                                                                                                                          0.0s
 => [internal] load .dockerignore                                                                                                                               0.0s
 => => transferring context: 2B                                                                                                                                 0.0s
 => ERROR [internal] load metadata for docker.io/confluentinc/cp-base:6.0.3
------
 > [internal] load metadata for docker.io/confluentinc/cp-base:6.0.3:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: docker.io/confluentinc/cp-base:6.0.3: not found
+ exit 1

Solutions

I had experienced this issue after upgrading to the latest docker desktop version on mac. Solved with the comment on this issue

➜  ~ export DOCKER_BUILDKIT=0
➜  ~ export COMPOSE_DOCKER_CLI_BUILD=0

Try to build

➜  ~ docker build --build-arg KAFKA_VERSION=5.3.3 --build-arg CONFLUENT_PLATFORM_LABEL= --build-arg CONFLUENT_MAJOR_VERSION=6 --build-arg CONFLUENT_MINOR_VERSION=0 --build-arg CONFLUENT_PATCH_VERSION=3 --build-arg COMMIT_ID=017a760 --build-arg BUILD_NUMBER=1 --build-arg ALLOW_UNSIGNED=false --build-arg CONFLUENT_PACKAGES_REPO=https://packages.confluent.io --build-arg CONFLUENT_MVN_LABEL= -t confluentinc/cp-base:latest -f debian/base/Dockerfile debian/base
Sending build context to Docker daemon  20.48kB
Step 1/33 : FROM arm64v8/debian
latest: Pulling from arm64v8/debian
5a5d73d4b732: Already exists
Digest: sha256:ce9968e25305b047efd18a239629c58edf0d791439a3e5d595612763f07acf90
Status: Downloaded newer image for arm64v8/debian:latest
 ---> 37fe96a532d3
Step 2/33 : ARG COMMIT_ID=unknown
 ---> Running in 77c782900493
Removing intermediate container 77c782900493
 ---> d7f12cf16ed9
...

Yah It works!

Dji Pocket 2 Note

#1 Lỗi corrupt file khi kết nối với iPhone

Mình dùng Dji pocket 2 với thẻ nhớ MicroSDXC SanDisk Extreme Pro V30 A2 128GB. Khi kết nối với iPhone bằng app Dji Mimo để xem file, không tắt app mà rút Pocket ra sẽ bị corrupt file đang xem / transfer. Mình thử dùng đầu đọc thẻ để copy qua cũng không được. Hiện tại chưa biết là do trình đọc của Pocket bị lỗi hay do thẻ.

Các giải quyết hiện tại để cứu file là dùng tính năng Trimmed Download để kiếm đoạn video không bị corrupt để down về.

Lưu ý: tuyệt đối phải tắt Dji Mimo trước khi rút Pocket ra khỏi iPhone

history-incremental-pattern-search-backward

When we need to search history in bash but multi command same pattern, you must type difference longest chain of result you want.

Example, my history bellow:

$ history
ssh srv-local-1
ssh srv-local-2
ssh srv-local-6
ping google.com
telnet srv-local-1
ssh srv-partner-1
ping srv-partner-6
ssh srv-partner-6

So, when I want retrieve command ssh srv-partner-6 I use control (^) + r (in macos) maybe I type (as short as possible): ping (because latest command used match pattern).

But when retrieve command ssh srv-local-1 you maybe type ssh with enter control + r multi time.

But when modify bind key control + r to history-incremental-pattern-search-backward you only need type intermittently different word by use regex.

echo "bindkey '^R' history-incremental-pattern-search-backward" >> ~/.zshrc
source ~/.zshrc

Now we can search ssh srv-local-1 by type:

~ ssh srv-local-1
bck-i-search: ssh*l*1_

Error 503 Cyberpanel

Khi truy cập website được host trên server Cyberpanel bị lỗi 503 cần kiểm tra file error.log của lightspeed

$ tail -n 1000 /usr/local/lsws/logs/error.log | grep ERROR
2021-06-27 05:15:14.061377 [ERROR] [2334451] [tiendie.655340]: Failed to listen socket [/tmp/lshttpd/tiendie.sock]: No space left on device
2021-06-27 05:15:15.064434 [ERROR] [2334451] [tiendie.655340]: Failed to listen socket [/tmp/lshttpd/tiendie.sock]: No space left on device
2021-06-27 05:15:16.067511 [ERROR] [2334451] [tiendie.655340]: Failed to listen socket [/tmp/lshttpd/tiendie.sock]: No space left on device
2021-06-27 05:15:17.070538 [ERROR] [2334451] [tiendie.655340]: Failed to listen socket [/tmp/lshttpd/tiendie.sock]: No space left on device
2021-06-27 05:15:18.074045 [ERROR] [2334451] [tiendie.655340]: Failed to listen socket [/tmp/lshttpd/tiendie.sock]: No space left on device
2021-06-27 05:15:19.078233 [ERROR] [2334451] [tiendie.655340]: Failed to listen socket [/tmp/lshttpd/tiendie.sock]: No space left on device
2021-06-27 05:15:20.081792 [ERROR] [2334451] [tiendie.655340]: Failed to listen socket [/tmp/lshttpd/tiendie.sock]: No space left on device
2021-06-27 05:15:21.085203 [ERROR] [2334451] [tiendie.655340]: Failed to listen socket [/tmp/lshttpd/tiendie.sock]: No space left on device
2021-06-27 05:15:22.089223 [ERROR] [2334451] [tiendie.655340]: Failed to listen socket [/tmp/lshttpd/tiendie.sock]: No space left on device

Nếu xuất hiện lỗi Failed to listen socket [/tmp/lshttpd/ cần kiểm tra thêm partition tmp xem có bị full hay không

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            474M     0  474M   0% /dev
tmpfs            99M  988K   98M   1% /run
/dev/vda1        25G   18G  6.5G  74% /
tmpfs           491M  1.0M  490M   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           491M     0  491M   0% /sys/fs/cgroup
/dev/vda15      105M  9.2M   96M   9% /boot/efi
/dev/loop6      1.5G  1.5G     0 100% /tmp
/dev/loop8       33M   33M     0 100% /snap/snapd/11588
/dev/loop7       56M   56M     0 100% /snap/core18/1997
/dev/loop1       70M   70M     0 100% /snap/lxd/20309
tmpfs            99M     0   99M   0% /run/user/0
/dev/loop3       56M   56M     0 100% /snap/core18/2066
/dev/loop2       33M   33M     0 100% /snap/snapd/12159
/dev/loop4       62M   62M     0 100% /snap/core20/1026
/dev/loop5       67M   67M     0 100% /snap/lxd/20789

Nguyên nhân là do session của php không được clear trong 1 thời gian dài dẫn đến full /tmp

Các bước khắc phục:

  • Stop lightspeed systemctl stop lshttpd
  • xóa các file file session trong /tmp/lshttpd/ bằng cách
$ cd /tmp && find . -name '*' | xargs rm -rf
# tắt phpsessionclean
$ systemctl stop phpsessionclean.service
$ systemctl disable phpsessionclean.service
$ systemctl stop phpsessionclean.timer
$ systemctl disable phpsessionclean.timer
# thêm cron bên dưới
$ crontab -e
*/30 * * * * find -O3 "/tmp" -ignore_readdir_race -depth -mindepth 1 -name 'sess_*' -type f -cmin +180 -delete

Cuối cùng, start lại lightspeed

systemctl start lshttpd

Pg_dump on MacOS without Postgresql

You could also use homebrew to install libpq.

brew install libpq

On Mac M1

arch -arm64 brew install libpq

This would give you psql, pg_dump and a whole bunch of other client utilities without installing Postgres.

Unfortunately since it provides some of the same utilities as are included in the full postgresql package, brew installs it “keg-only” which means it isn’t in the PATH by default. Homebrew will spit out some information on how to add it to your PATH after installation. In my case it was this:

echo 'export PATH="/opt/homebrew/Cellar/libpq/13.3/bin:$PATH"' >> ~/.zshrc

Alternatively, you can create symlinks for the utilities you need. E.g.:

ln -s /opt/homebrew/Cellar/libpq/13.3/bin/psql /usr/local/bin/psql

Note: used installed version instead of 13.3.

Alternatively, you could instruct homebrew to “link all of its binaries to the PATH anyway”

brew link --force libpq

but then you’d be unable to install the postgresql package later.

Found solutions at https://stackoverflow.com/a/49689589

Đem website vào Kindle dễ dàng bằng Epub Press

Mình phát hiện ra có extension có thể đưa nhiều nội dung website thành ebook và gửi thẳng vào Kindle (chỉ những dòng máy có hỗ trợ nhận ebook bằng email) đó là Epub.press

Epub Press có trên cả Chrome & Firefox. Sau khi tiến hành cài đặt mình thao tác như sau:

– Sau đó vào Epub Press cấu hình format file là .mobi và Delivery Email tương ứng với device trong Amazon

Tiếp theo mở những website mà bạn muốn đọc trên Kindle thành nhiều tabs, sau đó mở Epub Press chọn và Download. Chờ trong vài giây thì hoàn thành.

Bạn mở Kindle đã connect wifi, và kết quả: