Skip to content

Commit

Permalink
fix CLI command to enable starting the proxy from within Docker (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
whummer authored Jul 25, 2024
1 parent 2f0ac6f commit 1e7ec82
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/aws-replicator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python 3.10
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'

- name: Set up Terraform CLI
uses: hashicorp/setup-terraform@v2
Expand All @@ -32,8 +32,10 @@ jobs:
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
run: |
set -e
docker pull localstack/localstack-pro &
docker pull public.ecr.aws/lambda/python:3.8 &
# install latest CLI packages (dev releases)
pip install --upgrade --pre localstack localstack-ext
Expand All @@ -48,7 +50,11 @@ jobs:
localstack extensions init
(
cd aws-replicator
make install && make build && make enable
make install
. .venv/bin/activate
pip install --upgrade --pre localstack localstack-ext
make build
make enable
)
# install awslocal/tflocal command lines
Expand Down
9 changes: 6 additions & 3 deletions aws-replicator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ VENV_RUN = . $(VENV_ACTIVATE)
TEST_PATH ?= tests
PIP_CMD ?= pip

usage: ## Show this help
@grep -Fh "##" $(MAKEFILE_LIST) | grep -Fv fgrep | sed -e 's/:.*##\s*/##/g' | awk -F'##' '{ printf "%-25s %s\n", $$1, $$2 }'

venv: $(VENV_ACTIVATE)

$(VENV_ACTIVATE): setup.py setup.cfg
Expand Down Expand Up @@ -40,13 +43,13 @@ build: ## Build the extension
cp -r setup.py setup.cfg README.md aws_replicator build/
(cd build && python setup.py sdist)

enable: $(wildcard ./build/dist/localstack-extension-aws-replicator-*.tar.gz) ## Enable the extension in LocalStack
enable: $(wildcard ./build/dist/localstack_extension_aws_replicator-*.tar.gz) ## Enable the extension in LocalStack
$(VENV_RUN); \
pip uninstall --yes localstack-extension-aws-replicator; \
localstack extensions -v install file://./$?
localstack extensions -v install file://$?

publish: clean-dist venv dist
$(VENV_RUN); pip install --upgrade twine; twine upload dist/*
$(VENV_RUN); cd build; pip install --upgrade twine; twine upload dist/*

clean-dist: clean
rm -rf dist/
Expand Down
1 change: 1 addition & 0 deletions aws-replicator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ localstack extensions install "git+https://github.com/localstack/localstack-exte

## Change Log

* `0.1.18`: Update environment check to use SDK Docker client and enable starting the proxy from within Docker (e.g., from the LS main container as part of an init script)
* `0.1.17`: Add basic support for ARN-based pattern-matching for `secretsmanager` resources
* `0.1.16`: Update imports for localstack >=3.6 compatibility
* `0.1.15`: Move localstack dependency installation to extra since it's provided at runtime
Expand Down
9 changes: 6 additions & 3 deletions aws-replicator/aws_replicator/client/auth_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import requests
from botocore.awsrequest import AWSPreparedRequest
from botocore.model import OperationModel
from localstack import config
from localstack import config as localstack_config
from localstack.aws.spec import load_service
from localstack.config import external_service_url
Expand Down Expand Up @@ -51,7 +50,7 @@

LOG = logging.getLogger(__name__)
LOG.setLevel(logging.INFO)
if config.DEBUG:
if localstack_config.DEBUG:
LOG.setLevel(logging.DEBUG)

# TODO make configurable
Expand Down Expand Up @@ -371,10 +370,14 @@ def start_aws_auth_proxy_in_container(
target_host = get_docker_host_from_container()
env_vars["LOCALSTACK_HOST"] = target_host

# Use the Docker SDK command either if quiet mode is enabled, or if we're executing
# in Docker itself (e.g., within the LocalStack main container, as part of an init script)
use_docker_sdk_command = quiet or localstack_config.is_in_docker

try:
print("Proxy container is ready.")
command = f"{venv_activate}; localstack aws proxy -c {CONTAINER_CONFIG_FILE} -p {port} --host 0.0.0.0 > {CONTAINER_LOG_FILE} 2>&1"
if quiet:
if use_docker_sdk_command:
DOCKER_CLIENT.exec_in_container(
container_name, command=["bash", "-c", command], env_vars=env_vars, interactive=True
)
Expand Down
2 changes: 1 addition & 1 deletion aws-replicator/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = localstack-extension-aws-replicator
version = 0.1.17
version = 0.1.18
summary = LocalStack Extension: AWS replicator
description = Replicate AWS resources into your LocalStack instance
long_description = file: README.md
Expand Down

0 comments on commit 1e7ec82

Please sign in to comment.