-
Notifications
You must be signed in to change notification settings - Fork 7
ci: add install script #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Update S3 and Cloudfront | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- .github/workflows/update-s3-and-cloudfront.yaml | ||
- s3/install | ||
|
||
jobs: | ||
update-s3-and-cloudfront: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
S3_BUCKET_REGION: ${{ secrets.S3_BUCKET_REGION }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ secrets.S3_BUCKET_REGION }} | ||
|
||
- name: Deploy | ||
# The path to the install script will be /adc/install | ||
run: aws s3 sync ./s3 s3://${{ secrets.S3_BUCKET }}/adc | ||
|
||
- name: Invalidate CloudFront | ||
uses: chetan/invalidate-cloudfront-action@v2 | ||
env: | ||
DISTRIBUTION: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} | ||
PATHS: "/" | ||
AWS_REGION: "${{ secrets.S3_BUCKET_REGION }}" | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env bash | ||
|
||
ARCH="$(uname -m)" | ||
OS="$(uname)" | ||
|
||
# convert to standard arch names used in files | ||
if [ "x${ARCH}" = "xx86_64" ]; then | ||
ARCH="amd64" | ||
fi | ||
|
||
# convert to standard os names used in files | ||
if [ "x${OS}" = "xDarwin" ]; then | ||
OS="darwin" | ||
else | ||
OS="linux" | ||
fi | ||
|
||
# either specify the version in an environment variable or get the latest from GitHub | ||
if [ "x${ADC_VERSION}" = "x" ]; then | ||
ADC_VERSION=$(curl -L -s https://github.com/api7/adc/releases/latest | | ||
grep "adc/releases/tag/" | head -1 | awk -F '"' '{print $4}' | | ||
awk -F '/' '{print $NF}') | ||
fi | ||
|
||
if [ "x${ADC_VERSION}" = "x" ]; then | ||
printf "Unable to find the latest version of ADC. Please set the ADC_VERSION environment variable and try again. For example, export ADC_VERSION=0.5.0\n" | ||
exit 1 | ||
fi | ||
|
||
# if version has v in prefix, remove it | ||
ADC_VERSION=${ADC_VERSION#v} | ||
|
||
FILENAME="adc_${ADC_VERSION}_${OS}_${ARCH}.tar.gz" | ||
|
||
# example download URL format: https://github.com/api7/adc/releases/download/v0.5.0/adc_0.5.0_darwin_arm64.tar.gz | ||
URL="https://github.com/api7/adc/releases/download/v${ADC_VERSION}/${FILENAME}" | ||
|
||
printf "Downloading ADC v${ADC_VERSION} for ${OS} ${ARCH}..." | ||
# printf "Download URL: %s\n" "$URL" | ||
|
||
curl -L -s ${URL} -o ${PWD}/adc.tar.gz | ||
if [ $? -ne 0 ]; then | ||
echo "Error downloading ADC. Please check your internet connection and try again." | ||
exit 1 | ||
fi | ||
|
||
# temporary folder name to extract the downloaded file | ||
TEMP_FOLDER_NAME=$(tr -dc A-Za-z0-9 </dev/urandom 2>/dev/null | head -c 16) | ||
if [ -z "$TEMP_FOLDER_NAME" ]; then | ||
TEMP_FOLDER_NAME="TEMP_ADC_FOLDER" | ||
fi | ||
|
||
mkdir $TEMP_FOLDER_NAME | ||
|
||
printf "\nExtracting ADC to temporary folder %s...\n" "$TEMP_FOLDER_NAME" | ||
|
||
tar -xzf "${PWD}/adc.tar.gz" -C "${PWD}/${TEMP_FOLDER_NAME}" | ||
if [ $? -ne 0 ]; then | ||
echo "Error extracting ADC. The downloaded file might be corrupted. Please try again and make sure that you are installing the correct version." | ||
exit 1 | ||
fi | ||
|
||
INSTALL_DIR=${ADC_DIR} | ||
if [ -z "$INSTALL_DIR" ]; then | ||
INSTALL_DIR="/usr/local/bin" | ||
fi | ||
|
||
printf "Installing ADC in $INSTALL_DIR...\n" | ||
|
||
WHOAMI=$(whoami) | ||
|
||
# install adc binary, use sudo if user doesn't have permission to install in INSTALL_DIR | ||
if mv "${PWD}/$TEMP_FOLDER_NAME/adc" "$INSTALL_DIR/adc" >/dev/null 2>&1; then | ||
echo "ADC installed successfully!" | ||
else | ||
if sudo mv ${PWD}/$TEMP_FOLDER_NAME/adc $INSTALL_DIR/adc; then | ||
echo "ADC installed successfully with sudo permissions!" | ||
else | ||
echo "Unable to install ADC. Please check the permissions of the user $WHOAMI for the directory $INSTALL_DIR." | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# clean up temporary files | ||
printf "Removing temporary files...\n" | ||
rm -rf adc.tar.gz ${PWD}/$TEMP_FOLDER_NAME/ | ||
|
||
printf "Done!\n" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.