Skip to content

Commit

Permalink
feat: BASH_SHFMT linter + linter fixes (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
javydekoning authored Apr 8, 2024
1 parent ccd6684 commit 5d6e5ce
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 142 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ max_line_length = 120
indent_style = tab
indent_size = 4
tab_width = 4

[*.sh]
space_redirects = true
7 changes: 6 additions & 1 deletion .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ APPLY_FIXES: none
# If you use ENABLE_LINTERS variable, all other linters will be disabled by default
ENABLE_LINTERS:
- BASH_EXEC
- BASH_SHFMT
- CLOUDFORMATION_CFN_LINT
- DOCKERFILE_HADOLINT
- EDITORCONFIG_EDITORCONFIG_CHECKER
Expand All @@ -30,16 +31,20 @@ FILEIO_REPORTER: false

# Install plugin for list handling.
JSON_PRETTIER_PRE_COMMANDS:
- command: "npm install prettier-plugin-multiline-arrays@3.0.0"
- command: "npm install prettier-plugin-multiline-arrays@3.0.4"
cwd: "workspace"

CLOUDFORMATION_CFN_LINT_CONFIG_FILE: '.cfnlintrc'
CLOUDFORMATION_CFN_LINT_FILE_EXTENSIONS: [".yml", ".yaml"]

EDITORCONFIG_EDITORCONFIG_CHECKER_CONFIG_FILE: '.ecrc.json'

MARKDOWN_MARKDOWN_LINK_CHECK_ARGUMENTS: '-q'
MARKDOWN_MARKDOWNLINT_DISABLE_ERRORS: false

SPELL_CSPELL_ARGUMENTS: '--gitignore --no-progress --show-suggestions'
SPELL_CSPELL_FILE_EXTENSIONS: ["*"]

TERRAFORM_TFLINT_UNSECURED_ENV_VARIABLES:
- GITHUB_TOKEN

Expand Down
2 changes: 1 addition & 1 deletion samples/sample-ec2-java-app-codedeploy/scripts/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ echo "Waiting for 15 seconds before checking health.."
sleep 15

status_code=$(curl --write-out %{http_code} --silent --output /dev/null http://localhost:80)
if [[ "$status_code" -ne 200 ]] ; then
if [[ "$status_code" -ne 200 ]]; then
echo "App is not healthy - $status_code"
exit 1
else
Expand Down
33 changes: 16 additions & 17 deletions samples/sample-ec2-with-codedeploy/scripts/install-codedeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ set -xe

## Code Deploy Agent Bootstrap Script ##

exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
exec > >(tee /var/log/user-data.log | logger -t user-data -s 2> /dev/console) 2>&1
AUTOUPDATE=false

function installdep(){
function installdep() {
if [ ${PLAT} = "ubuntu" ]; then
apt-get -y update
# Satisfying even Ubuntu older versions.
Expand All @@ -21,7 +21,7 @@ function installdep(){
fi
}

function platformize(){
function platformize() {
# Linux OS detection
if hash lsb_release; then
echo "Ubuntu server OS detected"
Expand All @@ -35,21 +35,20 @@ function platformize(){
fi
}


function execute(){
function execute() {
if [ ${PLAT} = "ubuntu" ]; then
cd /tmp/
wget https://aws-codedeploy-${REGION}.s3.${REGION}.amazonaws.com/latest/install
chmod +x ./install

if ./install auto; then
echo "Installation completed"
if ! ${AUTOUPDATE}; then
echo "Disabling Auto Update"
sed -i '/@reboot/d' /etc/cron.d/codedeploy-agent-update
chattr +i /etc/cron.d/codedeploy-agent-update
rm -f /tmp/install
fi
if ! ${AUTOUPDATE}; then
echo "Disabling Auto Update"
sed -i '/@reboot/d' /etc/cron.d/codedeploy-agent-update
chattr +i /etc/cron.d/codedeploy-agent-update
rm -f /tmp/install
fi
exit 0
else
echo "Installation script failed, please investigate"
Expand All @@ -64,12 +63,12 @@ function execute(){

if ./install auto; then
echo "Installation completed"
if ! ${AUTOUPDATE}; then
echo "Disabling auto update"
sed -i '/@reboot/d' /etc/cron.d/codedeploy-agent-update
chattr +i /etc/cron.d/codedeploy-agent-update
rm -f /tmp/install
fi
if ! ${AUTOUPDATE}; then
echo "Disabling auto update"
sed -i '/@reboot/d' /etc/cron.d/codedeploy-agent-update
chattr +i /etc/cron.d/codedeploy-agent-update
rm -f /tmp/install
fi
exit 0
else
echo "Installation script failed, please investigate"
Expand Down
6 changes: 4 additions & 2 deletions samples/sample-ec2-with-codedeploy/scripts/install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ sudo useradd springboot
sudo chsh -s /sbin/nologin springboot

# forward port 80 to 8080
echo "<VirtualHost *:80>
echo "
<VirtualHost *:80>
ProxyRequests Off
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>" >> sudo /etc/httpd/conf/httpd.conf
</VirtualHost>
" | sudo tee -a /etc/httpd/conf/httpd.conf > /dev/null

# start the httpd service now and stop it until userdata
sudo service httpd start
Expand Down
3 changes: 2 additions & 1 deletion samples/sample-fargate-node-app/build/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
docker push $REPOSITORY_URI:latest
docker push $REPOSITORY_URI:$IMAGE_TAG

tmp=$(mktemp); jq --arg REPOSITORY_URI "$REPOSITORY_URI" --arg IMAGE_TAG "$IMAGE_TAG" '.Parameters.Image = $REPOSITORY_URI+":"+$IMAGE_TAG' params/global.json > "$tmp" && mv "$tmp" params/global.json
tmp=$(mktemp)
jq --arg REPOSITORY_URI "$REPOSITORY_URI" --arg IMAGE_TAG "$IMAGE_TAG" '.Parameters.Image = $REPOSITORY_URI+":"+$IMAGE_TAG' params/global.json > "$tmp" && mv "$tmp" params/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ set -e
SKIP_BUILD=0

# Walk through the options passed to this script
for i in "$@"
do
for i in "$@"; do
case $i in
--no-build)
SKIP_BUILD=1
;;
*)
echo "Unknown option: $i"
exit 1
;;
--no-build)
SKIP_BUILD=1
;;
*)
echo "Unknown option: $i"
exit 1
;;
esac
done

Expand All @@ -37,16 +36,15 @@ fi

# Get list of regions supported by this application
echo "Determine which regions need to be prepared"
app_regions=`aws ssm get-parameters --names /adf/deployment/$ADF_DEPLOYMENT_MAP_SOURCE/$ADF_PROJECT_NAME/regions --with-decryption --output=text --query='Parameters[0].Value'`
app_regions=$(aws ssm get-parameters --names /adf/deployment/$ADF_DEPLOYMENT_MAP_SOURCE/$ADF_PROJECT_NAME/regions --with-decryption --output=text --query='Parameters[0].Value')
# Convert json list to bash list (space delimited regions)
regions="`echo $app_regions | sed -e 's/\[\([^]]*\)\]/\1/g' | sed 's/,/ /g' | sed "s/'//g"`"
regions="$(echo $app_regions | sed -e 's/\[\([^]]*\)\]/\1/g' | sed 's/,/ /g' | sed "s/'//g")"

for region in $regions
do
for region in $regions; do
if [ $CONTAINS_TRANSFORM ]; then
echo "Packaging templates for region $region"
ssm_bucket_name="/adf/cross_region/s3_regional_bucket/$region"
bucket=`aws ssm get-parameters --names $ssm_bucket_name --with-decryption --output=text --query='Parameters[0].Value'`
bucket=$(aws ssm get-parameters --names $ssm_bucket_name --with-decryption --output=text --query='Parameters[0].Value')
sam package --s3-bucket $bucket --output-template-file $CODEBUILD_SRC_DIR/template_$region.yml --region $region
else
# If package is not needed, just copy the file for each region
Expand Down
Loading

0 comments on commit 5d6e5ce

Please sign in to comment.