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: 120
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 -j 5
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
19 changes: 13 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@
# limitations under the License.

ARG BASE_PYTHON_IMAGE
ARG BUILDER_PYTHON_IMAGE
FROM ${BASE_PYTHON_IMAGE} AS base

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 ${BUILDER_PYTHON_IMAGE} AS builder
RUN pip install --upgrade pip
RUN pip install poetry
COPY ./ /tmp/
RUN make -C /tmp package
RUN pip wheel psutil -w /tmp/dist/

FROM base AS final
COPY --from=builder /tmp/dist/*.whl /tmp/
RUN pip install --upgrade pip
RUN pip install /tmp/psutil*.whl /tmp/apache_skywalking*.whl
RUN rm /tmp/apache_skywalking*.whl /tmp/psutil*.whl
# So that the agent can be auto-started when container is started
ENTRYPOINT ["sw-python"]
47 changes: 44 additions & 3 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
# 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

TARGETS := py3.7 py3.8 py3.9 py3.10 py3.11 py3.7-slim py3.8-slim py3.9-slim py3.10-slim py3.11-slim
TARGETS := py3.7 py3.8 py3.9 py3.10 py3.7-slim py3.8-slim py3.9-slim py3.10-slim

py3.7: BASE_PYTHON_IMAGE = python:3.7
py3.8: BASE_PYTHON_IMAGE = python:3.8
Expand All @@ -31,24 +34,62 @@ 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-py3.7: BUILDER_PYTHON_IMAGE = python:3.7
push-py3.8: BUILDER_PYTHON_IMAGE = python:3.8
push-py3.9: BUILDER_PYTHON_IMAGE = python:3.9
push-py3.10: BUILDER_PYTHON_IMAGE = python:3.10
push-py3.11: BUILDER_PYTHON_IMAGE = python:3.11
push-py3.7-slim: BUILDER_PYTHON_IMAGE = python:3.7
push-py3.8-slim: BUILDER_PYTHON_IMAGE = python:3.8
push-py3.9-slim: BUILDER_PYTHON_IMAGE = python:3.9
push-py3.10-slim: BUILDER_PYTHON_IMAGE = python:3.10
push-py3.11-slim: BUILDER_PYTHON_IMAGE = python:3.11

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 --driver docker-container --name skywalking_python_main_$(version) > /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) \
--builder skywalking_python_main_$(version) \
-f docker/Dockerfile \
--platform linux/amd64,linux/arm64 --push \
--build-arg BASE_PYTHON_IMAGE=$(BASE_PYTHON_IMAGE) \
--build-arg BUILDER_PYTHON_IMAGE=$(BUILDER_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_$(version) || true;