Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ on:
branches:
- main
paths:
- 'localstack-wiremock/**'
- 'localstack-typedb/**'
push:
branches:
- main
paths:
- 'localstack-wiremock/**'
- 'localstack-typedb/**'
workflow_dispatch:

env:
Expand All @@ -19,14 +19,14 @@ env:

jobs:
integration-tests:
name: Run Integration Tests
name: Run TypeDB Extension Tests
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup LocalStack and extension
- name: Set up LocalStack and extension
run: |
cd localstack-typedb

Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/test-wiremock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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: 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 &
docker pull public.ecr.aws/lambda/python:3.9 &
pip install localstack terraform-local awscli-local[ver1]

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
6 changes: 5 additions & 1 deletion localstack-wiremock/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
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/
Expand Down
4 changes: 2 additions & 2 deletions localstack-wiremock/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 3 additions & 0 deletions localstack-wiremock/localstack_wiremock/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ class WireMockExtension(ProxiedDockerContainerExtension):
HOST = "wiremock.<domain>"
# 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,
)
8 changes: 5 additions & 3 deletions localstack-wiremock/sample-app/src/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"},
Expand All @@ -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"},
Expand Down