{"id":26365404,"url":"https://github.com/2moe/zsh-static-docker","last_synced_at":"2025-03-16T19:36:22.986Z","repository":{"id":229355919,"uuid":"774985113","full_name":"2moe/zsh-static-docker","owner":"2moe","description":"zsh-static + busybox-static","archived":false,"fork":false,"pushed_at":"2024-04-02T00:33:58.000Z","size":63,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"dev","last_synced_at":"2024-04-02T01:35:26.060Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://ghcr.io/2moe/zsh-static","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2moe.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-20T14:59:21.000Z","updated_at":"2024-04-02T01:35:26.217Z","dependencies_parsed_at":"2024-04-02T01:35:20.787Z","dependency_job_id":null,"html_url":"https://github.com/2moe/zsh-static-docker","commit_stats":null,"previous_names":["2moe/zsh-static-docker"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2moe%2Fzsh-static-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2moe%2Fzsh-static-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2moe%2Fzsh-static-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2moe%2Fzsh-static-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2moe","download_url":"https://codeload.github.com/2moe/zsh-static-docker/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243920718,"owners_count":20369095,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-16T19:36:22.365Z","updated_at":"2025-03-16T19:36:22.963Z","avatar_url":"https://github.com/2moe.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zsh-static-docker\n\n![platforms](./assets/markmap/platforms.svg)\n\n## get started\n\n### Dockerfile\n\n```dockerfile\n# zsh:\nCOPY --from=ghcr.io/2moe/zsh-static /opt/bin/zsh /bin/zsh\n# busybox:\n# COPY --chmod=755 --from=ghcr.io/2moe/zsh-static /opt/bin/busybox /bin/ash\n```\n\n### CLI\n\n```sh\n# files: ./tmp/zsh  ./tmp/busybox\ndocker run --rm -v \"$PWD/tmp\":/host ghcr.io/2moe/zsh-static cp busybox zsh /host/\n\n# Considering that not all architectures are added to the `latest` manifest.\n# If you are using an \"unpopular\" architecture (e.g., sparc, mipsle),\n# you will need to specify the tag manually. (e.g., ghcr.io/2moe/zsh-static:mipsle)\n```\n\n### Github Actions workflow\n\n```yaml\njobs:\n  test:\n    runs-on: ubuntu-latest\n    defaults:\n      run:\n        shell: zsh --pipefail -fex {0}\n    steps:\n      - name: install zsh\n        shell: sh -e {0}\n        run: docker run --rm -v /usr/local/bin:/host ghcr.io/2moe/zsh-static cp zsh /host/\n\n      - name: test zsh\n        run: |\n          local -A map=(\n            focal    \"20.04\"\n            groovy   \"20.10\"\n            hirsute  \"21.04\"\n            impish   \"21.10\"\n            jammy    \"22.04\"\n            kinetic  \"22.10\"\n            lunar    \"23.04\"\n            mantic   \"23.10\"\n            noble    \"24.04\"\n          )\n          for k v (${(kv)map}) {\n            print -P \"%F{cyan}key: %F{blue}$k%f \\t value: $v\"\n          }\n```\n\n### No Docker\n\n**If you don't have docker installed, or the kernel doesn't support.**\n\nrun it on posix-sh:\n\n```sh\n# [\n#   \"x64\", \"rv64gc\", \"arm64\", \"armv7a\", \"armv5te\", \"mips64le\",\n#   \"ppc64le\", \"s390x\", \"x86\", \"alpha\", \"hppa\", \"loong64\",\n#   \"m68k\", \"ppc\", \"ppc64\", \"sh4\", \"sparc64\", \"ia64\", \"x32\",\n#   \"mipsle\", \"mipsbe\", \"armv4t\", \"sparc\", \"s390\", \"armv3\"\n# ]\n#\n# You can change arch=x64 to another value.\n# e.g., arch=rv64gc, arch=arm64\narch=x64\n\nmkdir -p tmp/zsh-dir\ncd tmp\ncurl -LO \"https://github.com/2moe/zsh-static-docker/releases/download/latest/zsh-${arch}.tar.zst\"\ntar -C zsh-dir -xf zsh-${arch}.tar.zst\n\n# test zsh: print hello world\nzsh-dir/opt/bin/zsh -fc 'print -P %F{cyan}Hello World'\n\n# run nspawn as root (i.e., +sudo/+doas)\nsystemd-nspawn -D zsh-dir -E PATH=/usr/local/bin:/bin:/opt/bin\n```\n\n## other notes\n\n- About ia64(a.k.a., 64-Bit Intel Itanium architecture)\n  - Modern qemu does not support emulating ia64.\n  - If you don't have a machine (server) with ia64 cpu, then you may not be able to run ia64 architecture containers.\n\n## Q\u0026A\n\n**What follows is not necessary to read.**\n\n---\n\n\u003e Q: Should I use zsh-static?\n\nA: When you ask this question, I don't think you need to.\nIn most cases, you should use normal zsh (i.e., installed with a package manager).\nOnly in special cases do you need to use zsh-static.\n\n---\n\n\u003e Q: Is it useful?\n\nA: Let's say there is a situation where you use `apt update; apt install zsh` which takes 6s, and `docker` which takes 3s to pull \u0026 run the zsh-static container, and the 3s saved is useful to you, then it is useful.\n\n---\n\n\u003e Q: Why did you create this repo?\n\nA：\n初衷是为了方便在 Dockerfile 以及 CI 流程 中使用 zsh。\n\nThe main reason is that 我不太喜欢用 POSIX-sh \u0026 bash。\n\nIn my opinion, POSIX-sh 不太好用。\n\n在大多数情况下，使用 POSIX-sh 是出于 compatibility 的考量。\n因为不同 Unix-Like 系统预装的 shell 是不一样的，有些是 busybox ash, 有些是 bash, 有些是 zsh, 还有些是 pdksh。\n为了兼容不同的 Unix-Like 系统，我们只能用 POSIX-sh 的语法了。\n\n而 bash 呢？\n\n- 客观上看：bash 4.x 以及 5.2.15 的性能相较于 debian 自带的 dash 和 alpine 自带的 ash 没有优势\n  - 就算用 --posix --noprofile 也慢了很多\n- 主观上看 (仅代表个人看法)： 其语法相较于 zsh 没有优势。\n\n\u003e 上面这段话来自于 gitee 的某个 [issue](https://gitee.com/mo2/linux/issues/I91P73)\n\n其实我真的不是想要刻意贬低 bash 与 posix-sh，最主要的原因是我不太喜欢它们。\n\n\u003e 注：awk 不是 posix-sh, 它是一门单独的语言，挺有意思的。\n\n如果我是真心喜欢一门语言的话，那么它就算有再多的缺点，我都能欣然接受；\n如果我太不喜欢的话，那么它的缺点就会被无限放大。\n\n喜欢与否是一件相当主观的事情，上面内容仅代表本人的看法。\n君若无意，则不必强求。\n\n其实创建这个 repo 还有一个契机，容我慢慢与您道来。\n\n事情是这样子的：\n\n此前，我想要研究一下 ArchLinux 的基本 rootfs 的构建步骤。\n再加上之前有个疑问：为什么 ArchLinux 的最小 rootfs 压缩后都要 100M+？\n于是乎，好奇心驱使我对此进行探索。\n\n我想试试裁剪 rootfs, 不求做到 alpine 那种 2 ~ 4M 的大小，只想看看能否做到像 ubuntu noble 那样 25 ~ 40M 的大小。\n后来，我发现容器内只要包含 pacman-static + pacman 配置 + ca证书 + busybox-static, 就能构建不同架构的 rootfs 了。\n\nca 证书 (**/etc/ca-certificates/extracted/tls-ca-bundle.pem**) 是可选的，不过要是无证书的话，就无法保证 https 连接的安全性，此时就得要引入 pgp 相关依赖，这样就变得更麻烦了。\n\n\u003e 由于 `/bin` , `/usr/bin`,  `/sbin` \u0026 `/usr/sbin` 合并了，为了避免目录的干扰，故 busybox 安装在 `/opt/bin`。\n\n这些东西加起来，压缩后才 4M+ (i.e., 最小的 ArchLinux 可以像嵌入式发行版一样做到只有 4M)。\n这时候如果用 `pacman-static -Syy base --overwrite '*'` 安装 `base`，那么压缩后的体积又变成了 100M+。\n\n如果不装 `base`，只装一些特别基础的包，可以做到 70M+，不过得要手动修复一些问题。\n在未安装 systemd 的情况下，有些东西得要手动去配置 (e.g., `useradd` 会弹出没有 `users` 用户的警告)。\n\n\u003e 其实并非越精简越好，比如说：在某些情况下，我需要国际化与本地化数据 (i18n 与 L10n)，以及 man 文档，删掉或过滤掉的话，就与我的需求相违背了。\n\nDockerfile 里的构建步骤，本来是用 posix-sh 语法来写的。\n\n后来，我就想：反正我挺喜欢 zsh 的，不如搞个 zsh-static 容器，之后不单单是构建 ArchLinux,\n其他的东西（诸如 CI 流程）也能用 zsh 语法来写。\n\n最后，让我们庆祝这个 repo 的诞生 🥳！\n\n\u003cdel\u003e\nBlessings for your birthday!\n\nBlessings for your everyday!\n\nAunque el mundo se pueda acabar, disfrúalo.\n\u003c/del\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2moe%2Fzsh-static-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2moe%2Fzsh-static-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2moe%2Fzsh-static-docker/lists"}