Skip to content

Commit

Permalink
add bat script and support running under Windows (#1631)
Browse files Browse the repository at this point in the history
  • Loading branch information
whummer committed Oct 7, 2019
1 parent 6da8c6d commit db109b9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 deletions.
1 change: 1 addition & 0 deletions bin/localstack.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python %~dp0\localstack %*
1 change: 1 addition & 0 deletions localstack/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@

# environment variable to indicates that this process is running the Web UI
LOCALSTACK_WEB_PROCESS = 'LOCALSTACK_WEB_PROCESS'
LOCALSTACK_INFRA_PROCESS = 'LOCALSTACK_INFRA_PROCESS'

# Hardcoded AWS account ID used by moto
MOTO_ACCOUNT_ID = '123456789012'
4 changes: 3 additions & 1 deletion localstack/services/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from requests.models import Response
from localstack import constants, config
from localstack.constants import (
ENV_DEV, LOCALSTACK_VENV_FOLDER, ENV_INTERNAL_TEST_RUN,
ENV_DEV, LOCALSTACK_VENV_FOLDER, ENV_INTERNAL_TEST_RUN, LOCALSTACK_INFRA_PROCESS,
DEFAULT_PORT_APIGATEWAY_BACKEND, DEFAULT_PORT_SNS_BACKEND,
DEFAULT_PORT_IAM_BACKEND, DEFAULT_PORT_EC2_BACKEND, DEFAULT_SERVICE_PORTS)
from localstack.utils import common, persistence
Expand Down Expand Up @@ -400,6 +400,8 @@ def check_infra(retries=10, expect_shutdown=False, apis=None, additional_checks=

def start_infra(asynchronous=False, apis=None):
try:
os.environ[LOCALSTACK_INFRA_PROCESS] = '1'

is_in_docker = in_docker()
# print a warning if we're not running in Docker but using Docker based LAMBDA_EXECUTOR
if not is_in_docker and 'docker' in config.LAMBDA_EXECUTOR and not is_linux():
Expand Down
24 changes: 22 additions & 2 deletions localstack/utils/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import re
import sys
import pty
import time
import select
import pkgutil
Expand Down Expand Up @@ -437,13 +436,18 @@ def run(cmd, print_error=True, asynchronous=False, stdin=False,
stdout_arg = open(outfile, 'wb') if isinstance(outfile, six.string_types) else outfile
stderr_arg = stderr
if tty:
# Note: leave the "pty" import here (not supported in Windows)
import pty
master_fd, slave_fd = pty.openpty()
stdin_arg = slave_fd
stdout_arg = stderr_arg = None

# start the actual sub process
kwargs = {}
if is_linux() or is_mac_os():
kwargs['preexec_fn'] = os.setsid
process = subprocess.Popen(cmd, shell=True, stdin=stdin_arg, bufsize=-1,
stderr=stderr_arg, stdout=stdout_arg, env=env_dict, cwd=cwd, preexec_fn=os.setsid)
stderr=stderr_arg, stdout=stdout_arg, env=env_dict, cwd=cwd, **kwargs)

if tty:
# based on: https://stackoverflow.com/questions/41542960
Expand All @@ -468,6 +472,22 @@ def pipe_streams(*args):
raise e


def is_mac_os():
try:
out = to_str(subprocess.check_output('uname -a', shell=True))
return 'Darwin' in out
except subprocess.CalledProcessError:
return False


def is_linux():
try:
out = to_str(subprocess.check_output('uname -a', shell=True))
return 'Linux' in out
except subprocess.CalledProcessError:
return False


def mkdir(folder):
if not os.path.exists(folder):
try:
Expand Down
18 changes: 5 additions & 13 deletions localstack/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,11 +587,11 @@ def is_number(s):


def is_mac_os():
try:
out = to_str(subprocess.check_output('uname -a', shell=True))
return 'Darwin' in out
except subprocess.CalledProcessError:
return False
return bootstrap.is_mac_os()


def is_linux():
return bootstrap.is_linux()


def is_alpine():
Expand All @@ -602,14 +602,6 @@ def is_alpine():
return False


def is_linux():
try:
out = to_str(subprocess.check_output('uname -a', shell=True))
return 'Linux' in out
except subprocess.CalledProcessError:
return False


def short_uid():
return str(uuid.uuid4())[0:8]

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
author='Waldemar Hummer',
author_email='waldemar.hummer@gmail.com',
url='https://github.com/localstack/localstack',
scripts=['bin/localstack'],
scripts=['bin/localstack', 'bin/localstack.bat'],
packages=find_packages(exclude=('tests', 'tests.*')),
package_data=package_data,
install_requires=install_requires,
Expand Down

0 comments on commit db109b9

Please sign in to comment.