| 1 | #!/bin/sh |
| 2 | |
| 3 | # Replace / with _ to create a valid tag |
| 4 | TAG=$(echo "${BRANCH_NAME}" | sed -e "s/\//_/g") |
| 5 | TAG_PLOT=${TAG}_plot |
| 6 | echo "Running for ${TAG}" |
| 7 | |
| 8 | # Add commit and commit_message to docker container |
| 9 | echo "${GITHUB_SHA}" > freqtrade_commit |
| 10 | |
| 11 | if [ "${GITHUB_EVENT_NAME}" = "schedule" ]; then |
| 12 | echo "event ${GITHUB_EVENT_NAME}: full rebuild - skipping cache" |
| 13 | docker build -t freqtrade:${TAG} . |
| 14 | else |
| 15 | echo "event ${GITHUB_EVENT_NAME}: building with cache" |
| 16 | # Pull last build to avoid rebuilding the whole image |
| 17 | docker pull ${IMAGE_NAME}:${TAG} |
| 18 | docker build --cache-from ${IMAGE_NAME}:${TAG} -t freqtrade:${TAG} . |
| 19 | fi |
| 20 | # Tag image for upload and next build step |
| 21 | docker tag freqtrade:$TAG ${IMAGE_NAME}:$TAG |
| 22 | |
| 23 | docker build --cache-from freqtrade:${TAG} --build-arg sourceimage=${TAG} -t freqtrade:${TAG_PLOT} -f docker/Dockerfile.plot . |
| 24 | |
| 25 | docker tag freqtrade:$TAG_PLOT ${IMAGE_NAME}:$TAG_PLOT |
| 26 | |
| 27 | if [ $? -ne 0 ]; then |
| 28 | echo "failed building image" |
| 29 | return 1 |
| 30 | fi |
| 31 | |
| 32 | # Run backtest |
| 33 | docker run --rm -v $(pwd)/config_bittrex.json.example:/freqtrade/config.json:ro -v $(pwd)/tests:/tests freqtrade:${TAG} backtesting --datadir /tests/testdata --strategy-path /tests/strategy/strats/ --strategy DefaultStrategy |
| 34 | |
| 35 | if [ $? -ne 0 ]; then |
| 36 | echo "failed running backtest" |
| 37 | return 1 |
| 38 | fi |
| 39 | |
| 40 | if [ $? -ne 0 ]; then |
| 41 | echo "failed tagging image" |
| 42 | return 1 |
| 43 | fi |
| 44 | |
| 45 | # Tag as latest for develop builds |
| 46 | if [ "${TAG}" = "develop" ]; then |
| 47 | docker tag freqtrade:$TAG ${IMAGE_NAME}:latest |
| 48 | fi |
| 49 | |
| 50 | # Show all available images |
| 51 | docker images |
| 52 | |
| 53 | docker push ${IMAGE_NAME} |
| 54 | docker push ${IMAGE_NAME}:$TAG_PLOT |
| 55 | docker push ${IMAGE_NAME}:$TAG |
| 56 | if [ $? -ne 0 ]; then |
| 57 | echo "failed pushing repo" |
| 58 | return 1 |
| 59 | fi |