Skip to content

Commit 672a88c

Browse files
committed
add initial version of wiremock LocalStack extension
1 parent a111f4e commit 672a88c

15 files changed

Lines changed: 577 additions & 1 deletion

File tree

.github/workflows/test.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ name: LocalStack TypeDB Extension Tests
22

33
on:
44
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- 'localstack-wiremock/**'
9+
push:
10+
branches:
11+
- main
12+
paths:
13+
- 'localstack-wiremock/**'
514
workflow_dispatch:
615

716
env:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ This repo contains miscellaneous utilities for LocalStack.
44

55
## License
66

7-
The code in this repo is available under the Apache 2.0 license.
7+
The code in this repo is available under the Apache 2.0 license. (unless stated otherwise)

backstage/localstack.backstage.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ metadata:
2222
title: LocalStack Docker usage
2323
icon: docs
2424
annotations:
25+
backstage.io/techdocs-ref: https://docs.localstack.cloud
2526
# custom annotations we can use across our org
2627
localstack.cloud/docker-image: localstack/localstack:latest
2728
localstack.cloud/docs-url: https://docs.localstack.cloud/

localstack-wiremock/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.venv
2+
dist
3+
build
4+
**/*.egg-info
5+
.eggs
6+
.terraform*
7+
terraform.tfstate*
8+
*.zip

localstack-wiremock/Makefile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
VENV_BIN = python3 -m venv
2+
VENV_DIR ?= .venv
3+
VENV_ACTIVATE = $(VENV_DIR)/bin/activate
4+
VENV_RUN = . $(VENV_ACTIVATE)
5+
6+
usage: ## Shows usage for this Makefile
7+
@cat Makefile | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
8+
9+
venv: $(VENV_ACTIVATE)
10+
11+
$(VENV_ACTIVATE): pyproject.toml
12+
test -d .venv || $(VENV_BIN) .venv
13+
$(VENV_RUN); pip install --upgrade pip setuptools plux
14+
$(VENV_RUN); pip install -e .[dev]
15+
touch $(VENV_DIR)/bin/activate
16+
17+
clean:
18+
rm -rf .venv/
19+
rm -rf build/
20+
rm -rf .eggs/
21+
rm -rf *.egg-info/
22+
23+
install: venv ## Install dependencies
24+
$(VENV_RUN); python -m plux entrypoints
25+
26+
dist: venv ## Create distribution
27+
$(VENV_RUN); python -m build
28+
29+
publish: clean-dist venv dist ## Publish extension to pypi
30+
$(VENV_RUN); pip install --upgrade twine; twine upload dist/*
31+
32+
entrypoints: venv # Generate plugin entrypoints for Python package
33+
$(VENV_RUN); python -m plux entrypoints
34+
35+
format: ## Run ruff to format the whole codebase
36+
$(VENV_RUN); python -m ruff format .; python -m ruff check --output-format=full --fix .
37+
38+
test: ## Run integration tests (requires LocalStack running with the Extension installed)
39+
$(VENV_RUN); pytest tests $(PYTEST_ARGS)
40+
41+
sample: ## Deploy sample app
42+
bin/create-stubs.sh
43+
(cd sample-app; tflocal init; tflocal apply)
44+
45+
clean-dist: clean
46+
rm -rf dist/
47+
48+
.PHONY: clean clean-dist dist install publish usage venv format test

localstack-wiremock/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
WireMock on LocalStack
2+
===============================
3+
4+
This repo contains a [LocalStack Extension](https://github.com/localstack/localstack-extensions) that facilitates developing WireMock-based applications locally.
5+
6+
## Prerequisites
7+
8+
* Docker
9+
* LocalStack Pro (free trial available)
10+
* `localstack` CLI
11+
* `make`
12+
13+
## Install from GitHub repository
14+
15+
This extension can be installed directly from this Github repo via:
16+
17+
```bash
18+
localstack extensions install "git+https://github.com/whummer/localstack-utils.git#egg=localstack-wiremock&subdirectory=localstack-wiremock"
19+
```
20+
21+
## Install local development version
22+
23+
To install the extension into localstack in developer mode, you will need Python 3.11, and create a virtual environment in the extensions project.
24+
25+
In the newly generated project, simply run
26+
27+
```bash
28+
make install
29+
```
30+
31+
Then, to enable the extension for LocalStack, run
32+
33+
```bash
34+
localstack extensions dev enable .
35+
```
36+
37+
You can then start LocalStack with `EXTENSION_DEV_MODE=1` to load all enabled extensions:
38+
39+
```bash
40+
EXTENSION_DEV_MODE=1 localstack start
41+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
echo "Downloading WireMock stub definitions..."
4+
5+
# Define the URL for the stub definitions and the temporary file path
6+
STUBS_URL="https://library.wiremock.org/catalog/api/p/personio.de/personio-de-personnel/personio.de-personnel-stubs.json"
7+
TMP_STUBS_FILE="/tmp/personio-stubs.json"
8+
9+
# Define the WireMock server URL
10+
WIREMOCK_URL="http://localhost:8080"
11+
12+
# Download the stub definitions
13+
curl -s -o "$TMP_STUBS_FILE" "$STUBS_URL"
14+
15+
echo "Download complete. Stubs saved to $TMP_STUBS_FILE"
16+
echo "Importing stubs into WireMock..."
17+
18+
# Send a POST request to WireMock's import endpoint with the downloaded file
19+
curl -v -X POST -H "Content-Type: application/json" --data-binary "@$TMP_STUBS_FILE" "$WIREMOCK_URL/__admin/mappings/import"
20+
21+
echo ""
22+
echo "WireMock stub import request sent."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name = "localstack_wiremock"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from localstack_wiremock.utils.docker import ProxiedDockerContainerExtension
2+
3+
4+
class WireMockExtension(ProxiedDockerContainerExtension):
5+
name = "localstack-wiremock"
6+
7+
HOST = "wiremock.<domain>"
8+
# name of the Docker image to spin up
9+
DOCKER_IMAGE = "wiremock/wiremock"
10+
11+
def __init__(self):
12+
super().__init__(
13+
image_name=self.DOCKER_IMAGE,
14+
container_ports=[8080],
15+
host=self.HOST,
16+
)

localstack-wiremock/localstack_wiremock/utils/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)