-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathci.sh
More file actions
executable file
·247 lines (215 loc) · 8.4 KB
/
Copy pathci.sh
File metadata and controls
executable file
·247 lines (215 loc) · 8.4 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
set -e
# Enable BuildKit for faster, parallel docker builds and proper --cache-from support
export DOCKER_BUILDKIT=${DOCKER_BUILDKIT:-1}
export COMPOSE_DOCKER_CLI_BUILD=${COMPOSE_DOCKER_CLI_BUILD:-1}
# Common build arg used to embed cache metadata in pushed images so subsequent
# builds (in this and other runs) can actually reuse layers via --cache-from.
INLINE_CACHE_ARG="--build-arg BUILDKIT_INLINE_CACHE=1"
source $(dirname "${0}")/version.sh
# Check and updates version based on release branch name
update_version() {
echo "Checking versions"
if [[ "${BRANCH_NAME}" != "release"* ]]; then
echo "Not release branch - skipping version update"
return
fi
IFS=. read MAJOR_V MINOR_V MICRO_V <<<"${BRANCH_NAME##release-}"
if [ -z "${MAJOR_V}" ]; then
echo "Missing major version"
exit 1
fi
if [ -z "${MINOR_V}" ]; then
echo "Missing minor version"
exit 1
fi
if [ -z "${MICRO_V}" ]; then
echo "Missing micro version"
exit 1
fi
VERSION_BUMP=${MAJOR_V}.${MINOR_V}.${MICRO_V}
if [ "${BUILD_VERSION}" == "${VERSION_BUMP}" ]; then
echo "Versions match - skipping update"
return
fi
echo "Updating version ${BUILD_VERSION} to ${VERSION_BUMP}"
# Replace version in __init__.py
printf '%s\n' "%s/__version__ = .*/__version__ = \"${VERSION_BUMP}\"/g" 'x' | ex aperturedb/__init__.py
# Commit and push version bump
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add ./aperturedb/__init__.py
git commit -m "Version bump: ${BUILD_VERSION} to ${VERSION_BUMP}"
git push --set-upstream origin ${BRANCH_NAME}
BUILD_VERSION=${VERSION_BUMP}
}
# Fetch branch
if [ -z ${BRANCH_NAME+x} ]
then
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
fi
# Fetch branch
if [ -z ${COMMIT_HASH+x} ]
then
COMMIT_HASH=$(git rev-parse HEAD)
fi
echo "Branch: ${BRANCH_NAME}"
if [ -z "${BRANCH_NAME}" ]
then
echo "This is on a merge branch. Will not continue"
exit 0
fi
# Set default version to develop
BUILD_VERSION=develop
# Trigger read version
read_version
echo "Build version: ${BUILD_VERSION}"
if [ "${UPDATE_BRANCH}" == "true" ]
then
# Trigger update version
update_version
else
echo "UPDATE_BRANCH is not set"
fi
# Set image extension according to branch
if [ "${BRANCH_NAME}" == 'main' ]
then
IMAGE_EXTENSION_WITH_VERSION=":v${BUILD_VERSION}"
IMAGE_EXTENSION_LATEST=":latest"
DEPLOY_SERVER=yes
elif [ "${BRANCH_NAME}" == 'develop' ]
then
IMAGE_EXTENSION_WITH_VERSION="-develop:v${BUILD_VERSION}-${COMMIT_HASH}"
DEPLOY_SERVER=yes
else
IMAGE_EXTENSION_WITH_VERSION="-${BRANCH_NAME}:v${BUILD_VERSION}"
DEPLOY_SERVER=no
fi
# Set default repo if repo var is not set
if [ -n ${DOCKER_REPOSITORY+x} ]
then
DOCKER_REPOSITORY=aperturedata
fi
echo "Repository: ${DOCKER_REPOSITORY}"
build_tests(){
TESTS_IMAGE=${DOCKER_REPOSITORY}/aperturedb-python-tests:latest
mkdir -p docker/tests/aperturedata
sudo rm -rf test/aperturedb/{db*,logs} && sudo mkdir -m 777 -p test/aperturedb/logs/runner_state
cp -r aperturedb pyproject.toml README.md docker/tests/aperturedata
mkdir -m 777 -p docker/tests/aperturedata/test/aperturedb
cp -r test/*.py test/*.sh test/input docker/tests/aperturedata/test
echo "Building image ${TESTS_IMAGE}"
docker pull ${TESTS_IMAGE} || true
docker build ${INLINE_CACHE_ARG} --build-arg PIP_TRUSTED_HOST=${PIP_TRUSTED_HOST} --build-arg PIP_INDEX_URL=${PIP_INDEX_URL} -t ${TESTS_IMAGE} --cache-from ${TESTS_IMAGE} -f docker/tests/Dockerfile .
# Push the tests image so --cache-from works across runners and cold starts.
# Skipped on PR runs (NO_PUSH=true) to avoid polluting the registry with PR images.
if [ "${NO_PUSH}" != "true" ]
then
docker push ${TESTS_IMAGE}
fi
}
build_complete(){
COMPLETE_IMAGE=${DOCKER_REPOSITORY}/aperturedb-python-tests:complete
mkdir -p docker/complete/aperturedata
cp -r aperturedb pyproject.toml README.md LICENSE docker/complete/aperturedata
echo "Building image ${COMPLETE_IMAGE}"
docker build --build-arg PIP_TRUSTED_HOST=${PIP_TRUSTED_HOST} --build-arg PIP_INDEX_URL=${PIP_INDEX_URL} -t ${COMPLETE_IMAGE} --cache-from ${COMPLETE_IMAGE} -f docker/complete/Dockerfile .
}
build_notebook_dependencies_image(){
DEPS_IMAGE=${DOCKER_REPOSITORY}/aperturedb-notebook:dependencies
if [ "${PULL_DEPENDENCIES}" != "false" ]
then
# Default
# Build will use cache to speed up the process
# Runs from github events
cache_control="--cache-from ${DEPS_IMAGE}"
docker pull ${DEPS_IMAGE}
else
# Build won't use cache to create a fresh image
# Runs from cron-job
cache_control="--no-cache"
fi
echo "Building image ${DEPS_IMAGE}"
docker build ${INLINE_CACHE_ARG} --build-arg PIP_TRUSTED_HOST=${PIP_TRUSTED_HOST} --build-arg PIP_INDEX_URL=${PIP_INDEX_URL} -t ${DEPS_IMAGE} ${cache_control} -f docker/dependencies/Dockerfile .
if [ "${PUSH_DEPENDENCIES}" != "true" ]
then
# Default
# No need to push
echo "Not pushing image ${DEPS_IMAGE}"
else
# Runs from cron-job
echo "Pushing image ${DEPS_IMAGE}"
docker push ${DEPS_IMAGE}
fi
}
# Build notebook image
build_notebook_image(){
NOTEBOOK_IMAGE=${DOCKER_REPOSITORY}/aperturedb-notebook${IMAGE_EXTENSION_WITH_VERSION}
mkdir -p docker/notebook/aperturedata
cp -r aperturedb pyproject.toml LICENSE README.md docker/notebook/aperturedata
LATEST_IMAGE=${DOCKER_REPOSITORY}/aperturedb-notebook${IMAGE_EXTENSION_LATEST}
CPU_IMAGE=${DOCKER_REPOSITORY}/aperturedb-notebook:cpu
docker pull ${LATEST_IMAGE} || true
echo "Building image ${NOTEBOOK_IMAGE}"
docker build ${INLINE_CACHE_ARG} --build-arg PIP_TRUSTED_HOST=${PIP_TRUSTED_HOST} --build-arg PIP_INDEX_URL=${PIP_INDEX_URL} -t ${NOTEBOOK_IMAGE} -t ${LATEST_IMAGE} --cache-from ${LATEST_IMAGE} -f docker/notebook/Dockerfile .
docker build -t ${CPU_IMAGE} -f docker/notebook/Dockerfile.cpu .
if [ "${NO_PUSH}" != "true" ]
then
docker push --all-tags ${DOCKER_REPOSITORY}/aperturedb-notebook
fi
}
build_coverage_image(){
COV_IMAGE=${DOCKER_REPOSITORY}/aperturedb-python-coverage${IMAGE_EXTENSION_WITH_VERSION}
echo "Building image ${COV_IMAGE}"
docker build -t ${COV_IMAGE} -f coverage/Dockerfile .
if [ "${NO_PUSH}" != "true" ]
then
docker push ${COV_IMAGE}
ECR_REPO_NAME=aperturedb-python-coverage
COV_IMAGE=${DOCKER_REPOSITORY}/${ECR_REPO_NAME}${IMAGE_EXTENSION_WITH_VERSION}
ECR_NAME=${ECR_REPO_NAME}:v${BUILD_VERSION}
push_aws_ecr ${COV_IMAGE} ${ECR_NAME} ${ECR_REPO_NAME}
fi
}
push_aws_ecr(){
SRC_IMAGE=${1}
DST_IMAGE=${2}
ECR_REPO_NAME=${3}
REGION=us-west-2
PREFIX="aperturedata/"
docker tag ${SRC_IMAGE} \
684446431133.dkr.ecr.${REGION}.amazonaws.com/${DST_IMAGE}
docker run --rm -e AWS_ACCESS_KEY_ID -e AWS_DEFAULT_REGION -e AWS_SECRET_ACCESS_KEY amazon/aws-cli ecr get-login-password --region ${REGION} | docker login --username AWS --password-stdin 684446431133.dkr.ecr.${REGION}.amazonaws.com
docker run --rm -e AWS_ACCESS_KEY_ID -e AWS_DEFAULT_REGION -e AWS_SECRET_ACCESS_KEY amazon/aws-cli ecr create-repository --repository-name ${ECR_REPO_NAME} --region us-west-2 || true
docker push 684446431133.dkr.ecr.${REGION}.amazonaws.com/${DST_IMAGE}
}
if [ "${RUN_TESTS}" == "true" ] || [ "${BUILD_DEPENDENCIES}" == "true" ]
then
build_notebook_dependencies_image
fi
if [ "${RUN_TESTS}" == "true" ]
then
# BUILD_AUX_IMAGES controls whether we also build the notebook image and the
# coverage publishing image during a test run. These images are NOT required
# to execute the test suite (tests run inside aperturedb-python-tests, and
# the coverage image is just an nginx wrapper around the generated HTML used
# only when publishing). PR pipelines set BUILD_AUX_IMAGES=false to cut a
# large amount of work that would otherwise be discarded.
BUILD_AUX_IMAGES=${BUILD_AUX_IMAGES:-true}
if [ "${BUILD_AUX_IMAGES}" == "true" ]
then
build_notebook_image
fi
build_tests
pushd "test"
./run_test_container.sh
if [ "${BUILD_AUX_IMAGES}" == "true" ]
then
build_coverage_image
fi
rm -rf "./output/"
popd
fi
if [ "${BUILD_COMPLETE}" == "true" ]
then
build_complete
fi