Skip to content

Commit ba233d0

Browse files
committed
Add run.sh, entrypoint-dev
1 parent c5f43f6 commit ba233d0

File tree

4 files changed

+129
-7
lines changed

4 files changed

+129
-7
lines changed

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
2. ✅ Get events (Only reports when `results(<execution-id>, true)` as the events don't really give you much unless there is a failure)
1313
3. ✅ Get build logs (`getLogs()`)
1414
1. ✅ Cleanup `./tmp` (`doTmpDir("delete)`)
15-
1. Debug why executions are failing
16-
1. Verify file was pushed to image registry successfully
17-
1. Package container image + build container image
15+
1. Debug why executions are failing
16+
1. Verify file was pushed to image registry successfully
17+
1. Package container image + build container image
1818

19+
# Quick Start
20+
21+
A very simple script (`./run.sh`) is available for quickly testing this image. Simply modify the variables under "Image details" and "Slim details" and execute the script.
1922

2023
# Development
2124

@@ -37,12 +40,20 @@ Flags:
3740
-p | --paths | (Optional) Paths on filesystem to slim in comma separated list (I.e /usr,/bin,/etc
3841
```
3942
40-
# Example execution (dev)
43+
## Example execution
4144
4245
```bash
43-
./scripts/entrypoint.sh -o <organization-id> \
46+
# Build image
47+
docker build -t slim-saas-build -f Dockerfile .
48+
# Run slim-saas-build
49+
docker run --rm slim-saas-build -o <organization-id> \
4450
-a <api-token> \
4551
-c <connector-id> \
4652
-n codefresh -r cli -t latest \
4753
-d e64398f0928281d8154c9d5db155eaf854a968730a6d20a2e72ad9ffc12760f3
48-
```
54+
```
55+
## Notes
56+
57+
If you would like to use `entrypoint.sh` locally, make sure to use `entrypoint-dev.sh` as this contains the correct paths. `entrypoint.sh` is set up for usage inside the container image.
58+
59+

run.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# Image details
3+
imageNamespace=""
4+
imageRepo=""
5+
imageTag=""
6+
imageDigest="" # docker image inspect <namespace>/<repo>:<tag> | jq .[].RepoDigests -c | cut -d : -f 2 | cut -d '"' -f 1)
7+
# Slim details
8+
slimOrganizationID=""
9+
slimAPIToken=""
10+
slimConnectorID=""
11+
12+
#####################
13+
runtimeImage="mstantoncf/slim-saas-build"
14+
docker run --rm $runtimeImage \
15+
-o $slimOrganizationToken -a $slimAPIToken -c $slimConnectorID \
16+
-n $imageNamespace -r $imageRepo -t $imageTag -d $imageDigest

scripts/entrypoint-dev.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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

scripts/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ done
9090
## Check requirements are met
9191
requirements
9292
# Handoff
93-
executionScript="python ./scripts/execution.py"
93+
executionScript="python /usr/bin/execution.py"
9494
$executionScript $apiToken $organizationID $connectorID $digest $namespace $repo $tag $arch $os $paths
9595
exit 0

0 commit comments

Comments
 (0)