Skip to content

Instantly share code, notes, and snippets.

@andyone
Last active October 11, 2022 10:31
Show Gist options
  • Select an option

  • Save andyone/948f5b520059e043654418edd923a8ba to your computer and use it in GitHub Desktop.

Select an option

Save andyone/948f5b520059e043654418edd923a8ba to your computer and use it in GitHub Desktop.
Script for installing docker and tools
#!/bin/bash
################################################################################
DIVE_VER="0.10.0"
GRYPE_VER="0.20.0"
HADOLINT_VER="2.7.0"
TRIVY_VER="0.19.2"
################################################################################
main() {
installDocker
installDive
installGrype
installHadolint
installTrivy
}
installDocker() {
yum install -y yum-utils
yum-config-manager --add-repo "https://download.docker.com/linux/centos/docker-ce.repo"
yum install -y docker-ce docker-ce-cli containerd.io
configureKernel
systemctl start docker
}
configureKernel() {
if ! grep -q 'net.ipv4.ip_forward' /etc/sysctl.conf ; then
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p &> /dev/null
fi
}
installDive() {
installPackage "https://github.com/wagoodman/dive/releases/download/v${DIVE_VER}/dive_${DIVE_VER}_linux_amd64.rpm"
}
installGrype() {
installPackage "https://github.com/anchore/grype/releases/download/v${GRYPE_VER}/grype_${GRYPE_VER}_linux_amd64.rpm"
}
installHadolint() {
curl -# -L -o "hadolint" "https://github.com/hadolint/hadolint/releases/download/v${HADOLINT_VER}/hadolint-Linux-x86_64"
mv hadolint /usr/bin/hadolint
rm -f hadolint
}
installTrivy() {
installPackage "https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VER}/trivy_${TRIVY_VER}_Linux-64bit.rpm"
}
installPackage() {
local url="$1"
local rpm_file=$(basename "$url")
curl -# -L -o "$rpm_file" "$url"
rpm -i "$rpm_file"
rm -f "$rpm_file"
mv /usr/local/bin/* /usr/bin/
}
################################################################################
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment