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

feat: build apisix-openresty base on alpine #97

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
29 changes: 29 additions & 0 deletions .github/workflows/package-apisix-base-apk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: package apisix-base apk

on:
push:
branches: [ openresty/* ]
tags:
- "v*"
paths-ignore:
- '*.md'
pull_request:
branches: [ master ]
paths-ignore:
- '*.md'

jobs:
build:
runs-on: ubuntu-latest
env:
BUILD_APISIX_BASE_VERSION: 1.19.3.2.0
steps:
- uses: actions/checkout@v2

- name: install dependencies
run: |
sudo apt-get install -y make ruby ruby-dev rubygems build-essential

- name: build apisix-base apk
run: |
make package version=${BUILD_APISIX_BASE_VERSION} image_base=alpine image_tag=3.12 app=apisix-base type=apk
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
42 changes: 39 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ image_tag="7"
iteration=0
local_code_path=0
openresty="openresty"
openresty_version="1.19.3.2.0"
artifact="0"
apisix_repo="https://github.com/apache/apisix"
dashboard_repo="https://github.com/apache/apisix-dashboard"
Expand Down Expand Up @@ -67,6 +68,34 @@ define build
endef
endif

### function for building image
### $(1) is name
### $(2) is dockerfile filename
### $(3) is package type
### $(4) is openresty image name
### $(5) is openresty image version
### $(6) is code path
ifneq ($(buildx), True)
define build-image
docker build -t apache/$(1)-$(3):$(version) \
--build-arg OPENRESTY_NAME=$(4) \
--build-arg OPENRESTY_VERSION=$(5) \
--build-arg CODE_PATH=$(6) \
-f ./dockerfiles/Dockerfile.$(2).$(3) .
endef
else
define build-image
docker buildx build -t apache/$(1)-$(3):$(version) \
--build-arg OPENRESTY_NAME=$(4) \
--build-arg OPENRESTY_VERSION=$(5) \
--build-arg CODE_PATH=$(6) \
--load \
--cache-from=$(cache_from) \
--cache-to=$(cache_to) \
-f ./dockerfiles/Dockerfile.$(2).$(3) .
endef
endif

### function for packing
### $(1) is name
### $(2) is package type
Expand Down Expand Up @@ -155,6 +184,10 @@ build-apisix-base-rpm:
build-apisix-base-deb:
$(call build,apisix-base,apisix-base,deb,$(local_code_path))

.PHONY: build-apisix-base-apk
build-apisix-base-apk:
$(call build,apisix-base,apisix-base,apk,$(local_code_path))

### build rpm for apisix-base:
.PHONY: package-apisix-base-rpm
package-apisix-base-rpm:
Expand All @@ -180,10 +213,10 @@ build-fpm:
endif

ifeq ($(filter $(app),apisix dashboard apisix-base),)
$(info the app's value have to be apisix or dashboard!)
$(info the app's value have to be apisix, dashboard or apisix-base!)

else ifeq ($(filter $(type),rpm deb),)
$(info the type's value have to be rpm or deb!)
else ifeq ($(filter $(type),rpm deb apk),)
$(info the type's value have to be rpm, deb or apk!)

else ifeq ($(version), 0)
$(info you have to input a version value!)
Expand All @@ -198,6 +231,9 @@ package: build-fpm
package: build-apisix-base-deb
package: package-apisix-base-deb

else ifeq ($(app)_$(type),apisix-base_apk)
package: build-apisix-base-apk

else ifeq ($(checkout), 0)
$(info you have to input a checkout value!)

Expand Down
23 changes: 13 additions & 10 deletions build-apisix-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,18 @@ cd "$workdir" || exit 1

or_ver="1.19.3.2"
wget --no-check-certificate https://openresty.org/download/openresty-${or_ver}.tar.gz
tar -zxvpf openresty-${or_ver}.tar.gz
tar -zxvpf openresty-${or_ver}.tar.gz > /dev/null

if [ "$repo" == wasm-nginx-module ]; then
cp -r "$prev_workdir" .
else
git clone --depth=1 $wasm_nginx_module_ver \
https://github.com/api7/wasm-nginx-module.git
fi

cd wasm-nginx-module || exit 1
./install-wasmtime.sh
cd ..

if [ "$repo" == ngx_multi_upstream_module ]; then
cp -r "$prev_workdir" .
Expand All @@ -50,12 +61,7 @@ else
https://github.com/api7/apisix-nginx-module.git
fi

if [ "$repo" == wasm-nginx-module ]; then
cp -r "$prev_workdir" .
else
git clone --depth=1 $wasm_nginx_module_ver \
https://github.com/api7/wasm-nginx-module.git
fi


if [ "$repo" == lua-var-nginx-module ]; then
cp -r "$prev_workdir" .
Expand All @@ -72,9 +78,6 @@ cd apisix-nginx-module/patch || exit 1
./patch.sh ../../openresty-${or_ver}
cd ../..

cd wasm-nginx-module || exit 1
./install-wasmtime.sh
cd ..

version=${version:-0.0.0}
cc_opt=${cc_opt:-}
Expand Down
95 changes: 95 additions & 0 deletions dockerfiles/Dockerfile.apisix-base.apk
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
ARG IMAGE_BASE="alpine"
ARG IMAGE_TAG="3.12"

FROM ${IMAGE_BASE}:${IMAGE_TAG}

COPY ./utils/build-common.sh /tmp/build-common.sh
COPY build-apisix-base.sh /tmp/build-apisix-base.sh
COPY ./utils/determine-dist.sh /tmp/determine-dist.sh


ARG RESTY_OPENSSL_VERSION="1.1.1g"
ARG RESTY_OPENSSL_PATCH_VERSION="1.1.1f"
ARG RESTY_OPENSSL_URL_BASE="https://www.openssl.org/source"
ARG RESTY_PCRE_VERSION="8.44"
ARG RESTY_J="1"
ARG RESTY_EVAL_PRE_CONFIGURE=""
ARG VERSION

LABEL resty_image_base="${RESTY_IMAGE_BASE}"
LABEL resty_image_tag="${IMAGE_TAG}"
LABEL resty_openssl_version="${RESTY_OPENSSL_VERSION}"
LABEL resty_openssl_patch_version="${RESTY_OPENSSL_PATCH_VERSION}"
LABEL resty_openssl_url_base="${RESTY_OPENSSL_URL_BASE}"
LABEL resty_pcre_version="${RESTY_PCRE_VERSION}"
LABEL resty_eval_pre_configure="${RESTY_EVAL_PRE_CONFIGURE}"


RUN apk add --no-cache --virtual .build-deps \
build-base \
coreutils \
curl \
gd-dev \
geoip-dev \
libxslt-dev \
linux-headers \
make \
perl-dev \
readline-dev \
zlib-dev \
&& apk add --no-cache \
gd \
geoip \
libxslt \
zlib \
bash \
git \
sudo \
curl \
build-base \
libstdc++

# install latest Rust to build wasmtime
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rust-installer.sh \
&& chmod +x ./rust-installer.sh \
&& ./rust-installer.sh -y \
&& rm rust-installer.sh

RUN cd /tmp \
&& if [ -n "${RESTY_EVAL_PRE_CONFIGURE}" ]; then eval $(echo ${RESTY_EVAL_PRE_CONFIGURE}); fi \
&& cd /tmp \
&& curl -fSL "${RESTY_OPENSSL_URL_BASE}/openssl-${RESTY_OPENSSL_VERSION}.tar.gz" -o openssl-${RESTY_OPENSSL_VERSION}.tar.gz \
&& tar xzf openssl-${RESTY_OPENSSL_VERSION}.tar.gz \
&& cd openssl-${RESTY_OPENSSL_VERSION} \
&& echo 'patching OpenSSL 1.1.1 for OpenResty' \
&& curl -s https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-${RESTY_OPENSSL_PATCH_VERSION}-sess_set_get_cb_yield.patch | patch -p1 \
&& ./config \
no-threads shared zlib -g \
enable-ssl3 enable-ssl3-method \
--prefix=/usr/local/openresty/openssl111 \
--libdir=lib \
-Wl,-rpath,/usr/local/openresty/openssl111/lib \
&& make -j${RESTY_J} \
&& make -j${RESTY_J} install_sw

RUN cd /tmp \
&& curl -fSL https://ftp.pcre.org/pub/pcre/pcre-${RESTY_PCRE_VERSION}.tar.gz -o pcre-${RESTY_PCRE_VERSION}.tar.gz \
&& tar xzf pcre-${RESTY_PCRE_VERSION}.tar.gz \
&& cd /tmp/pcre-${RESTY_PCRE_VERSION} \
&& ./configure \
--prefix=/usr/local/openresty/pcre \
--disable-cpp \
--enable-jit \
--enable-utf \
--enable-unicode-properties \
&& make -j${RESTY_J} \
&& make -j${RESTY_J} install

ENV version=${VERSION}
RUN cd /tmp \
&& curl --version \
&& source /root/.cargo/env \
&& ./build-common.sh build_apisix_base_apk \
&& /usr/local/openresty/bin/openresty -V

CMD /bin/sh
55 changes: 55 additions & 0 deletions dockerfiles/Dockerfile.apisix.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
ARG ENABLE_PROXY=false
Copy link
Contributor

Choose a reason for hiding this comment

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

This file can be removed?

ARG OPENRESTY_VERSION
ARG OPENRESTY_NAME

FROM apache/${OPENRESTY_NAME}:${OPENRESTY_VERSION} AS production-stage

ARG APISIX_VERSION=2.9
LABEL apisix_version="${APISIX_VERSION}"

ARG ENABLE_PROXY
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 \
pcre \
pcre-dev \
&& mkdir ~/.luarocks \
&& luarocks config variables.OPENSSL_LIBDIR /usr/local/openresty/openssl/lib \
&& luarocks config variables.OPENSSL_INCDIR /usr/local/openresty/openssl/include \
&& luarocks install https://github.com/apache/apisix/raw/master/rockspec/apisix-${APISIX_VERSION}-0.rockspec --tree=/usr/local/apisix/deps \
&& cp -v /usr/local/apisix/deps/lib/luarocks/rocks-5.1/apisix/${APISIX_VERSION}-0/bin/apisix /usr/bin/ \
&& (if [ "$APISIX_VERSION" = "master" ] || [ "$APISIX_VERSION" \> "2.2" ]; then echo 'use shell ';else bin='#! /usr/local/openresty/luajit/bin/luajit\npackage.path = "/usr/local/apisix/?.lua;" .. package.path'; sed -i "1s@.*@$bin@" /usr/bin/apisix ; fi;) \
&& mv /usr/local/apisix/deps/share/lua/5.1/apisix /usr/local/apisix \
&& apk del .builddeps build-base make unzip

FROM alpine:3.13 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 tzdata

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

# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /usr/local/apisix/logs/access.log \
&& ln -sf /dev/stderr /usr/local/apisix/logs/error.log

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
9 changes: 9 additions & 0 deletions utils/build-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ build_apisix_base_deb() {
./build-apisix-base.sh
}

build_apisix_base_apk() {
export_openresty_variables
./build-apisix-base.sh
}

export_openresty_variables() {
export openssl_prefix=/usr/local/openresty/openssl111
export zlib_prefix=/usr/local/openresty/zlib
export pcre_prefix=/usr/local/openresty/pcre
export OR_PREFIX=/usr/local/openresty

export cc_opt="-DNGX_LUA_ABORT_AT_PANIC -I${zlib_prefix}/include -I${pcre_prefix}/include -I${openssl_prefix}/include"
export ld_opt="-L${zlib_prefix}/lib -L${pcre_prefix}/lib -L${openssl_prefix}/lib -Wl,-rpath,${zlib_prefix}/lib:${pcre_prefix}/lib:${openssl_prefix}/lib"
Expand All @@ -49,4 +55,7 @@ build_apisix_base_rpm)
build_apisix_base_deb)
build_apisix_base_deb
;;
build_apisix_base_apk)
build_apisix_base_apk
;;
esac