155 lines
5.1 KiB
Markdown
155 lines
5.1 KiB
Markdown
|
+++
|
||
|
date = "2024-02-11"
|
||
|
tags = ["github","arch","aios"]
|
||
|
title = "archベースのaiosを作った"
|
||
|
slug = "aios"
|
||
|
+++
|
||
|
|
||
|
|
||
|
少し前から[ai/bot](https://git.syui.ai/ai/bot)をリファクタリングしています。
|
||
|
|
||
|
せっかくなのでarchベースの[ai/os](https://git.syui.ai/ai/os)を作り、そこに乗せることにしました。
|
||
|
|
||
|
```sh
|
||
|
$ docker run -it syui/aios ai
|
||
|
```
|
||
|
|
||
|
archlinuxベースの自作osで名前は`ai os`です。
|
||
|
|
||
|
Arch Linuxが`archlinux`や`arch`と呼ばれるように`aios`や`ai`と呼ぶことがあります。使い分けは以下の通りです。
|
||
|
|
||
|
|var||
|
||
|
|---|---|
|
||
|
|ai os|Name|
|
||
|
|aios|Code||
|
||
|
|ai|ID|
|
||
|
|
||
|
### archiso
|
||
|
|
||
|
archは非常に使いやすいosです。あらゆる用途に使えますが、自作osにも使えます。その使い勝手の良さから、archベースのosはたくさんあります。例えば、`manjaro linux`, `steam os`, `asahi linux`, `alter linux`など。`ai os`もその中の一つになります。
|
||
|
|
||
|
特徴としては、rustを入れて`os`の拡張を目指します。最初は、systemとlogoを表示する機能を実装しました。
|
||
|
|
||
|
```sh
|
||
|
# pacman -S archiso
|
||
|
$ git clone https://gitlab.archlinux.org/archlinux/archiso
|
||
|
|
||
|
# buildmodes=('bootstrap')
|
||
|
$ vim ./archiso/configs/releng/profiledef.sh
|
||
|
|
||
|
$ mkarchiso -v -o ./ ./archiso/configs/releng
|
||
|
```
|
||
|
|
||
|
`/etc/os-release`を書き換える処理です。
|
||
|
|
||
|
```sh:archiso/archiso/mkarchiso
|
||
|
# archiso/archiso/mkarchiso
|
||
|
if [[ "${_os_release}" != "${pacstrap_dir}"* ]]; then
|
||
|
_msg_warning "os-release file '${_os_release}' is outside of valid path."
|
||
|
else
|
||
|
[[ ! -e "${_os_release}" ]] || sed -i '/^IMAGE_ID=/d;/^IMAGE_VERSION=/d' "${_os_release}"
|
||
|
printf 'IMAGE_ID=%s\nIMAGE_VERSION=%s\n' "${iso_name}" "${iso_version}" >>"${_os_release}"
|
||
|
fi
|
||
|
```
|
||
|
|
||
|
### docker
|
||
|
|
||
|
```sh
|
||
|
# git clone https://gitlab.archlinux.org/archlinux/archlinux-docker
|
||
|
|
||
|
$ tar xf aios-bootstrap*.tar.gz
|
||
|
$ tar -C root.x86_64 -c . | docker import - syui/aios
|
||
|
```
|
||
|
|
||
|
### gh-actions
|
||
|
|
||
|
`github actions`でbuildして、releases, packageとdocker-hubにpushします。
|
||
|
|
||
|
`github actions`は毎度のことながらハマるので注意です。例えば、docker loginは`docker.io`と`ghcr.io`で挙動が違います。
|
||
|
|
||
|
|env|body|
|
||
|
|---|---|
|
||
|
|${{ github.repository }}|syui/aios|
|
||
|
|${{ secrets.DOCKER_USERNAME }}|syui|
|
||
|
|${{ secrets.DOCKER_TOKEN }}|[token](https://matsuand.github.io/docs.docker.jp.onthefly/docker-hub/access-tokens/)|
|
||
|
|${{ secrets.APP_TOKEN }}|[token](https://docs.github.com/ja/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens), pacakge|
|
||
|
|
||
|
```yml:.github/workflows/release.yml
|
||
|
name: release
|
||
|
|
||
|
on:
|
||
|
push:
|
||
|
branches:
|
||
|
- main
|
||
|
schedule:
|
||
|
- cron: '0 0 * * *'
|
||
|
|
||
|
permissions:
|
||
|
contents: write
|
||
|
|
||
|
env:
|
||
|
REGISTRY: ghcr.io
|
||
|
IMAGE_NAME: ${{ github.repository }}
|
||
|
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
||
|
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
|
||
|
GITHUB_TOKEN: ${{ secrets.APP_TOKEN }}
|
||
|
|
||
|
jobs:
|
||
|
release:
|
||
|
name: Release
|
||
|
runs-on: ubuntu-latest
|
||
|
container:
|
||
|
image: archlinux
|
||
|
options: --privileged
|
||
|
steps:
|
||
|
- name: checkout
|
||
|
uses: actions/checkout@v4
|
||
|
|
||
|
- name: archiso
|
||
|
run: |
|
||
|
pacman -Syuu --noconfirm base-devel archiso docker git
|
||
|
git clone https://gitlab.archlinux.org/archlinux/archiso
|
||
|
cp -rf ./profiledef.sh /usr/share/archiso/configs/releng/
|
||
|
#mkarchiso -v -o ./ ./archiso/configs/releng/
|
||
|
./archiso/archiso/mkarchiso -v -o ./ /usr/share/archiso/configs/releng/
|
||
|
tar xf aios-bootstrap*.tar.gz
|
||
|
|
||
|
echo -e 'Server = http://mirrors.cat.net/archlinux/$repo/os/$arch\nServer = https://geo.mirror.pkgbuild.com/$repo/os/$arch' >> ./root.x86_64/etc/pacman.d/mirrorlist
|
||
|
sed -i s/CheckSpace/#CheckeSpace/ root.x86_64/etc/pacman.conf
|
||
|
arch-chroot root.x86_64 /bin/sh -c 'pacman-key --init'
|
||
|
arch-chroot root.x86_64 /bin/sh -c 'pacman-key --populate archlinux'
|
||
|
arch-chroot root.x86_64 /bin/sh -c 'pacman -Syu --noconfirm base base-devel linux vim git zsh rust openssh openssl jq'
|
||
|
|
||
|
#aiをbuildする
|
||
|
arch-chroot root.x86_64 /bin/sh -c 'git clone https://git.syui.ai/ai/bot && cd bot && cargo build && cp -rf ./target/debug/ai /bin/ && ai ai'
|
||
|
|
||
|
tar -zcvf aios-bootstrap.tar.gz root.x86_64/
|
||
|
tar -C ./root.x86_64 -c . | docker import - ${{ env.IMAGE_NAME }}
|
||
|
|
||
|
- name: docker-hub
|
||
|
run: |
|
||
|
echo "${{ env.DOCKER_TOKEN }}" | docker login -u ${{ env.DOCKER_USERNAME }} --password-stdin
|
||
|
docker push ${{ env.IMAGE_NAME }}
|
||
|
|
||
|
- name: docker login github
|
||
|
uses: docker/login-action@v3
|
||
|
with:
|
||
|
registry: ${{ env.REGISTRY }}
|
||
|
username: ${{ github.actor }}
|
||
|
password: ${{ env.GITHUB_TOKEN }}
|
||
|
|
||
|
- name: docker push github
|
||
|
run: |
|
||
|
docker tag ${{ env.IMAGE_NAME }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||
|
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||
|
|
||
|
- name: Create new release
|
||
|
uses: softprops/action-gh-release@v1
|
||
|
with:
|
||
|
name: latest
|
||
|
tag_name: latest
|
||
|
files:
|
||
|
aios-bootstrap.tar.gz
|
||
|
```
|
||
|
|