Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,58 @@
| `app-builder` | Web API Builder | |


## 🚀 Multi-Architecture Support (ARM64/Graviton)

このプロジェクトは、AWS Gravitonプロセッサ(ARM64アーキテクチャ)をサポートしています。

### 特徴
- **マルチアーキテクチャ対応**: AMD64(x86_64)とARM64の両方のアーキテクチャに対応
- **自動ビルド**: AWS CodeBuildでDocker Buildxを使用して自動的にマルチプラットフォームイメージをビルド
- **Graviton最適化**: AWS Gravitonインスタンスで実行することでコストパフォーマンスが向上

### ビルドの仕組み
`deploy/buildspec.yml`では、Docker Composeを使用してマルチプラットフォームイメージをビルドしています:

```bash
docker compose --file compose.production.yaml build --push
```

`compose.production.yaml`には、各サービスに`platforms`設定が追加されています:

```yaml
services:
web:
build:
platforms:
- linux/amd64
- linux/arm64
# ... 他の設定
```

### ローカル開発環境でのマルチプラットフォームビルド
ローカル環境でマルチプラットフォームイメージをビルドする場合、以下の2つの方法があります:

#### 方法1: Docker Compose(推奨)
```bash
# 通常のdocker composeコマンドでビルド(プッシュなし)
docker compose -f compose.production.yaml build

# プッシュも含める場合
docker compose -f compose.production.yaml build --push
```

#### 方法2: Docker Buildx Bake
```bash
# Docker Buildxの初期化
docker buildx create --name multi-platform-builder --use
docker buildx inspect --bootstrap

# Buildx bakeを使ったマルチプラットフォームビルド
docker buildx bake -f compose.production.yaml --push
```

**注意**: 方法1はDocker Compose v2.4.0以降が必要です。古いバージョンを使用している場合は方法2をご利用ください。

### ECSでの使用
- ECSタスク定義で`arm64`アーキテクチャを指定することで、Gravitonインスタンスでコンテナを実行できます
- 同じイメージがAMD64とARM64の両方で動作するため、アーキテクチャ間の移行が容易です
9 changes: 9 additions & 0 deletions compose.production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ services:
additional_contexts:
# apache-ctx: ./docker/web/apache
nginx-ctx: ./docker/web/nginx
platforms:
- linux/amd64
- linux/arm64
args:
BUILDKIT_INLINE_CACHE: 1
USER_UID: "${USER_UID-1000}"
Expand Down Expand Up @@ -67,6 +70,9 @@ services:
additional_contexts:
php-fpm-ctx: ./docker/app/php-fpm
src-ctx: ./src
platforms:
- linux/amd64
- linux/arm64
args:
BUILDKIT_INLINE_CACHE: 1
USER_UID: "${USER_UID-1000}"
Expand Down Expand Up @@ -116,6 +122,9 @@ services:
additional_contexts:
php-fpm-ctx: ./docker/app/php-fpm
src-ctx: ./src
platforms:
- linux/amd64
- linux/arm64
args:
BUILDKIT_INLINE_CACHE: 1
USER_UID: "${USER_UID-1000}"
Expand Down
6 changes: 5 additions & 1 deletion deploy/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ phases:
- APP_IMAGE_REPO_URI=${ECR_ENDPOINT}/${APP_IMAGE_REPO_NAME}
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_HASH:=latest}

- echo 🔧 Installing Docker Buildx for multi-platform builds...
- docker buildx create --name multi-platform-builder --use
- docker buildx inspect --bootstrap

pre_build:
commands:
Expand All @@ -30,7 +34,7 @@ phases:

build:
commands:
- echo 🐳 Building the Docker image..
- echo 🐳 Building the Docker images for multiple platforms (linux/amd64,linux/arm64)...
- docker compose --file compose.production.yaml build --push

- echo ✨ Build completed on `date`
Expand Down