Initial import.

This commit is contained in:
Kyle Isom 2023-10-18 18:17:43 -07:00
commit 48ca042005
13 changed files with 492 additions and 0 deletions

24
Containerfile Normal file
View File

@ -0,0 +1,24 @@
FROM docker.io/library/ubuntu:jammy
LABEL maintainer="K. Isom <kyle@imap.cc>"
ARG DEBIAN_FRONTEND=noninteractive
ARG AUTOMATED_MODE=yes
ARG USE_CLANG=yes
ENV TZ=America/Los_Angeles
# prepare build
RUN mkdir -p /usr/local/sc/bin /build
ENV PATH="${PATH}:/usr/local/sc/bin/"
RUN apt-get update && apt-get install -y bash ca-certificates sudo
# setup shimmering-clarity development
# environment
ADD *.sh /usr/local/sc/bin/
RUN container-setup.sh
# clean image
RUN apt-get autoclean && \
apt-get autoremove && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
WORKDIR /build

19
Containerfile.alpine Normal file
View File

@ -0,0 +1,19 @@
FROM docker.io/library/alpine:3.18
LABEL maintainer="K. Isom <kyle@imap.cc>"
ARG AUTOMATED_MODE=yes
ARG USE_CLANG=yes
ENV TZ=America/Los_Angeles
# prepare build
RUN mkdir -p /usr/local/sc/bin /build
ENV PATH="${PATH}:/usr/local/sc/bin/"
RUN apk add --update-cache bash
# setup shimmering-clarity development
# environment
ADD *.sh /usr/local/sc/bin/
RUN container-setup.sh
# clean image
RUN rm -f /var/cache/apk/*
WORKDIR /build

23
Containerfile.debian Normal file
View File

@ -0,0 +1,23 @@
FROM docker.io/library/debian:12.2
LABEL maintainer="K. Isom <kyle@imap.cc>"
ARG DEBIAN_FRONTEND=noninteractive
ARG AUTOMATED_MODE=yes
ARG USE_CLANG=yes
ENV TZ=America/Los_Angeles
# prepare build
RUN mkdir -p /usr/local/sc/bin /build
ENV PATH="${PATH}:/usr/local/sc/bin/"
RUN apt-get update && apt-get install -y bash ca-certificates sudo
# setup shimmering-clarity development
# environment
ADD *.sh /usr/local/sc/bin/
RUN container-setup.sh
# clean image
RUN apt-get autoclean && \
apt-get autoremove && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
WORKDIR /build

18
Containerfile.fedora Normal file
View File

@ -0,0 +1,18 @@
FROM docker.io/library/fedora:38
LABEL maintainer="K. Isom <kyle@imap.cc>"
ARG AUTOMATED_MODE=yes
ENV TZ=America/Los_Angeles
# prepare build
RUN mkdir -p /usr/local/sc/bin /build
ENV PATH="${PATH}:/usr/local/sc/bin/"
RUN dnf install -y bash
# setup shimmering-clarity development
# environment
ADD *.sh /usr/local/sc/bin/
RUN container-setup.sh
# clean package
RUN dnf clean all && rm -rf /var/cache/yum
WORKDIR /build

34
README.md Normal file
View File

@ -0,0 +1,34 @@
# sc3dev
## the shimmering clarity c++ development environment
This is a set of tools to set up the standard development environment
used across shimmering clarity projects.
### Scripts
- build-all-containers.sh automates building all supported
containers.
- build-container.sh automated building and pushing a container.
- check-code.sh wraps several code scanning tools.
- install-cmake-debian.sh install the latest CMake on Debian-
based systems.
- install-depdendencies.sh installs the tools needed to build and
package projects.
- setup-cmake.sh sets up cmake projects building a RelWithDebInfo
config.
- validate-container.sh attempts to clone a few repos and build/test
them, validating that the image contains the correct tools to
build them.
- install-devenv.sh - check-code.sh
### OCI imags
- Containerfile is an OCI-image spec for building development images.
- Containerfile.{flavor} provide additional images for testing. Current
flavors are:
- alpine: (Alpine 3.18) a minimal image, suitable for CI
- debian: (Debian 12.2) verify Debian installation
- fedora: (Fedora 38) verify Fedora installation

19
build-all-containers.sh Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
######################################################################
# @author : kyle (kyle@imap.cc)
# @file : build-all-containers.sh
# @created : Wednesday Oct 18, 2023 18:09:07 PDT
#
# @description : build the containers in this project and push them.
######################################################################
# most important is the main build
./build-container.sh Containerfile sc/dev:main
for container_file in Containerfile.*
do
flavor="${container_file#Containerfile.}"
./build-container.sh Container.${flavor} sc/dev:${flavor}
done

19
build-container.sh Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
######################################################################
# @author : kyle (kyle@imap.cc)
# @file : build-container.sh
# @created : Wednesday Oct 18, 2023 15:04:57 PDT
#
# @description : build a new container image
######################################################################
set -eu
CONTAINERFILE="${1}"
IMAGE_NAME="git.wntrmute.dev/${2}"
podman build -t ${IMAGE_NAME} -f ${CONTAINERFILE}
podman push ${IMAGE_NAME}
podman container prune --force
podman image prune --force

68
check-code.sh Executable file
View File

@ -0,0 +1,68 @@
#!/usr/bin/env sh
######################################################################
# @author : kyle (kyle@midgard)
# @file : check-code
# @created : Tuesday Oct 17, 2023 22:39:39 PDT
#
# @description :
######################################################################
run_clang_tidy () {
sources="${1:-*.cc}"
echo "[+] clang-tidy ${sources}"
if [ ! -e compile_commands.json ]
then
echo "[!] compile_commands.json not found" > /dev/stderr
candidate=$(find -name compile_commands.json | head)
if [ -z "${candidates}" ]
then
echo "[!] no suitable candidates found; can't proceed" > /dev/stderr
exit 1
fi
echo "[+] compile_commands.json candidate: $candidate"
ln -s ${candidate} .
echo "[+] if this isn't correct, you will need to manually link it"
fi
clang-tidy ${sources}
}
run_cppcheck () {
sources="${1:-*.cc}"
echo "[+] cppcheck ${sources}"
cppcheck --enable=all --suppress=unusedFunction --suppress=missingIncludeSystem -I. ${sources}
}
run_trunk () {
sources="${1:-}"
echo "[+] trunk check ${sources}"
trunk check --filter clang-tidy ${sources}
}
main () {
command="${1:-usage}"
shift
case ${command} in
clang-tidy) run_clang_tidy $@ ;;
cppcheck) run_cppcheck $@ ;;
trunk) run_trunk $@ ;;
*)
echo "[!] scanner ${command} isn't supported" > /dev/stderr
exit 1
;;
esac
}
main $@

20
cmake-build-and-test.sh Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
######################################################################
# @author : kyle (kyleimap.cc)
# @file : setup-cmake
# @created : Wednesday Oct 18, 2023 04:24:21 PDT
#
# @description : Prepare a CMake build environment, build, and test.
######################################################################
set -eux
if [ "${USE_CLANG:-}" == "yes" ]
then
export CC=$(command -v clang)
export CXX=$(command -v clang++)
fi
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo .. && make all test && ctest

16
container-setup.sh Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env sh
######################################################################
# @author : kyle (kyle@midgard)
# @file : container-setup
# @created : Wednesday Oct 18, 2023 18:13:11 PDT
#
# @description : small script to run the same tooling in each container.
#
# specifically, this enables easier renaming of scripts or refactoring
# scripts across every machine.
######################################################################
install-development-tools.sh
validate-container.sh

50
install-cmake-debian.sh Executable file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env bash
set -eu
source /etc/lsb-release
SUDO="sudo"
USE_CMAKE_RC="${USE_CMAKE_RC:-}"
preinstall () {
echo "[+] preparing to install"
if [ "$(whoami)" == "root" ]
then
SUDO=
fi
$SUDO apt-get -y update
$SUDO apt-get -y install ca-certificates gpg wget
}
do_install () {
if [ ! -f /etc/apt/sources.list.d/kitware.list ]
then
echo "[+] fetching initial keyring"
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | $SUDO tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
echo "[+] adding repo to sources.list.d"
echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ ${DISTRIB_CODENAME} main" | \
$SUDO tee /etc/apt/sources.list.d/kitware.list >/dev/null
$SUDO apt-get -y update
echo "[+] installing kitware keyring"
if [ -f "/usr/share/keyrings/kitware-archive-keyring.gpg" ]
then
$SUDO rm /usr/share/keyrings/kitware-archive-keyring.gpg
fi
$SUDO apt-get -y install kitware-archive-keyring
fi
if [ "${USE_CMAKE_RC}" = "YES" ]
then
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ ${DISTRIB_RELEASE}-rc main' | \
$SUDO tee -a /etc/apt/sources.list.d/kitware.list >/dev/null
$SUDO apt-get update
fi
}
preinstall
do_install
$SUDO apt-get install -y cmake

152
install-development-tools.sh Executable file
View File

@ -0,0 +1,152 @@
#!/usr/bin/env bash
#########################################################################
# This script attempts to install the appopriate build dependencies #
# for the host system. #
# #
# This is primarily developed on the latest Ubuntu LTS release and #
# MacOS; other platforms are not supported. #
# #
# The primary packages required: #
# #
# - clang #
# - clang-tidy #
# - cmake #
# - cppcheck #
# - doxygen #
# - git #
# - graphviz #
# - make #
# - scdoc #
# #
# Furthermore, certain CI systems require additional packages, and some #
# base system packages are also useful. #
# #
# - bash #
# - ca-certificates #
# - gzip #
# - ssh #
# - tar #
#########################################################################
set -eu
AUTOMATED_MODE=${AUTOMATED_MODE:-}
install_debianesque () {
APTARGS=""
SUDO="sudo"
if [ "$(whoami)" == "root" ]
then
SUDO=
fi
if [ ! -z "${AUTOMATED_MODE}" ]
then
APTARGS="-y"
fi
echo "[+] distribution is ${DISTRIB_ID}, choosing Debianesque install."
if [ -z "$(command -v cmake)" ]
then
install-cmake-debian.sh
fi
echo "[+] installing tools"
sudo $SUDO apt-get $APTARGS install git clang scdoc python3-pip doxygen graphviz
}
install_alpine () {
APK_ADD="apk add --update-cache"
echo "[+] distribution is ${DISTRIB_ID}, choosing Alpine install."
$APK_ADD alpine-sdk
echo "[+] setting up base system"
$APK_ADD bash ca-certificates gzip openssh tar
echo "[+] installing development tooling"
$APK_ADD clang clang-extra-tools cmake cppcheck doxygen g++ git \
graphviz make scdoc
}
install_redhat () {
DNF_INSTALL="dnf install -y"
SUDO="sudo"
if [ "$(whoami)" == "root" ]
then
SUDO=
fi
echo "[+] setting up base system"
# dnf is probably the slowest package manager I've used, so
# install everything in one shot.
$DNF_INSTALL ca-certificates gzip openssh tar \
clang clang-tools-extra cmake cppcheck doxygen \
gcc-c++ git graphviz libstdc++-devel make scdoc
}
install_unsupported () {
echo "[+] distribution is ${DISTRIB_ID}, choosing Redhat install."
echo "[!] This distribution is unsupported." > /dev/stderr
exit 1;
}
install_macos () {
# TODO: consider supporting macports?
echo "[+] host system is MacOS"
echo "[+] installing tools"
brew install git cmake scdoc
echo "[+] installing libraries and development headers"
# TODO: look up proper package names in homebrew
}
install_linux () {
DISTRIB_ID="${DISTRIB_ID:-}"
echo "[+] host system is Linux"
if [[ -f "/etc/lsb-release" ]]
then
source /etc/lsb-release
elif [[ -d "/etc/apt" ]]
then
DISTRIB_ID="apt-based"
elif [[ -f "/etc/rpi-issue" ]]
then
DISTRIB_ID=apt-based
elif [[ -d "/etc/apk" ]]
then
DISTRIB_ID=alpine
elif [[ -d "/etc/dnf" ]]
then
DISTRIB_ID="redhat"
else
DISTRIB_ID="unsupported/unknown"
fi
case ${DISTRIB_ID} in
Ubuntu) install_debianesque ;;
Debian) install_debianesque ;;
apt-based) install_debianesque ;;
alpine) install_alpine ;;
redhat) install_redhat ;;
*)
echo "[!] distribution ${DISTRIB_ID} isn't supported in this script." > /dev/null
exit 1
;;
esac
}
case "$(uname -s)" in
Linux) install_linux ;;
Darwin) install_macos ;;
*)
echo "[!] platform $(uname -s) isn't supported in this script." > /dev/null
;;
esac

30
validate-container.sh Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env sh
######################################################################
# @author : kyle (kyle@imap.cc)
# @file : validate-container.sh
# @created : Wednesday Oct 18, 2023 15:04:57 PDT
#
# @description : validate container build actually builds repos.
######################################################################
set -eux
check_repo () {
repo="${1}"
lpath="$(basename ${repo})"
cd /build
echo "[+] cloning ${repo}"
git clone ${repo}
cd ${lpath}
echo "[+] running build"
cmake-build-and-test.sh
echo "[+] removing ${lpath}"
cd .. && rm -rf ${lpath}
}
check_repo https://git.wntrmute.dev/sc/scsl
check_repo https://git.wntrmute.dev/sc/emsha