前回ラボのステージング環境を作りました。
本題のGit管理ツールのデプロイもOKだったので本番のラボにデプロイします。
gitea
オープンソースのGit管理ツールはGitlabくらいしか知らなかったのですが結構リソース要求が高い様です。
色々調べるとGiteaという軽量なツールがあるそうなのでこちらを採用することにしました。
composeファイル
Docker installはrootlessとrootあり版がありますが、とりあえずはroot使う用事がないのでrootless版にします。
公式のcomposeファイルで特にカスタムなしでデプロイします。
composeファイルのバージョンが2だとラボに対応していなかったので他のファイルを合わせて3.3に修正しました。
volumeのデータ置き場を統一するべきなのですがあまり設計していないのでとりあえずデフォルトです。
version: "3.3" services: server: image: gitea/gitea:1.20.5-rootless restart: always volumes: - ./data:/var/lib/gitea - ./config:/etc/gitea - /etc/timezone:/etc/timezone:ro - /etc/localtime:/etc/localtime:ro ports: - "3000:3000" - "2222:2222"
ステージング環境からファイルを持ってきます。
multipass mountではディレクトリの中身が表示されないという事象に陥ったので一旦transferで持ってきました。
❯ multipass transfer dev-lab:/home/ubuntu/gitea/docker-compose.yml . ❯ ls docker-compose.yml docker-compose.yml ❯ scp docker-compose.yml masashi@10.0.1.1:/home/masashi/gitea docker-compose.yml
デプロイ
ラボ側にディレクトリ準備します。(上のscp時に作成済み)
masashi@lab-docker1:~$ mkdir gitea masashi@lab-docker1:~$ cd gitea/ masashi@lab-docker1:~/gitea$ mkdir {data,config} masashi@lab-docker1:~/gitea$ ls config data
ステージングにもラボにもdocker-composeコマンドを入れていないのでswarmのserviceコマンドでデプロイ。
restartのエラーは一旦無視します。
masashi@lab-docker1:~/gitea$ docker stack deploy -c docker-compose.yml gitea Ignoring unsupported options: restart Creating network gitea_default Creating service gitea_server
コンテナ起動しましたよ。
masashi@lab-docker1:~/gitea$ docker service ls ID NAME MODE REPLICAS IMAGE PORTS 29w5a2b2snfy dokuwiki_dokuwiki replicated 1/1 bitnami/dokuwiki:20230404 *:82->8080/tcp plup1b33qmjy firefly_app replicated 1/1 fireflyiii/core:latest *:80->8080/tcp u0009w7ryo30 firefly_db replicated 1/1 mariadb:latest xj6n7hbbhowc gitea_server replicated 1/1 gitea/gitea:1.20.5-rootless *:2222->2222/tcp, *:3000->3000/tcp luna6ms9v7bi pi-hole_pihole replicated 1/1 pihole/pihole:latest *:53->53/tcp, *:81->80/tcp, *:53->53/udp fyijaxnx2903 portainer_agent global 2/2 portainer/agent:2.18.2 ddrxmnjz9is4 portainer_portainer replicated 1/1 portainer/portainer-ce:2.18.2 *:8000->8000/tcp, *:9000->9000/tcp, *:9443->9443/tcp
アクセス & 初期設定
Giteaにアクセスします。
初期設定画面が表示されました。
サイト名だけ変えてあとはデフォルト。
ユーザ登録は割愛して、リポジトリを作成します。
リポジトリにpush
ツール置いてあるディレクトリからcommit、pushします。
これはメイン機WindowsのWSL上にあります。
今は中身こんな感じ。
txtファイルはメモ、APIトークン、API投入コマンド系なので.gitignoreに入れておきます。
csvファイルは支払いデータですが一応管理対象にするか。(家の環境だからできることですね)
masashi@DESKTOP-HBP3520:/mnt/c/Users/masashi/tools/Household-account$ ls , 202301.csv 202304.csv 202307.csv Mar.txt command.txt jul.txt post.txt transactionapi.py 2021 202302.csv 202305.csv 202308.csv apr.txt feb.txt jun.txt salary.txt 2022 202303.csv 202306.csv 202309.csv aug.txt 'firefly token.txt' may.txt sep.txt
初期化
初回に表示されるアナウンスに沿っていきます。
masashi@DESKTOP-HBP3520:/mnt/c/Users/masashi/tools/Household-account$ touch README.md masashi@DESKTOP-HBP3520:/mnt/c/Users/masashi/tools/Household-account$ git init Initialized empty Git repository in /mnt/c/Users/masashi/tools/Household-account/.git/ masashi@DESKTOP-HBP3520:/mnt/c/Users/masashi/tools/Household-account$ git checkout -b main Switched to a new branch 'main' masashi@DESKTOP-HBP3520:/mnt/c/Users/masashi/tools/Household-account$ git status On branch main No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) , .gitignore 2021/ 2022/ 202301.csv 202302.csv 202303.csv 202304.csv 202305.csv 202306.csv 202307.csv 202308.csv 202309.csv README.md transactionapi.py nothing added to commit but untracked files present (use "git add" to track)
commit
addします。
txtが除外されてるので.gitignoreもOK。
masashi@DESKTOP-HBP3520:/mnt/c/Users/masashi/tools/Household-account$ git add * The following paths are ignored by one of your .gitignore files: Mar.txt apr.txt aug.txt command.txt feb.txt firefly token.txt jul.txt jun.txt may.txt post.txt salary.txt sep.txt Use -f if you really want to add them.
commitします。
masashi@DESKTOP-HBP3520:/mnt/c/Users/masashi/tools/Household-account$ git commit -m "first commit" [main (root-commit) 6c897cc] first commit 34 files changed, 1283 insertions(+) (略)
リモートリポジトリ設定
giteaを指定。
masashi@DESKTOP-HBP3520:/mnt/c/Users/masashi/tools/Household-account$ git remote add origin http://10.0.1.1:3000/masashi/Household-account.git masashi@DESKTOP-HBP3520:/mnt/c/Users/masashi/tools/Household-account$ git remote -v origin http://10.0.1.1:3000/masashi/Household-account.git (fetch) origin http://10.0.1.1:3000/masashi/Household-account.git (push)
push
これでやっとpush。
masashi@DESKTOP-HBP3520:/mnt/c/Users/masashi/tools/Household-account$ git push -u origin main Username for 'http://10.0.1.1:3000': masashi Password for 'http://masashi@10.0.1.1:3000': Enumerating objects: 38, done. Counting objects: 100% (38/38), done. Delta compression using up to 4 threads Compressing objects: 100% (37/37), done. Writing objects: 100% (38/38), 17.53 KiB | 326.00 KiB/s, done. Total 38 (delta 30), reused 0 (delta 0) remote: . Processing 1 references remote: Processed 1 references in total To http://10.0.1.1:3000/masashi/Household-account.git * [new branch] main -> main Branch 'main' set up to track remote branch 'main' from 'origin'.
OK。
giteaにも登録されました。
執筆中に気づいたのですが謎の,ディレクトリをcommitしてしまいました。
後で消しておこう。
まとめ
ついに家にもgit環境が作成されました!
まあそんなに更新することはなさそうですが家計簿ツールのバージョン管理 + 保存先ができたので一旦安心。
今後はgiteaのデータを守らないといけませんね。
いきなりやらかしましたが自宅環境だからと不要ファイル、大切なファイルまでcommitしない様に意識したいところです。
前回ステージング環境を作ったことでこれのデプロイテストもできて手順が確立できたので簡単にデプロイでしました。
作ってよかった。
コンテナも増えてきたのでそろそろプロキシ導入も検討します。