From 3681e4414aeec5a30807ee55be18f7ee6bcb02cf Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Sat, 21 Oct 2023 23:06:12 +0200 Subject: [PATCH] dev-environment: plain-http-upstream --- dev-environments/plain-http-upstream/Makefile | 13 +++++ .../plain-http-upstream/README.md | 45 ++++++++++++++ .../plain-http-upstream/apicast-config.json | 58 +++++++++++++++++++ .../plain-http-upstream/docker-compose.yml | 34 +++++++++++ 4 files changed, 150 insertions(+) create mode 100644 dev-environments/plain-http-upstream/Makefile create mode 100644 dev-environments/plain-http-upstream/README.md create mode 100644 dev-environments/plain-http-upstream/apicast-config.json create mode 100644 dev-environments/plain-http-upstream/docker-compose.yml diff --git a/dev-environments/plain-http-upstream/Makefile b/dev-environments/plain-http-upstream/Makefile new file mode 100644 index 000000000..7e0707631 --- /dev/null +++ b/dev-environments/plain-http-upstream/Makefile @@ -0,0 +1,13 @@ +SHELL = /usr/bin/env bash -o pipefail +.SHELLFLAGS = -ec +.DEFAULT_GOAL := gateway +MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) +WORKDIR := $(patsubst %/,%,$(dir $(MKFILE_PATH))) +DOCKER ?= $(shell which docker 2> /dev/null || echo "docker") + +gateway: ## run gateway configured to access plain HTTP 1.1 upstream + $(DOCKER) compose -f docker-compose.yml run --service-ports gateway + +clean: + $(DOCKER) compose down --volumes --remove-orphans + $(DOCKER) compose -f docker-compose.yml down --volumes --remove-orphans diff --git a/dev-environments/plain-http-upstream/README.md b/dev-environments/plain-http-upstream/README.md new file mode 100644 index 000000000..68290d8a6 --- /dev/null +++ b/dev-environments/plain-http-upstream/README.md @@ -0,0 +1,45 @@ +# Plain HTTP 1.1 upstream + +APIcast --> upstream plain HTTP 1.1 upstream + +APIcast configured with plain HTTP 1.1 upstream server equipped with traffic rely agent (socat) + +## Run the gateway + +Running local `apicast-test` docker image + +```sh +make gateway +``` + +Running custom apicast image + +```sh +make gateway IMAGE_NAME=quay.io/3scale/apicast:latest +``` + +Traffic between the proxy and upstream can be inspected looking at logs from `example.com` service + +``` +docker compose -p plain-http-upstream logs -f example.com +``` + +## Testing + +`GET` request + +```sh +curl --resolve get.example.com:8080:127.0.0.1 -v "http://get.example.com:8080/?user_key=123" +``` + +`POST` request + +```sh +curl --resolve post.example.com:8080:127.0.0.1 -v -X POST "http://post.example.com:8080/?user_key=123" +``` + +## Clean env + +```sh +make clean +``` diff --git a/dev-environments/plain-http-upstream/apicast-config.json b/dev-environments/plain-http-upstream/apicast-config.json new file mode 100644 index 000000000..30c2db396 --- /dev/null +++ b/dev-environments/plain-http-upstream/apicast-config.json @@ -0,0 +1,58 @@ +{ + "services": [ + { + "id": "1", + "backend_version": "1", + "proxy": { + "hosts": ["get.example.com"], + "api_backend": "http://example.com/get", + "backend": { + "endpoint": "http://127.0.0.1:8081", + "host": "backend" + }, + "policy_chain": [ + { + "name": "apicast.policy.apicast" + } + ], + "proxy_rules": [ + { + "http_method": "GET", + "pattern": "/", + "metric_system_name": "hits", + "delta": 1, + "parameters": [], + "querystring_parameters": {} + } + ] + } + }, + { + "id": "2", + "backend_version": "1", + "proxy": { + "hosts": ["post.example.com"], + "api_backend": "http://example.com/post", + "backend": { + "endpoint": "http://127.0.0.1:8081", + "host": "backend" + }, + "policy_chain": [ + { + "name": "apicast.policy.apicast" + } + ], + "proxy_rules": [ + { + "http_method": "POST", + "pattern": "/", + "metric_system_name": "hits", + "delta": 1, + "parameters": [], + "querystring_parameters": {} + } + ] + } + } + ] +} diff --git a/dev-environments/plain-http-upstream/docker-compose.yml b/dev-environments/plain-http-upstream/docker-compose.yml new file mode 100644 index 000000000..7e671800a --- /dev/null +++ b/dev-environments/plain-http-upstream/docker-compose.yml @@ -0,0 +1,34 @@ +--- +version: '3.8' +services: + gateway: + image: ${IMAGE_NAME:-apicast-test} + depends_on: + - example.com + - two.upstream + environment: + THREESCALE_CONFIG_FILE: /tmp/config.json + THREESCALE_DEPLOYMENT_ENV: staging + APICAST_CONFIGURATION_LOADER: lazy + APICAST_WORKERS: 1 + APICAST_LOG_LEVEL: debug + APICAST_CONFIGURATION_CACHE: "0" + expose: + - "8080" + - "8090" + ports: + - "8080:8080" + - "8090:8090" + volumes: + - ./apicast-config.json:/tmp/config.json + example.com: + image: alpine/socat:1.7.4.4 + container_name: example.com + command: "-d -v -d TCP-LISTEN:80,reuseaddr,fork TCP:two.upstream:80" + expose: + - "80" + restart: unless-stopped + two.upstream: + image: kennethreitz/httpbin + expose: + - "80"