-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from redirectionio/castor-version
Fix subsplit
- Loading branch information
Showing
42 changed files
with
760 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.castor.stub.php | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
|
||
use Castor\Attribute\AsArgument; | ||
use Castor\Attribute\AsTask; | ||
use function Castor\context; | ||
use function Castor\finder; | ||
use function Castor\fs; | ||
use function Castor\request; | ||
use function Castor\io; | ||
use function Castor\run; | ||
|
||
#[AsTask(name: 'run', description: 'Build, start and ensure examples are working as expected')] | ||
function _run( | ||
#[AsArgument(description: 'The name of the specific example to run', autocomplete: 'get_examples')] | ||
?string $example = null, | ||
): void | ||
{ | ||
if (!fs()->exists('.env')) { | ||
io()->error('No .env file found. Please create one by copying the .env.dist file and filling in the required values.'); | ||
return; | ||
} | ||
|
||
stop(); | ||
|
||
if ($example) { | ||
io()->title("Building and running example: $example"); | ||
|
||
example($example); | ||
|
||
return; | ||
} | ||
|
||
io()->title('Building and running all examples'); | ||
|
||
foreach (get_examples() as $example) { | ||
example($example); | ||
} | ||
} | ||
|
||
#[AsTask(description: 'Build the given example')] | ||
function build( | ||
#[AsArgument(description: 'The name of the specific example to run', autocomplete: 'get_examples')] | ||
?string $example = null, | ||
): void | ||
{ | ||
if (!$example) { | ||
foreach (get_examples() as $example) { | ||
build($example); | ||
} | ||
return; | ||
} | ||
|
||
io()->title("Building example: $example"); | ||
|
||
run('docker compose build', workingDirectory: $example); | ||
} | ||
|
||
#[AsTask(description: 'Start the given example')] | ||
function start( | ||
#[AsArgument(description: 'The name of the specific example to run', autocomplete: 'get_examples')] | ||
string $example, | ||
): void | ||
{ | ||
io()->title("Starting example: $example"); | ||
|
||
run('docker compose up -d', workingDirectory: $example); | ||
|
||
sleep(2); | ||
} | ||
|
||
#[AsTask(description: 'Test the given example')] | ||
function test( | ||
#[AsArgument(description: 'The name of the specific example to run', autocomplete: 'get_examples')] | ||
string $example, | ||
): void | ||
{ | ||
io()->title("Testing example: $example"); | ||
|
||
$fails = 0; | ||
!assertResponse('/', 200) && $fails++; | ||
!assertResponse('/example/301-rio.html', 301) && $fails++; | ||
!assertResponse('/example/302-rio.html', 302) && $fails++; | ||
!assertResponse('/example/404-nginx.html', 404) && $fails++; | ||
!assertResponse('/example/404-rio.html', 404) && $fails++; | ||
!assertResponse('/example/410-rio.html', 410) && $fails++; | ||
|
||
if ($fails > 0) { | ||
throw new \RuntimeException("Some tests were not successful for example \"$example\""); | ||
} | ||
|
||
io()->writeln(''); | ||
} | ||
|
||
#[AsTask(description: 'Stop the given example')] | ||
function stop( | ||
#[AsArgument(description: 'The name of the specific example to run', autocomplete: 'get_examples')] | ||
?string $example = null, | ||
): void | ||
{ | ||
if (!$example) { | ||
foreach (get_examples() as $example) { | ||
stop($example); | ||
} | ||
return; | ||
} | ||
|
||
io()->title("Stopping example: $example"); | ||
|
||
run('docker compose stop', workingDirectory: $example, allowFailure: true); | ||
} | ||
|
||
function get_examples(): iterable | ||
{ | ||
/** @var Symfony\Component\Finder\Finder $examples */ | ||
$examples = finder() | ||
->in(context()->workingDirectory) | ||
->notName('app') | ||
->directories() | ||
->depth(0) | ||
->sortByName() | ||
; | ||
|
||
foreach ($examples as $example) { | ||
yield $example->getBasename(); | ||
} | ||
} | ||
|
||
function example(string $example): void | ||
{ | ||
if (!fs()->exists("$example/docker-compose.yml")) { | ||
throw new \RuntimeException("The example directory \"$example\" does not exist or does not contain a docker-compose.yml file"); | ||
} | ||
|
||
build($example); | ||
start($example); | ||
test($example); | ||
stop($example); | ||
} | ||
|
||
function assertResponse(string $url, int $expectedStatusCode): bool | ||
{ | ||
$response = request('GET', 'http://127.0.0.1:8080' . $url, [ | ||
'max_redirects' => 0, | ||
]); | ||
|
||
$result = $response->getStatusCode() === $expectedStatusCode ? '✔️' : '❌'; | ||
|
||
io()->text("Asserting response for $url is status $expectedStatusCode: $result"); | ||
|
||
return $response->getStatusCode() === $expectedStatusCode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
REDIRECTIONIO_PROJECT_KEY=PASTE HERE YOUR REDIRECTION.IO PROJECT KEY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Continuous Integration | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
schedule: | ||
- cron: "0 0 * * MON" | ||
|
||
jobs: | ||
run-examples: | ||
name: Run all examples | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.3 | ||
tools: castor | ||
|
||
- name: Setup .env | ||
run: "echo 'REDIRECTIONIO_PROJECT_KEY=${{ secrets.REDIRECTIONIO_PROJECT_KEY }}' > $GITHUB_WORKSPACE/.env" | ||
|
||
- name: Build and run all examples | ||
run: castor run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Using the redirection.io agent as a reverse proxy in a Docker environment | ||
|
||
This example shows how to use the redirection.io agent as a reverse proxy in a Docker environment. It is the most simple and versatile way to install redirection.io in your Docker stack, as it can be used with any backend service. The redirection.io agent act as a very fast reverse proxy, intercepting requests and responses between the client and the backend service. | ||
|
||
> [!TIP] | ||
> You can read more about [the redirection.io agent as a reverse proxy in our documentation](https://redirection.io/documentation/developer-documentation/the-agent-as-a-reverse-proxy). | ||
## Description | ||
|
||
The `service` directory contains the **redirectionio-agent** service: a simple Dockerfile to get the agent running. The [`/etc/redirectionio/agent.yml`](./services/redirectionio-agent/etc/redirectionio/agent.yml) file is used to configure the agent and proxify the traffic to a backend service. | ||
|
||
The `docker-compose.yml` file also mentions a `nginx` service, which is a simple Nginx server used as a backend service. You can replace it with your own backend service. | ||
|
||
 | ||
|
||
### redirectionio-agent | ||
|
||
The agent is installed using our [manual installation](https://redirection.io/documentation/developer-documentation/installation-of-the-agent#manual-installation) instructions. Note that we have enabled a `/var/lib/redirectionio` volume, used to store [redirection.io agent's cache data](https://redirection.io/documentation/developer-documentation/agent-configuration-reference#datadir). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: '3' | ||
|
||
volumes: | ||
redirectionio-agent-data: {} | ||
|
||
services: | ||
redirectionio-agent: | ||
build: services/redirectionio-agent | ||
env_file: "../.env" | ||
environment: | ||
- INSTANCE_NAME=docker-reverse-proxy | ||
ports: | ||
- "8080:80" | ||
volumes: | ||
- redirectionio-agent-data:/var/lib/redirectionio | ||
|
||
# this is the application backend service | ||
# it can be any other HTTP service | ||
nginx: | ||
image: nginx | ||
volumes: | ||
- ../app:/usr/share/nginx/html |
2 changes: 1 addition & 1 deletion
2
services/redirectionio-agent/Dockerfile → ...y/services/redirectionio-agent/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM alpine:3.12 as alpine | ||
FROM alpine:3.19 as alpine | ||
|
||
WORKDIR /tmp | ||
|
||
|
7 changes: 7 additions & 0 deletions
7
agent-as-reverse-proxy/services/redirectionio-agent/etc/redirectionio/agent.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
instance_name: "${INSTANCE_NAME}" | ||
|
||
proxies: | ||
- | ||
listen: 0.0.0.0:80 | ||
forward: http://nginx:80 | ||
project_key: "${REDIRECTIONIO_PROJECT_KEY}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Compiling the redirection.io Apache module in a Docker environment | ||
|
||
It may happen that your hosting provider or provisioning solution installs a custom version of Apache, in non-standard paths or with incompatible dependencies. In this case, you may need to compile the redirection.io Apache module [from the sources](https://github.com/redirectionio/libapache2-mod-redirectionio). | ||
|
||
This example shows how to compile the redirection.io Apache module and load it in the latest release of the Apache image. | ||
|
||
## Description | ||
|
||
The `service` directory contains two services: | ||
|
||
* **apache**: an Apache Dockerfile based on the [`httpd`](https://hub.docker.com/_/httpd/) image, with redirection.io Apache module compiled from the sources. | ||
* **redirectionio-agent**: a simple Dockerfile to get the agent running | ||
|
||
 | ||
|
||
### apache | ||
|
||
redirection.io offers APT and RPM repositories, with many versions of | ||
`libapache2-mod-redirectionio` to match classical distribution apache packages. | ||
However, should your apache2 install vary from these traditional layouts, you will | ||
be forced to compile our apache module yourself, to match your own apache version. | ||
|
||
This is what the [apache Dockerfile](./services/apache/Dockerfile) achieves. Basically: | ||
* it downloads and builds the libredirectionio | ||
* it downloads the redirection.io apache2 module | ||
* it builds this module | ||
* it moves the built module in the right folder | ||
* it [loads the module](./services/apache/Dockerfile#L61) in the Apache configuration | ||
* it [enables redirection.io for the server](./services/apache/usr/local/apache2/conf/extra/httpd-vhosts.conf#L4-L5) | ||
|
||
### redirectionio-agent | ||
|
||
The agent is installed using our [manual installation](https://redirection.io/documentation/developer-documentation/installation-of-the-agent#manual-installation) instructions. Note that we have enabled a `/var/lib/redirectionio` volume, used to store [redirection.io agent's cache data](https://redirection.io/documentation/developer-documentation/agent-configuration-reference#datadir). |
Oops, something went wrong.