-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sh
49 lines (39 loc) · 1.63 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
#!/bin/bash
set -ev
function sanitize() {
local s="${1?need a string}" # receive input in first argument
s="${s//[^[:alnum:]]/-}" # replace all non-alnum characters to -
s="${s//+(-)/-}" # convert multiple - to single -
s="${s/#-}" # remove - from start
s="${s/%-}" # remove - from end
echo "${s,,}" # convert to lowercase
}
function docker_tag_exists() {
curl --silent -f -lSL https://index.docker.io/v1/repositories/$1/tags/$2 > /dev/null
}
SANITIZED_BRANCH=$(sanitize $TRAVIS_BRANCH)
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
IMAGE_NAME=$DOCKER_USERNAME/gupy-build-cache:$SANITIZED_BRANCH
# IMAGE_NAME=gupy-build-cache:$SANITIZED_BRANCH
if docker_tag_exists $DOCKER_USERNAME/gupy-build-cache $SANITIZED_BRANCH; then
docker image pull $IMAGE_NAME
fi
docker image build --cache-from $IMAGE_NAME -t $IMAGE_NAME src
[[ "$(docker ps -a | grep gupy-container)" ]] && docker container rm -f gupy-container
docker container run --name gupy-container $IMAGE_NAME
mkdir build
# copy the firmware
docker container cp gupy-container:/src/gupy/build/firmware.hex build/
# copy to build/tmp all py/mpy files
docker container cp gupy-container:/src/tmp/ build/
# update cache image on docker hub
docker image push $IMAGE_NAME
pushd build/tmp
tar -cvzf $(cat $TRAVIS_BUILD_DIR/integration/tag)-mpy-modules.tar.gz *.mpy
tar -cvzf $(cat $TRAVIS_BUILD_DIR/integration/tag)-py-modules.tar.gz *.py
cd ..
mv tmp/*.tar.gz .
mv tmp/usedspace.txt .
mv firmware.hex $(cat $TRAVIS_BUILD_DIR/integration/tag)-dexterindustries-gb-firmware.hex
mv tmp modules
popd