|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# build-container.sh |
| 4 | +# |
| 5 | +# Copyright (C) 2016-2021 Intel Corporation |
| 6 | +# |
| 7 | +# SPDX-License-Identifier: GPL-2.0-only |
| 8 | +# |
| 9 | + |
| 10 | +set -e |
| 11 | + |
| 12 | +# Allow the user to specify another command to use for building such as podman |
| 13 | +if [ "${ENGINE_CMD}" = "" ]; then |
| 14 | + ENGINE_CMD="docker" |
| 15 | +fi |
| 16 | + |
| 17 | +# DISTRO_TO_BUILD is essentially the prefix to the "base" and "builder" |
| 18 | +# directories you plan to use. i.e. "fedora-23" or "ubuntu-16.04" |
| 19 | + |
| 20 | +# First build the base |
| 21 | +TAG=$DISTRO_TO_BUILD-base |
| 22 | +dockerdir=`find -name $TAG` |
| 23 | +workdir=`mktemp --tmpdir -d tmp-$TAG.XXX` |
| 24 | + |
| 25 | +cp -r $dockerdir $workdir |
| 26 | +workdir=$workdir/$TAG |
| 27 | + |
| 28 | +cp install-multilib.sh $workdir |
| 29 | +cp build-install-dumb-init.sh $workdir |
| 30 | +cp install-buildtools.sh $workdir |
| 31 | +cp install-buildtools-make.sh $workdir |
| 32 | +cd $workdir |
| 33 | + |
| 34 | +baseimage=`grep FROM Dockerfile | sed -e 's/FROM //'` |
| 35 | +${ENGINE_CMD} pull $baseimage |
| 36 | + |
| 37 | +${ENGINE_CMD} buildx build \ |
| 38 | + --platform=linux/amd64,linux/arm64/v8 \ |
| 39 | + --build-arg http_proxy=$http_proxy \ |
| 40 | + --build-arg HTTP_PROXY=$http_proxy \ |
| 41 | + --build-arg https_proxy=$https_proxy \ |
| 42 | + --build-arg HTTPS_PROXY=$https_proxy \ |
| 43 | + --build-arg no_proxy=$no_proxy \ |
| 44 | + --build-arg NO_PROXY=$no_proxy \ |
| 45 | + -t $REPO:$TAG . |
| 46 | +rm $workdir -rf |
| 47 | +cd - |
| 48 | + |
| 49 | +# Now build the builder. We copy things to a temporary directory so that we |
| 50 | +# can modify the Dockerfile to use whatever REPO is in the environment. |
| 51 | +TAG=$DISTRO_TO_BUILD-builder |
| 52 | +workdir=`mktemp --tmpdir -d tmp-$TAG.XXX` |
| 53 | + |
| 54 | +# use the builder template to populate the distro specific Dockerfile |
| 55 | +cp dockerfiles/templates/Dockerfile.builder $workdir/Dockerfile |
| 56 | +cp distro-entry.sh $workdir |
| 57 | +sed -i "s/DISTRO_TO_BUILD/$DISTRO_TO_BUILD/g" $workdir/Dockerfile |
| 58 | + |
| 59 | +cp helpers/runbitbake.py $workdir |
| 60 | +cd $workdir |
| 61 | + |
| 62 | +# Replace the rewitt/yocto repo with the one from environment |
| 63 | +sed -i -e "s#crops/yocto#$REPO#" Dockerfile |
| 64 | + |
| 65 | +# Lastly build the image |
| 66 | +${ENGINE_CMD} buildx build \ |
| 67 | + --platform=linux/amd64,linux/arm64/v8 \ |
| 68 | + --build-arg http_proxy=$http_proxy \ |
| 69 | + --build-arg HTTP_PROXY=$http_proxy \ |
| 70 | + --build-arg https_proxy=$https_proxy \ |
| 71 | + --build-arg HTTPS_PROXY=$https_proxy \ |
| 72 | + --build-arg no_proxy=$no_proxy \ |
| 73 | + --build-arg NO_PROXY=$no_proxy \ |
| 74 | + -t $REPO:$TAG . |
| 75 | +cd - |
| 76 | + |
| 77 | +# base tests |
| 78 | +ENGINE_CMD=${ENGINE_CMD} |
| 79 | + ./tests/container/vnc-test.sh $REPO:$DISTRO_TO_BUILD-base |
| 80 | +# builder tests |
| 81 | +ENGINE_CMD=${ENGINE_CMD} |
| 82 | + ./tests/container/smoke.sh $REPO:$DISTRO_TO_BUILD-builder |
| 83 | + |
| 84 | +rm $workdir -rf |
| 85 | + |
0 commit comments