Add devcontainer.json for Swift development and daily update schedule for devcontainers package ecosystem (#55)

* Add devcontainer.json for Swift development

* Add daily update schedule for devcontainers package ecosystem

* Add Dev Container setup for Swift development

* Add Swift Build and Test workflow in DevContainer

* Fix typo in devcontainer.md

* Add Docker installation step for macOS

* Update Docker installation command in macOS workflow

* Update Docker.app path in macOS workflow

* Add docker buildx version check

* Update devcontainer.md with instructions for setting up the development environment

* Refactor GitHub workflow for Swift in DevContainer

* Fix typo in devcontainer.md

* Add installation instructions for Dev Containers extension

* Add Dev Container instructions

* Remove unnecessary command installation

* Add link to development guide
This commit is contained in:
Kawahara Shotaro
2024-03-18 01:04:19 +09:00
committed by GitHub
parent 7096568aac
commit 107796f13e
6 changed files with 109 additions and 0 deletions

View File

@ -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"
}

View File

@ -19,3 +19,8 @@ updates:
directory: "/" # Location of package manifests directory: "/" # Location of package manifests
schedule: schedule:
interval: "daily" interval: "daily"
- package-ecosystem: "devcontainers" # See documentation for possible values
directory: "/.devcontainer" # Location of package manifests
schedule:
interval: "daily"

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

37
Docs/devcontainer.md Normal file
View File

@ -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 のターミナルを使用するのがいいでしょう。