forked from microsoft/Oryx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildBuildImageBases.sh
69 lines (58 loc) · 2 KB
/
buildBuildImageBases.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license.
# --------------------------------------------------------------------------------------------
#
# This script builds some base images that are needed for the build image:
# - Python binaries
# - PHP binaries
# - Yarn package cache
#
set -ex
declare -r REPO_DIR=$( cd $( dirname "$0" ) && cd .. && pwd )
# Load all variables
source $REPO_DIR/build/__variables.sh
# Example: dontetcore, python
IMAGE_DIR_TO_BUILD="$1"
UNIQUE_TAG=""
if [ ! -z "$BUILD_NUMBER" ]; then
UNIQUE_TAG="-$BUILD_NUMBER"
fi
BUILD_IMAGES_DIR="$REPO_DIR/images/build"
# NOTE: We create a unique artifacts file per image directory here since they are going to be built in parallel on CI
ARTIFACTS_FILE="$BASE_IMAGES_ARTIFACTS_FILE_PREFIX/$IMAGE_DIR_TO_BUILD-buildimage-bases.txt"
# Clean artifacts
mkdir -p `dirname $ARTIFACTS_FILE`
> $ARTIFACTS_FILE
function buildImages() {
local dirName="$1"
local dockerFiles=$(find "$BUILD_IMAGES_DIR/$dirName" -type f -name "Dockerfile")
for dockerFile in $dockerFiles; do
versionDir=$(dirname "${dockerFile}")
versionDirName=$(basename $versionDir)
imageName="$BASE_IMAGES_REPO:$dirName-build-$versionDirName$UNIQUE_TAG"
docker build -f $dockerFile -t "$imageName" $REPO_DIR
echo "$imageName" >> $ARTIFACTS_FILE
done
}
case $IMAGE_DIR_TO_BUILD in
'python')
echo "Building Python base images"
echo
docker build -f $BUILD_IMAGES_DIR/python/prereqs/Dockerfile -t "python-build-prereqs" $REPO_DIR
buildImages "python"
;;
'yarn-cache')
echo "Building Yarn package cache base image"
echo
imageName="$BASE_IMAGES_REPO:build-yarn-cache$UNIQUE_TAG"
docker build -f $BUILD_IMAGES_DIR/yarn-cache/Dockerfile -t $imageName $REPO_DIR
echo "$imageName" >> $ARTIFACTS_FILE
;;
*) echo "Unknown image directory";;
esac
echo
echo "List of images built (from '$ARTIFACTS_FILE'):"
cat $ARTIFACTS_FILE
echo