azarasi1226 / inaba-backend

0 stars 0 forks source link

Devcontainersを利用した開発環境構築の簡易化 #4

Open keloud opened 5 months ago

keloud commented 5 months ago

重要度

低い、今から変更してもただ混乱のもとのような気もしている

概要

Devcontainersを利用した開発環境構築の簡易化

目的

内容

VSCodeのDevcontainersをIntellij IDEAでもサポートしているため、リモート開発からリポジトリをクローンするだけで環境を構築できる設定ファイルを作成する

keloud commented 5 months ago

プロジェクトディレクトリ/.devcontainer ディレクトリを作成する 中に以下のファイルを追加する

devcontainer.json

// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/java
{
    "name": "inaba Project",
    // "image": "mcr.microsoft.com/devcontainers/java:1-21-bullseye",
    "dockerComposeFile": "docker-compose.yml",
    "service": "app",
    "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",

    // Features to add to the dev container. More info: https://containers.dev/features.
    // "features": {}

    // 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": "java -version",

    // Configure tool-specific properties.
    // "customizations": {},

    // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
    // "remoteUser": "root"
}

docker-compose.yml

services:
  app:
    build: 
      context: .
      dockerfile: Dockerfile
    volumes:
      - ../..:/workspaces:cached
    command: sleep infinity

  axon-server:
    image: axoniq/axonserver:latest
    healthcheck:
      test: curl -f http://localhost:8024/actuator/health || exit 1;
    expose:
      - 8024
      - 8124

  common-datastore:
    image: mysql:latest
    expose:
      - 3306
    environment:
      MYSQL_ROOT_PASSWORD: passw0rd

  cognito:
    image: jagregory/cognito-local:latest
    expose:
      - 9229

Dockerfile

FROM mcr.microsoft.com/devcontainers/java:1-21-bullseye