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 multi-architecture Docker images for Python agent #297

Merged
merged 10 commits into from
Apr 1, 2023
51 changes: 51 additions & 0 deletions .github/workflows/publish-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

name: publish-docker

on:
push:
branches:
- master

env:
HUB: ghcr.io/apache/skywalking-python
PROJECT: skywalking-python

jobs:
build-docker:
if: github.repository == 'apache/skywalking-python'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
timeout-minutes: 30
env:
VERSION: ${{ github.sha }}
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Log in to the Container registry
uses: docker/login-action@v1.10.0
with:
registry: ${{ env.HUB }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push docker image
run: |
make push-image
Copy link
Member

Choose a reason for hiding this comment

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

I tried to build and push locally and hours passed it is still running, I think we can parallize this by adding make -j 10 push-image?

Copy link
Contributor Author

@jiang1997 jiang1997 Mar 24, 2023

Choose a reason for hiding this comment

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

I have tried make -j 10 push-image, but seems that docker buildx can't run parallel.
Firstly, container skywalking_python_main can't be shared between parallel building tasks, secondly, even though we create target-specific containers, because this line works at system level, CI still runs into errors.

After some digging, I found that the most time-consuming step is building gRPC related whl packages when building image for arm64 python3.11. Cuz there is no needed binary whl package off the shelf so far. grpc/grpc#32454

Copy link
Contributor Author

@jiang1997 jiang1997 Mar 26, 2023

Choose a reason for hiding this comment

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

I discovered that with the --builder option in Docker, we can make multiple targets simultaneously, but not to much(with make -j 10 may run out of disk space).
Compared with non-parallel building, we can save about 10 minutes.

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### 1.1.0

- Feature:
- Add a new workflow to push docker images for arm64 and amd64

### 1.0.0

- **Important Note and Breaking Changes:**
Expand Down
14 changes: 8 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

ARG BASE_PYTHON_IMAGE

FROM ${BASE_PYTHON_IMAGE}

ARG SW_PYTHON_AGENT_PROTOCOL
ARG SW_PYTHON_AGENT_VERSION

RUN pip install --no-cache-dir "apache-skywalking[${SW_PYTHON_AGENT_PROTOCOL}]==${SW_PYTHON_AGENT_VERSION}"
FROM ${BASE_PYTHON_IMAGE} as builder
RUN pip install poetry
COPY ./ /tmp/
RUN make -C /tmp/ package

FROM ${BASE_PYTHON_IMAGE} as final
COPY --from=builder /tmp/dist/apache_skywalking*.whl /tmp/
jiang1997 marked this conversation as resolved.
Show resolved Hide resolved
RUN pip install /tmp/apache_skywalking*.whl
RUN rm /tmp/apache_skywalking*.whl
# So that the agent can be auto-started when container is started
ENTRYPOINT ["sw-python"]
32 changes: 30 additions & 2 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

HUB ?= docker.io/apache
PROJECT ?= skywalking-python

D := docker

P := grpc http kafka
Expand All @@ -31,24 +34,49 @@ py3.9-slim: BASE_PYTHON_IMAGE = python:3.9-slim
py3.10-slim: BASE_PYTHON_IMAGE = python:3.10-slim
py3.11-slim: BASE_PYTHON_IMAGE = python:3.11-slim

push-py3.7: BASE_PYTHON_IMAGE = python:3.7
push-py3.8: BASE_PYTHON_IMAGE = python:3.8
push-py3.9: BASE_PYTHON_IMAGE = python:3.9
push-py3.10: BASE_PYTHON_IMAGE = python:3.10
push-py3.11: BASE_PYTHON_IMAGE = python:3.11
push-py3.7-slim: BASE_PYTHON_IMAGE = python:3.7-slim
push-py3.8-slim: BASE_PYTHON_IMAGE = python:3.8-slim
push-py3.9-slim: BASE_PYTHON_IMAGE = python:3.9-slim
push-py3.10-slim: BASE_PYTHON_IMAGE = python:3.10-slim
push-py3.11-slim: BASE_PYTHON_IMAGE = python:3.11-slim
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to remove this ? You removed 3.11 in the TARGETS

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's okay to remove it. I'm reserving it for future needs.


PUSH_TARGETS := $(TARGETS:%=push-%)

build: $(TARGETS)
push: $(PUSH_TARGETS)



$(TARGETS):
cd ..; \
for p in $(P); do \
$(D) build $(SW_BUILD_ARGS) \
-f docker/Dockerfile \
--build-arg BASE_PYTHON_IMAGE=$(BASE_PYTHON_IMAGE) \
--build-arg SW_PYTHON_AGENT_PROTOCOL=$$p \
--build-arg SW_PYTHON_AGENT_VERSION=${AGENT_VERSION} \
-t apache/skywalking-python:${AGENT_VERSION}-$$p-$@ \
-t $(HUB)/$(PROJECT):${AGENT_VERSION}-$$p-$@ \
kezhenxu94 marked this conversation as resolved.
Show resolved Hide resolved
. ; \
done


$(PUSH_TARGETS):
$(eval version := $(subst push-,,$@))
docker buildx create --use --driver docker-container --name skywalking_python_main > /dev/null 2>&1 || true
cd ..; \
for p in $(P); do \
$(D) push apache/skywalking-python:${AGENT_VERSION}-$$p-${version}; \
$(D) buildx build $(SW_BUILD_ARGS) \
-f docker/Dockerfile \
--platform linux/amd64,linux/arm64 --push \
--build-arg BASE_PYTHON_IMAGE=$(BASE_PYTHON_IMAGE) \
--build-arg SW_PYTHON_AGENT_PROTOCOL=$$p \
--build-arg SW_PYTHON_AGENT_VERSION=${AGENT_VERSION} \
-t $(HUB)/$(PROJECT):${AGENT_VERSION}-$$p-${version} \
. ; \
done
docker buildx rm skywalking_python_main || true