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
13 changes: 2 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make it multi-doc?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header does not make it multi-doc, it is just a document start marker that does not do any harm and pleases my IDE because I have a lint tool that requires document start markers. https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.document_start

perl-cache-paths: &perl-cache-paths
paths:
- ./local
Expand Down Expand Up @@ -29,14 +30,6 @@ commands:
- apicast-cpanm-v2-{{ arch }}-{{ .Branch }}
- apicast-cpanm-v2-{{ arch }}-master

install-docker-compose:
steps:
- run: |
curl -sLO https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-linux-x86_64
chmod +x docker-compose-linux-x86_64
mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose
docker-compose version

setup-docker:
steps:
- setup_remote_docker:
Expand All @@ -51,7 +44,6 @@ commands:
setup-build-env:
steps:
- run: apk update && apk add wget make bash curl git openssh-client
- install-docker-compose
- setup-docker
- attach-workspace

Expand Down Expand Up @@ -106,10 +98,9 @@ executors:
docker:
working_directory: /opt/app-root/apicast
docker:
- image: docker:stable
- image: docker:23.0.2-cli-alpine3.17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as in, docker stable is not good enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker:stable does not implement docker V2 (there is not docker compose command)

environment:
COMPOSE_TLS_VERSION: "TLSv1_2"
DOCKER_COMPOSE_VERSION: "v2.14.0"

openresty:
working_directory: /opt/app-root/apicast
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Opentelemetry support. Opentracing is now deprecated [PR #1379](https://github.com/3scale/APIcast/pull/1379) [THREESCALE-7735](https://issues.redhat.com/browse/THREESCALE-7735)
- `/admin/api/account/proxy_configs` endpoint for configuration loading [PR #1352](https://github.com/3scale/APIcast/pull/1352) [THREESCALE-8508](https://issues.redhat.com/browse/THREESCALE-8508)
- Pagination of services and proxy config endpoints [PR #1397](https://github.com/3scale/APIcast/pull/1397) [THREESCALE-8373](https://issues.redhat.com/browse/THREESCALE-8373)
- Upstream TLS v1.3 [PR #1400](https://github.com/3scale/APIcast/pull/1400) [THREESCALE-9193](https://issues.redhat.com/browse/THREESCALE-9193)

### Removed

Expand Down
71 changes: 42 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
.DEFAULT_GOAL := help
DOCKER_COMPOSE = docker-compose

DOCKER ?= $(shell which docker 2> /dev/null || echo "docker")
REGISTRY ?= quay.io/3scale
export TEST_NGINX_BINARY ?= openresty
NGINX = $(shell which $(TEST_NGINX_BINARY))
SHELL=/bin/bash -o pipefail

NPROC ?= $(firstword $(shell nproc 2>/dev/null) 1)

Expand All @@ -22,6 +23,8 @@ DEVEL_DOCKER_COMPOSE_VOLMOUNT_MAC_FILE ?= docker-compose-devel-volmount-mac.yml
DEVEL_DOCKER_COMPOSE_VOLMOUNT_DEFAULT_FILE ?= docker-compose-devel-volmount-default.yml

PROVE_DOCKER_COMPOSE_FILE ?= docker-compose.prove.yml
FORWARD_PROXY_DOCKER_COMPOSE_FILE ?= docker-compose.forward-proxy.yml
UPSTREAM_TLS_DOCKER_COMPOSE_FILE ?= docker-compose.upstream-tls.yml

DOCKER_VOLUME_NAME ?= apicast-local-volume

Expand Down Expand Up @@ -143,7 +146,7 @@ prove: $(ROVER) dependencies nginx ## Test nginx
prove-docker: export IMAGE_NAME ?= $(DEVEL_IMAGE)
prove-docker: ## Test nginx inside docker
make -C $(PROJECT_PATH) -f $(MKFILE_PATH) apicast-source
$(DOCKER_COMPOSE) -f $(PROVE_DOCKER_COMPOSE_FILE) run --rm -T \
$(DOCKER) compose -f $(PROVE_DOCKER_COMPOSE_FILE) run --rm -T \
-v $(DOCKER_VOLUME_NAME):/opt/app-root/src prove | \
awk '/Result: NOTESTS/ { print "FAIL: NOTESTS"; print; exit 1 }; { print }'

Expand All @@ -158,43 +161,51 @@ push: ## Push image to the registry
bash: export IMAGE_NAME ?= $(RUNTIME_IMAGE)
bash: export SERVICE = gateway
bash: ## Run bash inside the runtime image
$(DOCKER_COMPOSE) run --user=root --rm --entrypoint=bash $(SERVICE)
$(DOCKER) compose run --user=root --rm --entrypoint=bash $(SERVICE)

gateway-logs: export IMAGE_NAME = does-not-matter
gateway-logs:
$(DOCKER_COMPOSE) logs gateway
$(DOCKER) compose logs gateway

opentelemetry-gateway: ## run gateway instrumented with opentelemetry
$(DOCKER_COMPOSE) run opentelemetry-instrumented-gateway
$(DOCKER) compose run opentelemetry-instrumented-gateway

opentracing-gateway: ## run gateway instrumented with opentracing
$(DOCKER_COMPOSE) run opentracing-instrumented-gateway
$(DOCKER) compose run opentracing-instrumented-gateway

# Environment described in ./examples/forward-proxy
forward-proxy-gateway: ## run gateway configured to run along with a forward proxy
$(DOCKER) compose -f $(FORWARD_PROXY_DOCKER_COMPOSE_FILE) run gateway

# Environment described in ./examples/tlsv1.3-upstream
upstream-tls-gateway: ## run gateway configured to access upstream powered with TLS
$(DOCKER) compose -f $(UPSTREAM_TLS_DOCKER_COMPOSE_FILE) run gateway

test-runtime-image: export IMAGE_NAME ?= $(RUNTIME_IMAGE)
test-runtime-image: clean-containers ## Smoke test the runtime image. Pass any docker image in IMAGE_NAME parameter.
$(DOCKER_COMPOSE) --version
$(DOCKER_COMPOSE) run --rm --user 100001 gateway apicast -l -d
$(DOCKER) compose --version
$(DOCKER) compose run --rm --user 100001 gateway apicast -l -d
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm --user 100002 -e APICAST_CONFIGURATION_LOADER=boot -e THREESCALE_PORTAL_ENDPOINT=https://echo-api.3scale.net gateway bin/apicast -d
$(DOCKER) compose run --rm --user 100002 -e APICAST_CONFIGURATION_LOADER=boot -e THREESCALE_PORTAL_ENDPOINT=https://echo-api.3scale.net gateway bin/apicast -d
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm test sh -c 'sleep 5 && curl --fail http://gateway:8090/status/live'
$(DOCKER) compose run --rm test sh -c 'sleep 5 && curl --fail http://gateway:8090/status/live'
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm --user 100001 gateway bin/apicast --test
$(DOCKER) compose run --rm --user 100001 gateway bin/apicast --test
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm --user 100001 gateway bin/apicast --test --dev
$(DOCKER) compose run --rm --user 100001 gateway bin/apicast --test --dev
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm --user 100001 gateway bin/apicast --daemon
$(DOCKER) compose run --rm --user 100001 gateway bin/apicast --daemon
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm test bash -c 'for i in {1..5}; do curl --fail http://gateway:8090/status/live && break || sleep 1; done'
$(DOCKER_COMPOSE) logs gateway
$(DOCKER) compose run --rm test bash -c 'for i in {1..5}; do curl --fail http://gateway:8090/status/live && break || sleep 1; done'
$(DOCKER) compose logs gateway
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm test curl --fail -X PUT http://gateway:8090/config --data '{"services":[{"id":42}]}'
$(DOCKER) compose run --rm test curl --fail -X PUT http://gateway:8090/config --data '{"services":[{"id":42}]}'
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm test curl --fail http://gateway:8090/status/ready
$(DOCKER) compose run --rm test curl --fail http://gateway:8090/status/ready
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm test curl --fail -X POST http://gateway:8090/boot
$(DOCKER) compose run --rm test curl --fail -X POST http://gateway:8090/boot
@echo -e $(SEPARATOR)
$(DOCKER_COMPOSE) run --rm gateway bin/apicast -c http://echo-api.3scale.net -d -b
$(DOCKER) compose run --rm gateway bin/apicast -c http://echo-api.3scale.net -d -b

$(PROJECT_PATH)/lua_modules $(PROJECT_PATH)/local $(PROJECT_PATH)/.cpanm $(PROJECT_PATH)/vendor/cache $(PROJECT_PATH)/.cache :
mkdir -p $@
Expand All @@ -207,9 +218,9 @@ development: GROUP := $(shell id -g $(USER))
endif
development: ## Run bash inside the development image
@echo "Running on $(os)"
- $(DOCKER_COMPOSE) -f $(DEVEL_DOCKER_COMPOSE_FILE) -f $(DEVEL_DOCKER_COMPOSE_VOLMOUNT_FILE) up -d
- $(DOCKER) compose -f $(DEVEL_DOCKER_COMPOSE_FILE) -f $(DEVEL_DOCKER_COMPOSE_VOLMOUNT_FILE) up -d
@ # https://github.com/moby/moby/issues/33794#issuecomment-312873988 for fixing the terminal width
$(DOCKER_COMPOSE) -f $(DEVEL_DOCKER_COMPOSE_FILE) -f $(DEVEL_DOCKER_COMPOSE_VOLMOUNT_FILE) exec -e COLUMNS="`tput cols`" -e LINES="`tput lines`" --user $(USER):$(GROUP) development bash
$(DOCKER) compose -f $(DEVEL_DOCKER_COMPOSE_FILE) -f $(DEVEL_DOCKER_COMPOSE_VOLMOUNT_FILE) exec -e COLUMNS="`tput cols`" -e LINES="`tput lines`" --user $(USER):$(GROUP) development bash

stop-development: clean-containers ## Stop development environment

Expand All @@ -233,9 +244,11 @@ lua_modules/bin/rover:
dependencies: dep_folders lua_modules carton ## Install project dependencies

clean-containers:
- $(DOCKER_COMPOSE) down --volumes --remove-orphans
- $(DOCKER_COMPOSE) -f $(PROVE_DOCKER_COMPOSE_FILE) down --volumes --remove-orphans
- $(DOCKER_COMPOSE) -f $(DEVEL_DOCKER_COMPOSE_FILE) -f $(DEVEL_DOCKER_COMPOSE_VOLMOUNT_FILE) down --volumes --remove-orphans
$(DOCKER) compose down --volumes --remove-orphans
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this removes any potential compatibility with podman-compose (not sure if it was working beforehand), as it is a separate command and not a subcommand for podman.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this repo, we use docker, not podman. I do not think it works with podman, even before this change. Check this PR for a discussion regarding Podman vs Docker. I would be happy to move to podman/buildah. But it needs work and maybe it cannot be done.

This is about moving forward to docker compose V2. Docker compose V1 is deprecated https://www.docker.com/blog/new-docker-compose-v2-and-v1-deprecation/

$(DOCKER) compose -f $(PROVE_DOCKER_COMPOSE_FILE) down --volumes --remove-orphans
$(DOCKER) compose -f $(DEVEL_DOCKER_COMPOSE_FILE) -f $(DEVEL_DOCKER_COMPOSE_VOLMOUNT_FILE) down --volumes --remove-orphans
$(DOCKER) compose -f $(FORWARD_PROXY_DOCKER_COMPOSE_FILE) down --volumes --remove-orphans
$(DOCKER) compose -f $(UPSTREAM_TLS_DOCKER_COMPOSE_FILE) down --volumes --remove-orphans

clean-deps: ## Remove all local dependency folders
- rm -rf $(PROJECT_PATH)/lua_modules $(PROJECT_PATH)/local $(PROJECT_PATH)/.cpanm $(PROJECT_PATH)/vendor/cache $(PROJECT_PATH)/.cache :
Expand Down Expand Up @@ -270,12 +283,12 @@ benchmark: export COMPOSE_PROJECT_NAME = apicast-benchmark
benchmark: export WRK_REPORT ?= $(IMAGE_TAG).csv
benchmark: export DURATION ?= 300
benchmark:
- $(DOCKER_COMPOSE) up --force-recreate -d apicast
$(DOCKER_COMPOSE) run curl
- $(DOCKER) compose up --force-recreate -d apicast
$(DOCKER) compose run curl
## warmup round for $(DURATION)/10 seconds
DURATION=$$(( $(DURATION) / 10 )) $(DOCKER_COMPOSE) run wrk
DURATION=$$(( $(DURATION) / 10 )) $(DOCKER) compose run wrk
## run the real benchmark for $(DURATION) seconds
$(DOCKER_COMPOSE) run wrk
$(DOCKER) compose run wrk

# Check http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## Print this help
Expand Down
39 changes: 39 additions & 0 deletions docker-compose.forward-proxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
version: '3.8'
services:
gateway:
image: ${IMAGE_NAME:-apicast-test}
depends_on:
- proxy
- 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:
- ./examples/forward-proxy/apicast-config.json:/tmp/config.json
upstream:
image: nginx:1.23.4
expose:
- "443"
volumes:
- ./examples/forward-proxy/proxy-nginx.conf:/etc/nginx/nginx.conf
- ./examples/forward-proxy/upstream-cert/upstream.key:/etc/pki/tls.key
- ./examples/forward-proxy/upstream-cert/upstream.crt:/etc/pki/tls.crt
proxy:
build:
dockerfile: ./examples/forward-proxy/tinyproxy.Dockerfile
expose:
- "3128:3128"
- "443:443"
volumes:
- ./examples/forward-proxy/tinyproxy.conf:/etc/tinyproxy/tinyproxy.conf
30 changes: 30 additions & 0 deletions docker-compose.upstream-tls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
version: '3.8'
services:
gateway:
image: ${IMAGE_NAME:-apicast-test}
depends_on:
- one.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:
- ./examples/tlsv1.3-upstream/apicast-config.json:/tmp/config.json
one.upstream:
image: nginx:1.23.4
expose:
- "443"
volumes:
- ./examples/tlsv1.3-upstream/proxy-nginx.conf:/etc/nginx/nginx.conf
- ./examples/tlsv1.3-upstream/upstream-cert/one.upstream.key:/etc/pki/tls.key
- ./examples/tlsv1.3-upstream/upstream-cert/one.upstream.crt:/etc/pki/tls.crt
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version: '2.1'
---
version: '3.8'
services:
gateway:
image: ${IMAGE_NAME:-apicast-test}
Expand Down
9 changes: 9 additions & 0 deletions examples/forward-proxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# PROXY with upstream using TLSv1.3

APIcast --> tiny proxy (connect to 443 but no cert installed) --> upstream (TLSv1.3)

APicast starts SSL tunnel (via HTTP Connect method) against proxy to access upstream configured with TLSv1.3

```
curl -v -H "Host: one" http://${APICAST_IP}:8080/get?user_key=foo
```
36 changes: 36 additions & 0 deletions examples/forward-proxy/apicast-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"services": [
{
"backend_version": "1",
"proxy": {
"hosts": ["one"],
"api_backend": "https://upstream:443/",
"backend": {
"endpoint": "http://127.0.0.1:8081",
"host": "backend"
},
"policy_chain": [
{
"name": "apicast.policy.apicast"
},
{
"name": "apicast.policy.http_proxy",
"configuration": {
"https_proxy": "http://proxy:443/"
}
}
],
"proxy_rules": [
{
"http_method": "GET",
"pattern": "/",
"metric_system_name": "hits",
"delta": 1,
"parameters": [],
"querystring_parameters": {}
}
]
}
}
]
}
27 changes: 27 additions & 0 deletions examples/forward-proxy/proxy-nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events { worker_connections 1024; }

http {
server {
listen 443 ssl;

server_name upstream;

resolver 8.8.8.8;

access_log /dev/stdout;
error_log /dev/stdout info;

ssl_certificate /etc/pki/tls.crt;
ssl_certificate_key /etc/pki/tls.key;
ssl_protocols TLSv1.3;

location ~ ^/(.*)$ {
proxy_pass https://postman-echo.com/get/$1$is_args$args;
}
}
}
12 changes: 12 additions & 0 deletions examples/forward-proxy/tinyproxy.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM alpine:3.17.3

LABEL summary="Forward proxy based on tinyproxy for development purposes" \
description="Forward proxy based on tinyproxy for development purposes" \
io.k8s.description="Forward proxy based on tinyproxy for development purposes" \
io.k8s.display-name="Forward Proxy (Tinyproxy)" \
io.openshift.tags="tinyproxy, proxy" \
maintainer="3scale-engineering@redhat.com"

RUN apk --no-cache add tinyproxy=1.11.1-r2
ENTRYPOINT ["/usr/bin/tinyproxy"]
CMD ["-d"]
Loading