README.adoc 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. = Make Alpine Linux RootFS
  2. :script-name: alpine-make-rootfs
  3. :script-sha1: 2ebf310a0c6eb1b3ac9587d6211f1e84227846f0
  4. :gh-name: alpinelinux/{script-name}
  5. :version: 0.7.2
  6. ifdef::env-github[]
  7. image:https://github.com/{gh-name}/workflows/CI/badge.svg["Build Status", link="https://github.com/{gh-name}/actions"]
  8. endif::env-github[]
  9. This project provides a script for building customized https://alpinelinux.org/[Alpine Linux] rootfs (a base image if you like) for containers.
  10. It’s quite simple (300 LoC of shell), fast and requires minimum dependencies (just common Linux tools).
  11. TIP: Do you want to just quickly chroot into Alpine Linux, e.g. on CI?
  12. Check out https://github.com/alpinelinux/alpine-chroot-install[alpine-chroot-install]!
  13. == Requirements
  14. * Linux system
  15. * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html[POSIX-sh] compatible shell (e.g. Busybox ash, dash, ZSH, bash, …)
  16. * common userland with `chroot`, `getopt`, `grep`, `sed`, `sha256sum`, `wget` (e.g. from Busybox, GNU coreutils, …)
  17. * `tar` (full-blown)
  18. == Usage
  19. Read documentation in link:{script-name}[{script-name}].
  20. See link:.github/workflows/ci.yml[] for GitHub Actions example.
  21. You can copy link:{script-name}[{script-name}] into your repository or download it on demand, e.g.:
  22. [source, sh, subs="+attributes"]
  23. wget https://raw.githubusercontent.com/{gh-name}/v{version}/{script-name} \
  24. && echo '{script-sha1} {script-name}' | sha1sum -c \
  25. || exit 1
  26. == Examples
  27. === Installation Script in Heredoc
  28. [source, sh]
  29. ----
  30. sudo ./alpine-make-rootfs \ # <1>
  31. --branch v3.8 \ # <2>
  32. --packages 'ruby ruby-bigdecimal sqlite' \ # <3>
  33. --timezone 'Europe/Prague' \ # <4>
  34. --script-chroot \ # <5>
  35. example-$(date +%Y%m%d).tar.gz - <<'SHELL' # <6>
  36. # Copy some file from the repository root to the rootfs.
  37. install -D -m 755 examples/hello_world.rb /app/hello_world.rb
  38. # Install some dev packages and gem mailcatcher.
  39. apk add --no-progress -t .make build-base ruby-dev sqlite-dev
  40. gem install --no-document mailcatcher
  41. # Clean-up dev packages. <7>
  42. apk del --no-progress .make
  43. SHELL
  44. ----
  45. <1> The script needs to create files owned by _root_ or other users and optionally uses chroot (when `--script-chroot` is specified), so it must be run under _root_ (e.g. using `sudo`).
  46. <2> Alpine branch (release) to install (see https://wiki.alpinelinux.org/wiki/Alpine_Linux:Releases[Alpine Releases]).
  47. <3> You can name packages to install into the chroot, in addition to base packages (see `ALPINE_BASE_PKGS` in link:{script-name}[{script-name}]).
  48. <4> You may specify timezone to set (default is UTC).
  49. <5> This flag tells that the installation script will be executed inside chroot with the rootfs as new root.
  50. Your current working directory is binded at `/mnt` inside the chroot and `$PWD` for the script is set to `/mnt`, so you can easily access files out of the chroot and copy them into the rootfs.
  51. <6> Installation script may be provided also via STDIN, using a convenient heredoc syntax.
  52. The script passed is executed using `/bin/sh -e`.
  53. <7> Note that it’s not needed to clean `apk` cache, this is done automatically.
  54. === Create Docker Base Image
  55. Create your own (customized) up-to-date base image.
  56. [source, sh]
  57. ----
  58. sudo ./alpine-make-rootfs --branch v3.8 - | docker import -c 'CMD /bin/sh' - my/alpine:3.8
  59. ----
  60. === Create OCI Image
  61. You can use simply shell script https://github.com/jirutka/sloci-image/[sloci-image] to pack the generated rootfs as a single-layer OCI image.
  62. [source, sh]
  63. ----
  64. sudo ./alpine-make-rootfs --branch v3.8 --script-chroot rootfs.tar.gz ./install.sh
  65. ./sloci-image --entrypoint /start.sh --port 80/tcp --tar rootfs.tar.gz alpine:3.8
  66. ----
  67. == License
  68. This project is licensed under http://opensource.org/licenses/MIT/[MIT License].
  69. For the full text of the license, see the link:LICENSE[LICENSE] file.