forked from rh-aiservices-bu/insurance-claim-processing
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathpopulate-images.yaml
60 lines (54 loc) · 2.41 KB
/
populate-images.yaml
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
---
apiVersion: batch/v1
kind: Job
metadata:
name: populate-images
annotations:
argocd.argoproj.io/sync-wave: "2"
spec:
backoffLimit: 4
template:
spec:
initContainers:
- name: wait-for-minio
image: busybox:1.28
command: ['sh', '-c', 'until nc -z -v -w30 $MINIO_ENDPOINT 9000; do echo "Waiting for Minio connection..."; sleep 2; done;']
env:
- name: MINIO_ENDPOINT
value: minio.ic-shared-minio.svc.cluster.local
containers:
- name: add-images-to-bucket
image: image-registry.openshift-image-registry.svc:5000/redhat-ods-applications/s2i-generic-data-science-notebook:1.2
imagePullPolicy: IfNotPresent
command: ["/bin/bash"]
args:
- -ec
- |-
BRANCH_NAME="dev"
git clone https://github.com/rh-aiservices-bu/parasol-insurance.git && cd parasol-insurance && git checkout $BRANCH_NAME
cat << 'EOF' | python3
import boto3, os, botocore
s3 = boto3.client("s3",
endpoint_url=os.getenv("AWS_S3_ENDPOINT"),
aws_access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"))
# Create image bucket
bucket_name = "claim-images"
try:
s3.head_bucket(Bucket=bucket_name)
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == '404':
s3.create_bucket(Bucket=bucket_name)
# Upload original images to minio
for filename in os.listdir("/opt/app-root/src/parasol-insurance/bootstrap/ic-shared-database/images/original_images"):
with open(f"/opt/app-root/src/parasol-insurance/bootstrap/ic-shared-database/images/original_images/{filename}", "rb") as f:
s3.upload_fileobj(f, bucket_name, f"original_images/{filename}")
# Upload processed images to minio
for filename in os.listdir("/opt/app-root/src/parasol-insurance/bootstrap/ic-shared-database/images/processed_images"):
with open(f"/opt/app-root/src/parasol-insurance/bootstrap/ic-shared-database/images/processed_images/{filename}", "rb") as f:
s3.upload_fileobj(f, bucket_name, f"processed_images/{filename}")
EOF
envFrom:
- secretRef:
name: secret-minio
restartPolicy: Never