You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by kv...@apache.org on 2021/02/25 10:13:56 UTC
[apisix-docker] branch master updated: feat: support build apisix
image from local code (#137)
This is an automated email from the ASF dual-hosted git repository.
kvn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-docker.git
The following commit(s) were added to refs/heads/master by this push:
new 5675363 feat: support build apisix image from local code (#137)
5675363 is described below
commit 56753632774e06177e241e88ef7b3bf661104772
Author: Shuyang Wu <wo...@gmail.com>
AuthorDate: Thu Feb 25 18:13:49 2021 +0800
feat: support build apisix image from local code (#137)
* feat: support build apisix image from local code
Signed-off-by: yiyiyimu <wo...@gmail.com>
* fix typo
Signed-off-by: yiyiyimu <wo...@gmail.com>
* fix path
Signed-off-by: yiyiyimu <wo...@gmail.com>
* fix path
Signed-off-by: yiyiyimu <wo...@gmail.com>
* change cp to mv to reduce image size
Signed-off-by: yiyiyimu <wo...@gmail.com>
* fix typo
Signed-off-by: yiyiyimu <wo...@gmail.com>
* to get dir name of apisix
Signed-off-by: yiyiyimu <wo...@gmail.com>
* no need to copy apisix to image
Signed-off-by: yiyiyimu <wo...@gmail.com>
* revert
Signed-off-by: yiyiyimu <wo...@gmail.com>
* revert
Signed-off-by: yiyiyimu <wo...@gmail.com>
* add ARG
Signed-off-by: yiyiyimu <wo...@gmail.com>
* add doc
Signed-off-by: yiyiyimu <wo...@gmail.com>
---
.github/workflows/apisix-alpine-docker-test.yaml | 1 -
...t.yaml => apisix-alpine-local-docker-test.yaml} | 20 +++-------
Makefile | 4 ++
README.md | 12 +++++-
alpine-local/Dockerfile | 43 ++++++++++++++++++++++
{alpine => alpine-local}/docker-compose.yaml | 3 +-
alpine/docker-compose.yaml | 1 -
7 files changed, 64 insertions(+), 20 deletions(-)
diff --git a/.github/workflows/apisix-alpine-docker-test.yaml b/.github/workflows/apisix-alpine-docker-test.yaml
index 74d2c1a..e009d5d 100644
--- a/.github/workflows/apisix-alpine-docker-test.yaml
+++ b/.github/workflows/apisix-alpine-docker-test.yaml
@@ -48,4 +48,3 @@ jobs:
uses: actions/upload-artifact@v2
with:
path: ./package
-
diff --git a/.github/workflows/apisix-alpine-docker-test.yaml b/.github/workflows/apisix-alpine-local-docker-test.yaml
similarity index 71%
copy from .github/workflows/apisix-alpine-docker-test.yaml
copy to .github/workflows/apisix-alpine-local-docker-test.yaml
index 74d2c1a..e03c805 100644
--- a/.github/workflows/apisix-alpine-docker-test.yaml
+++ b/.github/workflows/apisix-alpine-local-docker-test.yaml
@@ -1,4 +1,4 @@
-name: APISIX Alpine docker Test
+name: APISIX Alpine local docker Test
on:
push:
@@ -15,10 +15,12 @@ jobs:
- uses: actions/checkout@v2
- name: Build and run
run: |
- make build-on-alpine
- docker-compose -f ./alpine/docker-compose.yaml up -d
+ git clone http://github.com/apache/apisix apisix-local
+ export APISIX_PATH="./apisix-local"
+ make build-on-alpine-local
+ docker-compose -f ./alpine-local/docker-compose.yaml up -d
sleep 30
- docker logs alpine_apisix_1
+ docker logs alpine-local_apisix_1
- name: Test
run: |
@@ -39,13 +41,3 @@ jobs:
printf "result_code: %s\n" "$result_code"
exit 125
fi
-
- - name: Tar Image
- run: |
- make save-alpine-tar
-
- - name: Upload Image
- uses: actions/upload-artifact@v2
- with:
- path: ./package
-
diff --git a/Makefile b/Makefile
index 26bb14a..0ffb124 100644
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,10 @@ build-on-centos:
build-on-alpine:
docker build -t $(IMAGE_NAME):$(APISIX_VERSION)-alpine -f ./alpine/Dockerfile .
+### build-on-alpine: Build apaceh/apisix:xx-alpine image
+build-on-alpine-local:
+ docker build -t $(IMAGE_NAME):alpine-local --build-arg APISIX_PATH=${APISIX_PATH} -f ./alpine-local/Dockerfile .
+
### save-centos-tar: tar apaceh/apisix:xx-centos image
save-centos-tar:
mkdir -p package
diff --git a/README.md b/README.md
index ee645b9..45a1a4d 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
### Build an image from source
-1. install release version:
+1. Build from release version:
```
# Assign Apache release version number to variable `APISIX_VERSION`, for example: 2.2 . The latest version can be find at `https://github.com/apache/apisix/releases`
@@ -14,12 +14,20 @@ export APISIX_VERSION=2.2
docker build -t apisix:${APISIX_VERSION}-alpine --build-arg APISIX_VERSION=${APISIX_VERSION} -f alpine/Dockerfile alpine
```
-2. install master branch version, which has latest code(ONLY for the developer's convenience):
+2. Build from master branch version, which has latest code(ONLY for the developer's convenience):
```
export APISIX_VERSION=master
docker build -t apisix:${APISIX_VERSION}-alpine --build-arg APISIX_VERSION=${APISIX_VERSION} -f alpine/Dockerfile alpine
```
+3. Build from local code:
+```
+# To copy apisix into image, we need to include it in build context
+cd <APISIX-PATH>
+docker build -t apisix:alpine-local --build-arg APISIX_PATH=. -f <APISIX-DOCKER-PATH>/alpine-local/Dockerfile alpine
+# Might need root privilege if encounter "error checking context: 'can't stat'"
+```
+
**Note:** For Chinese, the following command is always recommended. The additional build argument `ENABLE_PROXY=true` will enable proxy to definitely accelerate the progress.
```sh
diff --git a/alpine-local/Dockerfile b/alpine-local/Dockerfile
new file mode 100644
index 0000000..493eb3e
--- /dev/null
+++ b/alpine-local/Dockerfile
@@ -0,0 +1,43 @@
+ARG ENABLE_PROXY=false
+
+FROM openresty/openresty:alpine-fat AS production-stage
+
+ARG ENABLE_PROXY
+ARG APISIX_PATH
+COPY $APISIX_PATH ./apisix
+RUN set -x \
+ && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \
+ && apk add --no-cache --virtual .builddeps \
+ automake \
+ autoconf \
+ libtool \
+ pkgconfig \
+ cmake \
+ git \
+ && cd apisix \
+ && make deps \
+ && cp -v bin/apisix /usr/bin/ \
+ && mv ../apisix /usr/local/apisix \
+ && apk del .builddeps build-base make unzip
+
+FROM alpine:3.11 AS last-stage
+
+ARG ENABLE_PROXY
+# add runtime for Apache APISIX
+RUN set -x \
+ && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \
+ && apk add --no-cache bash libstdc++ curl
+
+WORKDIR /usr/local/apisix
+
+COPY --from=production-stage /usr/local/openresty/ /usr/local/openresty/
+COPY --from=production-stage /usr/local/apisix/ /usr/local/apisix/
+COPY --from=production-stage /usr/bin/apisix /usr/bin/apisix
+
+ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
+
+EXPOSE 9080 9443
+
+CMD ["sh", "-c", "/usr/bin/apisix init && /usr/bin/apisix init_etcd && /usr/local/openresty/bin/openresty -p /usr/local/apisix -g 'daemon off;'"]
+
+STOPSIGNAL SIGQUIT
diff --git a/alpine/docker-compose.yaml b/alpine-local/docker-compose.yaml
similarity index 95%
copy from alpine/docker-compose.yaml
copy to alpine-local/docker-compose.yaml
index 9850ea4..1893569 100644
--- a/alpine/docker-compose.yaml
+++ b/alpine-local/docker-compose.yaml
@@ -2,7 +2,7 @@ version: "3"
services:
apisix:
- image: apache/apisix:2.3-alpine
+ image: apache/apisix:alpine-local
restart: always
volumes:
- ../example/apisix_log:/usr/local/apisix/logs
@@ -32,7 +32,6 @@ services:
networks:
- apisix
-
networks:
apisix:
driver: bridge
diff --git a/alpine/docker-compose.yaml b/alpine/docker-compose.yaml
index 9850ea4..6598fef 100644
--- a/alpine/docker-compose.yaml
+++ b/alpine/docker-compose.yaml
@@ -32,7 +32,6 @@ services:
networks:
- apisix
-
networks:
apisix:
driver: bridge