Kaynağa Gözat

build(docker): support slim python image

add apt clean

Signed-off-by: zhanghongtong <rory-z@outlook.com>
zhanghongtong 3 yıl önce
ebeveyn
işleme
cb382c04b7

+ 5 - 28
.github/workflows/build_packages.yaml

@@ -83,10 +83,9 @@ jobs:
         matrix:
             suffix:
             - ""
-            - "-slim"
             - "-alpine"
+            - "-slim"
             - "-slim-python"
-            - "-alpine-python"
 
     steps:
     - uses: actions/checkout@v2
@@ -135,40 +134,18 @@ jobs:
       with:
         username: ${{ secrets.DOCKER_HUB_USER }}
         password: ${{ secrets.DOCKER_HUB_TOKEN }}
+    - name: Update version for setup.py
+      if: github.event_name == 'release'
+      run: sed -i -r "s|([ \t]*version=).*|\1'${GITHUB_REF#refs/tags/}',|1" sdk/python/setup.py
     - name: Build multi platform image
-      if: endsWith( matrix.suffix, 'python') == false
       uses: docker/build-push-action@v2
       with:
         context: .
-        platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386
+        platforms: linux/amd64,linux/arm64
         push: ${{ github.event_name == 'release' }}
         tags: ${{ steps.meta.outputs.tags }}
         labels: ${{ steps.meta.outputs.labels }}
         file: deploy/docker/Dockerfile${{ matrix.suffix }}
-    - name: Build multi platform image
-      if: matrix.suffix == '-slim-python'
-      uses: docker/build-push-action@v2
-      with:
-        context: .
-        platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386
-        push: ${{ github.event_name == 'release' }}
-        tags: ${{ steps.meta.outputs.tags }}
-        labels: ${{ steps.meta.outputs.labels }}
-        file: deploy/docker/Dockerfile-slim
-        build-args: |
-          RUN_FROM=python:3.8.12-slim-bullseye
-    - name: Build multi platform image
-      if: matrix.suffix == '-alpine-python'
-      uses: docker/build-push-action@v2
-      with:
-        context: .
-        platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386
-        push: ${{ github.event_name == 'release' }}
-        tags: ${{ steps.meta.outputs.tags }}
-        labels: ${{ steps.meta.outputs.labels }}
-        file: deploy/docker/Dockerfile-alpine
-        build-args: |
-          RUN_FROM=python:3.8.12-alpine3.15
 
   build-plugins:
     runs-on: ubuntu-latest

+ 4 - 1
deploy/docker/Dockerfile

@@ -18,7 +18,10 @@ COPY . /go/kuiper
 
 WORKDIR /go/kuiper
 
-RUN apt update && apt install -y pkg-config libczmq-dev
+RUN apt-get update \
+    && apt-get install -y pkg-config libczmq-dev wget \
+    && apt-get clean \
+    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
 
 RUN make build_with_edgex \
     && ln -s /go/kuiper/_build/kuiper-$(git describe --tags --always)-$(go env GOOS)-$(go env GOARCH) /usr/local/kuiper

+ 2 - 4
deploy/docker/Dockerfile-alpine

@@ -12,9 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-ARG BUILD_FROM=golang:1.17.3-alpine
-ARG RUN_FROM=alpine:3.15
-FROM ${BUILD_FROM} AS builder
+FROM golang:1.17.3-alpine AS builder
 
 COPY . /go/kuiper
 
@@ -23,7 +21,7 @@ WORKDIR /go/kuiper
 RUN apk add gcc make git libc-dev binutils-gold pkgconfig zeromq-dev 
 RUN make build_with_edgex
 
-FROM ${RUN_FROM}
+FROM alpine:3.15
 
 # Set environment vars
 ENV MAINTAINER="emqx.io" \

+ 6 - 5
deploy/docker/Dockerfile-slim

@@ -12,9 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-ARG BUILD_FROM=golang:1.17.3
-ARG RUN_FROM=debian:11
-FROM ${BUILD_FROM} AS builder
+FROM golang:1.17.3 AS builder
 
 COPY . /go/kuiper
 
@@ -23,12 +21,15 @@ WORKDIR /go/kuiper
 RUN apt update && apt install -y pkg-config libczmq-dev
 RUN make build_with_edgex
 
-FROM ${RUN_FROM}
+FROM debian:11
 
 COPY ./deploy/docker/docker-entrypoint.sh /usr/bin/docker-entrypoint.sh
 COPY --from=builder /go/kuiper/_build/kuiper-* /kuiper/
 
-RUN apt update && apt install -y pkg-config libczmq-dev wget
+RUN apt-get update \
+    && apt-get install -y pkg-config libczmq-dev wget \
+    && apt-get clean \
+    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
 
 WORKDIR /kuiper
 

+ 49 - 0
deploy/docker/Dockerfile-slim-python

@@ -0,0 +1,49 @@
+# Copyright 2021 EMQ Technologies Co., Ltd.
+#
+# Licensed 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 golang:1.17.3 AS builder
+
+COPY . /go/kuiper
+
+WORKDIR /go/kuiper
+
+RUN apt update && apt install -y pkg-config libczmq-dev
+RUN make build_with_edgex
+
+FROM python:3.8.12-slim-bullseye
+
+COPY --from=builder /go/kuiper/_build/kuiper-* /kuiper/
+COPY ./deploy/docker/docker-entrypoint.sh /usr/bin/docker-entrypoint.sh
+COPY ./sdk/python /sdk/python
+
+RUN apt-get update \
+    && apt-get install -y pkg-config libczmq-dev wget cmake \
+    && apt-get clean \
+    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
+
+WORKDIR /sdk/python
+RUN python3 setup.py sdist && python3 setup.py install
+
+WORKDIR /kuiper
+
+ENV MAINTAINER="emqx.io"
+ENV KUIPER_HOME /kuiper
+ENV KUIPER__BASIC__CONSOLELOG true
+
+VOLUME ["/kuiper/etc", "/kuiper/data", "/kuiper/plugins", "/kuiper/log"]
+EXPOSE 9081 20498
+
+ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"]
+
+CMD ["./bin/kuiperd"]