Skip to content

Commit c7a72d9

Browse files
authored
Merge pull request #2318 from valory-xyz/fix/build-image
Fix: Support building `linux/amd64,linux/arm64,linux/arm/v7` agent images
2 parents 4b6cf2a + 76e4b8c commit c7a72d9

File tree

12 files changed

+77
-16
lines changed

12 files changed

+77
-16
lines changed

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ jobs:
157157
run: |
158158
# export `TAG` variable
159159
source env.sh
160-
docker buildx build --platform linux/amd64,linux/arm64 -t valory/open-autonomy-user:$TAG deployments/Dockerfiles/autonomy-user --push
161-
docker buildx build --platform linux/amd64,linux/arm64 -t valory/open-autonomy-user:latest deployments/Dockerfiles/autonomy-user --push
160+
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t valory/open-autonomy-user:$TAG deployments/Dockerfiles/autonomy-user --push
161+
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t valory/open-autonomy-user:latest deployments/Dockerfiles/autonomy-user --push
162162
163163
publish-helper-images:
164164
name: Publish Helper Images

autonomy/cli/build_images.py

+15
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,18 @@
7272
type=str,
7373
help="Specify the target architecture platform for the image.",
7474
)
75+
@click.option(
76+
"--builder",
77+
type=str,
78+
help='Override the configured docker builder instance (default "default").',
79+
)
7580
@click.option("--push", is_flag=True, help="Push image to docker hub.", default=False)
81+
@click.option(
82+
"--pre-install-command",
83+
type=str,
84+
help="Run the command before installing dependencies.",
85+
default=None,
86+
)
7687
@image_author_option
7788
def build_image( # pylint: disable=too-many-arguments
7889
agent: Optional[PublicId],
@@ -85,6 +96,8 @@ def build_image( # pylint: disable=too-many-arguments
8596
image_author: Optional[str] = None,
8697
platform: Optional[str] = None,
8798
push: bool = False,
99+
builder: Optional[str] = None,
100+
pre_install_command: Optional[str] = None,
88101
) -> None:
89102
"""Build runtime images for autonomous agents."""
90103
if dev:
@@ -103,4 +116,6 @@ def build_image( # pylint: disable=too-many-arguments
103116
dockerfile=dockerfile,
104117
platform=platform,
105118
push=push,
119+
builder=builder,
120+
pre_install_command=pre_install_command,
106121
)

autonomy/cli/helpers/image.py

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def build_image( # pylint: disable=too-many-arguments
3939
dockerfile: Optional[Path] = None,
4040
platform: Optional[str] = None,
4141
push: bool = False,
42+
builder: Optional[str] = None,
43+
pre_install_command: Optional[str] = None,
4244
) -> None:
4345
"""Build agent/service image."""
4446
extra_dependencies = extra_dependencies or ()
@@ -58,4 +60,6 @@ def build_image( # pylint: disable=too-many-arguments
5860
dockerfile=dockerfile,
5961
platform=platform,
6062
push=push,
63+
builder=builder,
64+
pre_install_command=pre_install_command,
6165
)

autonomy/data/Dockerfiles/agent/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ ARG AEA_AGENT
66
ARG AUTHOR
77
ARG EXTRA_DEPENDENCIES
88

9+
ARG PRE_INSTALL_COMMAND=""
10+
RUN /bin/sh -c "${PRE_INSTALL_COMMAND}"
11+
912
RUN aea init --reset --remote --ipfs --author ${AUTHOR}
1013

1114
WORKDIR /root

autonomy/deploy/image.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def build_image( # pylint: disable=too-many-arguments,too-many-locals
6565
dockerfile: Optional[Path] = None,
6666
platform: Optional[str] = None,
6767
push: bool = False,
68+
builder: Optional[str] = None,
69+
pre_install_command: Optional[str] = None,
6870
) -> None:
6971
"""Command to build images from for skaffold deployment."""
7072

@@ -94,20 +96,28 @@ def build_image( # pylint: disable=too-many-arguments,too-many-locals
9496
f"AUTHOR={get_default_author_from_cli_config()}",
9597
"--build-arg",
9698
f"AEA_AGENT={str(agent)}",
97-
"--build-arg",
98-
f"EXTRA_DEPENDENCIES={generate_dependency_flag_var(extra_dependencies or ())}",
9999
"--tag",
100100
tag,
101101
"--no-cache",
102102
]
103+
+ (
104+
[
105+
"--build-arg",
106+
f"EXTRA_DEPENDENCIES={generate_dependency_flag_var(extra_dependencies)}",
107+
]
108+
if extra_dependencies
109+
else []
110+
)
111+
+ (
112+
["--build-arg", f"PRE_INSTALL_COMMAND={pre_install_command}"]
113+
if pre_install_command
114+
else []
115+
)
103116
+ (["--platform", platform] if platform else [])
104-
+ []
105117
+ (["--push"] if push else [])
106-
+ []
107118
+ (["--pull"] if pull else [])
108-
+ [
109-
path,
110-
]
119+
+ (["--builder", builder] if builder else [])
120+
+ [path]
111121
)
112122

113123
build_process.check_returncode()

deployments/Dockerfiles/autonomy-user/Dockerfile

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
# Base image
2-
FROM python:3.10-slim-bullseye as base
2+
FROM python:3.10-slim-bullseye AS base
33
ENV VIRTUAL_ENV=/opt/venv
44
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
55

6-
RUN apt-get update -y && apt-get install gcc -y && rm -rf /var/lib/apt/lists/*
6+
RUN apt-get update -y && apt-get install gcc git make libssl-dev libffi-dev -y && rm -rf /var/lib/apt/lists/*
77

88
# Install library dependencies into our venv
99
RUN python3 -m venv $VIRTUAL_ENV
1010
COPY requirements.txt .
11+
RUN pip install --upgrade pip
1112
RUN pip install -r requirements.txt
1213

1314
# Customize base image with agent deps
14-
FROM python:3.10-slim-bullseye as agent_deps
15+
FROM python:3.10-slim-bullseye AS agent_deps
1516
ARG AUTHOR=user
1617

18+
# Install docker
19+
VOLUME /var/run/docker.sock
20+
RUN apt-get update -y && apt-get install curl -y
21+
RUN curl -sSL https://get.docker.com/ | sh
22+
1723
ENV VIRTUAL_ENV=/opt/venv
1824
COPY --from=base $VIRTUAL_ENV $VIRTUAL_ENV
1925

deployments/Dockerfiles/autonomy/Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ ARG AEA_VERSION=latest
22

33
FROM valory/open-aea-user:${AEA_VERSION}
44

5+
VOLUME /var/run/docker.sock
56
RUN apt update
67

7-
RUN apt install git net-tools sudo -y
8+
RUN apt install git net-tools sudo curl -y
9+
10+
RUN curl -sSL https://get.docker.com/ | sh
811

912
COPY scripts /root/scripts
1013

deployments/Dockerfiles/autonomy/scripts/install.sh

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ aea fetch $AEA_AGENT --alias agent || exit 1
1313
cd agent
1414

1515
echo "Building the deployments host dependencies."
16+
pip install --upgrade pip
1617
aea build || exit 1
1718
echo "Successfully built the host dependencies."
1819

docs/api/cli/build_images.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,21 @@ Build images.
5252
type=str,
5353
help="Specify the target architecture platform for the image.",
5454
)
55+
@click.option(
56+
"--builder",
57+
type=str,
58+
help='Override the configured docker builder instance (default "default").',
59+
)
5560
@click.option("--push",
5661
is_flag=True,
5762
help="Push image to docker hub.",
5863
default=False)
64+
@click.option(
65+
"--pre-install-command",
66+
type=str,
67+
help="Run the command before installing dependencies.",
68+
default=None,
69+
)
5970
@image_author_option
6071
def build_image(agent: Optional[PublicId],
6172
service_dir: Optional[Path],
@@ -66,7 +77,9 @@ def build_image(agent: Optional[PublicId],
6677
version: Optional[str] = None,
6778
image_author: Optional[str] = None,
6879
platform: Optional[str] = None,
69-
push: bool = False) -> None
80+
push: bool = False,
81+
builder: Optional[str] = None,
82+
pre_install_command: Optional[str] = None) -> None
7083
```
7184

7285
Build runtime images for autonomous agents.

docs/api/cli/helpers/image.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def build_image(agent: Optional[PublicId],
1717
extra_dependencies: Optional[Tuple[Dependency, ...]] = None,
1818
dockerfile: Optional[Path] = None,
1919
platform: Optional[str] = None,
20-
push: bool = False) -> None
20+
push: bool = False,
21+
builder: Optional[str] = None,
22+
pre_install_command: Optional[str] = None) -> None
2123
```
2224

2325
Build agent/service image.

docs/api/deploy/image.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ def build_image(agent: PublicId,
3636
extra_dependencies: Optional[Tuple[Dependency, ...]] = None,
3737
dockerfile: Optional[Path] = None,
3838
platform: Optional[str] = None,
39-
push: bool = False) -> None
39+
push: bool = False,
40+
builder: Optional[str] = None,
41+
pre_install_command: Optional[str] = None) -> None
4042
```
4143

4244
Command to build images from for skaffold deployment.

tox.ini

+2
Original file line numberDiff line numberDiff line change
@@ -954,3 +954,5 @@ websocket-client: >=0.59.0
954954
sniffio: >=1.3.0
955955
; licence is MIT, but the tool does not detect it
956956
attrs: ==25.3.0
957+
; licence is GPL-compatible, but the tool does not detect it
958+
typing-extensions: ==4.13.0

0 commit comments

Comments
 (0)