Skip to content

Commit

Permalink
autostart and docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzon committed Jan 12, 2024
1 parent e6bc71c commit 03212e2
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class LocalstackPlugin {
* Start the LocalStack container in Docker, if it is not running yet.
*/
startLocalStack() {
if (!this.config.autostart) {
if (!this.config.autostart || !this.isActive()) {
return Promise.resolve();
}

Expand Down Expand Up @@ -452,27 +452,42 @@ class LocalstackPlugin {
return containerID;
}

const startContainer = () => {
this.log('Starting LocalStack in Docker. This can take a while.');
const cwd = process.cwd();
const env = this.clone(process.env);
env.DEBUG = '1';
env.LAMBDA_EXECUTOR = env.LAMBDA_EXECUTOR || 'docker';
env.LAMBDA_REMOTE_DOCKER = env.LAMBDA_REMOTE_DOCKER || '0';
env.DOCKER_FLAGS = (env.DOCKER_FLAGS || '') + ` -d -v ${cwd}:${cwd}`;
env.START_WEB = env.START_WEB || '0';
const maxBuffer = (+env.EXEC_MAXBUFFER)||50*1000*1000; // 50mb buffer to handle output
if (this.shouldRunDockerSudo()) {
env.DOCKER_CMD = 'sudo docker';
}
const options = {env: env, maxBuffer};
return exec('localstack start', options).then(getContainer)
.then((containerID) => addNetworks(containerID))
.then((containerID) => checkStatus(containerID));
}

const startCompose = () => {
return exec(`docker-compose -f ${this.config.compose_file} `).then(getContainer)
}

return getContainer().then(
(containerID) => {
if(containerID) {
return;
}
this.log('Starting LocalStack in Docker. This can take a while.');
const cwd = process.cwd();
const env = this.clone(process.env);
env.DEBUG = '1';
env.LAMBDA_EXECUTOR = env.LAMBDA_EXECUTOR || 'docker';
env.LAMBDA_REMOTE_DOCKER = env.LAMBDA_REMOTE_DOCKER || '0';
env.DOCKER_FLAGS = (env.DOCKER_FLAGS || '') + ` -d -v ${cwd}:${cwd}`;
env.START_WEB = env.START_WEB || '0';
const maxBuffer = (+env.EXEC_MAXBUFFER)||50*1000*1000; // 50mb buffer to handle output
if (this.shouldRunDockerSudo()) {
env.DOCKER_CMD = 'sudo docker';

if(this.config.compose_file){
console.log("Using docker-compose file: " + this.config.compose_file)

Check failure on line 485 in src/index.js

View workflow job for this annotation

GitHub Actions / Serverless LocalStack CI (2)

Unexpected console statement
return startCompose();
}
const options = {env: env, maxBuffer};
return exec('localstack start', options).then(getContainer)
.then((containerID) => addNetworks(containerID))
.then((containerID) => checkStatus(containerID));
console.log("No docker-compose file: ")

Check failure on line 488 in src/index.js

View workflow job for this annotation

GitHub Actions / Serverless LocalStack CI (2)

Unexpected console statement

return startContainer();
}
);
}
Expand Down

0 comments on commit 03212e2

Please sign in to comment.