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 static analysis feature #22

Merged
merged 3 commits into from
Feb 13, 2024
Merged
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
15 changes: 15 additions & 0 deletions features/src/static-analysis/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- markdownlint-disable MD003 MD024 -->
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.0.1] - 2024-02-12

### Added

- Initial release of feature
18 changes: 18 additions & 0 deletions features/src/static-analysis/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "static-analysis",
"version": "0.0.1",
"name": "Static Analysis",
"description": "Installs Checkov and Trivy",
"options": {
"checkovVersion": {
"type": "string",
"description": "Version of Checkov CLI to install",
"default": "latest"
},
"trivyVersion": {
"type": "string",
"description": "Version of Trivy CLI to install",
"default": "latest"
}
}
}
23 changes: 23 additions & 0 deletions features/src/static-analysis/install-checkov-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -e

# shellcheck source=/dev/null
# file not accessible until being built
source /usr/local/bin/devcontainer-utils

get_system_architecture

GITHUB_REPOSITORY="bridgecrewio/checkov"
VERSION="${CHECKOVCLIVERSION:-"latest"}"

if [[ "${VERSION}" == "latest" ]]; then
get_github_latest_tag "${GITHUB_REPOSITORY}"
VERSION="${GITHUB_LATEST_TAG}"
VERSION_STRIP_V="${GITHUB_LATEST_TAG_STRIP_V}"
else
# shellcheck disable=SC2034
VERSION_STRIP_V="${VERSION#v}"
fi

pip_install "checkov==${VERSION}"
36 changes: 36 additions & 0 deletions features/src/static-analysis/install-trivy-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

set -e

# shellcheck source=/dev/null
# file not accessible until being built
source /usr/local/bin/devcontainer-utils

get_system_architecture

GITHUB_REPOSITORY="aquasecurity/trivy"
VERSION="${TRIVYCLIVERSION:-"latest"}"

if [[ "${VERSION}" == "latest" ]]; then
get_github_latest_tag "${GITHUB_REPOSITORY}"
VERSION="${GITHUB_LATEST_TAG}"
VERSION_STRIP_V="${GITHUB_LATEST_TAG_STRIP_V}"
else
# shellcheck disable=SC2034
VERSION_STRIP_V="${VERSION#v}"
fi

if [[ "${ARCHITECTURE}" == "amd64" ]]; then
ARCHITECTURE="64bit"
elif [[ "${ARCHITECTURE}" == "arm64" ]]; then
ARCHITECTURE="ARM64"
fi

curl --fail-with-body --location "https://github.com/${GITHUB_REPOSITORY}/releases/download/${VERSION}/trivy_${VERSION_STRIP_V}_Linux-${ARCHITECTURE}.tar.gz" \
--output "trivy_${VERSION_STRIP_V}_Linux-${ARCHITECTURE}.tar.gz"

tar --extract --file "trivy_${VERSION_STRIP_V}_Linux-${ARCHITECTURE}.tar.gz"

install --owner=vscode --group=vscode --mode=775 trivy /usr/local/bin/trivy

rm --recursive --force rm -rf LICENSE README.md contrib "trivy_${VERSION_STRIP_V}_Linux-${ARCHITECTURE}.tar.gz"
11 changes: 11 additions & 0 deletions features/src/static-analysis/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# shellcheck source=/dev/null
# file not accessible until being built
source /usr/local/bin/devcontainer-utils

logger "info" "Installing Checkov CLI (version: ${CHECKOVCLIVERSION})"
bash "$(dirname "${0}")"/install-checkov-cli.sh

logger "info" "Installing Trivy CLI (version: ${TRIVYCLIVERSION})"
bash "$(dirname "${0}")"/install-trivy-cli.sh
12 changes: 12 additions & 0 deletions features/test/static-analysis/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -e

# shellcheck source=/dev/null
# file only accessible when using devcontainer CLI
source dev-container-features-test-lib

check "checkov version" checkov --version
check "trivy version" trivy --version

reportResults
Loading