|
| 1 | +#!/bin/bash |
| 2 | +helpMenu(){ |
| 3 | + echo "Usage: slim-saas-build [flags...]" |
| 4 | + echo "" |
| 5 | + echo "Flags:" |
| 6 | + echo " -a | --api-token | API token to access slim.ai (https://portal.slim.dev/settings)" |
| 7 | + echo " -o | --organization-id | Organization ID in slim.ai" |
| 8 | + echo " -c | --connector-id | Connector ID of slim.ai Registry" |
| 9 | + echo " -d | --digest | Digest for the Docker image (docker image inspect <namespace>/<repo>:<tag> | jq .[].RepoDigests -c | cut -d ":" -f 2 | cut -d '\"' -f 1)" |
| 10 | + echo " -n | --namespace | Namespace for Docker image (I.e <namespace>/<repo>:<tag>)" |
| 11 | + echo " -r | --repo | Repo for Docker image (I.e <namespace>/<repo>:<tag>)" |
| 12 | + echo " -t | --tag | Tag for Docker image (I.e <namespace>/<repo>:<tag>)" |
| 13 | + echo " -m | --arch | (Optional) Image Architecture (Default: amd64)" |
| 14 | + echo " -s | --operating-system | (Optional) Image Operating System (Default: linux)" |
| 15 | + echo " -p | --paths | (Optional) Paths on filesystem to slim in comma separated list (I.e /usr,/bin,/etc)" |
| 16 | +} |
| 17 | + |
| 18 | +# Run through requirements |
| 19 | +requirements(){ |
| 20 | + itemList=("apiToken" "organizationID" "connectorID" "digest" "namespace" "repo" "tag") |
| 21 | + # Iterate over required items |
| 22 | + for item in ${itemList[@]}; do |
| 23 | + # Checks the value of the item var from list to ensure a value is set |
| 24 | + # If item is 'paths' it does not check for this as that item is optional |
| 25 | + if [[ ${!item} == "" ]]; then |
| 26 | + echo "ERROR: Requirement ($item) not met" |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | + done |
| 30 | + # Iterate over optional items (Stored with default values) |
| 31 | + optionalItemsList=("arch=amd64" "os=linux" "paths=none") |
| 32 | + if [[ "$arch" == "" ]]; then |
| 33 | + arch="amd64" |
| 34 | + fi |
| 35 | + if [[ "$os" == "" ]]; then |
| 36 | + os="linux" |
| 37 | + fi |
| 38 | + if [[ $paths == "" ]]; then |
| 39 | + paths="none" |
| 40 | + fi |
| 41 | +} |
| 42 | + |
| 43 | +# Pre-flight |
| 44 | +## Verify there is input |
| 45 | +if [[ "$*" == "" ]]; then |
| 46 | + echo "ERROR: No flags were set" |
| 47 | + echo "-" |
| 48 | + helpMenu |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | +## Process flags |
| 52 | +while [ "$1" != "" ]; do |
| 53 | + case $1 in |
| 54 | + -h | --help) helpMenu |
| 55 | + exit |
| 56 | + ;; |
| 57 | + -o | --organization-id) shift |
| 58 | + organizationID=$1 |
| 59 | + ;; |
| 60 | + -a | --api-token) shift |
| 61 | + apiToken=$1 |
| 62 | + ;; |
| 63 | + -c | --connector-id) shift |
| 64 | + connectorID=$1 |
| 65 | + ;; |
| 66 | + -d | --digest) shift |
| 67 | + digest=$1 |
| 68 | + ;; |
| 69 | + -n | --namespace) shift |
| 70 | + namespace=$1 |
| 71 | + ;; |
| 72 | + -r | --repo) shift |
| 73 | + repo=$1 |
| 74 | + ;; |
| 75 | + -t | --tag) shift |
| 76 | + tag=$1 |
| 77 | + ;; |
| 78 | + -m | --arch) shift |
| 79 | + arch=$1 |
| 80 | + ;; |
| 81 | + -s | --operating-system) shift |
| 82 | + os=$1 |
| 83 | + ;; |
| 84 | + -p | --optional-paths) shift |
| 85 | + paths=$1 |
| 86 | + ;; |
| 87 | + esac |
| 88 | + shift |
| 89 | +done |
| 90 | +## Check requirements are met |
| 91 | +requirements |
| 92 | +# Handoff |
| 93 | +executionScript="python ./scripts/execution.py" |
| 94 | +$executionScript $apiToken $organizationID $connectorID $digest $namespace $repo $tag $arch $os $paths |
| 95 | +exit 0 |
0 commit comments