-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_container.sh
executable file
·54 lines (42 loc) · 1.7 KB
/
build_container.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
if [ ! -e "uv.lock" ]
then
echo "uv.lock does not exist. Please run 'uv sync' or 'uv lock' to create it"
echo "Error: Cannot build container without uv.lock -> Abort"
exit
fi
set -eou pipefail
build_tags=""
build_args=""
MODEL=${MODEL:-"bart_mnli"}
# if not a git repo, build locally
if [ -d .git ]; then
cd $(git rev-parse --show-toplevel)
repo_name=$(grep 'url =' .git/config | sed -E 's/.*[:\/]([^\/]+)\.git/\1/')
# if remote url for repo not given -> abort
if [ -z "$repo_name" ]; then
echo "Error: Could not get remote repository name. Please check your .git/config"
exit 1
fi
GITHUB_REPOSITORY_OWNER=${GITHUB_REPOSITORY_OWNER:-"ghcr.io/taranis-ai"}
build_args+="--build-arg GITHUB_REPOSITORY_OWNER='${GITHUB_REPOSITORY_OWNER}'"
build_tags+="--tag ${GITHUB_REPOSITORY_OWNER}/${REPO_NAME}>:latest "
build_tags+="--tag '${GITHUB_REPOSITORY_OWNER}/${REPO_NAME}:${MODEL}'"
# check if there are any commits yet
if git rev-parse --quiet --verify HEAD >/dev/null; then
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD | sed 's/[^a-zA-Z0-9_.-]/_/g')
echo "Building image for branch ${CURRENT_BRANCH} and model ${MODEL} on ${GITHUB_REPOSITORY_OWNER}"
build_tags+="--tag ${GITHUB_REPOSITORY_OWNER}/${REPO_NAME}:${CURRENT_BRANCH} "
else
echo "The repository has no commits yet."
fi
else
build_tags+="--tag cybersec_classifier:${MODEL} "
build_tags+="--tag cybersec_classifier:latest"
echo "Current directory is not a git repo. Building image for model ${MODEL} locally"
fi;
build_args+="--build-arg MODEL='${MODEL}'"
docker buildx build --file Containerfile \
$build_args \
$build_tags \
--load .