Skip to content

Commit 5e6815d

Browse files
committed
Support apt install in docker image
Now docker/image-builder.sh supports building docker image either building host packages or performing apt install from JFrog.
1 parent 1c554ae commit 5e6815d

File tree

11 files changed

+91
-44
lines changed

11 files changed

+91
-44
lines changed

.github/workflows/artifacts.yaml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
paths:
55
- '.github/workflows/artifacts.yaml'
66
- 'tools/buildimage/**'
7+
- 'docker/**'
78
push:
89
branches:
910
- main
@@ -60,14 +61,11 @@ jobs:
6061
run: |
6162
short_sha=$(echo ${{ github.sha }} | cut -c1-8)
6263
echo "x86_64_image_path=orchestration-image-x86_64-${short_sha}.tar" >> $GITHUB_ENV
63-
- name: Install bazel
64-
run: sudo bash tools/buildutils/installbazel.sh
65-
- name: bazel version
66-
run: bazel version
64+
echo "image_name=cuttlefish-orchestration:${short_sha}" >> $GITHUB_ENV
6765
- name: Build docker image
68-
run: bazel build --sandbox_writable_path=$HOME //docker:orchestration_image_tar
69-
- name: Set filename of docker image
70-
run: mv bazel-bin/docker/orchestration-image.tar ${{ env.x86_64_image_path }}
66+
run: docker/image-builder.sh -t ${{ env.image_name }}
67+
- name: Save docker image
68+
run: docker save --output ${{ env.x86_64_image_path }} ${{ env.image_name }}
7169
- name: Publish docker image
7270
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # aka v4.0.0
7371
with:
@@ -82,14 +80,11 @@ jobs:
8280
run: |
8381
short_sha=$(echo ${{ github.sha }} | cut -c1-8)
8482
echo "arm64_image_path=orchestration-image-arm64-${short_sha}.tar" >> $GITHUB_ENV
85-
- name: Install bazel
86-
run: sudo bash tools/buildutils/installbazel.sh
87-
- name: bazel version
88-
run: bazel version
83+
echo "image_name=cuttlefish-orchestration:${short_sha}" >> $GITHUB_ENV
8984
- name: Build docker image
90-
run: bazel build --sandbox_writable_path=$HOME //docker:orchestration_image_tar
91-
- name: Set filename of docker image
92-
run: mv bazel-bin/docker/orchestration-image.tar ${{ env.arm64_image_path }}
85+
run: docker/image-builder.sh -t ${{ env.image_name }}
86+
- name: Save docker image
87+
run: docker save --output ${{ env.arm64_image_path }} ${{ env.image_name }}
9388
- name: Publish docker image
9489
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # aka v4.0.0
9590
with:

.github/workflows/presubmit.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ jobs:
104104
# Overall action timing breakdown:
105105
#
106106
# [614 / 616] Executing genrule @@images//docker/debs-builder-docker:debs_tar [for tool]; 608s linux-sandbox
107-
# [615 / 616] Executing genrule @@images//docker:orchestration_image_tar; 11s linux-sandbox
107+
# [615 / 616] Executing genrule @@images//docker:orchestration_image_dev_tar; 11s linux-sandbox
108108
# //orchestration:create_fixed_build_id_and_target PASSED in 99.9s
109109
# //orchestration:create_local_image PASSED in 92.4s
110110
#

docker/BUILD.bazel

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
# limitations under the License.
1414

1515
genrule(
16-
name = "orchestration_image_tar",
17-
outs = ["orchestration-image.tar"],
18-
cmd = "$(location :orchestration_image_builder) -o $@",
19-
tools = [":orchestration_image_builder"],
16+
name = "orchestration_image_dev_tar",
17+
outs = ["orchestration-image-dev.tar"],
18+
cmd = "$(location :orchestration_image_dev_builder) -o $@",
19+
tools = [":orchestration_image_dev_builder"],
2020
visibility = ["//visibility:public"],
2121
)
2222

2323
sh_binary(
24-
name = "orchestration_image_builder",
24+
name = "orchestration_image_dev_builder",
2525
srcs = ["image-build-bazel-wrapper.sh"],
2626
deps = ["@bazel_tools//tools/bash/runfiles"],
2727
)

docker/Dockerfile

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
# Docker image includes HO(Host Orchestrator) inside,
33
# so it could execute CF instance with API in HO.
44

5-
FROM debian:12 AS cuttlefish-hostpkg-builder
5+
ARG BUILD_OPTION=prod
6+
7+
8+
FROM debian:12 AS host-package-builder
69

710
USER root
811
WORKDIR /root
@@ -15,11 +18,12 @@ RUN apt install -y --no-install-recommends \
1518
equivs \
1619
sudo
1720

18-
# Build CF debian packages
21+
# Build CF debian packages
1922
COPY . /root/android-cuttlefish
2023
RUN ["/bin/bash", "-c", "/root/android-cuttlefish/tools/buildutils/build_packages.sh"]
2124

22-
FROM debian:12 AS cuttlefish-orchestration
25+
26+
FROM debian:12 AS runner-base
2327

2428
# Expose Operator Port (HTTP:1080, HTTPS:1443)
2529
EXPOSE 1080 1443
@@ -44,19 +48,36 @@ RUN apt install -y --no-install-recommends \
4448
sudo
4549
RUN update-ca-certificates
4650

51+
COPY ./docker/guest/run_services.sh /root/
52+
RUN chmod +x /root/run_services.sh
53+
54+
55+
FROM runner-base AS runner-dev
56+
4757
# Install CF debian packages.
48-
COPY --from=cuttlefish-hostpkg-builder /root/android-cuttlefish/cuttlefish-*.deb /root/debian/
58+
COPY --from=host-package-builder /root/android-cuttlefish/cuttlefish-*.deb /root/debian/
4959
RUN apt install -y --no-install-recommends -f \
5060
/root/debian/cuttlefish-base_*.deb \
5161
/root/debian/cuttlefish-user_*.deb \
5262
/root/debian/cuttlefish-orchestration_*.deb
5363

54-
RUN echo "num_cvd_accounts=100" >> /etc/default/cuttlefish-host-resources
5564

65+
FROM runner-base AS runner-prod
66+
67+
RUN apt install -y --no-install-recommends \
68+
wget
69+
RUN wget -qO- https://artifacts.codelinaro.org/artifactory/linaro-372-googlelt-gigabyte-ampere-cuttlefish-installer/gigabyte-ampere-cuttlefish-installer/latest/debian/linaro-glt-gig-archive-bookworm.asc \
70+
| tee /etc/apt/trusted.gpg.d/linaro-glt-gig-archive-bookworm.asc
71+
RUN echo "deb https://artifacts.codelinaro.org/linaro-372-googlelt-gigabyte-ampere-cuttlefish-installer/gigabyte-ampere-cuttlefish-installer/latest/debian bookworm main" \
72+
| tee /etc/apt/sources.list.d/linaro-glt-gig-archive-bookworm.list
73+
RUN apt update
74+
RUN apt install -y --no-install-recommends \
75+
cuttlefish-base cuttlefish-user cuttlefish-orchestration
76+
77+
78+
FROM runner-${BUILD_OPTION} AS runner
79+
80+
RUN echo "num_cvd_accounts=100" >> /etc/default/cuttlefish-host-resources
5681
RUN usermod -aG kvm root
5782
RUN usermod -aG cvdnetwork root
58-
59-
COPY --from=cuttlefish-hostpkg-builder /root/android-cuttlefish/docker/guest/run_services.sh /root/
60-
RUN chmod +x /root/run_services.sh
61-
RUN rm -rf /root/android-cuttlefish
6283
ENTRYPOINT ["/root/run_services.sh"]

docker/image-build-bazel-wrapper.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ fi
3838
# --- end runfiles.bash initialization ---
3939

4040
usage() {
41-
echo "usage: $0 -o /path/to/image.tar"
41+
echo "usage: $0 -o <output>"
42+
echo " -o: path for tar format output"
4243
}
4344

4445
output=
45-
4646
while getopts ":ho:" opt; do
4747
case "${opt}" in
4848
h)
@@ -84,6 +84,6 @@ function remove_image() {
8484
trap remove_image EXIT
8585

8686
# Build docker image
87-
${repo_root_dir}/docker/image-builder.sh "${name}"
87+
${repo_root_dir}/docker/image-builder.sh -t "${name}" -d
8888

8989
docker save --output ${output} ${name}

docker/image-builder.sh

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,49 @@
77
script_location=`realpath -s $(dirname ${BASH_SOURCE[0]})`
88
android_cuttlefish_root_dir=$(realpath -s $script_location/..)
99

10-
if [[ "$1" == "" ]]; then
11-
tag=cuttlefish-orchestration
12-
else
13-
tag=$1
14-
fi
10+
usage() {
11+
echo "usage: $0 [-t <tag>] [-d]"
12+
echo " -t: name or name:tag of docker image (default cuttlefish-orchestration)"
13+
echo " -d: build dev image instead of prod image"
14+
echo " Dev image builds host packages from the local source"
15+
echo " Prod image downloads and installs host packages"
16+
}
17+
18+
name=cuttlefish-orchestration
19+
build_option=prod
20+
while getopts ":hdt:" opt; do
21+
case "${opt}" in
22+
h)
23+
usage
24+
exit 0
25+
;;
26+
d)
27+
build_option=dev
28+
;;
29+
t)
30+
name="${OPTARG}"
31+
;;
32+
\?)
33+
echo "Invalid option: ${OPTARG}" >&2
34+
usage
35+
exit 1
36+
;;
37+
:)
38+
echo "Invalid option: ${OPTARG} requires an argument" >&2
39+
usage
40+
exit 1
41+
;;
42+
esac
43+
done
1544

1645
# Build docker image
1746
pushd $android_cuttlefish_root_dir
18-
docker build \
47+
DOCKER_BUILDKIT=1 docker build \
1948
--force-rm \
2049
--no-cache \
2150
-f docker/Dockerfile \
22-
-t $tag \
51+
-t $name \
52+
--target runner \
53+
--build-arg BUILD_OPTION=$build_option \
2354
.
2455
popd

e2etests/orchestration/common/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func NewDockerHelper() (*DockerHelper, error) {
7979
}
8080

8181
func (h *DockerHelper) LoadImage() (string, error) {
82-
imgFile, err := os.Open("../../external/images/docker/orchestration-image.tar")
82+
imgFile, err := os.Open("../../external/images/docker/orchestration-image-dev.tar")
8383
if err != nil {
8484
return "", err
8585
}

e2etests/orchestration/create_from_images_zip_test/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ go_test(
2020
data = [
2121
"//orchestration/artifacts:cvd_host_package",
2222
"//orchestration/artifacts:images_zip",
23-
"@images//docker:orchestration_image_tar",
23+
"@images//docker:orchestration_image_dev_tar",
2424
],
2525
deps = [
2626
"//orchestration/common",

e2etests/orchestration/create_local_image_test/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ go_test(
2020
data = [
2121
"//orchestration/artifacts:cvd_host_package",
2222
"//orchestration/artifacts:images_zip",
23-
"@images//docker:orchestration_image_tar",
23+
"@images//docker:orchestration_image_dev_tar",
2424
],
2525
deps = [
2626
"//orchestration/common",

e2etests/orchestration/create_single_instance_test/def.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def create_single_instance_test(name, build_id, build_target):
1919
name = name,
2020
srcs = ["main_test.go"],
2121
data = [
22-
"@images//docker:orchestration_image_tar",
22+
"@images//docker:orchestration_image_dev_tar",
2323
],
2424
env = {
2525
"BUILD_ID": build_id,

0 commit comments

Comments
 (0)