Skip to content

Commit 3418e4c

Browse files
author
Rub21
committed
Upload replication files to azure and update the var for the code
1 parent 4d7dce4 commit 3418e4c

File tree

3 files changed

+54
-26
lines changed

3 files changed

+54
-26
lines changed

envs/.env.db-utils.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ OVERWRITE_PLANET_FILE=false
1919
#######################################
2020

2121
# TODO:update start.sh and helm templates, for making this customizable
22-
REPLICATION_FOLDER=/replication/minute
22+
REPLICATION_FOLDER=replication/minute
2323

2424
#######################################
2525
# Environment variables for minute Replication job settings

images/replication-job/start.sh

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,47 @@ else
88
echo JAVACMD_OPTIONS=\"-server -Xmx$memory\" >~/.osmosis
99
fi
1010

11-
workingDirectory="/mnt/data/data"
11+
workingDirectory="/mnt/data"
12+
mkdir -p $workingDirectory
1213

1314
# Check if state.txt exist in the workingDirectory,
1415
# in case the file does not exist locally and does not exist in the cloud the replication will start from 0
1516
if [ ! -f $workingDirectory/state.txt ]; then
1617
echo "File $workingDirectory/state.txt does not exist"
17-
echo "let's get check the cloud"
18+
### AWS
1819
if [ $CLOUDPROVIDER == "aws" ]; then
19-
aws s3 ls $AWS_S3_BUCKET$REPLICATION_FOLDER/state.txt
20+
aws s3 ls $AWS_S3_BUCKET/$REPLICATION_FOLDER/state.txt
2021
if [[ $? -eq 0 ]]; then
21-
echo "File exist, let's get it"
22-
aws s3 cp $AWS_S3_BUCKET$REPLICATION_FOLDER/state.txt $workingDirectory/state.txt
22+
echo "File exist, let's get it from $CLOUDPROVIDER - $AWS_S3_BUCKET"
23+
aws s3 cp $AWS_S3_BUCKET/$REPLICATION_FOLDER/state.txt $workingDirectory/state.txt
2324
fi
2425
fi
26+
27+
### GCP
2528
if [ $CLOUDPROVIDER == "gcp" ]; then
26-
gsutil ls $GCP_STORAGE_BUCKET$REPLICATION_FOLDER/state.txt
29+
gsutil ls $GCP_STORAGE_BUCKET/$REPLICATION_FOLDER/state.txt
2730
if [[ $? -eq 0 ]]; then
28-
echo "File exist, let's get it"
29-
gsutil cp $GCP_STORAGE_BUCKET$REPLICATION_FOLDER/state.txt $workingDirectory/state.txt
31+
echo "File exist, let's get it from $CLOUDPROVIDER - $GCP_STORAGE_BUCKET"
32+
gsutil cp $GCP_STORAGE_BUCKET/$REPLICATION_FOLDER/state.txt $workingDirectory/state.txt
3033
fi
3134
fi
32-
# In case the state.txt does not exist anywhere, lets create the folder data.
33-
mkdir -p $workingDirectory
35+
36+
### Azure
37+
if [ $CLOUDPROVIDER == "azure" ]; then
38+
state_file_exists=$(az storage blob exists --container-name $AZURE_CONTAINER_NAME --name $REPLICATION_FOLDER/state.txt --query="exists")
39+
if [[ $state_file_exists=="true" ]]; then
40+
echo "File exist, let's get it from $CLOUDPROVIDER - $AZURE_CONTAINER_NAME"
41+
az storage blob download \
42+
--container-name $AZURE_CONTAINER_NAME \
43+
--name $REPLICATION_FOLDER/state.txt \
44+
--file $workingDirectory/state.txt --query="name"
45+
fi
46+
fi
47+
mkdir -p $workingDirectory
3448
fi
3549

3650
# Creating the replication files
37-
function generateReplication () {
51+
function generateReplication() {
3852
osmosis -q \
3953
--replicate-apidb \
4054
iterations=0 \
@@ -48,17 +62,31 @@ function generateReplication () {
4862
--write-replication \
4963
workingDirectory=$workingDirectory &
5064
while true; do
51-
for file in $(find $workingDirectory/ -cmin -1); do
52-
if [ -f "$file" ]; then
53-
bucketFile=${file#*"$workingDirectory"}
54-
echo $(date +%F_%H:%M:%S)": New files..." $file
55-
# AWS
65+
for local_file in $(find $workingDirectory/ -cmin -1); do
66+
if [ -f "$local_file" ]; then
67+
68+
cloud_file=$REPLICATION_FOLDER/${local_file#*"$workingDirectory/"}
69+
echo $(date +%F_%H:%M:%S)": Copy file...$local_file to $cloud_file"
70+
71+
### AWS
5672
if [ $CLOUDPROVIDER == "aws" ]; then
57-
aws s3 cp $file $AWS_S3_BUCKET$REPLICATION_FOLDER$bucketFile --acl public-read
73+
aws s3 cp $local_file $AWS_S3_BUCKET/$cloud_file --acl public-read
5874
fi
59-
# Google Storage
75+
76+
### GCP
6077
if [ $CLOUDPROVIDER == "gcp" ]; then
61-
gsutil cp -a public-read $file $GCP_STORAGE_BUCKET$REPLICATION_FOLDER$bucketFile
78+
#TODO, emable public acces
79+
gsutil cp -a public-read $local_file $GCP_STORAGE_BUCKET/$cloud_file
80+
fi
81+
82+
### Azure
83+
if [ $CLOUDPROVIDER == "azure" ]; then
84+
#TODO, emable public acces
85+
az storage blob upload \
86+
--container-name $AZURE_CONTAINER_NAME \
87+
--file $local_file \
88+
--name $cloud_file \
89+
--output none
6290
fi
6391
fi
6492
done
@@ -69,8 +97,8 @@ function generateReplication () {
6997
# Check if Postgres is ready
7098
flag=true
7199
while "$flag" = true; do
72-
pg_isready -h $POSTGRES_HOST -p 5432 >/dev/null 2>&2 || continue
73-
# Change flag to false to stop ping the DB
74-
flag=false
75-
generateReplication
76-
done
100+
pg_isready -h $POSTGRES_HOST -p 5432 >/dev/null 2>&2 || continue
101+
# Change flag to false to stop ping the DB
102+
flag=false
103+
generateReplication
104+
done

osm-seed/templates/replication-job-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ spec:
4141
- name: POSTGRES_USER
4242
value: {{ .Values.db.env.POSTGRES_USER }}
4343
- name: REPLICATION_FOLDER
44-
value: /replication/minute
44+
value: replication/minute
4545
- name: CLOUDPROVIDER
4646
value: {{ .Values.cloudProvider }}
4747
# In case cloudProvider=aws

0 commit comments

Comments
 (0)