kb84tkhrのブログ

何を書こうか考え中です あ、あと組織とは関係ないってやつです 個人的なやつ

PPP3: Ubuntuデスクトップの構築(横道・続き5)

日本語化からdesktopのインストールからVagrantfileに書いてあるのがよさげ

ほぼそのままもらって実行してみたら案の定?grubで止まってた
grubを除外するようにしたら別のとこでエラーになってた
なかなか道は遠い

あと、本気でやるとしたら冪等になるように書くべき?
かもしれないけど今はそこまではやらないでおこう

ある程度までやってBox化するのが幸せ?
いやそれだと新しいBoxを使おうと思ったらそれまでの環境捨てなきゃいけないか
やっぱり基本的にはサーバの環境を整えるものと思ったほうがよさそうな気がしてきた

今はひとつのタイミングだと思うのでBox化やってみる

まずは読む Boxes - Vagrant by HashiCorp

For other users, we recommend the Bento boxes.

bentoおすすめだってさ ubuntuより?

ところでBoxだからBentoだということに今まで気づいてなかった私をお許しください

It is often a point of confusion, but Canonical (the company that makes the Ubuntu operating system) publishes boxes under the “ubuntu” namespace on Vagrant Cloud. These boxes only support Virtualbox and do not provide an ideal experience for most users. If you encounter issues with these boxes, please try the Bento boxes instead.

書いてあった・・・

カノニカル(Ubuntuオペレーティングシステムを作っている会社)は“ubuntu”という名前でVagrant CloudにBoxを登録しています。これらのBoxはVirtualboxにしか対応しておらず、多くのユーザは理想的な体験を得ることができません。これらのBoxで問題が発生したなら、BentoのBoxを試してみてください。

うん、そうしたけどね
先に知りたかったな
やっぱ公式大事ともいう

Finally, you can update boxes with vagrant box update. This will download and install the new box. This will not magically update running Vagrant environments. If a Vagrant environment is already running, you will have to destroy and recreate it to acquire the new updates in the box.

vagrant box updateでBoxを更新することができます。これは、新しいBoxをダウンロードしてインストールしますが、動いているVagrant環境を魔法のように更新してくれるわけではありません。Vagrantの環境がすでに動作しているなら、新しいBoxを使うためには既存の環境を破棄して再度作り直す必要があります。

やっぱそうだよね

ってこの項目読み進めてみたけどBoxの作り方は出てこなかった
要するにvagrant packageすればいいっぽい

$ vagrant package --output devhost-base.box
==> default: Exporting VM...
==> default: Compressing package to: ..../devhost/devhost-base.box

Boxができたのでaddする

$ vagrant box add devhost-base devhost-base.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'devhost-base' (v0) for provider:
    box: Unpacking necessary files from: file://..../devhost/devhost-base.box
    box:
==> box: Successfully added box 'devhost-base' (v0) for 'virtualbox'!

できたか

$ vagrant box list
  :
devhost-base       (virtualbox, 0)
  :

できてる
~/.vagrant.d/boxes にもディレクトリができている

$ ls ~/.vagrant.d/boxes/
...  devhost-base  ...

Vagrantfileを作ってup

$ cd devhost2
$ cp ../devhost/Vagrantfile
$ sed 's|bento/ubuntu-18.04|devhost-base|' -i Vagrantfile
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'devhost-base'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: devhost2_default_1555210271721_15914
==> default: Clearing any previously set network interfaces...
  : 

動いた

せっかくだから公開もやってみる?
あ、パスワード変えちゃったからそのままじゃ公開できないな
戻すか
ほかにはまだ何も残してないはず・・・

あ、コマンド履歴とかもあるか
やっぱ公開はやめておこう

じゃ次のステップはvscodeのインストールかな
ちょうどvscodeがsnapってやつでインストールできるように
なったっていうニュースを見たからそれでやってみよう

MSとCanonical、「Visual Studio Code」を「Snap」として提供 - ZDNet Japan

ただ、日本語入力がうまくいかないという記事もある
Ubuntu 18.04にsnapを利用してVisual Studio Codeをインストールする - Qiita

※2018/9/19時点での情報です

snap経由でインストールしたVisual Studio Codeでは日本語入力ができないという問題があると、Twitter経由で連絡がありました。現時点でもこの問題が発生することを確認しています。

でもカノニカルとマイクロソフトが組んだっていうんだから
きっと直ってる
消すのも簡単にできると思うのでとにかくやってみる

ところでsnapって何
上の記事によると

CanonicalのSnapはクラウド、デスクトップ、IoTデバイスで動作するコンテナ化されたソフトウェアパッケージだ。プログラムのインストールを容易にするだけでなく、自動更新機能やロールバック機能、強化されたセキュリティを備え、開発者に高い柔軟性をもたらし、ユーザーによりシームレスな体験を提供する。

コンテナ化のコンテナは、dockerとかでいうコンテナのことだろうか
それはそれでありうるかもしれないけど単にひとつの入れものにまとめて
入れましたってだけかもしれない

Snap Documentation - Documentation for snaps: Universal Linux packages

Snaps are app packages for desktop, cloud and IoT that are easy to install, secure, cross-platform and dependency-free.

Snapは、デスクトップ・クラウドやIoTのためのアプリケーションパッケージです。簡単にインストールでき、セキュアで、クロスプラットフォームで、依存性から解放されます。

まあインストールするだけならこれくらいの理解でもいいのかな
Getting startedくらい見ておくか

まずはsnapがインストールされてるかどうか

vagrant@vagrant:~$ snap version
snap    2.37.4+18.04.1
snapd   2.37.4+18.04.1
series  16
ubuntu  18.04
kernel  4.15.0-29-generic

入ってる
snapを探す

vagrant@vagrant:~$ snap find "Visual Studio Code"
Name                  Version   Publisher  Notes    Summary
code                  51b0b281  vscode✓    classic  Code editing. Redefined.
code-insiders         b7c5e104  vscode✓    classic  Code editing. Redefined.
epipolar-consistency  0.1       thahamsta  -        Consistency Conditions for any two X-ray images.

なんかへんなのも入ってるけどまあいい
チェックマークは公式のしるし

snapについて調べる

vagrant@vagrant:~$ snap info code
name:      code
summary:   Code editing. Redefined.
publisher: Visual Studio Code (vscode✓)
contact:   https://twitter.com/code
license:   Proprietary
description: |
  Visual Studio Code is a lightweight but powerful source code editor which 
  :

いまどんなsnapが入っているかを調べる

vagrant@vagrant:~$ snap list
No snaps are installed yet. Try 'snap install hello-world'.

空っぽ
LibreOfficeとかはsnapで入ってるんじゃないんだ

hello-world入れてみろと言ってる
vscode入れる前にちょっとこれ入れてみよう

一瞬で終わると思ったらけっこう時間かかったし
つい(Windowsの)vscodeのターミナルからやってしまって
盛大にログが流れてしまった
一度消してやりなおそう

続きはUbuntuのほうでやる

vagrant@vagrant:~$ snap list
Name         Version  Rev   Tracking  Publisher   Notes
core         16-2.38  6673  stable    canonical✓  core
hello-world  6.3      27    stable    canonical✓  -

あ、“core”ってやつをダウンロードするのに時間がかかったんだなたぶん

で、どうやって消すんだ
アンインストールはGetting Startedには出てこなかった
snap remove

vagrant@vagrant:~$ snap remove --help
Usage:
  snap remove [remove-OPTIONS] <snap>...

The remove command removes the named snap instance from the system.

By default all the snap revisions are removed, including their data and the
common data directory. When a --revision option is passed only the specified
revision is removed.

[remove command options]
      --no-wait     Do not wait for the operation to finish but just print the
                    change id.
      --revision=   Remove only the given revision

完全に理解した
消す

vagrant@vagrant:~$ snap remove hello-world
hello-world removed
vagrant@vagrant:~$ snap list
Name  Version  Rev   Tracking  Publisher   Notes
core  16-2.38  6673  stable    canonical✓  core

消えた
coreは残ってる

ということは・・・

vagrant@vagrant:~$ snap install hello-world
hello-world 6.3 from Canonical✓ installed

hello-worldだけのインストールなら一瞬
ところでこれって何してくれるの
アプリケーションには含まれてない模様

こうかな

vagrant@vagrant:~$ hello-world
Hello World!

すげえ!(うそ
ところで“Hello World!”は正しくは(以下略

vagrant@vagrant:~$ which hello-world
/snap/bin/hello-world

ふーん
snapで入れたアプリは/snap/binから起動するらしいよ

vagrant@vagrant:~$ hello-world --help
Hello World!

別に何も出ない
イースターエッグとかないかな
とか言ってないで

snap、あとは以前のバージョンに戻すとか一時的にアプリを無効にするとか
あとChannelといってstableとかbetaとかいう状態を管理してたりとか
いろいろある
でも普通に使う分にはしらなくてもよさそう

じゃあvscodeを入れる

vagrant@vagrant:~$ sudo snap install code
error: This revision of snap "code" was published using classic confinement and
       thus may perform arbitrary system changes outside of the security
       sandbox that snaps are usually confined to, which may put your system at
       risk.

       If you understand and want to proceed repeat the command including
       --classic.

そうだった--classicつけなきゃいけないんだった
こういうやつはね

Name                  Version   Publisher  Notes    Summary
code                  51b0b281  vscode✓    classic  Code editing. Redefined.

classicっていうのはconfinementの一種で、confinementっていうのは
アプリの権限みたいなもので、classicだとなんでもできてしまうってことらしい
classicじゃないやつはサンドボックスの中で実行されるらしい

マイクロソフトを信じてつける

vagrant@vagrant:~$ sudo snap install code --classic
code 51b0b281 from Visual Studio Code (vscode✓) installed

入った
起動

f:id:kb84tkhr:20190414185817p:plain

日本語も大丈夫ぽい

f:id:kb84tkhr:20190414202609p:plain
これで仮想マシン上でも作業できるようになったかな
(別にviでも作業できるけど)