From 9614b49d73de0c9e14fcccd1d5faaaf4693f168e Mon Sep 17 00:00:00 2001 From: Waldemar Hummer Date: Thu, 11 Dec 2025 14:19:15 -0800 Subject: [PATCH 1/4] add simple CI build for wiremock extension --- .../workflows/{test.yml => test-typedb.yml} | 6 +-- .github/workflows/test-wiremock.yml | 53 +++++++++++++++++++ localstack-wiremock/README.md | 4 +- 3 files changed, 58 insertions(+), 5 deletions(-) rename .github/workflows/{test.yml => test-typedb.yml} (91%) create mode 100644 .github/workflows/test-wiremock.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test-typedb.yml similarity index 91% rename from .github/workflows/test.yml rename to .github/workflows/test-typedb.yml index 3200b25..907a672 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test-typedb.yml @@ -5,12 +5,12 @@ on: branches: - main paths: - - 'localstack-wiremock/**' + - 'localstack-typedb/**' push: branches: - main paths: - - 'localstack-wiremock/**' + - 'localstack-typedb/**' workflow_dispatch: env: @@ -19,7 +19,7 @@ env: jobs: integration-tests: - name: Run Integration Tests + name: Run TypeDB Extension Tests runs-on: ubuntu-latest timeout-minutes: 10 steps: diff --git a/.github/workflows/test-wiremock.yml b/.github/workflows/test-wiremock.yml new file mode 100644 index 0000000..0f12b45 --- /dev/null +++ b/.github/workflows/test-wiremock.yml @@ -0,0 +1,53 @@ +name: LocalStack WireMock Extension Tests + +on: + pull_request: + branches: + - main + paths: + - 'localstack-wiremock/**' + push: + branches: + - main + paths: + - 'localstack-wiremock/**' + workflow_dispatch: + +env: + LOCALSTACK_DISABLE_EVENTS: "1" + LOCALSTACK_AUTH_TOKEN: ${{ secrets.TEST_LOCALSTACK_AUTH_TOKEN }} + +jobs: + integration-tests: + name: Run WireMock Extension Tests + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup LocalStack and extension + run: | + cd localstack-wiremock + + docker pull localstack/localstack-pro & + docker pull wiremock/wiremock & + pip install localstack terraform-local + + make install + make dist + localstack extensions -v install file://$(ls ./dist/localstack_wiremock-*.tar.gz) + + DEBUG=1 localstack start -d + localstack wait + + - name: Run sample app test + run: | + cd localstack-wiremock + make sample + + - name: Print logs + if: always() + run: | + localstack logs + localstack stop diff --git a/localstack-wiremock/README.md b/localstack-wiremock/README.md index 6295ecf..f00b1fa 100644 --- a/localstack-wiremock/README.md +++ b/localstack-wiremock/README.md @@ -1,7 +1,7 @@ WireMock on LocalStack -=============================== +======================== -This repo contains a [LocalStack Extension](https://github.com/localstack/localstack-extensions) that facilitates developing WireMock-based applications locally. +This repo contains a [LocalStack Extension](https://github.com/localstack/localstack-extensions) that facilitates developing [WireMock](https://wiremock.org)-based applications locally. ## Prerequisites From 68ce396c789bf96833b094a0394f9c66253b0466 Mon Sep 17 00:00:00 2001 From: Waldemar Hummer Date: Thu, 11 Dec 2025 14:26:30 -0800 Subject: [PATCH 2/4] minor fixes --- .github/workflows/test-wiremock.yml | 7 +++++-- localstack-wiremock/Makefile | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-wiremock.yml b/.github/workflows/test-wiremock.yml index 0f12b45..526668c 100644 --- a/.github/workflows/test-wiremock.yml +++ b/.github/workflows/test-wiremock.yml @@ -26,13 +26,16 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Setup LocalStack and extension + - name: Set up Terraform + uses: hashicorp/setup-terraform@v3 + + - name: Set up LocalStack and extension run: | cd localstack-wiremock docker pull localstack/localstack-pro & docker pull wiremock/wiremock & - pip install localstack terraform-local + pip install localstack terraform-local awscli-local[ver1] make install make dist diff --git a/localstack-wiremock/Makefile b/localstack-wiremock/Makefile index cb86e37..c46f91b 100644 --- a/localstack-wiremock/Makefile +++ b/localstack-wiremock/Makefile @@ -42,7 +42,7 @@ sample: ## Deploy sample app bin/create-stubs.sh (cd sample-app; tflocal init; tflocal apply -auto-approve) apiId=$$(awslocal apigateway get-rest-apis | jq -r '.items[0].id'); \ - curl -k https://$$apiId.execute-api.us-east-1.localhost.localstack.cloud/dev/time-off + curl -k https://$$apiId.execute-api.us-east-1.localhost.localstack.cloud/dev/time-off | grep time_off_date clean-dist: clean rm -rf dist/ From 51f5164b2feac87eddae8bcd81fb29164a69a4df Mon Sep 17 00:00:00 2001 From: Waldemar Hummer Date: Thu, 11 Dec 2025 15:55:43 -0800 Subject: [PATCH 3/4] minor fixes --- .github/workflows/test-typedb.yml | 2 +- .github/workflows/test-wiremock.yml | 1 + localstack-wiremock/Makefile | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-typedb.yml b/.github/workflows/test-typedb.yml index 907a672..45c9fa9 100644 --- a/.github/workflows/test-typedb.yml +++ b/.github/workflows/test-typedb.yml @@ -26,7 +26,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Setup LocalStack and extension + - name: Set up LocalStack and extension run: | cd localstack-typedb diff --git a/.github/workflows/test-wiremock.yml b/.github/workflows/test-wiremock.yml index 526668c..5bf7c0d 100644 --- a/.github/workflows/test-wiremock.yml +++ b/.github/workflows/test-wiremock.yml @@ -35,6 +35,7 @@ jobs: docker pull localstack/localstack-pro & docker pull wiremock/wiremock & + docker pull public.ecr.aws/lambda/python:3.9 & pip install localstack terraform-local awscli-local[ver1] make install diff --git a/localstack-wiremock/Makefile b/localstack-wiremock/Makefile index c46f91b..28a654f 100644 --- a/localstack-wiremock/Makefile +++ b/localstack-wiremock/Makefile @@ -39,10 +39,14 @@ test: ## Run integration tests (requires LocalStack running with the Extens $(VENV_RUN); pytest tests $(PYTEST_ARGS) sample: ## Deploy sample app + echo "Creating stubs in WireMock ..." bin/create-stubs.sh + echo "Deploying sample app into LocalStack via Terraform ..." (cd sample-app; tflocal init; tflocal apply -auto-approve) apiId=$$(awslocal apigateway get-rest-apis | jq -r '.items[0].id'); \ - curl -k https://$$apiId.execute-api.us-east-1.localhost.localstack.cloud/dev/time-off | grep time_off_date + endpoint=https://$$apiId.execute-api.us-east-1.localhost.localstack.cloud/dev/time-off; \ + echo "Invoking local API Gateway endpoint: $$endpoint"; \ + curl -k -v $$endpoint | grep time_off_date clean-dist: clean rm -rf dist/ From 2b9db5164c11cc9a99f5b05986c111e917b087de Mon Sep 17 00:00:00 2001 From: Waldemar Hummer Date: Thu, 11 Dec 2025 16:37:24 -0800 Subject: [PATCH 4/4] update container host name --- localstack-wiremock/localstack_wiremock/extension.py | 3 +++ localstack-wiremock/sample-app/src/handler.py | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/localstack-wiremock/localstack_wiremock/extension.py b/localstack-wiremock/localstack_wiremock/extension.py index becc135..b899051 100644 --- a/localstack-wiremock/localstack_wiremock/extension.py +++ b/localstack-wiremock/localstack_wiremock/extension.py @@ -7,10 +7,13 @@ class WireMockExtension(ProxiedDockerContainerExtension): HOST = "wiremock." # name of the Docker image to spin up DOCKER_IMAGE = "wiremock/wiremock" + # name of the container + CONTAINER_NAME = "ls-wiremock" def __init__(self): super().__init__( image_name=self.DOCKER_IMAGE, container_ports=[8080], + container_name=self.CONTAINER_NAME, host=self.HOST, ) diff --git a/localstack-wiremock/sample-app/src/handler.py b/localstack-wiremock/sample-app/src/handler.py index 61c2b3c..fc31bb1 100644 --- a/localstack-wiremock/sample-app/src/handler.py +++ b/localstack-wiremock/sample-app/src/handler.py @@ -8,9 +8,9 @@ def get_time_off(event, context): and returns a transformed JSON response. """ try: - # Define the mock API endpoint URL (hardcoding `host.docker.internal` for now) - # url = "http://wiremock.localhost.localstack.cloud:8080/company/time-offs/534813865" - url = "http://host.docker.internal:8080/company/time-offs/534813865" + # Define the mock API endpoint URL (hardcoding `wiremock.localhost.localstack.cloud` for + # local dev for now - could be injected via env variables in the future ...) + url = "http://wiremock.localhost.localstack.cloud:4566/company/time-offs/534813865" # Make a GET request to the mock API response = requests.get(url, timeout=5) @@ -41,6 +41,7 @@ def get_time_off(event, context): "message": "Could not connect to the downstream HR service.", "error": str(e), } + print("Error:", error_message) return { "statusCode": 503, # Service Unavailable "headers": {"Content-Type": "application/json"}, @@ -49,6 +50,7 @@ def get_time_off(event, context): except Exception as e: # Handle other unexpected errors (e.g., JSON parsing issues, programming errors) error_message = {"message": "An unexpected error occurred.", "error": str(e)} + print("Error:", error_message) return { "statusCode": 500, # Internal Server Error "headers": {"Content-Type": "application/json"},