Skip to content
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

Add .circleci/config.yml #1

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
version: 2.1
defaults: &defaults
working_directory: ~/repo
docker:
- image: circleci/node:14.16.0-browsers
- image: circleci/postgres:9.6-alpine
jobs:
EndToEndTestPackages:
machine:
image: ubuntu-2004:202010-01
steps:
- checkout
- attach_workspace:
at: ~/repo
- run:
name: Install [email protected]
command: |
export NVM_DIR="/opt/circleci/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install v14.16.0
nvm alias default v14.16.0
- run: |
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/node" "/usr/local/bin/node"
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/npm" "/usr/local/bin/npm"
- run: sudo npm i
- run: npm version

- run:
name: Install awscli
command: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
- run:
name: Install Docker Compose
command: |
curl -L https://github.com/docker/compose/releases/download/1.25.3/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
chmod +x ~/docker-compose
sudo mv ~/docker-compose /usr/local/bin/docker-compose
- run:
name: Install awscli
command: yarn build

# - run:
# name: Install awscli
# command: pip install awscli
# - run:
# name: Run packages
# command: |
# (cd packages/services && npm start)
# (cd packages/dashboard && npm start)

workflows:
version: 2
pull-requests-build-and-test:
jobs:
# - setup:
# filters: &pullRequestsFilters
# branches:
# ignore:
# - main
# - /^release\/.+$/
- EndToEndTestPackages:
# requires:
# - setup
filters: &pullRequestsFilters
branches:
ignore:
- main
- /^release\/.+$/
# - buildStaging:
# requires:
# - setup
# filters:
# <<: *pullRequestsFilters
# - testPackages:
# requires:
# - setup
# filters:
# <<: *pullRequestsFilters
168 changes: 168 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#!/bin/bash
set -e

_ROOT_DIR="${PWD}"
_WORKDIR="${_ROOT_DIR}/unfor19-awscli"
_DOWNLOAD_FILENAME="unfor19-awscli.zip"
_VERBOSE=${VERBOSE:-"false"}
_DEFAULT_VERSION=2
_AWS_CLI_VERSION=_DEFAULT_VERSION
_DOWNLOAD_URL=""
_LIGHTSAIL_INSTALL=${LIGHTSAILCTL:-"false"}

msg_error(){
msg=$1
echo -e ">> [ERROR]: ${msg}"
exit 1
}


msg_log(){
msg=$1
echo -e ">> [LOG]: ${msg}"
}


set_workdir(){
mkdir -p "${_WORKDIR}"
cd "${_WORKDIR}"
}


valid_semantic_version(){
msg_log "Validating semantic version - $_AWS_CLI_VERSION"
if [[ $_AWS_CLI_VERSION =~ ^([1,2]|[1,2](\.[0-9]{1,2}\.[0-9]{1,3}))$ ]]; then
msg_log "Valid version input"
else
msg_error "Invalid version input \"$_AWS_CLI_VERSION\", should match: ^([1,2]|[1,2](\.[0-9]{1,2}\.[0-9]{1,3}))$"
fi
}


set_download_url(){
msg_log "Setting _DOWNLOAD_URL"
# v1
if [[ $_AWS_CLI_VERSION =~ ^1.*$ ]]; then
if [[ $_AWS_CLI_VERSION = "1" ]]; then
_DOWNLOAD_URL="https://s3.amazonaws.com/aws-cli/awscli-bundle.zip"
else
_DOWNLOAD_URL="https://s3.amazonaws.com/aws-cli/awscli-bundle-${_AWS_CLI_VERSION}.zip"
fi
# v2
elif [[ $_AWS_CLI_VERSION =~ ^2.*$ ]]; then
if [[ $_AWS_CLI_VERSION = "2" ]]; then
# Latest v2
_DOWNLOAD_URL="https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"
else
# Specific v2
_DOWNLOAD_URL="https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${_AWS_CLI_VERSION}.zip"
fi
fi
msg_log "_DOWNLOAD_URL = ${_DOWNLOAD_URL}"
}


check_version_exists(){
msg_log "Checking if the provided version exists in AWS"
local exists
set +e
exists=$(wget -q -S --spider "$_DOWNLOAD_URL" 2>&1 | grep 'HTTP/1.1 200 OK')
set -e
if [[ -n $exists ]]; then
msg_log "Provided version exists - ${_AWS_CLI_VERSION}"
else
msg_error "Provided version does not exist - ${_AWS_CLI_VERSION}"
fi
}


download_aws_cli(){
msg_log "Downloading ..."
wget -q -O "$_DOWNLOAD_FILENAME" "$_DOWNLOAD_URL"
[[ $_VERBOSE = "true" ]] && ls -lah "$_DOWNLOAD_FILENAME"
wait
}


install_aws_cli(){
local aws_path
msg_log "Unzipping ${_DOWNLOAD_FILENAME}"
unzip -qq "$_DOWNLOAD_FILENAME"
[[ $_VERBOSE = "true" ]] && ls -lah
wait
msg_log "Installing AWS CLI - ${_AWS_CLI_VERSION}"
if [[ $_AWS_CLI_VERSION =~ ^1.*$ ]]; then
./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
elif [[ $_AWS_CLI_VERSION =~ ^2.*$ ]]; then
set +e
aws_path=$(which aws)
[[ -n $aws_path ]] && msg_log "aws_path = $aws_path"
set -e
if [[ $aws_path =~ ^.*aws.*not.*found || -z $aws_path ]]; then
# Fresh install
./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli
else
# Update
./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
fi
fi
msg_log "Installation completed"
}


cleanup(){
cd "${_ROOT_DIR}"
[[ $_VERBOSE = "true" ]] && ls -lh
rm -rf "${_WORKDIR}"
[[ $_VERBOSE = "true" ]] && ls -lh
wait
}


test_aws_cli(){
msg_log "Printing AWS CLI installed version"
aws --version
}


install_lightsailctl(){
if [[ $_LIGHTSAIL_INSTALL = "true" ]]; then
if [[ $_AWS_CLI_VERSION =~ ^2.*$ ]]; then
msg_log "Installing Lightsailctl"
wget -q -O "/usr/local/bin/lightsailctl" "https://s3.us-west-2.amazonaws.com/lightsailctl/latest/linux-amd64/lightsailctl"
wait
chmod +x /usr/local/bin/lightsailctl
msg_log "Installation complete"
else
msg_error "Cannot install Lightsail plugin with CLI 1.x"
fi
fi
}


test_lightsailctl(){
local installed_lightsail
if [[ $_LIGHTSAIL_INSTALL = "true" ]]; then
set +e
installed_lightsail=$(lightsailctl 2>&1 | grep "it is meant to be invoked by AWS CLI")
set -e
if [[ -n $installed_lightsail ]]; then
msg_log "Lightsail was installed successfully"
else
error_msg "Failed to install lightsailctl"
fi
fi
}


# Main
set_workdir
valid_semantic_version
set_download_url
check_version_exists
download_aws_cli
install_aws_cli
install_lightsailctl
cleanup
test_aws_cli
test_lightsailctl