From b7e01d039b2245f2b0efe4bb86d0656ceac07cbe Mon Sep 17 00:00:00 2001 From: wunder957 Date: Mon, 13 Nov 2023 17:31:06 +0800 Subject: [PATCH 1/2] Change to tow-step build --- .github/workflows/build-latest-images.yml | 11 ++- .github/workflows/docker-image.yml | 41 ++++++++++ .../{build-images.yml => docker-publish.yml} | 18 ++--- .github/workflows/publish.yml | 81 ------------------- .github/workflows/python-package.yml | 2 +- .github/workflows/python-publish.yml | 39 +++++++++ docker/Dockerfile | 17 ++-- docker/Dockerfile.dev | 32 -------- 8 files changed, 105 insertions(+), 136 deletions(-) create mode 100644 .github/workflows/docker-image.yml rename .github/workflows/{build-images.yml => docker-publish.yml} (68%) delete mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/python-publish.yml delete mode 100644 docker/Dockerfile.dev diff --git a/.github/workflows/build-latest-images.yml b/.github/workflows/build-latest-images.yml index 7b5020a..3f65e0d 100644 --- a/.github/workflows/build-latest-images.yml +++ b/.github/workflows/build-latest-images.yml @@ -1,14 +1,14 @@ -name: Build latest images manually +name: Build latest images automatically on: - workflow_dispatch: {} + push: + branches: + - main jobs: deploy: strategy: - fail-fast: false - matrix: - latest-version: ["0.0.2"] + fail-fast: true runs-on: ubuntu-latest @@ -36,7 +36,6 @@ jobs: context: . build-args: | BCC_VERSION=v0.28.0 - DUETECTOR_VERSION=${{ matrix.latest-version }} platforms: linux/amd64,linux/arm64/v8 file: ./docker/Dockerfile push: true diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..0f7794d --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,41 @@ +name: Testing docker image build + +on: + pull_request: + branches: [ "master", "main" ] + +jobs: + deploy: + strategy: + fail-fast: true + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + # Build docker images + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push release + id: docker_build_release + uses: docker/build-push-action@v4 + with: + context: . + build-args: | + BCC_VERSION=v0.28.0 + platforms: linux/amd64,linux/arm64/v8 + file: ./docker/Dockerfile + push: false + tags: ${{ secrets.DOCKERHUB_USERNAME }}/duetector:latest diff --git a/.github/workflows/build-images.yml b/.github/workflows/docker-publish.yml similarity index 68% rename from .github/workflows/build-images.yml rename to .github/workflows/docker-publish.yml index 3d11cdc..facd6bd 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/docker-publish.yml @@ -1,21 +1,20 @@ -name: Build images manually +name: Release docker image on: - workflow_dispatch: {} + workflow_dispatch: {} + release: + types: [published] + +permissions: + contents: write jobs: deploy: - strategy: - fail-fast: false - matrix: - duetector-version: ["0.0.1", "0.0.2"] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - # Build docker images - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -36,8 +35,7 @@ jobs: context: . build-args: | BCC_VERSION=v0.28.0 - DUETECTOR_VERSION=${{ matrix.duetector-version }} platforms: linux/amd64,linux/arm64/v8 file: ./docker/Dockerfile push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/duetector:${{ matrix.duetector-version }} + tags: ${{ secrets.DOCKERHUB_USERNAME }}/duetector:${{ github.ref_name }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 9f593f8..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,81 +0,0 @@ -name: Upload Python Package and Build Image - -on: - release: - types: [published] - -permissions: - contents: write - -jobs: - deploy: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v3 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build twine hatch - - name: Build package - run: python -m build - - name: Publish package - uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} - - name: Upload dists to release - uses: svenstaro/upload-release-action@v2 - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - file: dist/* - file_glob: true - tag: ${{ github.ref }} - overwrite: true - # Build docker images - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push image - id: docker_build - uses: docker/build-push-action@v4 - with: - context: . - build-args: | - BCC_VERSION=v0.28.0 - DUETECTOR_VERSION=${{ github.ref_name }} - platforms: linux/amd64,linux/arm64/v8 - file: ./docker/Dockerfile - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/duetector:${{ github.ref_name }} - - # Build latest if release - - - name: Build and push release - if: '!github.event.release.prerelease' - id: docker_build_release - uses: docker/build-push-action@v4 - with: - context: . - build-args: | - BCC_VERSION=v0.28.0 - DUETECTOR_VERSION=${{ github.ref_name }} - platforms: linux/amd64,linux/arm64/v8 - file: ./docker/Dockerfile - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/duetector:latest diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index b645c08..b525c1c 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -1,4 +1,4 @@ -name: Python package +name: Testing python package on: push: diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..cf218e9 --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,39 @@ +name: Upload Python Package + +on: + release: + types: [published] + +permissions: + contents: write + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build twine hatch + - name: Build package + run: python -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + - name: Upload dists to release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: dist/* + file_glob: true + tag: ${{ github.ref }} + overwrite: true diff --git a/docker/Dockerfile b/docker/Dockerfile index a5752fd..a549e35 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,23 +1,28 @@ ARG BCC_VERSION=v0.28.0 -FROM dataucon/ubuntu-bcc:${BCC_VERSION} +FROM python:3.10.12-slim-bookworm as builder + +RUN pip install build twine hatch +COPY . /source +WORKDIR /source +RUN python -m buil -ARG DUETECTOR_VERSION +FROM dataucon/ubuntu-bcc:${BCC_VERSION} RUN apt-get update && apt-get install -y tini \ && rm -rf /var/lib/apt/lists/* -RUN pip install jupyterlab - -RUN pip install duetector==${DUETECTOR_VERSION} --no-cache-dir +COPY --from=builder /source/dist/*.whl /tmp/ +RUN pip install /tmp/*.whl --no-cache-dir # Add application user - ARG APPLICATION_UID=9999 ARG APPLICATION_GID=9999 RUN addgroup --system --gid ${APPLICATION_GID} application && \ adduser --system --gid ${APPLICATION_GID} --home /home/application --uid ${APPLICATION_UID} --disabled-password application && \ usermod -s /bin/bash application +# Install Jupyterlab as example application +RUN pip install jupyterlab --no-cache-dir COPY docker/start.sh /start.sh RUN chmod +x /start.sh diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev deleted file mode 100644 index 04c2cad..0000000 --- a/docker/Dockerfile.dev +++ /dev/null @@ -1,32 +0,0 @@ -ARG BCC_VERSION=v0.28.0 - -FROM dataucon/ubuntu-bcc:${BCC_VERSION} - -RUN apt-get update && apt-get install -y tini \ - && rm -rf /var/lib/apt/lists/* - -RUN pip install jupyterlab - -COPY . /duetector -RUN pip install -e /duetector --no-cache-dir - - -ARG APPLICATION_UID=9999 -ARG APPLICATION_GID=9999 -RUN addgroup --system --gid ${APPLICATION_GID} application && \ - adduser --system --gid ${APPLICATION_GID} --home /home/application --uid ${APPLICATION_UID} --disabled-password application && \ - usermod -s /bin/bash application - -COPY docker/start.sh /start.sh -RUN chmod +x /start.sh - -CMD [ "/sbin/tini", "--" ] -ENTRYPOINT [ "/start.sh" ] - -# docker build -t duetector:dev -f docker/Dockerfile.dev . - -# Current kernel build with CONFIG_IKHEADERS=m -# docker run -it --rm -p 8888:8888 --cap-add=sys_admin -v /sys/kernel/kheaders.tar.xz:/sys/kernel/kheaders.tar.xz -v /sys/kernel/debug:/sys/kernel/debug duetector:dev - -# Currnet kernel installed with headers -# docker run -it --rm -p 8888:8888 --cap-add=sys_admin -v /usr/lib/modules:/usr/lib/modules -v /sys/kernel/debug:/sys/kernel/debug duetector:dev From 1ca314ff068a7fc899baf9b07ccf7ed42327f5fc Mon Sep 17 00:00:00 2001 From: wunder957 Date: Mon, 13 Nov 2023 17:39:58 +0800 Subject: [PATCH 2/2] Fixing CI --- .github/workflows/build-latest-images.yml | 4 ++-- .github/workflows/docker-image.yml | 6 +++--- .github/workflows/docker-publish.yml | 4 ++-- docker/Dockerfile | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-latest-images.yml b/.github/workflows/build-latest-images.yml index 3f65e0d..92f544f 100644 --- a/.github/workflows/build-latest-images.yml +++ b/.github/workflows/build-latest-images.yml @@ -29,8 +29,8 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push release - id: docker_build_release + name: Build and push + id: docker_build_latest uses: docker/build-push-action@v4 with: context: . diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 0f7794d..bfba132 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -28,8 +28,8 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push release - id: docker_build_release + name: Build image + id: docker_build_test uses: docker/build-push-action@v4 with: context: . @@ -38,4 +38,4 @@ jobs: platforms: linux/amd64,linux/arm64/v8 file: ./docker/Dockerfile push: false - tags: ${{ secrets.DOCKERHUB_USERNAME }}/duetector:latest + tags: build diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index facd6bd..6d7dff9 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -28,8 +28,8 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push image - id: docker_build + name: Build and push + id: docker_build_release uses: docker/build-push-action@v4 with: context: . diff --git a/docker/Dockerfile b/docker/Dockerfile index a549e35..7f5c40d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -5,7 +5,7 @@ FROM python:3.10.12-slim-bookworm as builder RUN pip install build twine hatch COPY . /source WORKDIR /source -RUN python -m buil +RUN python -m build FROM dataucon/ubuntu-bcc:${BCC_VERSION}