Created
November 5, 2019 17:16
-
-
Save zonggen/291f586c4865a83ad0e389e19c285b92 to your computer and use it in GitHub Desktop.
Script for building and testing rhcos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export COREOS_ASSEMBLER_PRIVILEGED=true | |
# export COREOS_ASSEMBLER_CONFIG_GIT="/srv/ootpa/src/config" | |
# export COREOS_ASSEMBLER_GIT="/root/coreos-assembler/coreos-assembler" | |
export COREOS_ASSEMBLER_CONTAINER_RUNTIME_ARGS="-v /etc/pki/ca-trust:/etc/pki/ca-trust:ro -v /etc/pki/tls:/etc/pki/tls:ro" | |
cecho(){ | |
RED="\033[0;31m" | |
GREEN="\033[0;32m" | |
YELLOW="\033[1;33m" | |
# ... ADD MORE COLORS | |
NC="\033[0m" # No Color | |
printf "${!1}${2} ${NC}\n" | |
} | |
cosa() { | |
env | grep COREOS_ASSEMBLER | |
set -x # so we can see what command gets run | |
sudo podman run --rm -ti -v ${PWD}:/srv/ --userns=host --device /dev/kvm --name cosa \ | |
${COREOS_ASSEMBLER_PRIVILEGED:+--privileged} \ | |
${COREOS_ASSEMBLER_CONFIG_GIT:+-v $COREOS_ASSEMBLER_CONFIG_GIT:/srv/src/config/:ro} \ | |
${COREOS_ASSEMBLER_GIT:+-v $COREOS_ASSEMBLER_GIT/src/:/usr/lib/coreos-assembler/:ro} \ | |
${COREOS_ASSEMBLER_CONTAINER_RUNTIME_ARGS} \ | |
${COREOS_ASSEMBLER_CONTAINER:-quay.io/coreos-assembler/coreos-assembler:latest} $@ | |
rc=$?; set +x; return $rc | |
} | |
print_help(){ | |
cecho "GREEN"\ | |
"options:\n\ | |
-c | --clean-dir: rm whole dir except auto-cosa\n\ | |
-i | --init: cosa init\n\ | |
-f | --fetch: cosa fetch\n\ | |
-b | --build: cosa build\n\ | |
-r | --run: cosa run\n\ | |
--clean: cosa clean\n\ | |
--base-ign: build base.ign in builds/latest/base.ign\n\ | |
--shell: log into the vm shell" | |
exit 1 | |
} | |
if [[ "$#" -eq 0 ]]; then | |
print_help | |
fi | |
# Call getopt to validate the provided input. | |
rc=0 | |
options=$(getopt --options=hcifbr --longoptions=help,clean-dir,init,fetch,build,run,clean,base-ign,shell -- "$@") || rc=$? | |
[ $rc -eq 0 ] || { | |
print_help | |
exit 1 | |
} | |
eval set -- "$options" | |
while true; do | |
case "$1" in | |
-e | --env) | |
setup_env | |
;; | |
-h | --help) | |
print_help | |
;; | |
-c | --clean-dir) | |
shopt -s extglob | |
$(rm -rf !(autocosa_rhcos.sh)) | |
;; | |
-i | --init) | |
cosa init --force https://gitlab.cee.redhat.com/coreos/redhat-coreos.git | |
;; | |
-f | --fetch) | |
cosa fetch | |
;; | |
-b | --build) | |
cosa build | |
;; | |
-r | --run) | |
cosa run | |
;; | |
--clean) | |
cosa clean | |
;; | |
--base-ign) | |
base_ign | |
;; | |
--shell) | |
cosa shell | |
;; | |
--) | |
shift | |
break | |
;; | |
-*) | |
cecho "RED" "$0: unrecognized option: $1" | |
exit 1 | |
;; | |
*) | |
break | |
;; | |
esac | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment