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

docs: add docs for building apisix development environment in Docker #10899

Merged
merged 11 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
Binary file added docs/assets/images/develop-apisix-dev.png
Copy link
Member

Choose a reason for hiding this comment

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

remove this images, change it to text

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 96 additions & 0 deletions docs/en/latest/build-apisix-dev-environment-in-docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
id: build-apisix-dev-environment-in-docker
title: Build development environment in Docker
description: This article introduces how to quickly build the development environment of the Apache APISIX API gateway using Docker.
---

<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->

If you wish to quickly build and develop APISIX on your system, you can refer to this tutorial.

:::note

This tutorial is suitable for situations where you need to quickly get started with introductory development. If you want to take further steps for a better development experience, a preferable option is a Linux-based virtual machine or directly using such systems as your development environment.

You can see the specific supported systems [here](install-dependencies.md#install).

:::

## Quick Setup of Apache APISIX Development Environment

### Implementation Idea

![Build Apache APISIX Development Environment in Docker](../../assets/images/develop-apisix-dev.png)

### Implementation Steps

First, clone the APISIX source code, build an image that can run test cases, and compile the Apache APISIX.

```shell
git clone https://github.com/apache/apisix.git
cd apisix
docker build -t apisix-dev-env -f example/build-dev-image.dockerfile .
kayx23 marked this conversation as resolved.
Show resolved Hide resolved
```

Next, start Etcd:

```shell
docker run -d --name etcd-apisix --net=host pachyderm/etcd:v3.5.2
```

Mount the APISIX directory and start the development environment container:

```shell
docker run -d --name apisix-dev-env --net=host -v $(pwd):/apisix:rw apisix-dev-env:latest
```

Finally, enter the container, build the Apache APISIX runtime, and configure the test environment:

```shell
docker exec -it apisix-dev-env /bin/bash

make deps
ln -s /usr/bin/openresty /usr/bin/nginx
```

### Run and Stop APISIX

```shell
make run
kayx23 marked this conversation as resolved.
Show resolved Hide resolved
make stop
```

:::note

If you encounter an error message like `nginx: [emerg] bind() to unix:/apisix/logs/worker_events.sock failed (95: Operation not supported)` while running `make run`, please use this solution.

Change the `File Sharing` settings of your Docker-Desktop:

![Docker-Desktop File Sharing Setting](../../assets/images/update-docker-desktop-file-sharing.png)

Changing to either `gRPC FUSE` or `osxfs` can resolve this issue.

:::

### Run Specific Test Cases

```shell
prove t/admin/routes.t
```
4 changes: 4 additions & 0 deletions docs/en/latest/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@
"type": "doc",
"id": "building-apisix"
},
{
"type": "doc",
"id": "build-apisix-dev-environment-in-docker"
},
{
"type": "doc",
"id": "support-fips-in-apisix"
Expand Down
96 changes: 96 additions & 0 deletions docs/zh/latest/build-apisix-dev-environment-in-docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
id: build-apisix-dev-environment-in-docker
title: 通过 Docker 构建开发环境
description: 本文介绍了如何用 Docker 的方式快速构建 API 网关 Apache APISIX 开发环境。
---

<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->

如果你希望快速的在你的系统上构建和开发 APISIX,你可以参考本教程。
Copy link
Member

Choose a reason for hiding this comment

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

mainly for Mac Os users, not others


:::note

本教程适合需要快速开始入门阶段开发的情况,如果你想要更进一步,有更好的开发体验,更好的选择是 Linux-based 虚拟机,或是直接使用这类系统作为你的开发环境。

你可以在[这里](install-dependencies.md#安装)看到具体支持的系统。

:::

## 快速搭建 Apache APISIX 开发环境

### 实现思路

![Build Apache APISIX Development Environment in Docker](../../assets/images/develop-apisix-dev.png)

### 实现步骤

首先,我们需要拉取 APISIX 源码,并构建一个可以运行测试用例以及编译运行 Apache APISIX 的镜像:

```shell
git clone https://github.com/apache/apisix.git
cd apisix
docker build -t apisix-dev-env -f example/build-dev-image.dockerfile .
```

然后,我们要启动 Etcd:

```shell
docker run -d --name etcd-apisix --net=host pachyderm/etcd:v3.5.2
```

挂载 APISIX 目录并启动开发环境容器:

```shell
docker run -d --name apisix-dev-env --net=host -v $(pwd):/apisix:rw apisix-dev-env:latest
```

最后,进入容器,构建 Apache APISIX 运行时并配置测试环境:

```shell
docker exec -it apisix-dev-env /bin/bash

make deps
ln -s /usr/bin/openresty /usr/bin/nginx
```

### 启动和停止 APISIX

```shell
make run
Copy link
Member

Choose a reason for hiding this comment

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

we'd better call them, in this way docker exec ... ...

make stop
```

:::note

如果你在运行 `make run` 时收到类似 `nginx: [emerg] bind() to unix:/apisix/logs/worker_events.sock failed (95: Operation not supported)` 的错误消息,请使用此解决方案。

更改你的 Docker-Desktop 的 `File Sharing` 设置:

![Docker-Desktop File Sharing 设置](../../assets/images/update-docker-desktop-file-sharing.png)

修改为 `gRPC FUSE` 或 `osxfs` 都可以解决此问题。

:::

### 运行指定测试用例

```shell
prove t/admin/routes.t
```
4 changes: 4 additions & 0 deletions docs/zh/latest/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@
"type": "doc",
"id": "building-apisix"
},
{
"type": "doc",
"id": "build-apisix-dev-environment-in-docker"
},
{
"type": "doc",
"id": "support-fips-in-apisix"
Expand Down
31 changes: 31 additions & 0 deletions example/build-dev-image.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
membphis marked this conversation as resolved.
Show resolved Hide resolved
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

FROM ubuntu

# Install Test::Nginx
RUN apt update
RUN apt install -y cpanminus make
RUN cpanm --notest Test::Nginx

RUN apt install -y sudo git gawk curl
Copy link
Member

Choose a reason for hiding this comment

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

add vim


WORKDIR /apisix

ENV PERL5LIB=.:$PERL5LIB

ENTRYPOINT ["tail", "-f", "/dev/null"]
Loading