Created
November 24, 2016 05:19
-
-
Save wokamoto/c699d8e5d0008d3c457e68157dd9f429 to your computer and use it in GitHub Desktop.
S3 に yum リポジトリのクローン用意して、同期完了後に CloudFront に対して invalidation 走らせるスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LANG=C | |
REPOSITORIES="__YUM_REPOSITORIES_HERE__" | |
TOP="__REPOSITORY_DIRECTORY_HERE__" | |
S3_REGION="__S3_REGION__HERE__" | |
S3_BUCKET="__S3_BUCKET_NAME_HERE__" | |
CF_DISTID="__CLOUDFRONT_DISTRIBUTION_ID_HERE__" | |
echo "## `date`: BEGIN MIRRORING" | |
for repository in $REPOSITORIES; do | |
echo "#### `date`: BEGIN REPOSITORY ${repository}" | |
repo_path="${TOP}/${repository}" | |
if [ ! -e ${repo_path} ]; then | |
mkdir -p ${repo_path} | |
fi | |
reposync -r $r{epository} | |
createrepo -v ${repo_path} | |
aws --region ${S3_REGION} s3 sync ${repo_path}/ s3://${S3_BUCKET}/enterprise/6/${repository}/RPMS/ | |
aws --region ${S3_REGION} s3 sync ${repo_path}/ s3://${S3_BUCKET}/enterprise/6/${repository}/x86_64/ | |
echo "#### `date`: END REPOSITORY ${repository}" | |
done | |
echo "## `date`: END MIRRORING" | |
echo "CloudFront invalidation..." | |
echo "{ | |
\"Paths\": { | |
\"Quantity\": 1, | |
\"Items\": [\"/*\"] | |
}, | |
\"CallerReference\": \"invalidation-$(date +'%Y%m%d_%H%M%S')\" | |
}" > invbatch.json | |
aws cloudfront create-invalidation \ | |
--invalidation-batch file://invbatch.json \ | |
--distribution-id ${CF_DISTID} | |
rm -f invbatch.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment