@@ -1059,6 +1059,7 @@ export async function importExternalStack(stackId: string): Promise<Stack> {
1059
1059
1060
1060
// 3. Read the compose file if available, or create a new one
1061
1061
let composeContent = '' ;
1062
+ let envContent : string | undefined = undefined ; // Variable to store .env content
1062
1063
let actualComposeFilePathUsed = '' ; // For logging the path that was attempted
1063
1064
1064
1065
const configFilesLabel = labels [ 'com.docker.compose.project.config_files' ] ;
@@ -1094,6 +1095,21 @@ export async function importExternalStack(stackId: string): Promise<Stack> {
1094
1095
console . log ( `Attempting to read compose file for import from: ${ actualComposeFilePathUsed } ` ) ;
1095
1096
composeContent = await fs . readFile ( actualComposeFilePathUsed , 'utf8' ) ;
1096
1097
console . log ( `Successfully read compose file: ${ actualComposeFilePathUsed } . Content length: ${ composeContent . length } ` ) ;
1098
+
1099
+ // Attempt to read .env file from the same directory
1100
+ const composeFileDir = path . dirname ( actualComposeFilePathUsed ) ;
1101
+ const envFilePath = path . join ( composeFileDir , '.env' ) ;
1102
+ try {
1103
+ envContent = await fs . readFile ( envFilePath , 'utf8' ) ;
1104
+ console . log ( `Successfully read .env file from: ${ envFilePath } ` ) ;
1105
+ } catch ( envErr ) {
1106
+ const nodeEnvErr = envErr as NodeJS . ErrnoException ;
1107
+ if ( nodeEnvErr . code === 'ENOENT' ) {
1108
+ console . log ( `.env file not found at ${ envFilePath } , proceeding without it.` ) ;
1109
+ } else {
1110
+ console . warn ( `Could not read .env file at ${ envFilePath } during import:` , envErr ) ;
1111
+ }
1112
+ }
1097
1113
} catch ( err ) {
1098
1114
console . warn ( `Could not read compose file at ${ actualComposeFilePathUsed } during import:` , err ) ;
1099
1115
// composeContent will remain empty, leading to generation logic below
@@ -1117,7 +1133,7 @@ export async function importExternalStack(stackId: string): Promise<Stack> {
1117
1133
const serviceName = containerLabels [ 'com.docker.compose.service' ] || cont . Names [ 0 ] ?. replace ( `/${ stackId } _` , '' ) . replace ( / _ \d + $ / , '' ) || `service_${ cont . Id . substring ( 0 , 8 ) } ` ;
1118
1134
1119
1135
// Inspect the container to get more details
1120
- const containerDetails = await docker . getContainer ( cont . Id ) . inspect ( ) ;
1136
+ // const containerDetails = await docker.getContainer(cont.Id).inspect(); // Uncomment if more details are needed
1121
1137
1122
1138
services [ serviceName ] = {
1123
1139
image : cont . Image
@@ -1135,11 +1151,12 @@ export async function importExternalStack(stackId: string): Promise<Stack> {
1135
1151
1136
1152
services:
1137
1153
${ yaml . dump ( { services } , { indent : 2 } ) . substring ( 'services:' . length ) . trimStart ( ) } `;
1154
+ // Note: If compose file is generated, we don't have a path to look for an associated .env file.
1155
+ // envContent will remain undefined in this case.
1138
1156
}
1139
1157
1140
1158
// 5. Create a new stack in Arcane's managed stacks
1141
- // The createStack function will set hasArcaneMeta to true.
1142
- return await createStack ( stackId , composeContent ) ;
1159
+ return await createStack ( stackId , composeContent , envContent ) ; // Pass envContent here
1143
1160
}
1144
1161
1145
1162
/**
0 commit comments