diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..37bde46 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,44 @@ +{ + "name": "Swift", + "image": "swift:5.9", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "installZsh": "false", + "username": "vscode", + "userUid": "1000", + "userGid": "1000", + "upgradePackages": "false" + }, + "ghcr.io/devcontainers/features/git:1": { + "version": "os-provided", + "ppa": "false" + } + }, + "runArgs": [ + "--cap-add=SYS_PTRACE", + "--security-opt", + "seccomp=unconfined" + ], + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "lldb.library": "/usr/lib/liblldb.so" + }, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "sswg.swift-lang" + ] + } + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "swift --version", + + // Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +} diff --git a/.github/dependabot.yml b/.github/dependabot.yml index acd143b..ff053a6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -19,3 +19,8 @@ updates: directory: "/" # Location of package manifests schedule: interval: "daily" + + - package-ecosystem: "devcontainers" # See documentation for possible values + directory: "/.devcontainer" # Location of package manifests + schedule: + interval: "daily" diff --git a/.github/workflows/swift-in-devcontainer.yml b/.github/workflows/swift-in-devcontainer.yml new file mode 100644 index 0000000..05b93c3 --- /dev/null +++ b/.github/workflows/swift-in-devcontainer.yml @@ -0,0 +1,23 @@ +name: Swift Build and Test in DevContainer +on: + push: + pull_request: + +jobs: + build: + name: Swift on ubuntu-latest + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: true + + - name: Build and Test in DevContainer + uses: devcontainers/ci@v0.3 + with: + push: never + runCmd: | + swift build -Xswiftc -strict-concurrency=complete -v + swift test -c release -Xswiftc -strict-concurrency=complete -v diff --git a/Docs/Images/install-devcontainers-extension.png b/Docs/Images/install-devcontainers-extension.png new file mode 100644 index 0000000..c522a68 Binary files /dev/null and b/Docs/Images/install-devcontainers-extension.png differ diff --git a/Docs/Images/reopen-in-container.png b/Docs/Images/reopen-in-container.png new file mode 100644 index 0000000..cdedd9f Binary files /dev/null and b/Docs/Images/reopen-in-container.png differ diff --git a/Docs/devcontainer.md b/Docs/devcontainer.md new file mode 100644 index 0000000..2dcee17 --- /dev/null +++ b/Docs/devcontainer.md @@ -0,0 +1,37 @@ +# Dev Container + +このリポジトリーには、VS Code の Dev Container を使用して開発するための設定が含まれています。 +確実に動作する Swift の開発環境が自動的に構築され、すべて Docker コンテナー内で実行されます。 +Docker コンテナーとのやりとりは VS Code が行ってくれます。 +もちろん、Docker コンテナーの外に影響を与えることはありません。 + +## 前提条件 + +- Docker がインストールされていること +- VS Code (または互換性のあるエディター、たとえば Cursor など)がインストールされていること + +## 開発環境の起動 + +こちらも参考にしてください:[開発ガイド](./development_guide.md) + +1. VS Code でこのリポジトリーを開きます + +2. もし、[Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) 拡張機能がインストールされていない場合は、インストールします。 + ただし、VS Code は Dev Container の設定ファイルを検出すると、自動的に拡張機能をインストールするように求めます。 + + ![Dev Containers 拡張機能をインストールする。`ms-vscode-remote.remote-containers` を検索するか、右下の通知をクリックしてインストールします。](Images/install-devcontainers-extension.png) + +3. 左下の `><` アイコンをクリックし、`Reopen in Container` を選択します。 + ただし、こちらも同様に、VS Code は Dev Container の設定ファイルを検出して、拡張機能がインストールされていれば、自動的に Dev Container を開くように求めます。 + + ![Dev Container を開く。左下の `><` アイコンをクリックし、`Reopen in Container` を選択するか、右下の通知をクリックして開きます。](Images/reopen-in-container.png) + +4. しばらくすると、Dev Container が起動します。 + 初回の起動時には、Docker イメージをダウンロードする必要があるので、かなり時間がかかります。 + 次回以降は、Docker イメージがキャッシュされるため、起動時間は短縮されます。 + +5. [Swift](https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang) の拡張機能が自動的にインストールされるようになっていて、この拡張機能が依存関係の解決を行います。 + +6. これで、Swift の開発環境が起動しました。 + Docker コンテナー内でコマンドを実行したければ、VS Code のターミナルを使用するのがいいでしょう。 + \ No newline at end of file