2021年2月26日金曜日

Eclipse Che のユーザー情報を引き継いだまま別ネームスペースへデプロイしたい

元 che の keycloak エクスポート → 新 che デプロイ → 新 che で keycloak インポート。という感じでできるようだ。

前提

  • OS: Windows 10 Pro
  • ランタイム: Docker Desktop の Kubernetes

環境準備

ソースの取得

mkdir che_tmp
cd che_tmp

$WORK_DIR=$(pwd)

git clone --depth 1 https://github.com/eclipse/che.git

cd che
$CHE_SOURCE=$(pwd)

helm のバージョンアップ

Chocolatey で管理しているので、アップグレードする。

choco upgrade kubernetes-helm

デプロイ環境準備

ingress デプロイ

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud/deploy.yaml

pod の確認。

PS C:\Users\mikoto\project\tmp\che_tmp\che>  kubectl get pods --all-namespaces
NAMESPACE       NAME                                        READY   STATUS      RESTARTS   AGE
ingress-nginx   ingress-nginx-admission-create-fnssb        0/1     Completed   0          81s
ingress-nginx   ingress-nginx-admission-patch-nxmpv         0/1     Completed   0          81s
ingress-nginx   ingress-nginx-controller-7fc74cf778-txd7v   1/1     Running     0          81s
kube-system     coredns-f9fd979d6-bsn9l                     1/1     Running     8          36d
kube-system     coredns-f9fd979d6-dxd4n                     1/1     Running     8          36d
kube-system     etcd-docker-desktop                         1/1     Running     15         36d
kube-system     kube-apiserver-docker-desktop               1/1     Running     16         36d
kube-system     kube-controller-manager-docker-desktop      1/1     Running     8          36d
kube-system     kube-proxy-td79h                            1/1     Running     8          36d
kube-system     kube-scheduler-docker-desktop               1/1     Running     20         36d
kube-system     storage-provisioner                         1/1     Running     34         36d
kube-system     vpnkit-controller                           1/1     Running     8          36d

IP アドレスをメモ

TYPE が LoadBalancer の CLUSTER-IP をメモする。この場合は 10.111.81.251。 以降は $DOMAIN_IP にメモした IP を設定したこととして進める。

PS C:\Users\mikoto\project\tmp\che_tmp\che> kubectl get services --namespace ingress-nginx
NAME                                 TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller             LoadBalancer   10.111.81.251   localhost     80:31411/TCP,443:32118/TCP   20m
ingress-nginx-controller-admission   ClusterIP      10.99.113.1     <none>        443/TCP                      20m
$DOMAIN_IP="10.111.81.251"
$DOMAIN="$(echo ${DOMAIN_IP} | sed -e "s/\./-/g").nip.io"

ループバックアドレスの設定

start-process -verb runas powershell -ArgumentList netsh,interface,ipv4,add,address,Loopback,$DOMAIN_IP

追加されたことを確認。

netsh interface ipv4 show address Loopback

che を namespace che でデプロイ

kubectl create namespace che
cd $CHE_SOURCE\deploy\kubernetes\helm\che
helm dependency update
helm upgrade --install che --namespace che --set global.cheWorkspacesNamespace="che" --set global.ingressDomain=${DOMAIN}.nip.io  --set global.multiuser=true ./

アプリの確認。

PS C:\Users\mikoto\project\tmp\che_tmp\che\deploy\kubernetes\helm\che> helm list -n che
NAME    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
che     che             1               2021-02-26 06:40:16.5220543 +0900 JST   deployed        che-0.1.0

pod の確認。

PS C:\Users\mikoto\project\tmp\che_tmp\che\deploy\kubernetes\helm\che> kubectl get pods -n che
NAME                                READY   STATUS    RESTARTS   AGE
che-6b7475579d-k4pj2                1/1     Running   0          3m17s
che-dashboard-649cb64655-jwtsc      1/1     Running   0          6m48s
devfile-registry-7f5f8fdf4d-fpmtw   1/1     Running   0          6m48s
keycloak-5b4ff5bd5d-zndb8           1/1     Running   0          3m20s
plugin-registry-558796b4bd-xt96b    1/1     Running   0          6m48s
postgres-55d7974489-zwkht           1/1     Running   0          3m20s

keycloak にアクセス

keycloak にアクセスして管理者設定・ユーザー追加を行う。

start http://keycloak-che.${DOMAIN}.nip.io

che にアクセス

start http://che-che.${DOMAIN}.nip.io

ログインできることを確認する。

ユーザー情報エクスポート

Kuberenetes の Keycloak コンテナへログインする。

PS C:\Users\mikoto\project\tmp\che_tmp\che\deploy\kubernetes\helm\che> kubectl get pods -n che
NAME                                READY   STATUS    RESTARTS   AGE
che-696449ffff-rlmt9                1/1     Running   0          38m
che-dashboard-649cb64655-jwtsc      1/1     Running   0          61m
devfile-registry-7f5f8fdf4d-fpmtw   1/1     Running   0          61m
keycloak-cccb6d4b8-6jz8f            1/1     Running   0          41s
plugin-registry-558796b4bd-xt96b    1/1     Running   0          61m
postgres-55d7974489-zwkht           1/1     Running   0          57m
PS C:\Users\mikoto\project\tmp\che_tmp\che\deploy\kubernetes\helm\che> kubectl exec -it -n che -it keycloak-cccb6d4b8-6jz8f -- /bin/bash

ユーザー情報エクスポート。

/opt/jboss/keycloak/bin/standalone.sh -Dkeycloak.migration.action=export -Dkeycloak.migration.provider=dir -Dkeycloak.migration.dir=/opt/jboss/keycloak-export -Dkeycloak.migration.usersExportStrategy=DIFFERENT_FILES -Dkeycloak.migration.usersPerFile=100 -Djboss.http.port=8888 -Djboss.https.port=9999 -Djboss.management.http.port=7777 -Djboss.management.https.port=7776

以下のような表示が出たら完了。

22:35:14,133 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: Keycloak 6.0.1 (WildFly Core 8.0.0.Final) started in 11106ms - Started 617 of 880 services (563 services are lazy, passive or on-demand)

Ctrl+C で終了する。

エクスポートした情報をローカル PC へコピー

kubectl cp -n che keycloak-cccb6d4b8-6jz8f:keycloak-export ./keycloak-export

別 namespace にデプロイし、ユーザー情報をインポートする

ネームスペースを変更してデプロイする。

kubectl create namespace newnamespace
helm dependency update
helm upgrade --install che --namespace newnamespace --set global.cheWorkspacesNamespace="newnamespace" --set global.ingressDomain=${DOMAIN}.nip.io  --set global.multiuser=true ./

pod の確認。

PS C:\Users\mikoto\project\tmp\che_tmp\che\deploy\kubernetes\helm\che> kubectl get pods -n newnamespace
NAME                                READY   STATUS    RESTARTS   AGE
che-7b97c6cb46-f6zq7                1/1     Running   0          106s
che-dashboard-649cb64655-pc2sz      1/1     Running   0          106s
devfile-registry-7f5f8fdf4d-9qb4j   1/1     Running   0          106s
keycloak-74d657c877-dgnnc           1/1     Running   0          106s
plugin-registry-558796b4bd-z85zq    1/1     Running   0          106s
postgres-55d7974489-dw94p           1/1     Running   0          106s

ユーザー情報インポート

エクスポートした情報を Kuberenetes の Keycloak コンテナへコピーし、ログインする。

PS C:\Users\mikoto\project\tmp\che_tmp\che\deploy\kubernetes\helm\che> kubectl get pods -n newnamespace
NAME                                READY   STATUS    RESTARTS   AGE
che-7cb46784f7-hmz6v                1/1     Running   0          40m
che-dashboard-649cb64655-rvdpz      1/1     Running   0          40m
devfile-registry-7f5f8fdf4d-rpx8j   1/1     Running   0          40m
keycloak-74d657c877-b66gt           1/1     Running   0          40m
plugin-registry-558796b4bd-6k9nw    1/1     Running   0          40m
postgres-55d7974489-r268l           1/1     Running   0          40m
PS C:\Users\mikoto\project\tmp\che_tmp\che\deploy\kubernetes\helm\che> kubectl cp -n newnamespace ./keycloak-export keycloak-74d657c877-b66gt:./
PS C:\Users\mikoto\project\tmp\che_tmp\che\deploy\kubernetes\helm\che> kubectl exec -it -n newnamespace -it keycloak-74d657c877-b66gt -- /bin/bash

ユーザー情報インポート。

/opt/jboss/keycloak/bin/standalone.sh -Dkeycloak.migration.action=import -Dkeycloak.migration.provider=dir -Dkeycloak.migration.dir=/opt/jboss/keycloak-export -Dkeycloak.migration.usersExportStrategy=DIFFERENT_FILES -Dkeycloak.migration.usersPerFile=100 -Djboss.http.port=8888 -Djboss.https.port=9999 -Djboss.management.http.port=7777 -Djboss.management.https.port=7776 -Dkeycloak.migration.realmName=che

以下のような表示が出たら完了。

22:54:15,594 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: Keycloak 6.0.1 (WildFly Core 8.0.0.Final) started in 13818ms - Started 617 of 880 services (563 services are lazy, passive or on-demand)

Ctrl+C で終了する。

keycloak にアクセス

keycloak にアクセスして管理者設定を行う。

start http://keycloak-newnamespace.${DOMAIN}.nip.io

この時点で、 che の namespace で作成したユーザーが登録されているはず。

che にアクセス

start http://che-newnamespace.${DOMAIN}.nip.io

ログインできることを確認する。

参考資料

2021年2月3日水曜日

Vim をソースからビルドして、 Yocto のレイヤーとして追加する

前回からの続き。

前回作成したイメージに、ソースからビルドした Vim を追加する。

レシピ作成

devtool add myvim https://github.com/vim/vim.git

レシピ編集

レシピ作成で生成される myvim_git.bb を編集する。

vim workspace/recipes/myvim/myvim_git.bb

myvim_git.bb

do_configure, do_compile, do_install 内に、それぞれのフェーズで実行するコマンドを列挙する。

詳細は以下ファイルを参照。

myvim_git.bb

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
#
# The following license files were not able to be identified and are
# represented as "Unknown" below, you will need to check them yourself:
#   LICENSE
#   src/xdiff/COPYING
#   src/xpm/COPYRIGHT
#
# NOTE: multiple licenses have been detected; they have been separated with &
# in the LICENSE value for now since it is a reasonable assumption that all
# of the licenses apply. If instead there is a choice between the multiple
# licenses then you should change the value to separate the licenses with |
# instead of &. If there is any doubt, check the accompanying documentation
# to determine which situation is applicable.
LICENSE = "Unknown & MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=6b30ea4fa660c483b619924bc709ef99 \
                    file://src/libvterm/LICENSE;md5=be5681ffe0dc58ccc9756bc6260fe0cd \
                    file://src/xdiff/COPYING;md5=278f2557e3b277b94e9a8430f6a6d0a9 \
                    file://src/xpm/COPYRIGHT;md5=1e8b098093f3bb7a8fed64938e8e465e"

SRC_URI = "git://github.com/vim/vim.git;protocol=https"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "0346b799fc228a3b48967ca0747e6b23586dbaa6"

S = "${WORKDIR}/git"

# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
# recipe automatically - you will need to examine the Makefile yourself and ensure
# that the appropriate arguments are passed in.

do_configure () {
    # specify any needed configure commands here
    :
    export vim_cv_toupper_broken="no"
    export vim_cv_terminfo="yes"
    export vim_cv_tgetent="zero"
    export vim_cv_getcwd_broken="no"
    export vim_cv_stat_ignores_slash="yes"
    export vim_cv_memmove_handles_overlap="yes"
    ./configure --build=x86_64-linux --host=-arm-poly-linux-gnueabi --with-features=huge --enable-fail-if-missing --with-tlib=ncurses --prefix=${D}/${prefix}
}

do_compile () {
    # You will almost certainly need to add additional arguments here
    :
    make
}

do_install () {
    # NOTE: unable to determine what to put here - there is a Makefile but no
    # target named "install", so you will need to define this yourself
    :
    make install
}

レシピのビルド

devtool build myvim

エラーが出た。

checking for linking with ncurses library... configure: error: FAILED
WARNING: exit code 1 from a shell command.

パッケージ ncurses が足りないようだ。 DEPENDS += " ncurses" を追加。

myvim_git.bb

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
#
# The following license files were not able to be identified and are
# represented as "Unknown" below, you will need to check them yourself:
#   LICENSE
#   src/xdiff/COPYING
#   src/xpm/COPYRIGHT
#
# NOTE: multiple licenses have been detected; they have been separated with &
# in the LICENSE value for now since it is a reasonable assumption that all
# of the licenses apply. If instead there is a choice between the multiple
# licenses then you should change the value to separate the licenses with |
# instead of &. If there is any doubt, check the accompanying documentation
# to determine which situation is applicable.
LICENSE = "Unknown & MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=6b30ea4fa660c483b619924bc709ef99 \
                    file://src/libvterm/LICENSE;md5=be5681ffe0dc58ccc9756bc6260fe0cd \
                    file://src/xdiff/COPYING;md5=278f2557e3b277b94e9a8430f6a6d0a9 \
                    file://src/xpm/COPYRIGHT;md5=1e8b098093f3bb7a8fed64938e8e465e"

SRC_URI = "git://github.com/vim/vim.git;protocol=https"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "0346b799fc228a3b48967ca0747e6b23586dbaa6"

S = "${WORKDIR}/git"

DEPENDS += " ncurses"

# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
# recipe automatically - you will need to examine the Makefile yourself and ensure
# that the appropriate arguments are passed in.

do_configure () {
    # specify any needed configure commands here
    :
    export vim_cv_toupper_broken="no"
    export vim_cv_terminfo="yes"
    export vim_cv_tgetent="zero"
    export vim_cv_getcwd_broken="no"
    export vim_cv_stat_ignores_slash="yes"
    export vim_cv_memmove_handles_overlap="yes"
    ./configure --build=x86_64-linux --host=-arm-poly-linux-gnueabi --with-features=huge --enable-fail-if-missing --with-tlib=ncurses --prefix=${D}/${prefix}
}

do_compile () {
    # You will almost certainly need to add additional arguments here
    :
    make
}

do_install () {
    # NOTE: unable to determine what to put here - there is a Makefile but no
    # target named "install", so you will need to define this yourself
    :
    make install
}

また、エラーが出た。

ERROR: myvim-1.0+git999-r0 do_package: QA Issue: File '/usr/bin/vim' from myvim was already stripped, this will prevent future debugging! [already-stripped]
ERROR: myvim-1.0+git999-r0 do_package: QA Issue: File '/usr/bin/xxd' from myvim was already stripped, this will prevent future debugging! [already-stripped]
ERROR: myvim-1.0+git999-r0 do_package: QA Issue: myvim: Files/directories were installed but not shipped in any package:

以下 2 点に対応する。

  1. コンパイルで strip 済みバイナリを生成すると、 myvim was already stripped というエラーになるようだ
    • INSANE_SKIP_${PN} += "already-stripped" を追加
  2. FILES_${PN} 書き忘れ

myvim_git.bb

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
#
# The following license files were not able to be identified and are
# represented as "Unknown" below, you will need to check them yourself:
#   LICENSE
#   src/xdiff/COPYING
#   src/xpm/COPYRIGHT
#
# NOTE: multiple licenses have been detected; they have been separated with &
# in the LICENSE value for now since it is a reasonable assumption that all
# of the licenses apply. If instead there is a choice between the multiple
# licenses then you should change the value to separate the licenses with |
# instead of &. If there is any doubt, check the accompanying documentation
# to determine which situation is applicable.
LICENSE = "Unknown & MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=6b30ea4fa660c483b619924bc709ef99 \
                    file://src/libvterm/LICENSE;md5=be5681ffe0dc58ccc9756bc6260fe0cd \
                    file://src/xdiff/COPYING;md5=278f2557e3b277b94e9a8430f6a6d0a9 \
                    file://src/xpm/COPYRIGHT;md5=1e8b098093f3bb7a8fed64938e8e465e"

SRC_URI = "git://github.com/vim/vim.git;protocol=https"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "0346b799fc228a3b48967ca0747e6b23586dbaa6"

S = "${WORKDIR}/git"

FILES_${PN} = " \
        ${bindir} \
        ${prefix}/share \
"

DEPENDS += " ncurses"

INSANE_SKIP_${PN} += "already-stripped"

# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
# recipe automatically - you will need to examine the Makefile yourself and ensure
# that the appropriate arguments are passed in.

do_configure () {
    # specify any needed configure commands here
    :
    export vim_cv_toupper_broken="no"
    export vim_cv_terminfo="yes"
    export vim_cv_tgetent="zero"
    export vim_cv_getcwd_broken="no"
    export vim_cv_stat_ignores_slash="yes"
    export vim_cv_memmove_handles_overlap="yes"
    ./configure --build=x86_64-linux --host=-arm-poly-linux-gnueabi --with-features=huge --enable-fail-if-missing --with-tlib=ncurses --prefix=${D}/${prefix}
}

do_compile () {
    # You will almost certainly need to add additional arguments here
    :
    make
}

do_install () {
    # NOTE: unable to determine what to put here - there is a Makefile but no
    # target named "install", so you will need to define this yourself
    :
    make install
}

レイヤーを作成し、レシピをレイヤーに追加

bitbake-layers create-layer "$BUILDDIR/meta-myvim"
bitbake-layers add-layer "$BUILDDIR/meta-myvim"
devtool finish myvim meta-myvim

echo 'CORE_IMAGE_EXTRA_INSTALL += "myvim"' >> conf/local.conf

レイヤーを追加したイメージをビルド

bitbake core-image-minimal

またまた、エラー。

ERROR: myvim-1.0+gitAUTOINC+e7bebc495d-r0 do_package_qa: QA Issue: /usr/share/vim/vim82/tools/demoserver.py contained in package myvim requires /usr/bin/python, but no providers found in RDEPENDS_myvim? [file-rdeps]
ERROR: myvim-1.0+gitAUTOINC+e7bebc495d-r0 do_package_qa: QA Issue: /usr/share/vim/vim82/tools/efm_perl.pl contained in package myvim requires /work/poky/build/tmp/hosttools/perl, but no providers found in RDEPENDS_myvim? [file-rdeps]
ERROR: myvim-1.0+gitAUTOINC+e7bebc495d-r0 do_package_qa: QA Issue: /usr/share/vim/vim82/tools/mve.awk contained in package myvim requires /work/poky/build/tmp/hosttools/gawk, but no providers found in RDEPENDS_myvim? [file-rdeps]
ERROR: myvim-1.0+gitAUTOINC+e7bebc495d-r0 do_package_qa: QA Issue: /usr/share/vim/vim82/tools/vim132 contained in package myvim requires /bin/csh, but no providers found in RDEPENDS_myvim? [file-rdeps]

python, perl, gawk, csh が必要。

  1. python, perl, gawk のパッケージ依存を追加
    • RDEPENDS_${PN} += " python3 perl gawk" を追加
  2. エラー対象のスクリプトの、 shebang を修正
    1. patch を作る
    2. SRC_URI に patch のパスを指定

devtool finish を実行した後は、 myvim_git.bbmeta-myvim/recipes-myvim/myvim/myvim_git.bb に移動しているのでそれを修正。

RDEPENDS_${PN} の追加

myvim_git.bb

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
#
# The following license files were not able to be identified and are
# represented as "Unknown" below, you will need to check them yourself:
#   LICENSE
#   src/xdiff/COPYING
#   src/xpm/COPYRIGHT
#
# NOTE: multiple licenses have been detected; they have been separated with &
# in the LICENSE value for now since it is a reasonable assumption that all
# of the licenses apply. If instead there is a choice between the multiple
# licenses then you should change the value to separate the licenses with |
# instead of &. If there is any doubt, check the accompanying documentation
# to determine which situation is applicable.
LICENSE = "Unknown & MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=6b30ea4fa660c483b619924bc709ef99 \
                    file://src/libvterm/LICENSE;md5=be5681ffe0dc58ccc9756bc6260fe0cd \
                    file://src/xdiff/COPYING;md5=278f2557e3b277b94e9a8430f6a6d0a9 \
                    file://src/xpm/COPYRIGHT;md5=1e8b098093f3bb7a8fed64938e8e465e"

SRC_URI = "git://github.com/vim/vim.git;protocol=https"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "0346b799fc228a3b48967ca0747e6b23586dbaa6"

S = "${WORKDIR}/git"

FILES_${PN} = " \
        ${bindir} \
        ${prefix}/share \
"

RDEPENDS_${PN} += " python3 perl gawk"
DEPENDS += " ncurses"

INSANE_SKIP_${PN} += "already-stripped"

# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
# recipe automatically - you will need to examine the Makefile yourself and ensure
# that the appropriate arguments are passed in.

do_configure () {
    # specify any needed configure commands here
    :
    export vim_cv_toupper_broken="no"
    export vim_cv_terminfo="yes"
    export vim_cv_tgetent="zero"
    export vim_cv_getcwd_broken="no"
    export vim_cv_stat_ignores_slash="yes"
    export vim_cv_memmove_handles_overlap="yes"
    ./configure --build=x86_64-linux --host=-arm-poly-linux-gnueabi --with-features=huge --enable-fail-if-missing --with-tlib=ncurses --prefix=${D}/${prefix}
}

do_compile () {
    # You will almost certainly need to add additional arguments here
    :
    make
}

do_install () {
    # NOTE: unable to determine what to put here - there is a Makefile but no
    # target named "install", so you will need to define this yourself
    :
    make install
}

Shebang の修正とパッチ作成

Shebang 修正

エラーに表示された以下ファイルの Shebang を修正する。

  • /usr/share/vim/vim82/tools/demoserver.py
    • #!/usr/bin/python -> #!/usr/bin/env python
  • /usr/share/vim/vim82/tools/efm_perl.pl
    • #!/usr/bin/perl -w -> #!/usr/bin/env perl -w
  • /usr/share/vim/vim82/tools/mve.awk
    • #!/usr/bin/nawk -f -> #!/usr/bin/env nawk -f
  • /usr/share/vim/vim82/tools/vim132
    • #!/bin/csh -f -> #!/bin/sh

パッチ作成

cd workspace/sources/myvim
git diff > ../../../meta-myvim/recipes-myvim/shebang.patch
cd ../../..

SRC_URI にパッチのパスを設定

今回の場合、 SRC_URI += " file:///work/poky/build/meta-myvim/recipes-myvim/shebang.patch;patch=1" を追加。

myvim_git.bb

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
#
# The following license files were not able to be identified and are
# represented as "Unknown" below, you will need to check them yourself:
#   LICENSE
#   src/xdiff/COPYING
#   src/xpm/COPYRIGHT
#
# NOTE: multiple licenses have been detected; they have been separated with &
# in the LICENSE value for now since it is a reasonable assumption that all
# of the licenses apply. If instead there is a choice between the multiple
# licenses then you should change the value to separate the licenses with |
# instead of &. If there is any doubt, check the accompanying documentation
# to determine which situation is applicable.
LICENSE = "Unknown & MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=6b30ea4fa660c483b619924bc709ef99 \
                    file://src/libvterm/LICENSE;md5=be5681ffe0dc58ccc9756bc6260fe0cd \
                    file://src/xdiff/COPYING;md5=278f2557e3b277b94e9a8430f6a6d0a9 \
                    file://src/xpm/COPYRIGHT;md5=1e8b098093f3bb7a8fed64938e8e465e"

SRC_URI = "git://github.com/vim/vim.git;protocol=https"
SRC_URI += " file:///work/poky/build/meta-myvim/recipes-myvim/shebang.patch;patch=1"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "0346b799fc228a3b48967ca0747e6b23586dbaa6"

S = "${WORKDIR}/git"

# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
# recipe automatically - you will need to examine the Makefile yourself and ensure
# that the appropriate arguments are passed in.

do_configure () {
    # specify any needed configure commands here
    :
    export vim_cv_toupper_broken="no"
    export vim_cv_terminfo="yes"
    export vim_cv_tgetent="zero"
    export vim_cv_getcwd_broken="no"
    export vim_cv_stat_ignores_slash="yes"
    export vim_cv_memmove_handles_overlap="yes"
    ./configure --build=x86_64-linux --host=-arm-poly-linux-gnueabi --with-features=huge --enable-fail-if-missing --with-tlib=ncurses --prefix=${D}/${prefix}
}

do_compile () {
    # You will almost certainly need to add additional arguments here
    :
    make
}

do_install () {
    # NOTE: unable to determine what to put here - there is a Makefile but no
    # target named "install", so you will need to define this yourself
    :
    make install
}

再度ビルドに挑戦。

bitbake core-image-minimal

WARNING が大量に出つつも成功。

ビルド成果物を qemu-system-arm で実行

root でログインして vim コマンドで clone してきた vim が起動することを確認。

qemu-system-arm -M virt -m 1024 \
  -kernel tmp/deploy/images/qemuarm/zImage \
  -drive if=none,file=tmp/deploy/images/qemuarm/core-image-minimal-qemuarm.ext4,format=raw,id=hd \
  -device virtio-blk-device,drive=hd \
  -netdev user,id=usernet \
  -device virtio-net-device,netdev=usernet \
  -append "root=/dev/vda" \
  -nographic -no-reboot

以上。

参考資料

Yocto にレシピとレイヤーを追加する

前回からの続き。

前回作成したイメージに、 “Hello, World!” をコンソールへ表示するシェルスクリプトを追加する。

追加するソースコードは mikoto2000/helloworld.sh

ファイル編集に必要なパッケージをインストール

レシピ等の定義ファイルを編集するのに vim を使うのでインストール。

apt-get install -y vim

レシピ作成

devtool add helloworld https://github.com/mikoto2000/helloworld.sh

レシピ編集

レシピ作成で生成される helloworld_git.bb を編集する。

vim workspace/recipes/helloworld/helloworld_git.bb

helloworld_git.bb

do_configure, do_compile, do_install 内に、それぞれのフェーズで実行するコマンドを列挙する。

今回は、シェルスクリプトを /usr/bin へコピーするだけ。

また、コピー対象ファイルを FILES_${PN} 変数へ列挙する。 FILES_${PN}${D} に展開されたファイルを確認し、不整合があった場合にエラーとなる。

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=2e01c4af99b331098518b1d669b8a696"

SRC_URI = "git://github.com/mikoto2000/helloworld.sh;protocol=https"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "a078be941b9f55654a1269f6de368fa11e5a7a25"

S = "${WORKDIR}/git"

FILES_${PN} = "${bindir}"

# NOTE: no Makefile found, unable to determine what needs to be done

do_configure () {
    # Specify any needed configure commands here
    :
}

do_compile () {
    # Specify compilation commands here
    :
}

do_install () {
    # Specify install commands here
    :
    install -D -m 755 ./helloworld.sh ${D}/${bindir}/helloworld.sh
}

レシピのビルド

devtool build helloworld

レイヤーを作成し、レシピをレイヤーに追加

bitbake-layers create-layer "$BUILDDIR/meta-helloworld"
bitbake-layers add-layer "$BUILDDIR/meta-helloworld"
devtool finish helloworld meta-helloworld

echo 'CORE_IMAGE_EXTRA_INSTALL += "helloworld"' >> conf/local.conf

レイヤーを追加したイメージをビルド

bitbake core-image-minimal

ビルド成果物を qemu-system-arm で実行

root でログインして helloworld.sh コマンドが実行できることを確認。

qemu-system-arm -M virt -m 1024 \
  -kernel tmp/deploy/images/qemuarm/zImage \
  -drive if=none,file=tmp/deploy/images/qemuarm/core-image-minimal-qemuarm.ext4,format=raw,id=hd \
  -device virtio-blk-device,drive=hd \
  -netdev user,id=usernet \
  -device virtio-net-device,netdev=usernet \
  -append "root=/dev/vda" \
  -nographic -no-reboot

レシピの再修正

以下のような流れになるはず。

devtool modify -n helloworld /work/poky/build/workspace/sources/helloworld

# ファイル修正
...(snip)

# ビルド
devtool build helloworld

# レシピ修正完了
devtool finish helloworld meta-helloworld

以上。

参考資料

qemu-system-arm で動く Linux を Yocto でビルドする

Yocto Project Quick Build — The Yocto Project ® 3.2.1 documentationqemuarm で試す。

前提

  • OS: Windows 10 Pro
  • Docker: Docker version 20.10.2, build 2291f61
  • 使用する Docker イメージ: debian:buster-slim

作業用コンテナ起動

docker run -it --name myyocto --workdir="/work" debian:buster-slim

必要パッケージのインストール

WORK_DIR=$(pwd)
apt-get update

# Quick Build に記載されているパッケージをインストール
apt-get install -y gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat cpio python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev pylint3 xterm python3-subunit mesa-common-dev

# Quick Build には記載されていないが、これが無いとビルド時にエラーが発生した
apt-get install -y python2

# qemu インストール
apt-get install -y qemu-system-arm

yocto の clone とビルド

# yocto を clone
git clone git://git.yoctoproject.org/poky.git
cd poky
git checkout tags/yocto-3.2.1 -b my-yocto-3.2.1

# yocto 環境設定読み込み
source oe-init-build-env

# arm 用のバイナリをビルドするための設定
sed -i -e 's/MACHINE ??= "qemux86-64"/MACHINE ??= "qemuarm"/' conf/local.conf

# root でビルドできるように設定
touch conf/sanity.conf

# 詳細不明だが、エラーが発生した
# エラーになっても 2, 3 回同じコマンドを繰り返すと成功することがある。
# 一発で成功することもある。謎。
bitbake core-image-minimal

ビルド成果物を qemu-system-arm で実行

runqemu を実行すると、「tun モジュールが無い」と怒られたので、 qemu-system-arm コマンドで実行する。

qemu-system-arm -M virt -m 1024 \
  -kernel tmp/deploy/images/qemuarm/zImage \
  -drive if=none,file=tmp/deploy/images/qemuarm/core-image-minimal-qemuarm.ext4,format=raw,id=hd \
  -device virtio-blk-device,drive=hd \
  -netdev user,id=usernet \
  -device virtio-net-device,netdev=usernet \
  -append "root=/dev/vda" \
  -nographic -no-reboot

以上。

参考資料