-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdeploy.sh
executable file
·51 lines (40 loc) · 1.34 KB
/
deploy.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
#!/usr/bin/env bash
# Deploy model to Hugging Face Spaces
# Note: PWD must be the original GitHub/Bitbucket repo
# Usage:
# ./deploy <HuggingFace HTTPS Git Repo> <SSH Private Key Path>
# example:
# ./deploy https://huggingface.co/spaces/tomfern/cats-and-dogs /home/semaphore/.ssh/id_ed25519
repo=$1
shift
privkey=$1
shift
set -e
deploy_tmp=$(mktemp -d)
if [ ! -f "$privkey" ]; then
echo "Private key not found or not supplied"
exit 1
fi
# ensure correct permissions
chmod 600 "$privkey"
git lfs install
# clone HF repo
GIT_SSH_COMMAND="ssh -i '$privkey' -o StrictHostKeyChecking=accept-new" git clone "$repo" "$deploy_tmp"
# copy files
cp requirements.txt "$deploy_tmp"
mkdir -p "$deploy_tmp"/src "$deploy_tmp"/models
cp src/app.py src/utils.py "$deploy_tmp"/src
cp models/model.pkl models/model.pth "$deploy_tmp"/models
# add changes
git config user.email "[email protected]"
git config user.name "semaphoreci"
git add models src requirements.txt
# check if there changes and commit
if [ -n "$(git status --porcelain)" ]; then
echo "==> Deploying $SEMAPHORE_GIT_BRANCH - commit $SEMAPHORE_GIT_SHA"
git commit -m "deploy branch $SEMAPHORE_GIT_BRANCH - commit $SEMAPHORE_GIT_SHA"
GIT_SSH_COMMAND="ssh -i '$privkey' -o StrictHostKeyChecking=accept-new" git push origin main
else
echo "==> No changes to deploy"
fi
rm -rf "$deploy_tmp"