root/build-tools/build-docker-images
Davlet Panech 4183a924cf docker-images: don't embed wheel tar in images
This patch fixes a problem introduced by [1]: docker image script
embeds the wheels tarball in the docker image via a COPY command; then
deletes it during the build. This makes docker images unnecessarily
large. This lets us use local tar files with the docker image(s) being
built.

Recently [2] a patch was merged that adds a web server to the Debian
build environment, allowing us to access local files over HTTP and
making the COPY step unnecessary in the Docker file.

This patch removes the explicit downloading of the wheels tarball and
the COPY directive, while passing the wheel tarball to Loci as a URL,
allowing Loci to download it during the build w/o contributing to the FS
layer size.

This reduces the size of stx-fm-rest-api image by ~220 MB. Other Loci
images should experience similar savings.

[1] https://review.opendev.org/c/starlingx/root/+/857505
[2] https://review.opendev.org/c/starlingx/tools/+/873010

TESTS
=================

* Build a loci image with wheels tarball passed as a URL
* Build a loci image with wheels tarball passed as a local file name

Story: 2010294
Task: 47343

Change-Id: I6dca6f95b0845e549ad35c9b6e95aa58c86fc774
Signed-off-by: Davlet Panech <davlet.panech@windriver.com>
2023-02-10 15:23:40 -05:00
..
2022-09-14 10:56:06 -04:00
2019-03-24 21:03:21 -04:00

## Example commands for building StarlingX images

PRIVATE_REGISTRY_USERID=myuser
PRIVATE_REGISTRY=xxx.xxx.xxx.xxx:9001
VERSION=2018.11.13
OS=centos
OS_VERSION=7.5.1804
BUILD_STREAM=stable
HOST_PORT=8088

## Step 1: Build stx-centos
time $MY_REPO/build-tools/build-docker-images/build-stx-base.sh \
    --os ${OS} \
    --os-version ${OS_VERSION} \
    --version ${VERSION} \
    --user ${PRIVATE_REGISTRY_USERID} \
    --registry ${PRIVATE_REGISTRY} \
    --push \
    --repo stx-local-build,http://${HOSTNAME}:${HOST_PORT}/${MY_WORKSPACE}/std/rpmbuild/RPMS \
    --repo stx-mirror-distro,http://${HOSTNAME}:${HOST_PORT}/${MY_REPO}/cgcs-root/cgcs-${OS}-repo/Binary \
    --clean


## Step 2: Build wheels (output as tarball)
time $MY_REPO/build-tools/build-wheels/build-wheel-tarball.sh \
    --os ${OS} \
    --os-version ${OS_VERSION} \
    --stream ${BUILD_STREAM}

## Step 3: Build images
time $MY_REPO/build-tools/build-docker-images/build-stx-images.sh \
    --os ${OS} \
    --version ${VERSION} \
    --stream ${BUILD_STREAM} \
    --base ${PRIVATE_REGISTRY}/${PRIVATE_REGISTRY_USERID}/stx-${OS}:${VERSION} \
    --wheels http://${HOSTNAME}:${HOST_PORT}/${MY_WORKSPACE}/std/build-wheels-${OS}-${BUILD_STREAM}/stx-${OS}-${BUILD_STREAM}-wheels.tar \
    --user ${PRIVATE_REGISTRY_USERID} \
    --registry ${PRIVATE_REGISTRY} \
    --push --latest \
    --clean


## Note: Verify that lighttpd is not bound to "localhost"
vi /etc/lighttpd/lighttpd.conf
# server.bind = "localhost"
systemctl restart lighttpd

## Note: You may need to add an iptables rule to allow the docker
## containers to access the http server on your host. For example:
iptables -I INPUT 6 -i docker0 -p tcp --dport ${HOST_PORT} -m state --state NEW,ESTABLISHED -j ACCEPT