Skip to content

Commit 3137d57

Browse files
authored
feat(workflow): push apisix:dev image on commit (#12300)
1 parent 460c3be commit 3137d57

File tree

8 files changed

+400
-0
lines changed

8 files changed

+400
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Build and Push `apisix:dev` to DockerHub on Commit
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- "docs/**"
7+
- "**/*.md"
8+
push:
9+
paths-ignore:
10+
- "docs/**"
11+
- "**/*.md"
12+
workflow_dispatch:
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
env:
19+
APISIX_DOCKER_TAG: master-debian-dev
20+
21+
steps:
22+
- name: Check out the repo
23+
uses: actions/checkout@v4
24+
25+
- name: Build and run
26+
run: |
27+
make build-on-debian-dev
28+
docker compose -f ./docker/compose/docker-compose-master.yaml up -d
29+
sleep 30
30+
docker logs compose-apisix-1
31+
32+
- name: Test APISIX
33+
run: |
34+
curl http://127.0.0.1:9180/apisix/admin/routes/1 \
35+
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
36+
{
37+
"uri": "/get",
38+
"upstream": {
39+
"type": "roundrobin",
40+
"nodes": { "httpbin.org:80": 1 }
41+
}
42+
}'
43+
44+
result_code=$(curl -I -m 10 -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/get)
45+
if [[ $result_code -ne 200 ]]; then
46+
printf "result_code: %s\n" "$result_code"
47+
exit 125
48+
fi
49+
50+
- name: Login to Docker Hub
51+
if: github.ref == 'refs/heads/master'
52+
uses: docker/login-action@v1
53+
with:
54+
username: ${{ secrets.DOCKERHUB_USER }}
55+
password: ${{ secrets.DOCKERHUB_TOKEN }}
56+
57+
- name: Set up QEMU
58+
if: github.ref == 'refs/heads/master'
59+
uses: docker/setup-qemu-action@v1
60+
61+
- name: Set up Docker Buildx
62+
if: github.ref == 'refs/heads/master'
63+
uses: docker/setup-buildx-action@v1
64+
65+
- name: Push apisix image to Docker Hub
66+
if: github.ref == 'refs/heads/master'
67+
run: |
68+
make push-multiarch-dev-on-debian

Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ ENV_INST_LUADIR ?= $(ENV_INST_PREFIX)/share/lua/5.1
4949
ENV_INST_BINDIR ?= $(ENV_INST_PREFIX)/bin
5050
ENV_RUNTIME_VER ?= $(shell $(ENV_NGINX_EXEC) -V 2>&1 | tr ' ' '\n' | grep 'APISIX_RUNTIME_VER' | cut -d '=' -f2)
5151

52+
IMAGE_NAME = apache/apisix
53+
ENV_APISIX_IMAGE_TAG_NAME ?= $(IMAGE_NAME):$(VERSION)
54+
5255
-include .requirements
5356
export
5457

@@ -488,3 +491,29 @@ ci-env-stop:
488491
@$(call func_echo_status, "$@ -> [ Start ]")
489492
$(ENV_DOCKER_COMPOSE) stop
490493
@$(call func_echo_success_status, "$@ -> [ Done ]")
494+
495+
### build-on-debian-dev : Build apache/apisix:xx-debian-dev image
496+
.PHONY: build-on-debian-dev
497+
build-on-debian-dev:
498+
@$(call func_echo_status, "$@ -> [ Start ]")
499+
$(ENV_DOCKER) build -t $(ENV_APISIX_IMAGE_TAG_NAME)-debian-dev \
500+
--build-arg CODE_PATH=. \
501+
--build-arg ENTRYPOINT_PATH=./docker/debian-dev/docker-entrypoint.sh \
502+
--build-arg INSTALL_BROTLI=./docker/debian-dev/install-brotli.sh \
503+
--build-arg CHECK_STANDALONE_CONFIG=./docker/utils/check_standalone_config.sh \
504+
-f ./docker/debian-dev/Dockerfile .
505+
@$(call func_echo_success_status, "$@ -> [ Done ]")
506+
507+
### push-multiarch-dev-on-debian : Push apache/apisix:dev image
508+
.PHONY: push-multiarch-dev-on-debian
509+
push-multiarch-dev-on-debian:
510+
@$(call func_echo_status, "$@ -> [ Start ]")
511+
$(ENV_DOCKER) buildx build --network=host --push \
512+
-t $(IMAGE_NAME):dev \
513+
--platform linux/amd64,linux/arm64 \
514+
--build-arg CODE_PATH=. \
515+
--build-arg ENTRYPOINT_PATH=./docker/debian-dev/docker-entrypoint.sh \
516+
--build-arg INSTALL_BROTLI=./docker/debian-dev/install-brotli.sh \
517+
--build-arg CHECK_STANDALONE_CONFIG=./docker/utils/check_standalone_config.sh \
518+
-f ./docker/debian-dev/Dockerfile .
519+
@$(call func_echo_success_status, "$@ -> [ Done ]")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
apisix:
19+
node_listen: 9080 # APISIX listening port
20+
enable_ipv6: false
21+
22+
deployment:
23+
admin:
24+
allow_admin: # https://nginx.org/en/docs/http/ngx_http_access_module.html#allow
25+
- 0.0.0.0/0 # We need to restrict ip access rules for security. 0.0.0.0/0 is for test.
26+
27+
admin_key:
28+
- name: "admin"
29+
key: edd1c9f034335f136f87ad84b625c8f1
30+
role: admin # admin: manage all configuration data
31+
32+
etcd:
33+
host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster.
34+
- "http://etcd:2379" # multiple etcd address
35+
prefix: "/apisix" # apisix configurations prefix
36+
timeout: 30 # 30 seconds
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
version: "3"
19+
20+
services:
21+
apisix:
22+
image: "apache/apisix:${APISIX_DOCKER_TAG}"
23+
restart: always
24+
volumes:
25+
- ./apisix_conf/master/config.yaml:/usr/local/apisix/conf/config.yaml:ro
26+
depends_on:
27+
- etcd
28+
ports:
29+
- "9180:9180/tcp"
30+
- "9080:9080/tcp"
31+
- "9091:9091/tcp"
32+
- "9443:9443/tcp"
33+
networks:
34+
- apisix
35+
36+
etcd:
37+
image: bitnami/etcd:3.4.9
38+
user: root
39+
restart: always
40+
environment:
41+
ETCD_DATA_DIR: /etcd_data
42+
ETCD_ENABLE_V2: "true"
43+
ALLOW_NONE_AUTHENTICATION: "yes"
44+
ETCD_ADVERTISE_CLIENT_URLS: "http://etcd:2379"
45+
ETCD_LISTEN_CLIENT_URLS: "http://0.0.0.0:2379"
46+
ports:
47+
- "2379:2379/tcp"
48+
networks:
49+
- apisix
50+
51+
networks:
52+
apisix:
53+
driver: bridge

docker/debian-dev/Dockerfile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
FROM debian:bullseye-slim AS build
18+
19+
ARG ENABLE_PROXY=false
20+
ARG CODE_PATH
21+
22+
ENV DEBIAN_FRONTEND=noninteractive
23+
ENV ENV_INST_LUADIR=/usr/local/apisix
24+
25+
COPY ${CODE_PATH} /apisix
26+
27+
WORKDIR /apisix
28+
29+
RUN set -x \
30+
&& apt-get -y update --fix-missing \
31+
&& apt-get install -y \
32+
make \
33+
git \
34+
sudo \
35+
libyaml-dev \
36+
&& ls -al \
37+
&& make deps \
38+
&& mkdir -p ${ENV_INST_LUADIR} \
39+
&& cp -r deps ${ENV_INST_LUADIR} \
40+
&& make install
41+
42+
FROM debian:bullseye-slim
43+
44+
ARG ENTRYPOINT_PATH=./docker-entrypoint.sh
45+
ARG INSTALL_BROTLI=./install-brotli.sh
46+
ARG CHECK_STANDALONE_CONFIG=./check_standalone_config.sh
47+
48+
COPY --from=build /usr/local/apisix /usr/local/apisix
49+
COPY --from=build /usr/local/openresty /usr/local/openresty
50+
COPY --from=build /usr/bin/apisix /usr/bin/apisix
51+
COPY --from=build /usr/lib/x86_64-linux-gnu/libyaml* /usr/local/lib/
52+
53+
COPY ${INSTALL_BROTLI} /install-brotli.sh
54+
RUN chmod +x /install-brotli.sh \
55+
&& cd / && ./install-brotli.sh && rm -rf /install-brotli.sh
56+
57+
ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
58+
59+
WORKDIR /usr/local/apisix
60+
61+
RUN ln -sf /dev/stdout /usr/local/apisix/logs/access.log \
62+
&& ln -sf /dev/stderr /usr/local/apisix/logs/error.log
63+
64+
EXPOSE 9080 9443
65+
66+
COPY ${ENTRYPOINT_PATH} /docker-entrypoint.sh
67+
COPY ${CHECK_STANDALONE_CONFIG} /check_standalone_config.sh
68+
RUN chmod +x /docker-entrypoint.sh /check_standalone_config.sh
69+
70+
ENTRYPOINT ["/docker-entrypoint.sh"]
71+
72+
CMD ["docker-start"]
73+
74+
STOPSIGNAL SIGQUIT
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
set -eo pipefail
20+
21+
PREFIX=${APISIX_PREFIX:=/usr/local/apisix}
22+
23+
if [[ "$1" == "docker-start" ]]; then
24+
if [ "$APISIX_STAND_ALONE" = "true" ]; then
25+
# If the file is not present then initialise the content otherwise update relevant keys for standalone mode
26+
if [ ! -f "${PREFIX}/conf/config.yaml" ]; then
27+
cat > ${PREFIX}/conf/config.yaml << _EOC_
28+
deployment:
29+
role: data_plane
30+
role_data_plane:
31+
config_provider: yaml
32+
_EOC_
33+
else
34+
# Check if the deployment role is set to data_plane and config provider is set to yaml for standalone mode
35+
source /check_standalone_config.sh
36+
fi
37+
38+
if [ ! -f "${PREFIX}/conf/apisix.yaml" ]; then
39+
cat > ${PREFIX}/conf/apisix.yaml << _EOC_
40+
routes:
41+
-
42+
#END
43+
_EOC_
44+
fi
45+
/usr/bin/apisix init
46+
else
47+
/usr/bin/apisix init
48+
/usr/bin/apisix init_etcd
49+
fi
50+
51+
# For versions below 3.5.0 whose conf_server has not been removed.
52+
if [ -e "/usr/local/apisix/conf/config_listen.sock" ]; then
53+
rm -f "/usr/local/apisix/conf/config_listen.sock"
54+
fi
55+
56+
if [ -e "/usr/local/apisix/logs/worker_events.sock" ]; then
57+
rm -f "/usr/local/apisix/logs/worker_events.sock"
58+
fi
59+
60+
exec /usr/local/openresty/bin/openresty -p /usr/local/apisix -g 'daemon off;'
61+
fi
62+
63+
exec "$@"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
install_brotli() {
20+
apt-get -qy update
21+
apt-get install -y sudo cmake wget unzip
22+
local BORTLI_VERSION="1.1.0"
23+
wget -q https://github.com/google/brotli/archive/refs/tags/v${BORTLI_VERSION}.zip || exit 1
24+
unzip v${BORTLI_VERSION}.zip && cd ./brotli-${BORTLI_VERSION} && mkdir build && cd build || exit 1
25+
local CMAKE=$(command -v cmake3 >/dev/null 2>&1 && echo cmake3 || echo cmake) || exit 1
26+
${CMAKE} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/brotli .. || exit 1
27+
sudo ${CMAKE} --build . --config Release --target install || exit 1
28+
if [ -d "/usr/local/brotli/lib64" ]; then
29+
echo /usr/local/brotli/lib64 | sudo tee /etc/ld.so.conf.d/brotli.conf
30+
else
31+
echo /usr/local/brotli/lib | sudo tee /etc/ld.so.conf.d/brotli.conf
32+
fi
33+
sudo ldconfig || exit 1
34+
ln -sf /usr/local/brotli/bin/brotli /usr/bin/brotli
35+
cd ../..
36+
rm -rf brotli-${BORTLI_VERSION}
37+
rm -rf /v${BORTLI_VERSION}.zip
38+
export SUDO_FORCE_REMOVE=yes
39+
apt purge -qy cmake sudo wget unzip
40+
apt-get remove --purge --auto-remove -y
41+
}
42+
install_brotli

0 commit comments

Comments
 (0)