169 lines
4.7 KiB
Bash
169 lines
4.7 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
set -eu
|
||
|
|
||
|
source ./utils/common.sh
|
||
|
|
||
|
WORKDIR=/home/oscarzhou/source/github.com/portainer
|
||
|
GLOBAL_VOLUME=/home/oscarzhou/volumes
|
||
|
TRUE=0;
|
||
|
FALSE=1;
|
||
|
REPO_DIR=
|
||
|
REPO_VOLUME=
|
||
|
|
||
|
function debug_portainer_client() {
|
||
|
print_highlight "[debug portainer client]"
|
||
|
yarn
|
||
|
yarn start:client
|
||
|
}
|
||
|
|
||
|
function generate_portainer_jwt_token() {
|
||
|
print_highlight "[generate portainer jwt token]"
|
||
|
|
||
|
read -p "Username(admin):" username
|
||
|
if [ -z "$username" ]; then
|
||
|
username="admin";
|
||
|
fi
|
||
|
|
||
|
read -p "Password(****):" password
|
||
|
read -p "Address(http://127.0.0.1:9000):" address
|
||
|
if [ -z "$address" ]; then
|
||
|
address="http://127.0.0.1:9000";
|
||
|
fi
|
||
|
|
||
|
payload="{\"username\":\"${username}\",\"password\":\"${password}\"}"
|
||
|
curl -d ${payload} -H 'Content-Type: application/json' "${address}/api/auth"
|
||
|
}
|
||
|
|
||
|
function list_portainer_ee_menu() {
|
||
|
print_highlight "Your current working directory is ${WORKDIR}/portainer-ee"
|
||
|
if ! prompt_continue; then
|
||
|
exit;
|
||
|
fi
|
||
|
|
||
|
REPO_DIR=${WORKDIR}/portainer-ee
|
||
|
print_highlight "Your current volume is ${VOLUME}/portainer-ee-data"
|
||
|
if ! prompt_continue; then
|
||
|
exit;
|
||
|
fi
|
||
|
|
||
|
REPO_VOLUME=${VOLUME}/portainer-ee-data
|
||
|
|
||
|
PS3='Please select the action: '
|
||
|
OPTIONS=(
|
||
|
'Debug Client'
|
||
|
'Lint Client'
|
||
|
'Run Unit Test for Client'
|
||
|
'Before Commit'
|
||
|
'Build Client'
|
||
|
'Build Server'
|
||
|
'Run Unit Test for Server'
|
||
|
'Get Portainer CE API Reference'
|
||
|
'Quit'
|
||
|
)
|
||
|
|
||
|
select opt in "${OPTIONS[@]}"
|
||
|
do
|
||
|
case $opt in
|
||
|
'Debug Client')
|
||
|
debug_portainer_client
|
||
|
;;
|
||
|
'PortainerCE')
|
||
|
build_portainer_frontend
|
||
|
;;
|
||
|
'Build Portainer EE/CE Backend')
|
||
|
build_portainer_backend
|
||
|
;;
|
||
|
'Generate Portainer EE/CE JWT')
|
||
|
generate_portainer_jwt
|
||
|
;;
|
||
|
'Run Before Commit [Portainer EE/CE]')
|
||
|
run_before_commit
|
||
|
;;
|
||
|
'Get Portainer CE API Reference')
|
||
|
get_portainer_ce_api_reference
|
||
|
;;
|
||
|
'Quit')
|
||
|
break
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
}
|
||
|
|
||
|
function code_security_scan_summary() {
|
||
|
echo "
|
||
|
1. Scan client with snyk: $(print_highlight "snyk test")
|
||
|
2. Scan server with snyk: $(print_highlight "cd api && snyk test")
|
||
|
3. If snyk is not authenticated: $(print_highlight "snyk auth")
|
||
|
4. Specify the severity threshold: $(print_highlight "snyk test --severity-threshold=<low|medium|high|critical>")
|
||
|
5. Other commands with snyk: $(print_highlight "snyk --help")
|
||
|
"
|
||
|
|
||
|
echo "
|
||
|
Steps to scan portainer image with Trivy:
|
||
|
1. Build the local image: $(print_highlight "docker build -t oscarzhou/portainer:dev-ee -f build/linux/Dockfile .")
|
||
|
2. Scan with trivy: $(print_highlight 'docker run --rm -v "/var/run/docker.sock":"/var/run/docker.sock" aquasec/trivy:latest image oscarzhou/portainer:dev-ee')
|
||
|
3. Other commands with trivy: $(print_highlight 'docker run --rm -v "/var/run/docker.sock":"/var/run/docker.sock" aquasec/trivy:latest --help')
|
||
|
"
|
||
|
}
|
||
|
|
||
|
|
||
|
function menu() {
|
||
|
PS3='Please select the action/repository: '
|
||
|
OPTIONS=(
|
||
|
'PortainerEE'
|
||
|
'PortainerCE'
|
||
|
'Build Portainer EE/CE Backend'
|
||
|
'Generate Portainer JWT Token'
|
||
|
'Run Before Commit [Portainer EE/CE]'
|
||
|
'Get Portainer CE API Reference'
|
||
|
'Run Before Commit [k8s]'
|
||
|
'Code Security Scan'
|
||
|
'Cleanup Temporary Volume'
|
||
|
'Quit'
|
||
|
)
|
||
|
|
||
|
select opt in "${OPTIONS[@]}"
|
||
|
do
|
||
|
case $opt in
|
||
|
'PortainerEE')
|
||
|
list_portainer_ee_menu
|
||
|
;;
|
||
|
'PortainerCE')
|
||
|
build_portainer_frontend
|
||
|
;;
|
||
|
'Build Portainer EE/CE Backend')
|
||
|
build_portainer_backend
|
||
|
;;
|
||
|
'Generate Portainer JWT Token')
|
||
|
generate_portainer_jwt
|
||
|
;;
|
||
|
'Run Before Commit [Portainer EE/CE]')
|
||
|
run_before_commit
|
||
|
;;
|
||
|
'Get Portainer CE API Reference')
|
||
|
get_portainer_ce_api_reference
|
||
|
;;
|
||
|
'Run Before Commit [k8s]')
|
||
|
run_before_commit_k8s
|
||
|
;;
|
||
|
'Code Security Scan')
|
||
|
code_security_scan_summary
|
||
|
;;
|
||
|
'Cleanup Temporary Volume')
|
||
|
cleanup_temporary_volume
|
||
|
;;
|
||
|
'Quit')
|
||
|
break
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
}
|
||
|
|
||
|
# check if the function exists (bash specific)
|
||
|
if [ "$#" -eq 0 ]; then
|
||
|
menu
|
||
|
else
|
||
|
"$@"
|
||
|
fi
|