Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Policy development tutorial #1384

Merged
merged 61 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
4882ed9
Documentation providing a policy dev tutorial
pimg Jun 24, 2020
266f167
Apply suggestions from code review
pimg Jun 25, 2020
d2affa0
address comment
eguzki Dec 22, 2022
04aa3fa
address comment
eguzki Dec 22, 2022
b53b5ea
address comment
eguzki Dec 22, 2022
aed6c38
Update doc/policy_tutorial/DEV_ENV_SETUP.md
eguzki Dec 22, 2022
37fed11
Update doc/policy_tutorial/DEV_ENV_SETUP.md
eguzki Dec 22, 2022
23fbc01
Update doc/policy_tutorial/DEV_ENV_SETUP.md
eguzki Dec 22, 2022
db39059
Update doc/policy_tutorial/DEV_ENV_SETUP.md
eguzki Dec 22, 2022
ed87ab9
Update doc/policy_tutorial/DEV_ENV_SETUP.md
eguzki Jan 10, 2023
79b9cec
Update doc/policy_tutorial/DEV_ENV_SETUP.md
eguzki Jan 10, 2023
e086efe
Update doc/policy_tutorial/DEV_ENV_SETUP.md
eguzki Jan 10, 2023
c7db342
Update doc/policy_tutorial/DEV_ENV_SETUP.md
eguzki Jan 10, 2023
a499f85
Update doc/policy_tutorial/DEV_ENV_SETUP.md
eguzki Jan 10, 2023
610016f
Update doc/policy_tutorial/DEV_ENV_SETUP.md
eguzki Jan 10, 2023
2358caa
Update doc/policy_tutorial/DEV_ENV_SETUP.md
eguzki Jan 10, 2023
7259c15
Update doc/policy_tutorial/DEV_ENV_SETUP.md
eguzki Jan 10, 2023
39d5241
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
867dab9
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
6527bb8
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
0eaf62a
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
8ffa61d
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
07e3c31
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
a2241ab
Update doc/policy_tutorial/README.md
eguzki Jan 10, 2023
a8c469e
Update doc/policy_tutorial/README.md
eguzki Jan 10, 2023
c888c9f
Update doc/policy_tutorial/README.md
eguzki Jan 10, 2023
12c9495
Update doc/policy_tutorial/README.md
eguzki Jan 10, 2023
8923ffe
Update doc/policy_tutorial/README.md
eguzki Jan 10, 2023
5f9f7ee
Update doc/policy_tutorial/README.md
eguzki Jan 10, 2023
4de620e
Update doc/policy_tutorial/README.md
eguzki Jan 10, 2023
af9a6cb
Update doc/policy_tutorial/README.md
eguzki Jan 10, 2023
96a26fc
Update doc/policy_tutorial/README.md
eguzki Jan 10, 2023
def5c97
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
d5725ed
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
1ce04e7
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
145322d
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
4239d8a
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
9b1e81d
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
d5caab0
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
9494aa0
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
ee8cfd0
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
369a432
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
583cb88
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
94d9f93
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
867f509
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
e62b9c5
Update doc/policy_tutorial/POLICY_SCAFFOLD.md
eguzki Jan 10, 2023
de7d739
Update doc/policy_tutorial/POLICY_RUN_LOCALLY.md
eguzki Jan 10, 2023
316a3f7
Update doc/policy_tutorial/POLICY_SCAFFOLD.md
eguzki Jan 10, 2023
f3a7ee3
Update doc/policy_tutorial/POLICY_SCAFFOLD.md
eguzki Jan 10, 2023
dfcf380
Update doc/policy_tutorial/POLICY_SCAFFOLD.md
eguzki Jan 10, 2023
f2ab0de
Update doc/policy_tutorial/POLICY_SCAFFOLD.md
eguzki Jan 10, 2023
f210656
Update doc/policy_tutorial/POLICY_SCAFFOLD.md
eguzki Jan 10, 2023
22bc23b
Update doc/policy_tutorial/POLICY_SCAFFOLD.md
eguzki Jan 10, 2023
5c59103
Update doc/policy_tutorial/POLICY_SCAFFOLD.md
eguzki Jan 10, 2023
ddefe07
Update doc/policy_tutorial/POLICY_SCAFFOLD.md
eguzki Jan 10, 2023
d40769f
Update doc/policy_tutorial/POLICY_SCAFFOLD.md
eguzki Jan 10, 2023
54081ba
Update doc/policy_tutorial/POLICY_SCAFFOLD.md
eguzki Jan 10, 2023
ce7af43
Update doc/policy_tutorial/POLICY_SCAFFOLD.md
eguzki Jan 10, 2023
26df920
Update doc/policy_tutorial/POLICY_SCAFFOLD.md
eguzki Jan 10, 2023
113cf41
Update doc/policy_tutorial/POLICY_SCAFFOLD.md
eguzki Jan 10, 2023
5bcc967
Update doc/policy_tutorial/README.md
eguzki Jan 10, 2023
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
104 changes: 104 additions & 0 deletions doc/policy_tutorial/DEV_ENV_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Setting up the development environment

You need to configure an environment to work with Lua because APIcast policies are created in the Lua programming language. Additionally, you can use an actual APIcast server to perform local tests.

Following simple steps, you can set up a development environment for APIcast using Docker and Docker Compose.

### prerequisites
You must install Docker and Docker Compose:

* Docker version 19.03.8. You can find instructions for installing Docker in the Docker [website](https://docs.docker.com/get-docker/).
* Docker Compose version 1.25.4. You can find instructions for installing Docker Compose on the Docker [website](https://docs.docker.com/compose/install/).

Instructions for installing Docker Compose can also be found on the Docker [website](https://docs.docker.com/compose/install/).

### Setting up the development image
After you have installed Docker and Docker Compose, you can configure the APIcast development image.

. Clone the APIcast git repository. Use the stable branch of APIcast to base the policy on the latest 3scale release.

```shell
git clone https://github.com/3scale/apicast.git
cd apicast/
```

. To start the APIcast containers using `docker-compose`, use the *make* file provided by 3scale. Run this command in the APIcast directory:
```shell
make development
```

```bash
Running on Linux
docker-compose -f docker-compose-devel.yml -f docker-compose-devel-volmount-default.yml up -d
[+] Running 2/2
⠿ Container apicast_build_0-redis-1 Started 0.8s
⠿ Container apicast_build_0-development-1 Started 0.7s
docker-compose -f docker-compose-devel.yml -f docker-compose-devel-volmount-default.yml exec -e COLUMNS="`tput cols`" -e LINES="`tput lines`" --user 1000:1000 development bash
bash-4.4$
```
. The Docker container starts in the foreground with a bash session. The next step is to install all the dependencies inside the container, using a *make* command:

```shell
make dependencies
```

+
* The output will be very long. After a successful completion of the installation of all the dependencies, you will see a message similar to this:
+

```
Complete! Modules were installed into /opt/app-root/src/local
local/bin/carton bundle 2> /dev/null
Bundling modules using /opt/app-root/src/gateway/cpanfile
Complete! Modules were bundled into /opt/app-root/src/vendor/cache
bash-4.4$
```

Now we can run some APIcast unit tests to see if we are up and running and ready to start the development of our policy.
eguzki marked this conversation as resolved.
Show resolved Hide resolved

. To run the Lua unit tests use this command **inside** the container:
eguzki marked this conversation as resolved.
Show resolved Hide resolved

```shell
bash-4.4$ make busted
EXTRA_CFLAGS="-DHAVE_EVP_KDF_CTX=1" /usr/local/openresty/luajit/bin/rover install --roverfile=/opt/app-root/src/gateway/Roverfile > /dev/null
/usr/local/openresty/luajit/bin/rover exec bin/busted
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●◌●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●◌●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
1208 successes / 0 failures / 0 errors / 2 pending : 6.209112 seconds

Pending → spec/policy/rate_limit/redis_shdict_spec.lua @ 33
Redis Shared Dictionary incr without default

Pending → spec/resty/http_ng_spec.lua @ 35
http_ng options method works with default options
```

After confirming that the unit tests run successfully, you can start the policy development.

The project’s source code will be available in the container and sync’ed with your local apicast directory, so you can edit files in your preferred environment and still be able to run whatever you need inside the Docker container.
eguzki marked this conversation as resolved.
Show resolved Hide resolved

The development container for APIcast uses a Docker volume mount to mount the local apicast directory inside the container. This means all files changed locally in the repository are synced with the container and used in the tests and runtime of the development container.
eguzki marked this conversation as resolved.
Show resolved Hide resolved

![APIcast-dev-container-mount](img/apicast-dev-container-mount.png)

It also means you can use your favorite IDE or editor develop your APIcast policy.
eguzki marked this conversation as resolved.
Show resolved Hide resolved

### Stopping the development container
Stopping the development environment container is a two step process. In the interactive Bash session simple press:
eguzki marked this conversation as resolved.
Show resolved Hide resolved

```
Ctrl + C
```

This exits the foreground bash shell, but the containers are still running. Execute the following make command to cleanly stop all containers:
eguzki marked this conversation as resolved.
Show resolved Hide resolved

```shell
$ make stop-development
docker-compose -f docker-compose-devel.yml -f docker-compose-devel-volmount-mac.yml down
Stopping apicast_build_0_development_1 ... done
Stopping apicast_build_0_redis_1 ... done
Removing apicast_build_0_development_1 ... done
Removing apicast_build_0_redis_1 ... done
Removing network apicast_build_0_default
```

Now we are ready to create a 3scale APIcast policy. The next step in the tutorial is [here](POLICY_SCAFFOLD.md)
eguzki marked this conversation as resolved.
Show resolved Hide resolved
Loading