mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-22 06:17:20 +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>
81 lines
1.9 KiB
Bash
Executable File
81 lines
1.9 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.
|
|
###
|
|
|
|
# See http://www.davidpashley.com/articles/writing-robust-shell-scripts/
|
|
set -u
|
|
set -e
|
|
|
|
./scripts/build/check-dependency.sh aws
|
|
|
|
function usage() {
|
|
echo "Usage: $0"
|
|
echo ""
|
|
echo "Options"
|
|
echo ""
|
|
echo " -f <file>"
|
|
echo " -b <s3 bucket>"
|
|
echo " -v <version>"
|
|
echo " -p <product name>"
|
|
echo " -k [S3 key prefix]"
|
|
exit 1
|
|
}
|
|
|
|
ARGV_FILE=""
|
|
ARGV_BUCKET=""
|
|
ARGV_VERSION=""
|
|
ARGV_PRODUCT_NAME=""
|
|
ARGV_PREFIX=""
|
|
|
|
while getopts ":f:b:v:p:k:" option; do
|
|
case $option in
|
|
f) ARGV_FILE="$OPTARG" ;;
|
|
b) ARGV_BUCKET="$OPTARG" ;;
|
|
v) ARGV_VERSION="$OPTARG" ;;
|
|
p) ARGV_PRODUCT_NAME="$OPTARG" ;;
|
|
k) ARGV_PREFIX="$OPTARG" ;;
|
|
*) usage ;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "$ARGV_FILE" ] || \
|
|
[ -z "$ARGV_BUCKET" ] || \
|
|
[ -z "$ARGV_VERSION" ] || \
|
|
[ -z "$ARGV_PRODUCT_NAME" ]
|
|
then
|
|
usage
|
|
fi
|
|
|
|
FILENAME=$(basename "$ARGV_FILE")
|
|
|
|
if [ -n "$ARGV_PREFIX" ]; then
|
|
S3_KEY="$ARGV_PRODUCT_NAME/$ARGV_PREFIX/$ARGV_VERSION/$FILENAME"
|
|
else
|
|
S3_KEY="$ARGV_PRODUCT_NAME/$ARGV_VERSION/$FILENAME"
|
|
fi
|
|
|
|
aws s3api put-object \
|
|
--bucket "$ARGV_BUCKET" \
|
|
--acl public-read \
|
|
--key "$S3_KEY" \
|
|
--body "$ARGV_FILE"
|
|
|
|
# Escape plus signs when printing the final URL
|
|
URL="$(echo "https://$ARGV_BUCKET.s3.amazonaws.com/$S3_KEY" | sed 's/\+/%2B/g')"
|
|
|
|
echo "Uploaded $(basename "$ARGV_FILE") to $URL"
|