#!/bin/bash # ファイルフルパス INITIAL_DIR=$(pwd) LOG_FILE="$INITIAL_DIR/logfile.log" ODMS_CLOUD_DIR="../" # ログ関数 log_message() { echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE" } # 1: ODMS Cloudにディレクトリ変更docker-compose up実行 cd $ODMS_CLOUD_DIR 2>>"$LOG_FILE" if [ $? -ne 0 ]; then log_message "ERROR: Failed to navigate to /ODMS%Cloud/" exit 1 else log_message "Navigated to /ODMS%Cloud/" fi log_message "Running docker-compose up -d" docker-compose up -d 2>>"$LOG_FILE" if [ $? -ne 0 ]; then log_message "ERROR: Failed to run docker-compose up -d" exit 1 else log_message "Successfully ran docker-compose up -d" fi # 2: dictation_clientにDev Container起動する log_message "Starting Dev Container in dictation_client/" devcontainer up --workspace-folder "dictation_client/" 2>>"$LOG_FILE" if [ $? -ne 0 ]; then log_message "ERROR: Failed to start Dev Container in dictation_client/" exit 1 else log_message "Dev Container started in dictation_client/" fi # DevContainerの起動待ち log_message "Waiting for Dev Container to be ready..." sleep 5 # 3: コンテナーID・名取得 log_message "Retrieving the container ID of the Dev Container" CONTAINER_ID=$(docker ps --filter "label=devcontainer.local_folder=$(pwd)/dictation_client" --format "{{.ID}}") if [ -z "$CONTAINER_ID" ]; then log_message "ERROR: Could not find the Dev Container for dictation_client/" exit 1 else log_message "Found Dev Container with ID: $CONTAINER_ID" fi # 4: docker execでDev Containerに'npm install'実行 COMMAND="npm install" log_message "Executing command inside Dev Container: $COMMAND" docker exec --user vscode "$CONTAINER_ID" $COMMAND >>"$LOG_FILE" 2>&1 if [ $? -ne 0 ]; then log_message "ERROR: Command execution failed inside Dev Container" exit 1 else log_message "Command executed successfully inside Dev Container" fi # 5: 'npm run build:local'実行 COMMAND="npm run build:local" log_message "Executing command inside Dev Container: $COMMAND" docker exec --user vscode "$CONTAINER_ID" $COMMAND >>"$LOG_FILE" 2>&1 if [ $? -ne 0 ]; then log_message "ERROR: Command execution failed inside Dev Container" exit 1 else log_message "Command executed successfully inside Dev Container" fi