mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-23 14:57:18 +00:00

This commit makes Appveyor and Travis CI publish snapshot builds to S3 when a pull request is merged, by making use of the `publish-aws-s3` Makefile target. The changes required for such type of deployment are the followings: - Set `S3_BUCKET` to `resin-nightly-downloads` when doing snapshot builds - Add deploy sections to `.travis.yml` and `appveyor.yml` that run `make publish-aws-s3` - Don't change `PRODUCT_NAME` when doing snapshot builds (given we'll be publishing to a different S3 bucket) - Install `awscli` in Appveyor CI and Travis CI - Make GNU/Linux Docker containers inherit `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` from the environment (so `awscli` is configured correctly inside them) - Add a prefix option to `aws-s3.sh` publish script to prepend a string to the S3 path, so we can add a timestamp to more easily distinguish files inside the `resin-nightly-downloads` bucket - Print the published URL from `aws-s3.sh` for convenience purposes, so we can click it when skimming through CI builds logs - Add the `-R` and `-L` options when recursively copying `node_modules` during a snapshot build to prevent weird Appveyor errors related to hard links. The options listed before make sure that we recursively resolve every link while copying - Move from `wget` to `curl` to avoid certificate check failures Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
95 lines
2.0 KiB
Bash
Executable File
95 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
###
|
|
# Copyright 2016 resin.io
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
###
|
|
|
|
set -u
|
|
set -e
|
|
|
|
./scripts/build/check-dependency.sh curl
|
|
|
|
SHA256SUM=$(./scripts/build/check-dependency.sh sha256sum "shasum -a 256")
|
|
|
|
function usage() {
|
|
echo "Usage: $0"
|
|
echo ""
|
|
echo "Options"
|
|
echo ""
|
|
echo " -u <url>"
|
|
echo " -c <sha256 checksum>"
|
|
echo " -x set execute permissions"
|
|
echo " -o <output>"
|
|
exit 1
|
|
}
|
|
|
|
ARGV_URL=""
|
|
ARGV_CHECKSUM=""
|
|
ARGV_EXECUTE_PERMISSIONS=false
|
|
ARGV_OUTPUT=""
|
|
|
|
while getopts ":u:c:o:x" option; do
|
|
case $option in
|
|
u) ARGV_URL="$OPTARG" ;;
|
|
c) ARGV_CHECKSUM="$OPTARG" ;;
|
|
x) ARGV_EXECUTE_PERMISSIONS=true ;;
|
|
o) ARGV_OUTPUT="$OPTARG" ;;
|
|
*) usage ;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "$ARGV_URL" ] || \
|
|
[ -z "$ARGV_CHECKSUM" ] || \
|
|
[ -z "$ARGV_OUTPUT" ]
|
|
then
|
|
usage
|
|
fi
|
|
|
|
function checksum_matches() {
|
|
local file=$1
|
|
local hash=$2
|
|
test "$($SHA256SUM $file | cut -d ' ' -f1)" = "$hash"
|
|
}
|
|
|
|
TEMP_OUTPUT="$ARGV_OUTPUT.TMP"
|
|
|
|
if [ -f "$TEMP_OUTPUT" ]; then
|
|
rm "$TEMP_OUTPUT"
|
|
fi
|
|
|
|
if [ -f "$ARGV_OUTPUT" ]; then
|
|
if checksum_matches "$ARGV_OUTPUT" "$ARGV_CHECKSUM"; then
|
|
echo "Re-using from cache"
|
|
exit 0
|
|
else
|
|
rm "$ARGV_OUTPUT"
|
|
fi
|
|
fi
|
|
|
|
echo "Downloading $ARGV_URL"
|
|
curl --continue-at - --retry 100 --location --output "$TEMP_OUTPUT" "$ARGV_URL"
|
|
|
|
if ! checksum_matches "$TEMP_OUTPUT" "$ARGV_CHECKSUM"; then
|
|
echo "Checksum mismatch" 1>&2
|
|
rm "$TEMP_OUTPUT"
|
|
exit 1
|
|
else
|
|
mv "$TEMP_OUTPUT" "$ARGV_OUTPUT"
|
|
fi
|
|
|
|
if [ "$ARGV_EXECUTE_PERMISSIONS" == "true" ]; then
|
|
chmod +x "$ARGV_OUTPUT"
|
|
fi
|