-
Notifications
You must be signed in to change notification settings - Fork 13
Dev Container の追加 #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
dc684be
ADD devcontainer
kimushun1101 e639bf8
Merge branch 'main' into feature/devcontainer
kimushun1101 4f646c1
ADD description for Dev Container
kimushun1101 e25897b
FIX versions
kimushun1101 3805444
MOD .gitignore for .vscode dir
kimushun1101 837c841
FIX devcontainer README.md
kimushun1101 3aabf44
ADD hyper link
kimushun1101 457ae17
Update README for devcontainer
kimushun1101 5666959
MOD vscode task label
kimushun1101 47996d3
Update README for devcontainer
kimushun1101 9fde1d9
Upgrade nodejs version
kimushun1101 c3b62cd
Update README for devcontainer
kimushun1101 c5810ce
Insert final newline
3w36zj6 a4a6f16
Fix typo
3w36zj6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Rust v1.77 as a base image | ||
FROM rust:1.77-slim | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends \ | ||
curl \ | ||
# install python3, jinja2 pyyaml | ||
python3 \ | ||
python3-pip \ | ||
&& pip3 install --break-system-packages jinja2 pyyaml \ | ||
# install nodejs and serve | ||
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ | ||
&& apt-get install -y nodejs \ | ||
&& npm install -g serve \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
|
||
WORKDIR /workspace | ||
ENV PATH="/root/.cargo/bin:${PATH}" | ||
3w36zj6 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Dev Containerについて | ||
|
||
Visual Studio Codeで編集する場合には、[Dev Container](https://code.visualstudio.com/docs/devcontainers/containers)を使用してローカル環境でWebページの仕上がりを確認することができます。 | ||
Visual Studio Codeでtypst-jp.github.ioディレクトリを開き以下の操作を実施してください。 | ||
1. Ctrl+Shift+Pから`>Dev Containers: Reopen in Container`を実行 | ||
2. ビルドが完了したらブラウザで http://localhost:3000 に接続 | ||
3. ページを更新した際には、Ctrl+shift+Pから`Tasks: Run task`を実行し`preview: typst-jp documentation`を選択。ビルドが完了したらブラウザを更新。 | ||
|
||
|
||
## 別のエディターを使用している場合 | ||
|
||
別のエディターで編集している場合にもDockerfileの使用のみであれば可能です。 | ||
ターミナルから typst-jp.github.io ディレクトリ上で以下のコマンドを実行してください。 | ||
1. Docker imageをビルドして実行 | ||
``` | ||
docker build . -f .devcontainer/Dockerfile -t typst-jp-doc | ||
docker run --name typst-jp-doc -p 3000:3000 -it -v "$(pwd):/workspace" -w /workspace --rm typst-jp-doc /bin/bash | ||
``` | ||
2. Dockerコンテナ内でビルド | ||
``` | ||
cargo test --package typst-docs --lib -- tests::test_docs --exact --nocapture && python3 ./gen.py && npx serve -n ./dist | ||
``` | ||
3. ビルドが完了したらブラウザで http://localhost:3000 に接続 | ||
4. ファイルを更新した際には、2 のコマンドを再度実行して、ブラウザを更新。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "typst-jp-domumentation", | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
"context": ".." | ||
}, | ||
"forwardPorts": [3000], | ||
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached", | ||
"workspaceFolder": "/workspace", | ||
"postStartCommand": "cargo test --package typst-docs --lib -- tests::test_docs --exact --nocapture && python3 ./gen.py && npx serve -n ./dist" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "preview: typst-jp documentation", | ||
"type": "shell", | ||
"command": "cargo test --package typst-docs --lib -- tests::test_docs --exact --nocapture && python3 ./gen.py && echo reload or open http://localhost:3000", | ||
"problemMatcher": [] | ||
} | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO: PythonとNode.jsのバージョンが明示的に指定されていないため、Dockerfileをビルドする時期によって環境が変わってしまうことが懸念されます。
複数の言語ランタイムを併用する状況が今後も続くと思われるので、mise等の開発環境を一括で管理できるツールを導入すると良いかもしれません。
また、Pythonの依存関係のJinja2とPyYAMLについてもバージョンが固定されていないため、同様の懸念が生じます。そこで、
requirements.txt
を追加して依存関係を明示的に管理するか、Ryeのようなパッケージ管理ツールを導入すると良いかもしれません。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
大変勉強になります。
懸念点は理解できます。一方でバージョン固定対応をすることで、記述が複雑になったり、管理すべき別ファイルが増えたり、docker build の時間が増えたり、などのデメリットも大きく感じます。
取り急ぎ以下のような編集を行いました。
Python に関しては .github/workflows/deploy.yml での記述に合わせました。こちらでもバージョン固定はされておりませんでしたので、バージョンアップによる不具合が発生した場合にはこちらでも検知でき、.devcontainer/Dockerfile の記述を deploy.yml と合わせておくという認識が取れていれば(覚えていれば)スムーズに対応できるかと思います。
https://github.com/typst-jp/typst-jp.github.io/blob/3805444542ae077ed849bb47bcccfda39b5bb1a2/.github/workflows/deploy.yml#L22
https://github.com/typst-jp/typst-jp.github.io/blob/3805444542ae077ed849bb47bcccfda39b5bb1a2/.devcontainer/Dockerfile#L10
Node.js については、私自身が不慣れでよくわかっていない部分もありますが
https://github.com/typst-jp/typst-jp.github.io/blob/3805444542ae077ed849bb47bcccfda39b5bb1a2/.devcontainer/Dockerfile#L12
こちらでメジャーバージョンは18を指定できていると思います。
serve パッケージのバージョンについては現在の最新版である v14.2.3 に指定いたしました。
https://github.com/typst-jp/typst-jp.github.io/blob/3805444542ae077ed849bb47bcccfda39b5bb1a2/.devcontainer/Dockerfile#L14
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python, Node.jsの環境については、それぞれ
pyproject.toml
,package.json
のように標準的な環境管理のためのファイル形式が存在していて、言語ランタイムそのものの管理については、pyenvの.python-version
やnodenvの.node-version
がmiseを含む後発の環境管理ツールで広くサポートされています。CI/CDはアプリケーション本体の開発のために補助的に存在しているものなので、言語ランタイムと依存関係はこういった標準的なファイル形式で集約して管理すべきだと考えています。しかし、現状では依存しているライブラリが少なく、これらで破壊的な変更が行われる可能性も非常に低いので、確かに管理すべきファイルが増えることのデメリットを上回るメリットがないように感じます。そこで、これらの環境については、サイト構築用のスクリプトの大規模な改変や、Node.js製のLinterの導入をする際に、個別に環境を整備すると良いかと思いました。
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コメントありがとうございます。方針は同意です。
Node.js のバージョンの方はよくわかっていなかったのですが、deploy.yml をみると JamesIves/github-pages-deploy-action@v4 が使用されているらしく。
https://github.com/typst-jp/typst-jp.github.io/blob/04dc4a65dc013e16cee68ad4722554ff8852bba9/.github/workflows/deploy.yml#L25-L30
確認したところ、こちらの最新版では node20 になっているようでした。
https://github.com/JamesIves/github-pages-deploy-action/blob/dev/action.yml
これも時々刻々と変わってしまうものだと思いますので、とりあえずこのDokcerfile では 18 固定のままでもよろしいでしょうか?大した手間ではなかったので 20 にしておきました。
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub Actionsの各Action内で使用されるNode.jsのバージョンは独立しており、各Actionは内部で指定されているNode.jsのバージョンを使用して実行されます。Marketplaceで公開されているActionの利用者は、内部で指定されているNode.jsのバージョンを気にする必要はありません。
注意が必要なのは、ワークフロー内にてNode.jsに依存するコマンドを
run:
で実行したい場合です。Node.jsに依存した処理を実行するには、前のステップでNode.jsのセットアップを完了させておく必要があり、ここでバージョンを明示的に指定してセットアップを行うと良いです。このPRにおいてDockerfileで指定するNode.jsのバージョンについては、このままでも大きな問題はないと思いますが、どちらかと言えば既にMaintenanceになっている18.xよりも現在のActive LTSである20.xで固定する方が良いかもしれません1。
Footnotes
https://github.com/nodejs/release#release-schedule ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参考ページを提示していただきありがとうございます!
完全に理解しました()
typst-jp/typst-jp.github.io@9fde1d9
こちらで 20.x にして、Dockerコンテナ内で
node -v
して確認できました。