-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·164 lines (147 loc) · 5.43 KB
/
build.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env bash
# NOTE: This script is also used inside of an alpine linux container and
# as such, needs to find bash at a different path than where it is
# in ubuntu. The indirection through /usr/bin/env is required.
# By default, point to a user dev image in the local registry
DEFAULT_IMAGE_URI="esnet-smartnic-fw:${USER}-dev"
if [ $# -lt 1 ] ; then
# Use a default container URI
IMAGE_URI=${DEFAULT_IMAGE_URI}
elif [ $# -eq 1 ] ; then
# User has provided the desired URI for the image we're building
IMAGE_URI="$1"
else
# Too many command line parameters
echo "ERROR: incorrect number of parameters provided"
echo
echo "Usage: $0 [<ImageURI>]"
echo " ImageURI: optional Container Image URI to use as a tag for this image"
echo " See: https://github.com/opencontainers/.github/blob/master/docs/docs/introduction/digests.md#unique-resource-identifiers"
echo " e.g.: <registry>/<project>/<container>:<tag>@<digest>"
echo " e.g.: wharf.es.net/ht/esnet-smartnic-fw:33228-gf4c89e64"
echo " When no ImageURI is provided a default of '${DEFAULT_IMAGE_URI}' will be used"
echo
exit 1
fi
echo "Building container '${IMAGE_URI}'"
# Make sure these variables are **only** taken from the .env file
unset SMARTNIC_DPDK_IMAGE_URI
unset LABTOOLS_IMAGE_URI
unset SN_HW_GROUP
unset SN_HW_REPO
unset SN_HW_BRANCH
unset SN_HW_BOARD
unset SN_HW_APP_NAME
unset SN_HW_VER
unset SN_HW_COMMIT
unset SN_FW_GROUP
unset SN_FW_REPO
unset SN_FW_BRANCH
unset SN_FW_APP_NAME
unset SN_FW_VER
unset SN_FW_COMMIT
# Read build-time arguments from .env
source .env
# Check for missing mandatory build-arguments and fill in default values for optional arguments
SMARTNIC_DPDK_IMAGE_URI=${SMARTNIC_DPDK_IMAGE_URI:-smartnic-dpdk-docker:${USER}-dev}
LABTOOLS_IMAGE_URI=${LABTOOLS_IMAGE_URI:-xilinx-labtools-docker:${USER}-dev}
SN_HW_GROUP="${SN_HW_GROUP:-unset}"
SN_HW_REPO="${SN_HW_REPO:-unset}"
SN_HW_BRANCH="${SN_HW_BRANCH:-unset}"
if [ ! -v SN_HW_BOARD ] ; then
echo "ERROR: Missing environment variable 'SN_HW_BOARD' which is required"
exit 1
fi
if [ ! -v SN_HW_APP_NAME ] ; then
echo "ERROR: Missing environment variable 'SN_HW_APP_NAME' which is required"
exit 1
fi
if [ ! -v SN_HW_VER ] ; then
echo "ERROR: Missing environment variable 'SN_HW_VER' which is required"
exit 1
fi
SN_HW_COMMIT="${SN_HW_COMMIT:-unset}"
SN_FW_GROUP="${SN_FW_GROUP:-unset}"
SN_FW_REPO="${SN_FW_REPO:-unset}"
SN_FW_BRANCH="${SN_FW_BRANCH:-unset}"
SN_FW_APP_NAME="${SN_FW_APP_NAME:-unset}"
SN_FW_VER="${SN_FW_VER:-unset}"
SN_FW_COMMIT="${SN_FW_COMMIT:-unset}"
# Build the image
export DOCKER_BUILDKIT=1
docker build \
--progress=plain \
--build-arg SMARTNIC_DPDK_IMAGE_URI=${SMARTNIC_DPDK_IMAGE_URI} \
--build-arg SN_HW_GROUP=${SN_HW_GROUP} \
--build-arg SN_HW_REPO=${SN_HW_REPO} \
--build-arg SN_HW_BRANCH=${SN_HW_BRANCH} \
--build-arg SN_HW_BOARD=${SN_HW_BOARD} \
--build-arg SN_HW_APP_NAME=${SN_HW_APP_NAME} \
--build-arg SN_HW_VER=${SN_HW_VER} \
--build-arg SN_HW_COMMIT=${SN_HW_COMMIT} \
--build-arg SN_FW_GROUP=${SN_FW_GROUP} \
--build-arg SN_FW_REPO=${SN_FW_REPO} \
--build-arg SN_FW_BRANCH=${SN_FW_BRANCH} \
--build-arg SN_FW_APP_NAME=${SN_FW_APP_NAME} \
--build-arg SN_FW_VER=${SN_FW_VER} \
--build-arg SN_FW_COMMIT=${SN_FW_COMMIT} \
-t ${IMAGE_URI} .
if [ $? -ne 0 ] ; then
echo "ERROR: Failed to build container"
exit 1
fi
# Rewrite a cleaned-up, simplified version of the input .env file used to build this image
# The buildinfo.env file will be available to users that embed the sn-stack directory into a larger compose stack
#
# NOTE: No blank lines or comment lines are allowed in this file since it may be used by downstream gitlab-ci builds
# which limits the format: https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportsdotenv
#
cat <<_EOF > sn-stack/buildinfo.env
SMARTNIC_FW_IMAGE_URI=${IMAGE_URI}
LABTOOLS_IMAGE_URI=${LABTOOLS_IMAGE_URI}
SMARTNIC_DPDK_IMAGE_URI=${SMARTNIC_DPDK_IMAGE_URI}
SN_FW_GROUP=${SN_FW_GROUP}
SN_FW_REPO=${SN_FW_REPO}
SN_FW_BRANCH=${SN_FW_BRANCH}
SN_FW_APP_NAME=${SN_FW_APP_NAME}
SN_FW_VER=${SN_FW_VER}
SN_FW_COMMIT=${SN_FW_COMMIT}
SN_HW_GROUP=${SN_HW_GROUP}
SN_HW_REPO=${SN_HW_REPO}
SN_HW_BRANCH=${SN_HW_BRANCH}
SN_HW_BOARD=${SN_HW_BOARD}
SN_HW_APP_NAME=${SN_HW_APP_NAME}
SN_HW_VER=${SN_HW_VER}
SN_HW_COMMIT=${SN_HW_COMMIT}
_EOF
# Update or create the user's sn-stack/.env file to refer to the container image URLs used during this build
if [ ! -e sn-stack/.env ] ; then
# No previous .env file exists, initialize it from the example.env file
cp sn-stack/example.env sn-stack/.env
fi
ENV_BLOCK_TOP="# block-start auto-generated by build"
ENV_BLOCK_BOT="# block-end auto-generated by build"
# Check if we have a full marker block in the file already
# Quit immediately with exit-code of 0 if block is found
# else quit with exit-code of 1 on end of file
if egrep -q "^${ENV_BLOCK_TOP}\$" sn-stack/.env ; then
# Found the marker block, update it in place
sed -i -r \
-e "/${ENV_BLOCK_TOP}/,/${ENV_BLOCK_BOT}/c\
${ENV_BLOCK_TOP}\n\
SMARTNIC_FW_IMAGE_URI=${IMAGE_URI}\n\
LABTOOLS_IMAGE_URI=${LABTOOLS_IMAGE_URI}\n\
SMARTNIC_DPDK_IMAGE_URI=${SMARTNIC_DPDK_IMAGE_URI}\n\
${ENV_BLOCK_BOT}" \
sn-stack/.env
else
# No marker block found, append it to the end of the file
cat >>sn-stack/.env <<EOF
${ENV_BLOCK_TOP}
SMARTNIC_FW_IMAGE_URI=${IMAGE_URI}
LABTOOLS_IMAGE_URI=${LABTOOLS_IMAGE_URI}
SMARTNIC_DPDK_IMAGE_URI=${SMARTNIC_DPDK_IMAGE_URI}
${ENV_BLOCK_BOT}
EOF
fi
exit 0