-
Notifications
You must be signed in to change notification settings - Fork 1
82 lines (66 loc) · 3.04 KB
/
encrypt-and-upload-model.yml
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Model Upload with Versioning and Cleanup
on:
push:
paths:
- "models/**" # Trigger on changes in the 'models' directory
- "model_versions.json" # Trigger on changes in the version file
jobs:
upload_model:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up AWS CLI
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Compare model versions
id: compare_versions
run: |
# Read the current and previous model versions
CURRENT_VERSIONS=$(cat model_versions.json)
S3_BUCKET="${{ secrets.S3_BUCKET_NAME }}"
CHANGED_MODELS=""
for MODEL in $(jq -r 'keys[]' <<< "$CURRENT_VERSIONS"); do
CURRENT_VERSION=$(jq -r --arg model "$MODEL" '.[$model]' <<< "$CURRENT_VERSIONS")
S3_FILE="s3://$S3_BUCKET/${MODEL}-${CURRENT_VERSION}"
# Check if the model with the current version already exists in S3
if ! aws s3 ls "$S3_FILE" >/dev/null 2>&1; then
echo "New or updated model detected: $MODEL (version $CURRENT_VERSION)"
CHANGED_MODELS="$CHANGED_MODELS $MODEL"
fi
done
echo "::set-output name=changed_models::$CHANGED_MODELS"
- name: Upload updated models
if: steps.compare_versions.outputs.changed_models != ''
run: |
CHANGED_MODELS="${{ steps.compare_versions.outputs.changed_models }}"
CURRENT_VERSIONS=$(cat model_versions.json)
S3_BUCKET="${{ secrets.S3_BUCKET_NAME }}"
KMS_KEY_ID="${{ secrets.KMS_KEY_ID }}"
for MODEL in $CHANGED_MODELS; do
CURRENT_VERSION=$(jq -r --arg model "$MODEL" '.[$model]' <<< "$CURRENT_VERSIONS")
MODEL_PATH="models/$MODEL"
S3_FILE="s3://$S3_BUCKET/${MODEL}-${CURRENT_VERSION}"
echo "Uploading $MODEL (version $CURRENT_VERSION) to $S3_FILE"
# Upload to S3 with SSE-KMS
aws s3 cp "$MODEL_PATH" "$S3_FILE" --sse aws:kms --sse-kms-key-id "$KMS_KEY_ID"
# Check if upload was successful, then delete the file from the repo
if [ $? -eq 0 ]; then
echo "Model uploaded successfully, deleting $MODEL from the repository."
rm "$MODEL_PATH"
else
echo "Model upload failed for $MODEL."
fi
done
- name: Commit model deletions
if: steps.compare_versions.outputs.changed_models != ''
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
# Stage deleted files and commit the changes
git add -u
git commit -m "Delete updated models from repo after S3 upload"
git push