forked from wirepas/gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-images.sh
executable file
·142 lines (114 loc) · 4.03 KB
/
build-images.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
#!/usr/bin/env bash
# Copyright 2019 Wirepas Ltd
set -e
export VERSION
export BUILD_DATE
export IMAGE_NAME
export REGISTRY_NAME
export DOCKER_BASE
export CROSS_BUILD_START_CMD
export CROSS_BUILD_END_CMD
export GIT_MANIFEST_FILE
export GIT_MANIFEST_URL
export GIT_MANIFEST_BRANCH
export LXGW_C_MESH_API_HASH
export LXGW_SERVICES_HASH
export BUILD_TAG
SKIP_PULL=${1:-}
VERSION=$(< python_transport/wirepas_gateway/__about__.py awk '/__version__/{print $NF}'| tr -d '\"')
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
REGISTRY_NAME="wirepas"
DOCKERFILE_PATH="./container"
BUILD_TAG=${BUILD_TAG:-$TRAVIS_TAG}
##
## @brief Changes to the corresponding target and builds the image
##
function _build
{
_PATH=${1:-"${DOCKERFILE_PATH}/x86"}
_ARCH=${2:-"x86"}
_CACHE=${3:-}
# build based on architecture
IMAGE_NAME="${REGISTRY_NAME}/gateway-${_ARCH}:${BUILD_TAG}"
if [[ ${_ARCH} == "arm" ]]
then
DOCKER_BASE=balenalib/raspberrypi3
CROSS_BUILD_START_CMD=cross-build-start
CROSS_BUILD_END_CMD=cross-build-end
else
DOCKER_BASE=ubuntu:19.04
CROSS_BUILD_START_CMD=:
CROSS_BUILD_END_CMD=:
fi
echo "building ${_PATH}: ${IMAGE_NAME} (from: ${DOCKER_BASE})"
# to speed up builds
docker pull "${IMAGE_NAME}" || true
#shellcheck disable=SC2086
docker-compose -f "${_PATH}" \
build ${_CACHE} \
--compress \
--parallel \
}
function _fetch_dependencies
{
if [[ -z "${SKIP_PULL}" ]]
then
# pull repository dependency
GIT_REPO_FOLDER=${1}
GIT_MANIFEST_FILE=${GIT_MANIFEST_FILE:-"gateway/dev.xml"}
GIT_MANIFEST_URL=${GIT_MANIFEST_URL:-"https://github.com/wirepas/manifest.git"}
GIT_MANIFEST_BRANCH=${GIT_MANIFEST_BRANCH:-"master"}
_ROOT_PATH=$(pwd)
echo "fetching dependencies from: ${GIT_MANIFEST_URL}/${GIT_MANIFEST_FILE}/${GIT_MANIFEST_BRANCH}"
_ROOT_PATH=$(pwd)
rm -rf "${GIT_REPO_FOLDER}"
mkdir "${GIT_REPO_FOLDER}"
cd "${GIT_REPO_FOLDER}"
git config --global color.ui true
pipenv run --two repo init \
-u "${GIT_MANIFEST_URL}" \
-m "${GIT_MANIFEST_FILE}" \
-b "${GIT_MANIFEST_BRANCH}" \
--depth 2 \
--no-tags \
--no-clone-bundle
pipenv --rm
pipenv run --two repo sync
cd "${_ROOT_PATH}"
fi
}
##
## @brief What this script will do when it is executed
##
function _main
{
# builds x86 and arm images based on manifest files
if [[ ! -z "${BUILD_TAG}" ]]
then
GIT_MANIFEST_FILE=gateway/stable.xml
GIT_MANIFEST_BRANCH=refs/tags/gateway/${BUILD_TAG}
REPO_STABLE=".ci/_repo_stable"
_fetch_dependencies "${REPO_STABLE}"
LXGW_SERVICES_HASH="$(git -C ${REPO_STABLE}/ log -n1 --pretty=%h)"
LXGW_C_MESH_API_HASH="$(git -C ${REPO_STABLE}/sink_service/c-mesh-api log -n1 --pretty=%h)"
_build "${DOCKERFILE_PATH}/stable/arm/docker-compose.yml" "arm" "--no-cache"
_build "${DOCKERFILE_PATH}/stable/x86/docker-compose.yml" "x86" "--no-cache"
else
BUILD_TAG="edge"
GIT_MANIFEST_BRANCH=master
# builds x86 and arm images based on top of current revision
REPO_EDGE=".ci/_repo_edge"
_fetch_dependencies "${REPO_EDGE}"
LXGW_SERVICES_HASH="$(git log -n1 --pretty=%h)"
LXGW_C_MESH_API_HASH="$(git -C ${REPO_EDGE}/sink_service/c-mesh-api log -n1 --pretty=%h)"
# The edge builds relies on the current gateway branch.
# The c-mesh-api must be pulled into the root level so that
# it is taken in use by the current build.
# If you would use the source from REPO_EDGE, you end up building
# the previous commit merged in master.
cp -vr "${REPO_EDGE}/sink_service/c-mesh-api" "sink_service"
_build "${DOCKERFILE_PATH}/dev/docker-compose.yml" "arm"
_build "${DOCKERFILE_PATH}/dev/docker-compose.yml" "x86"
fi
}
_main "${@}"