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 4 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
89 changes: 89 additions & 0 deletions doc/policy_tutorial/DEV_ENV_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# 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
This means both Docker and Docker compose must be installed.
eguzki marked this conversation as resolved.
Show resolved Hide resolved

* 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` in the Docker [website](https://docs.docker.com/compose/install/).
eguzki marked this conversation as resolved.
Show resolved Hide resolved

Instructions for installing Docker-compose can also be found on the Docker [website](https://docs.docker.com/compose/install/).
eguzki marked this conversation as resolved.
Show resolved Hide resolved

### Setting up the development image
After you have installed both Docker and `docker-compose`, you can configure the APIcast development image.
eguzki marked this conversation as resolved.
Show resolved Hide resolved

. 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
```

. Switch to a stable branch. In this case, the example uses version `3.8`:
```shell
cd apicast/
git checkout 3.8-stable
```

. 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
```

![make-development](img/make-development.png)

. 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:

This can also be done using a Make command, which again must be issued **inside** the container.
```shell
make dependencies
```
It will now download and install a plethora of dependencies inside the container.

+
* 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:
+

![make-dependencies](img/make-dependencies.png)

Now as a final verification we can run some APIcast unit tests to see if we are up and running and ready to start the development of our policy.

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

```shell
make busted
```
![make-busted](img/make-busted.png)

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