Skip to content

Commit 128278a

Browse files
jiang1997wu-sheng
andauthored
[feat]Build multi-architecture Docker images for Python agent (#297)
Co-authored-by: 吴晟 Wu Sheng <[email protected]>
1 parent 58a9f47 commit 128278a

File tree

4 files changed

+111
-9
lines changed

4 files changed

+111
-9
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: publish-docker
19+
20+
on:
21+
push:
22+
branches:
23+
- master
24+
25+
env:
26+
HUB: ghcr.io/apache/skywalking-python
27+
PROJECT: skywalking-python
28+
29+
jobs:
30+
build-docker:
31+
if: github.repository == 'apache/skywalking-python'
32+
runs-on: ubuntu-latest
33+
permissions:
34+
contents: read
35+
packages: write
36+
timeout-minutes: 120
37+
env:
38+
VERSION: ${{ github.sha }}
39+
steps:
40+
- uses: actions/checkout@v2
41+
with:
42+
submodules: true
43+
- name: Log in to the Container registry
44+
uses: docker/[email protected]
45+
with:
46+
registry: ${{ env.HUB }}
47+
username: ${{ github.actor }}
48+
password: ${{ secrets.GITHUB_TOKEN }}
49+
- name: Build and push docker image
50+
run: |
51+
make push-image -j 5

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
### 1.1.0
44

5+
- Feature:
6+
- Add a new workflow to push docker images for arm64 and amd64
7+
58
### 1.0.0
69

710
- **Important Note and Breaking Changes:**

docker/Dockerfile

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@
1515
# limitations under the License.
1616

1717
ARG BASE_PYTHON_IMAGE
18+
ARG BUILDER_PYTHON_IMAGE
19+
FROM ${BASE_PYTHON_IMAGE} AS base
1820

19-
FROM ${BASE_PYTHON_IMAGE}
20-
21-
ARG SW_PYTHON_AGENT_PROTOCOL
22-
ARG SW_PYTHON_AGENT_VERSION
23-
24-
RUN pip install --no-cache-dir "apache-skywalking[${SW_PYTHON_AGENT_PROTOCOL}]==${SW_PYTHON_AGENT_VERSION}"
21+
FROM ${BUILDER_PYTHON_IMAGE} AS builder
22+
RUN pip install --upgrade pip
23+
RUN pip install poetry
24+
COPY ./ /tmp/
25+
RUN make -C /tmp package
26+
RUN pip wheel psutil -w /tmp/dist/
2527

28+
FROM base AS final
29+
COPY --from=builder /tmp/dist/*.whl /tmp/
30+
RUN pip install --upgrade pip
31+
RUN pip install /tmp/psutil*.whl /tmp/apache_skywalking*.whl
32+
RUN rm /tmp/apache_skywalking*.whl /tmp/psutil*.whl
2633
# So that the agent can be auto-started when container is started
2734
ENTRYPOINT ["sw-python"]

docker/Makefile

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
HUB ?= docker.io/apache
18+
PROJECT ?= skywalking-python
19+
1720
D := docker
1821

1922
P := grpc http kafka
2023

21-
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
24+
TARGETS := py3.7 py3.8 py3.9 py3.10 py3.7-slim py3.8-slim py3.9-slim py3.10-slim
2225

2326
py3.7: BASE_PYTHON_IMAGE = python:3.7
2427
py3.8: BASE_PYTHON_IMAGE = python:3.8
@@ -31,24 +34,62 @@ py3.9-slim: BASE_PYTHON_IMAGE = python:3.9-slim
3134
py3.10-slim: BASE_PYTHON_IMAGE = python:3.10-slim
3235
py3.11-slim: BASE_PYTHON_IMAGE = python:3.11-slim
3336

37+
push-py3.7: BASE_PYTHON_IMAGE = python:3.7
38+
push-py3.8: BASE_PYTHON_IMAGE = python:3.8
39+
push-py3.9: BASE_PYTHON_IMAGE = python:3.9
40+
push-py3.10: BASE_PYTHON_IMAGE = python:3.10
41+
push-py3.11: BASE_PYTHON_IMAGE = python:3.11
42+
push-py3.7-slim: BASE_PYTHON_IMAGE = python:3.7-slim
43+
push-py3.8-slim: BASE_PYTHON_IMAGE = python:3.8-slim
44+
push-py3.9-slim: BASE_PYTHON_IMAGE = python:3.9-slim
45+
push-py3.10-slim: BASE_PYTHON_IMAGE = python:3.10-slim
46+
push-py3.11-slim: BASE_PYTHON_IMAGE = python:3.11-slim
47+
48+
push-py3.7: BUILDER_PYTHON_IMAGE = python:3.7
49+
push-py3.8: BUILDER_PYTHON_IMAGE = python:3.8
50+
push-py3.9: BUILDER_PYTHON_IMAGE = python:3.9
51+
push-py3.10: BUILDER_PYTHON_IMAGE = python:3.10
52+
push-py3.11: BUILDER_PYTHON_IMAGE = python:3.11
53+
push-py3.7-slim: BUILDER_PYTHON_IMAGE = python:3.7
54+
push-py3.8-slim: BUILDER_PYTHON_IMAGE = python:3.8
55+
push-py3.9-slim: BUILDER_PYTHON_IMAGE = python:3.9
56+
push-py3.10-slim: BUILDER_PYTHON_IMAGE = python:3.10
57+
push-py3.11-slim: BUILDER_PYTHON_IMAGE = python:3.11
58+
3459
PUSH_TARGETS := $(TARGETS:%=push-%)
3560

3661
build: $(TARGETS)
3762
push: $(PUSH_TARGETS)
3863

64+
65+
3966
$(TARGETS):
67+
cd ..; \
4068
for p in $(P); do \
4169
$(D) build $(SW_BUILD_ARGS) \
70+
-f docker/Dockerfile \
4271
--build-arg BASE_PYTHON_IMAGE=$(BASE_PYTHON_IMAGE) \
4372
--build-arg SW_PYTHON_AGENT_PROTOCOL=$$p \
4473
--build-arg SW_PYTHON_AGENT_VERSION=${AGENT_VERSION} \
45-
-t apache/skywalking-python:${AGENT_VERSION}-$$p-$@ \
74+
-t $(HUB)/$(PROJECT):${AGENT_VERSION}-$$p-$@ \
4675
. ; \
4776
done
4877

4978

5079
$(PUSH_TARGETS):
5180
$(eval version := $(subst push-,,$@))
81+
docker buildx create --driver docker-container --name skywalking_python_main_$(version) > /dev/null 2>&1 || true;
82+
cd ..; \
5283
for p in $(P); do \
53-
$(D) push apache/skywalking-python:${AGENT_VERSION}-$$p-${version}; \
84+
$(D) buildx build $(SW_BUILD_ARGS) \
85+
--builder skywalking_python_main_$(version) \
86+
-f docker/Dockerfile \
87+
--platform linux/amd64,linux/arm64 --push \
88+
--build-arg BASE_PYTHON_IMAGE=$(BASE_PYTHON_IMAGE) \
89+
--build-arg BUILDER_PYTHON_IMAGE=$(BUILDER_PYTHON_IMAGE) \
90+
--build-arg SW_PYTHON_AGENT_PROTOCOL=$$p \
91+
--build-arg SW_PYTHON_AGENT_VERSION=${AGENT_VERSION} \
92+
-t $(HUB)/$(PROJECT):${AGENT_VERSION}-$$p-${version} \
93+
. ; \
5494
done
95+
docker buildx rm skywalking_python_main_$(version) || true;

0 commit comments

Comments
 (0)