ããã«ã¡ã¯ã@nojima ã§ãã
æè¿ã社å
ã®ã¢ã¼ãã£ãã¡ã¯ãã® deb åãæ¨é²ãã¦ãã¾ãã
Building Microservices ã§ãç´¹ä»ããã¦ããããã«ãdeb 㯠apt-get install
ã§ã¤ã³ã¹ãã¼ã«ã§ããããä¾åé¢ä¿ãèªåã§ç®¡çã§ããããããããåç´ãª tar.gz ã使ããããå©ç¹ãå¤ãã§ãã
Debian çéã§ã¯ dpkg-buildpackage
ãªã©ã®ãã¼ã«ã使ã£ã¦ãã½ã¼ã¹ã³ã¼ãã®ãã«ããã deb ã®ä½æã¾ã§ãä¸è²«ãã¦ç®¡çãããã¨ãä¸è¬çã§ãã
ããããæ¢ã«ã½ã¼ã¹ã³ã¼ãã®ãã«ããè¡ãä»çµã¿ãæã£ã¦ããå ´åãæ¢åã®ãã«ãæé ããã®ã¾ã¾ä½¿ãã¤ã¤ deb ããã±ã¼ã¸ãä½æãããå ´åãããã¾ãã
ããã§ãã®è¨äºã§ã¯ããã«ãæ¸ã¿ã®ãã¤ããªãããã¨ãã«ãããã deb ããã±ã¼ã¸åããæ¹æ³ãç´¹ä»ãã¾ãã
â» ãã®è¨äºã§ç´¹ä»ããæ¹æ³ã¯ä¸»ã«å人ã社å
ã§å©ç¨ãã deb ããã±ã¼ã¸ãä½æãããã¨ã念é ã«ããã¦ãã¾ããDebian ã Ubuntu ã®å
¬å¼ã¬ãã¸ããªã§é
å¸ããããã㪠deb ãä½æãããå ´å㯠dpkg-buildpackage
ã使ãã¹ãã§ãã
TL;DR
- ã¤ã³ã¹ãã¼ã«ããããã¡ã¤ã«ãä¸æãã£ã¬ã¯ããªã«ç½®ãã¦
DEBIAN/control
ãã¡ã¤ã«ãæ¸ãã¦fakeroot dpkg-deb --build
ãæã¤ï¼ï¼
5åã§ã§ãã deb åå ¥é
ä¾é¡ã¨ã㦠direnv ãããã£ã¨ deb åãã¦ã¿ã¾ãã
direnv ã®å ¥æã¨ãã«ã
ã¾ããdirenv ããã«ããã¦ãã¤ããªãä½ãã¾ãã
$ git clone https://github.com/direnv/direnv $ cd direnv $ git checkout v2.8.0 $ make
ãã£ã¬ã¯ããªæ§é ã®ä½æ
ãããã deb ããã±ã¼ã¸ãä½ãããã®æºåããã¦ããã¾ãã
åºå¥ããããããããã«ãä¸ã§ direnv ããã«ããããã£ã¬ã¯ããªã $ORIG
ã¨å¼ã³ã
ããããä½æããã¯ã¼ãã³ã°ãã£ã¬ã¯ããªã $WORK
ã¨å¼ã¶ãã¨ã«ãã¾ãã
$WORK
ã¯é©å½ãªä½ç½®ã«é©å½ãªååã§ä½æãã¦ãã ããã
ã¾ãã$WORK
ã®ä¸ã«ã¤ã³ã¹ãã¼ã«ãã¹ããã¡ã¤ã«ãé
ç½®ãã¾ãã
ããã§ã¯ã/usr/bin/direnv
ã« direnv ã®å®è¡ãã¤ããªãã¤ã³ã¹ãã¼ã«ãããã®ã§ã
$WORK/usr/bin/direnv
ã«ãã«ããããã¤ããªãé
ç½®ãã¾ãã
$ mkdir -p $WORK/usr/bin $ cp $ORIG/direnv $WORK/usr/bin/direnv
($WORK/path/to/something
ã«ç½®ãããã¡ã¤ã«ã¯ /path/to/something
ã«ã¤ã³ã¹ãã¼ã«ãããã¨ããã«ã¼ã«ã«ãªã£ã¦ãã¾ããåç´ã§ãã)
control ãã¡ã¤ã«ã®ä½æ
次ã«ã$WORK/DEBIAN/control
ã« deb ããã±ã¼ã¸ã®ã¡ã¿ãã¼ã¿ãæ¸ãã¾ãã
control ã«æ¸ããé
ç®ã¯ããããããã¾ãããã¨ããããã¯ä»¥ä¸ã®ï¼ã¤ã®é
ç®ãæå®ããã°å¤§ä¸å¤«ã§ãã
Package: direnv Maintainer: Yusuke Nojima <[email protected]> Architecture: amd64 Version: 2.8.0-1 Description: Environment switcher for the shell direnv hooks into the shell to load or unload environment variables depending on the current directory.
åé ç®ã®æå³ã¯ä»¥ä¸ã®éãã§ãã
é ç® | æå³ |
---|---|
Package |
ããã±ã¼ã¸åã§ãã |
Maintainer |
deb ããã±ã¼ã¸ã®ã¡ã³ããã®ååã¨ã¡ã¼ã«ã¢ãã¬ã¹ãæå®ãã¾ãã |
Architecture |
ã¤ã³ã¹ãã¼ã«å¯è½ãªã¢ã¼ããã¯ãã£ãæå®ãã¾ããå¼ç¤¾ã®å ´åã¯å¤§ä½ amd64 ãæå®ãã¦ãã¾ãã |
Version |
ãã¼ã¸ã§ã³ã§ããåºæ¬çã« <upstream_version>-<debian_version> ã¨ããå½¢å¼ã§ä»ãã¾ãã詳ãã㯠man deb-version ãåç
§ãã¦ãã ããã |
Description |
ããã±ã¼ã¸ã®èª¬æãæ¸ãã¾ããè¤æ°è¡ãã£ã¼ã«ãã«ãªã£ã¦ãã¦ãä¸è¡ç®ã«çã説æãæ¸ããäºè¡ç®ä»¥éã«é·ã説æãæ¸ãã¾ããäºè¡ç®ä»¥éã¯è¡é ã«ç©ºç½ãä¸ã¤å ¥ããå¿ è¦ãããã¾ãã |
control ãã¡ã¤ã«ã¯ãããã®é
ç®ã®ä»ã«ãããããã¨é
ç®ãæå®ãããã¨ãã§ãã¾ãã
詳ãã㯠man deb-control
ãåç
§ãã¦ãã ããã
ã¾ããDEBIAN
ãã£ã¬ã¯ããªã«ã¯ control
ãã¡ã¤ã«ã®ä»ã«ããããããã¡ã¤ã«ãç½®ããã¨ãã§ãã¾ãã
ããã¤ãã®ãã¡ã¤ã«ã«ã¤ãã¦ã¯å¾ã§è¿°ã¹ã¾ãã
deb ã®ä½æ
æºåãã§ããã®ã§ deb ãä½æãã¾ãã
以ä¸ã®ã³ãã³ããæã£ã¦ãã ããã
(fakeroot
ããªãã¨è¨ãããå ´å㯠sudo apt-get install fakeroot
ããã¦ãã ãã)
$ fakeroot dpkg-deb --build $WORK .
ããã§ã«ã¬ã³ããã£ã¬ã¯ããªã« direnv_2.8.0-1_amd64.deb
ãä½æãããã¯ãã§ãã
dpkg-deb --build
㯠deb ããã±ã¼ã¸ãä½æããããã®ã³ãã³ãã§ãä¸çªç®ã®å¼æ°ã§ããã±ã¼ã¸ã®ä¸èº«ã¨ãªããã£ã¬ã¯ããªãæå®ããäºçªç®ã®å¼æ°ã§ããã±ã¼ã¸ãåºåãããã£ã¬ã¯ããªãæå®ãã¾ãã
ããã±ã¼ã¸ã®åå㯠<package>_<version>_<architecture>.deb
ã¨ããã«ã¼ã«ã§èªåçã«ä»ãã¦ããã¾ãã
ã¾ããdpkg-deb --build
ããã㨠$WORK
ãã£ã¬ã¯ããªå
ã®ãã¡ã¤ã«ã® uid, gid ããã®ã¾ã¾ deb ã«å«ã¾ãã¦ãã¾ãã¾ãã
æ®éãdeb ããã±ã¼ã¸ã«ãã£ã¦ã¤ã³ã¹ãã¼ã«ããããã¡ã¤ã«ã® uid, gid 㯠0 (root) ã§ãã£ã¦æ¬²ããã®ã§ãããã§ã¯å°ãã¾ãã
ãããé²ãããã« fakeroot
ã«ãã£ã¦è¦ããã® uid, gid ã 0 ã«ãã¦ãã¾ãã
åºæ¬çã«ãdpkg-deb --build
ãããå ´å㯠fakeroot
ã®ä¸ã§è¡ãã¨æã£ã¦ããã°ããã¨æãã¾ãã
ã¤ã³ã¹ãã¼ã«ãã¦ã¿ã
æ©éã¤ã³ã¹ãã¼ã«ãã¦ã¿ã¾ãããã
$ sudo dpkg -i direnv_2.8.0-1_amd64.deb $ direnv --help
ã¤ãã§ã«ã¢ã³ã¤ã³ã¹ãã¼ã«ããã¦ã¿ã¾ãããã
$ sudo dpkg -r direnv
以ä¸ã§ deb åå ¥éã¯çµããã§ãã 以ä¸ã¯ Tips éã§ãã
ã¤ã³ã¹ãã¼ã«/ã¢ã³ã¤ã³ã¹ãã¼ã«æã«ä½ãå¦çãè¡ã
ã¤ã³ã¹ãã¼ã«æã«ã¦ã¼ã¶ã追å ããããupdate-alternatives
ãããããããã¨ãããã¾ãã
ãã®ãããªå ´åãDEBIAN
ãã£ã¬ã¯ããªã®ä¸ã«ä»¥ä¸ã®ãããªã¹ã¯ãªãããã¡ã¤ã«ãç½®ããã¨ã§ãä»»æã®å¦çãå®è¡ã§ãã¾ãã
ãã¡ã¤ã«å | 説æ |
---|---|
preinst |
ã¤ã³ã¹ãã¼ã«ã®åãã¢ããã°ã¬ã¼ãã®åã«å®è¡ããã |
postinst |
ã¤ã³ã¹ãã¼ã«ã®å¾ãã¢ããã°ã¬ã¼ãã®å¾ã«å®è¡ããã |
prerm |
ã¢ã³ã¤ã³ã¹ãã¼ã«ã®åãã¢ããã°ã¬ã¼ãã®åã«å®è¡ããã |
postrm |
ã¢ã³ã¤ã³ã¹ãã¼ã«ã®å¾ãã¢ããã°ã¬ã¼ãã®å¾ã«å®è¡ããã |
ä¾ãã°ãã¤ã³ã¹ãã¼ã«æã« www-data
ã¦ã¼ã¶ãä½æããå ´åã以ä¸ã®æ§ãªãã¡ã¤ã«ã DEBIAN/postinst
ã«é
ç½®ããã°ããã§ãã
(chmod +x
ãã¦å®è¡å¯è½ã«ãã¦ããã¦ãã ãã)
#!/bin/sh -e adduser --system --group --quiet --home /var/lib/www-data www-data
注æç¹ã¨ãã¦ãã¹ã¯ãªããã¯ä½ãã¨ã©ã¼ãèµ·ãã£ãæã«ã¯ 0 以å¤ã®çµäºã¹ãã¼ã¿ã¹ã§çµäºãã¹ãã§ãã ã¾ããã¨ã©ã¼ã«ãªã£ãã¨ãã«åå®è¡ã§ããããã«ãã¹ã¯ãªããã¯åªçã«æ¸ãã¹ãã§ãã
ãããã®ã¹ã¯ãªãããå¼ã°ããã¿ã¤ãã³ã°ãå¼æ°ã«ã¤ãã¦ã¯ Debian ããªã·ã¼ããã¥ã¢ã« Chapter 6 ã«è©³ããæ¸ãã¦ããã¾ãã
ä»ã®ããã±ã¼ã¸ã¸ã®ä¾åãå®ç¾©ãã
ããã±ã¼ã¸ã«ãã£ã¦ã¯ä»ã®ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ããã¦ããªãã¨åä½ããªãå ´åãããã¾ãã
ãã®ãããªå ´åãcontrol
ãã¡ã¤ã«ã« Depends
ãæ¸ãã¦ãããã¨ã§ãapt-get install
ããã¨ãã«èªåçã«ä¾åã解決ãã¦ããããã¨ãã§ãã¾ãã
ä¾ãã°ãJava ã«ä¾åããããã±ã¼ã¸ãä½ãå ´åãcontrol
ã«ä»¥ä¸ã®ãããªè¡ãæ¸ãã¨ããã§ãã
Depends: java7-runtime-headless
è¤æ°åã®ä¾åãããå ´åã¯ã«ã³ãåºåãã§æå®ãã¾ãã ã¾ãããã¼ã¸ã§ã³ã®å¶éãããå ´åã¯ããã±ã¼ã¸åã®å¾ã«ã«ãã³ã§æå®ãã¾ãã
Depends: libjline-java, liblog4j1.2-java (>= 1.2), libnetty-java
ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ããæç¹ã§æ¢ã«ä»ã®ããã±ã¼ã¸ãå¿
è¦ã¨ããå ´åãããã¾ãã
ãã®ãããªå ´åãDepends
ã§ã¯ãªã㦠Pre-Depends
ã«æ¸ãã¦ãã ããã
Pre-Depends: adduser
ãã¼ãã£ã«ããã±ã¼ã¸ã Provide ãã
åãæ©è½ãæä¾ããããã±ã¼ã¸ãè¤æ°ååå¨ãããã¨ãããã¾ãã
ä¾ãã°ãJava ã®å ´åãOpenJDK 㨠OracleJDK ã大ä½åãæ©è½ãæä¾ãã¦ãã¾ãã
ãã®ãããªå ´åããOpenJDK ã¾ã㯠OracleJDK ã«ä¾åãã¨ãã宣è¨ãå¤çºãããã¨ã«ãªãã®ã§ãããããããã¡ãã¡ OR ã§å®£è¨ããã®ã¯é¢åã§ãã
ããã§ãjava-runtime
ã¨ããä»®æ³çãªããã±ã¼ã¸ãä½ããJava ã©ã³ã¿ã¤ã ã«ä¾åãããããã±ã¼ã¸ã¯ããã« Depends
ãããã¨ã«ãã
OpenJDK ã OracleJDK 㯠java-runtime
ã¨ããæ©è½ã Provides
ãããã¨ã§ãç°¡åã«ä¾åãè¨è¿°ã§ããããã«ãã¦ãã¾ãã
ã¨ãããã¨ã§ãOracleJDK ã¨ããç¬èªã«ããã±ã¼ã¸ã³ã°ããå ´åããããã®ãã¼ãã£ã«ããã±ã¼ã¸ã Provides
ã«å®£è¨ãã¦ããå¿
è¦ãããã¾ãã
Provides: java-compiler, java-sdk, java-runtime, java-runtime-headless
â» å®éã« JDK ãããã±ã¼ã¸ã³ã°ããå ´å㯠java6-sdk
, java7-runtime-headless
ãªã©ãã¼ã¸ã§ã³ãå«ãã ãã¼ãã£ã«ããã±ã¼ã¸ã Provide ããå¿
è¦ãããã¾ãã詳ããã¯å
¬å¼ã® JDK ã®ããã±ã¼ã¸ãè¦ã¦ã¿ã¦ãã ããã
å ¬å¼ããã±ã¼ã¸ã®ä¸èº«ãè¦ã¦ã¿ã
apt-get download
ã㦠dpkg-deb --raw-extract
ããã¨å
¬å¼ããã±ã¼ã¸ã®ä¸èº«ãè¦ãã¾ãã
control
ã postinst
ã¨ããåèã«ãããå ´åã«ä¾¿å©ã§ãã
ä¾ãã°ãmysql-server-5.5
ã®ä¸èº«ãè¦ããå ´åã¯ä»¥ä¸ã®ããã«ãã¾ãã
$ apt-get download mysql-server-5.5 $ mkdir foo $ dpkg-deb --raw-extract mysql-server-5.5_5.5.47-0ubuntu0.14.04.1_amd64.deb foo
apt ãµã¼ããç«ã¦ã
HTTP ãµã¼ããã¤ã³ã¹ãã¼ã«
@apt-server $ sudo apt-get install nginx
server { listen 80; location / { root /srv/apt-repo; autoindex on; } }
deb ãé ç½®
@apt-server $ sudo mkdir -p /srv/apt-repo/pool $ sudo cp direnv_2.8.0-1_amd64.deb /srv/apt-repo/pool
Packages.gz ãä½æ
@apt-server $ cd /srv/apt-repo $ apt-ftparchive packages pool | gzip | sudo dd of=Packages.gz bs=1M
ã¤ã³ã¹ãã¼ã«ãã¦ã¿ã
@local $ cat <<EOF | sudo dd of=/etc/apt/sources.list.d/my-apt-repo.list deb [trusted=yes] http://ãµã¼ãå/ ./ EOF $ sudo apt-get update $ sudo apt-get install direnv
è¨å®ãã¡ã¤ã«ãæå®ãã
DEBIAN/conffiles
ã«è¨å®ãã¡ã¤ã«ã®ãªã¹ããæå®ãããã¨ãã§ãã¾ãã
deb ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ããã¨ãã«æ¢ã«ãã¡ã¤ã«ãåå¨ããå ´åãæ®éã¯åçç¡ç¨ã§ deb ããã±ã¼ã¸ã®ä¸ã®ãã¡ã¤ã«ã§ä¸æ¸ãããã¾ãã ããããè¨å®ãã¡ã¤ã«ã¯ã¤ã³ã¹ãã¼ã«å¾ã«ã¦ã¼ã¶ãå¤æ´ãããã¨ããããããä¸æ¸ããã¦ãããã©ããããããã¾ããã
ããã§ãè¨å®ãã¡ã¤ã«ã DEBIAN/conffiles
ã«æå®ãã¦ããã¨ãdpkg
ãããç¨åº¦ãããªã«æ±ã£ã¦ããã¾ãã
conffiles
ã®ä¾:
/etc/logrotate.d/mysql-server /etc/mysql/conf.d/mysqld_safe_syslog.cnf /etc/mysql/debian-start /etc/init.d/mysql /etc/logcheck/ignore.d.paranoid/mysql-server-5_5 /etc/logcheck/ignore.d.workstation/mysql-server-5_5 /etc/logcheck/ignore.d.server/mysql-server-5_5 /etc/apparmor.d/usr.sbin.mysqld /etc/init/mysql.conf
詳ãã㯠Debian ããªã·ã¼ããã¥ã¢ã« Appendix E ãåç §ãã¦ãã ããã
ã¤ã³ã¹ãã¼ã«æ/ã¢ã³ã¤ã³ã¹ãã¼ã«æã®æå
deb ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ããã¨ãã«ãã¤ã³ã¹ãã¼ã«å¯¾è±¡ã®ãã¡ã¤ã«ãæ¢ã«ãã¡ã¤ã«ã·ã¹ãã ã«åå¨ãã¦ãããã¨ãããã¾ãã ã¾ããã¢ã³ã¤ã³ã¹ãã¼ã«æã«ã¢ã³ã¤ã³ã¹ãã¼ã«å¯¾è±¡ã®ãã¡ã¤ã«ãæ¢ã«åå¨ããªãã£ããä»ã®ããã±ã¼ã¸ããã¾ã åç §ããã¦ããããããã¨ãããã¾ãã ãã®ãããªå ´åã以ä¸ã®ãããªã«ã¼ã«ã§å¦çãè¡ããã¾ãã
ä½ããé ç½®ãããã¨ããã¨ãã®ã«ã¼ã«:
Install file/node | Install symlink | Install directory | |
---|---|---|---|
Not exists | Extract | Extract | Extract |
File/node/symlink | Atomic overwrite | Atomic overwrite | Non-atomic overwrite |
Directory | Non-atomic overwrite | Do nothing | Do nothing |
ä½ããåé¤ãããã¨ããã¨ãã®ã«ã¼ã«:
- åé¤ãã¡ã¤ã«ã
conffile
ã«å«ã¾ããå ´åãpurge
ãããã¾ã§ã¯åé¤ããæ®ãã¦ããã - åé¤å¯¾è±¡ãåå¨ããªãå ´åãç¡è¦ããã
- åé¤å¯¾è±¡ããã£ã¬ã¯ããªã§ãããããã£ã¬ã¯ããªã¸ã®ã·ã³ããªãã¯ãªã³ã¯ã§ããå ´åãåé¤å¯¾è±¡ãä»ã®ããã±ã¼ã¸ããåç §ããã¦ããªãå ´åã®ã¿åé¤ããã
- åé¤å¯¾è±¡ããã£ã¬ã¯ããªã§ãªããããã£ã¬ã¯ããªã¸ã®ã·ã³ããªãã¯ãªã³ã¯ã§ãªãå ´åãåé¤ããã
å§ç¸®æ¹æ³ãæå®ãã
dpkg-deb --build
ã¯ããã©ã«ãã§ãã¼ã¿ã xz ã§å§ç¸®ãã¾ãã
ããããjar ãã¡ã¤ã«ã®ããã«å
ã
å§ç¸®ããã¦ãããã¡ã¤ã«ã xz ã§åã³å§ç¸®ããã®ã¯ãæéã®ããã«ãµã¤ãºãæ¸ããªãã®ã§ãããããªãã§ãã
ãã®ãããªå ´åããªãã·ã§ã³ã« -Z none
ãæå®ããã¨ç¡å§ç¸®ã«ã§ãã¾ãã
ãããã«
ãã®ããã« deb ããã±ã¼ã¸ãä½æããã®ã¯ã¨ã¦ãç°¡åã§ãã
tar.gz ãå¿ãè¾¼ã㦠scp ãããããªéç¨ããåæ¥ãã¦ãã¹ãã¼ãã« apt-get install
ããä¸çãç®æãã¦ããã¾ãããï¼ï¼