Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
push image from CI; minor fixes in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
whummer committed Apr 29, 2017
1 parent 9015062 commit a240285
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
17 changes: 13 additions & 4 deletions Makefile
@@ -1,4 +1,5 @@
IMAGE_NAME ?= atlassianlabs/localstack
IMAGE_TAG ?= $(shell cat setup.py | grep version= | sed "s/.*version=['\"]\(.*\)['\"].*/\1/")
VENV_DIR = .venv
VENV_RUN = . $(VENV_DIR)/bin/activate
AWS_STS_URL = http://central.maven.org/maven2/com/amazonaws/aws-java-sdk-sts/1.11.14/aws-java-sdk-sts-1.11.14.jar
Expand Down Expand Up @@ -37,7 +38,7 @@ compile: ## Compile Java code (KCL library utils)
# TODO enable once we want to support Java-based Lambdas
# (cd localstack/mock && mvn package)

publish: ## Publish the library to a PyPi repository
publish: ## Publish the library to the central PyPi repository
# build and upload archive
($(VENV_RUN) && ./setup.py sdist upload)

Expand All @@ -52,15 +53,23 @@ infra: ## Manually start the local infrastructure for testing

docker-build: ## Build Docker image
docker build -t $(IMAGE_NAME) .
docker tag $(IMAGE_NAME) $(IMAGE_NAME):$(shell cat setup.py | grep version= | sed "s/.*version=['\"]\(.*\)['\"].*/\1/")
docker tag $(IMAGE_NAME) $(IMAGE_NAME):$(IMAGE_TAG)

docker-push: ## Push Docker image to registry
docker push $(IMAGE_NAME)
docker push $(IMAGE_NAME):$(IMAGE_TAG)

docker-push-master:## Push Docker image to registry IF we are currently on the master branch
(test `git rev-parse --abbrev-ref HEAD` != 'master' && echo "Not on master branch.") || \
(which pip || (wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py); \
which docker-squash || pip install docker-squash; \
docker info | grep Username || docker login -u $$DOCKER_USERNAME -p $$DOCKER_PASSWORD; \
docker-squash -t $(IMAGE_NAME):$(IMAGE_TAG) $(IMAGE_NAME):$(IMAGE_TAG) && docker tag $(IMAGE_NAME):$(IMAGE_TAG) $(IMAGE_NAME):latest; \
docker push $(IMAGE_NAME):$(IMAGE_TAG) && docker push $(IMAGE_NAME):latest)

docker-run: ## Run Docker image locally
port_mappings="$(shell echo $(SERVICES) | sed 's/[^0-9]/ /g' | sed 's/\([0-9][0-9]*\)/-p \1:\1/g' | sed 's/ */ /g')"; \
mkdir -p $(TMP_DIR); \
docker run -it $(ENTRYPOINT) -e DEBUG=$(DEBUG) -e SERVICES=$(SERVICES) -e LAMDA_EXECUTOR=$(LAMDA_EXECUTOR) -e KINESIS_ERROR_PROBABILITY=$(KINESIS_ERROR_PROBABILITY) -p 4567-4581:4567-4581 -p 8080:8080 $$port_mappings -v $(TMP_DIR):$(TMP_DIR) -v $(DOCKER_SOCK):$(DOCKER_SOCK) -e DOCKER_HOST="unix://$(DOCKER_SOCK)" $(IMAGE_NAME) $(CMD)
docker run -it $(ENTRYPOINT) -e DEBUG=$(DEBUG) -e SERVICES=$(SERVICES) -e LAMBDA_EXECUTOR=$(LAMBDA_EXECUTOR) -e KINESIS_ERROR_PROBABILITY=$(KINESIS_ERROR_PROBABILITY) -p 4567-4581:4567-4581 -p 8080:8080 $$port_mappings -v $(TMP_DIR):$(TMP_DIR) -v $(DOCKER_SOCK):$(DOCKER_SOCK) -e DOCKER_HOST="unix://$(DOCKER_SOCK)" $(IMAGE_NAME) $(CMD)

web: ## Start web application (dashboard)
($(VENV_RUN); bin/localstack web --port=8080)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -113,7 +113,7 @@ You can pass the following environment variables to LocalStack:
inject `ProvisionedThroughputExceededException` errors into Kinesis API responses.
* `DYNAMODB_ERROR_PROBABILITY`: Decimal value between 0.0 (default) and 1.0 to randomly
inject `ProvisionedThroughputExceededException` errors into DynamoDB API responses.
* `LAMDA_EXECUTOR`: Method to use for executing Lambda functions. Valid values are `local` (run
* `LAMBDA_EXECUTOR`: Method to use for executing Lambda functions. Valid values are `local` (run
the code in a temporary directory on the local machine) or `docker` (run code in a separate
Docker container). In the latter case, if *LocalStack* itself is started inside Docker, then
the `docker` command needs to be available inside the container (usually requires to run the
Expand Down
1 change: 1 addition & 0 deletions bitbucket-pipelines.yml
Expand Up @@ -8,3 +8,4 @@ pipelines:
- step:
script:
- make docker-build
- make docker-push-master
2 changes: 1 addition & 1 deletion localstack/config.py
Expand Up @@ -12,7 +12,7 @@
HOSTNAME = os.environ.get('HOSTNAME') or LOCALHOST

# whether to use Lambda functions in a Docker container
LAMDA_EXECUTOR = os.environ.get('LAMDA_EXECUTOR') or 'docker'
LAMBDA_EXECUTOR = os.environ.get('LAMBDA_EXECUTOR') or 'docker'

# temporary folder
TMP_FOLDER = '/tmp/localstack'
Expand Down
5 changes: 3 additions & 2 deletions localstack/mock/apis/lambda_api.py
Expand Up @@ -29,6 +29,7 @@

LAMBDA_RUNTIME_PYTHON27 = 'python2.7'
LAMBDA_RUNTIME_NODEJS = 'nodejs'
LAMBDA_RUNTIME_NODEJS610 = 'nodejs6.10'
LAMBDA_RUNTIME_JAVA = 'java8'

LAMBDA_DEFAULT_HANDLER = 'handler.handler'
Expand Down Expand Up @@ -101,7 +102,7 @@ def use_docker():
global DO_USE_DOCKER
if DO_USE_DOCKER is None:
DO_USE_DOCKER = False
if config.LAMDA_EXECUTOR == 'docker':
if config.LAMBDA_EXECUTOR == 'docker':
try:
run('docker images', print_error=False)
DO_USE_DOCKER = True
Expand Down Expand Up @@ -221,7 +222,7 @@ def exec_lambda_code(script, handler_function='handler', lambda_cwd=None):

def get_handler_file_from_name(handler_name, runtime=LAMBDA_RUNTIME_PYTHON27):
# TODO: support Java Lambdas in the future
file_ext = '.js' if runtime == LAMBDA_RUNTIME_NODEJS else '.py'
file_ext = '.js' if runtime.startswith(LAMBDA_RUNTIME_NODEJS) else '.py'
return '%s%s' % (handler_name.split('.')[0], file_ext)


Expand Down
2 changes: 1 addition & 1 deletion localstack/mock/generic_proxy.py
Expand Up @@ -131,7 +131,7 @@ def run_cmd(self, params):
self.httpd.serve_forever()
except Exception, e:
if not self.quiet:
LOGGER.error(traceback.format_exc(e))
LOGGER.error('Unable to start proxy on port %s: %s' % (self.port, traceback.format_exc()))
raise

def stop(self, quiet=False):
Expand Down
6 changes: 3 additions & 3 deletions localstack/mock/infra.py
Expand Up @@ -75,7 +75,7 @@ def start_elasticsearch(port=PORT_ELASTICSEARCH, delete_data=True, async=False,
start_proxy(port, backend_port, update_listener, quiet=True)
if is_root():
cmd = "su -c '%s' localstack" % cmd
thread = do_run(cmd, async)
thread = do_run(cmd, async, print_output=True)
return thread


Expand Down Expand Up @@ -284,7 +284,7 @@ def check_infra_elasticsearch(expect_shutdown=False, print_error=False):
assert isinstance(out, basestring)


def check_infra(retries=7, expect_shutdown=False, apis=None, additional_checks=[]):
def check_infra(retries=8, expect_shutdown=False, apis=None, additional_checks=[]):
try:
print_error = retries <= 0
# check Kinesis
Expand Down Expand Up @@ -349,10 +349,10 @@ def start_infra(async=False,
aws_stack.delete_all_elasticsearch_data()
# run actual Elasticsearch endpoint
thread = start_elasticsearch(async=True)
sleep_time = max(sleep_time, 5)
if 'es' in apis:
# run Elasticsearch Service (ES) endpoint
thread = start_elasticsearch_service(async=True)
sleep_time = max(sleep_time, 5)
if 's3' in apis:
thread = start_s3(async=True, update_listener=s3_update_listener)
sleep_time = max(sleep_time, 3)
Expand Down

0 comments on commit a240285

Please sign in to comment.