Skip to content

Commit f75c7d8

Browse files
committed
refs sparkfabrik-innovation-team/board#807: add support for cross provider buckets
1 parent 6bb784c commit f75c7d8

File tree

7 files changed

+75
-22
lines changed

7 files changed

+75
-22
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ cli-dev: build
1717
docker run --rm -it \
1818
--env-file .env \
1919
-v ${PWD}/app:/app \
20+
-v ${HOME}/.config/gcloud:/root/.config/gcloud \
2021
-w /app \
2122
$(IMAGE_NAME):$(IMAGE_TAG) ash -li
2223

app/commands/bucket/main.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ SCRIPT=$(basename $0)
77
export SUBCOMMAND=""
88

99
export PROVIDER=${PROVIDER:-}
10-
export PROVIDER_LOWER=
10+
export PROVIDER_SRC=${PROVIDER_SRC:-}
11+
export PROVIDER_SRC_LOWER=
12+
export PROVIDER_DST=${PROVIDER_DST:-}
13+
export PROVIDER_DST_LOWER=
1114
export BUCKET_SRC_ENDPOINT=${BUCKET_SRC_ENDPOINT:-}
1215
export BUCKET_SRC=${BUCKET_SRC:-}
1316
export FILE_SRC=${FILE_SRC:-""}
@@ -78,7 +81,9 @@ shift
7881
PARAMS=""
7982
while [ -n "${1:-}" ]; do
8083
case "${1}" in
81-
--provider) PROVIDER="${2}"; shift 2 ;;
84+
--provider) PROVIDER_SRC="${2}"; PROVIDER_DST="${2}"; shift 2 ;;
85+
--provider-src) PROVIDER_SRC="${2}"; shift 2 ;;
86+
--provider-dst) PROVIDER_DST="${2}"; shift 2 ;;
8287
--bucket-src-endpoint) BUCKET_SRC_ENDPOINT="${2}"; shift 2 ;;
8388
--bucket-src) BUCKET_SRC="${2}"; shift 2 ;;
8489
--file-src) FILE_SRC="${2}"; shift 2 ;;
@@ -96,7 +101,8 @@ done
96101

97102
eval set -- "$PARAMS"
98103

99-
PROVIDER_LOWER=$(echo ${PROVIDER} | awk '{print tolower($0)}')
104+
PROVIDER_SRC_LOWER=$(echo ${PROVIDER_SRC} | awk '{print tolower($0)}')
105+
PROVIDER_DST_LOWER=$(echo ${PROVIDER_DST} | awk '{print tolower($0)}')
100106

101107
# Check dry run execution
102108
if [ ${DRY_RUN} -eq 1 ]; then

app/commands/bucket/subcommands/copy-bucket.sh

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,31 @@
44
. ${BASE}/functions
55

66
# Check for the required input
7-
if [ -z "${PROVIDER}" ]; then
8-
echo "You have to define the bucket provider"
7+
if [ -z "${PROVIDER_SRC}" ]; then
8+
echo "You have to define the source bucket provider"
99
exit 12
1010
fi
11-
if [ "${PROVIDER_LOWER}" != "aws" ] && [ "${PROVIDER_LOWER}" != "gcs" ] && [ "${PROVIDER_LOWER}" != "minio" ]; then
11+
if [ -z "${PROVIDER_DST}" ]; then
12+
echo "You have to define the destination bucket provider"
13+
exit 12
14+
fi
15+
if [ "${PROVIDER_SRC_LOWER}" != "aws" ] && [ "${PROVIDER_SRC_LOWER}" != "gcs" ] && [ "${PROVIDER_SRC_LOWER}" != "minio" ]; then
1216
echo "You have to define a valid bucket provider (aws, gcs, minio)"
1317
exit 12
1418
fi
15-
if [ "${PROVIDER_LOWER}" = "minio" ] && [ -z "${BUCKET_SRC_ENDPOINT}" ]; then
19+
if [ "${PROVIDER_DST_LOWER}" != "aws" ] && [ "${PROVIDER_DST_LOWER}" != "gcs" ] && [ "${PROVIDER_DST_LOWER}" != "minio" ]; then
20+
echo "You have to define a valid bucket provider (aws, gcs, minio)"
21+
exit 12
22+
fi
23+
if [ "${PROVIDER_SRC_LOWER}" = "minio" ] && [ -z "${BUCKET_SRC_ENDPOINT}" ]; then
1624
echo "You have to define the source bucket endpoint"
1725
exit 12
1826
fi
1927
if [ -z "${BUCKET_SRC}" ]; then
2028
echo "You have to define the source bucket name"
2129
exit 12
2230
fi
23-
if [ "${PROVIDER_LOWER}" = "minio" ] && [ -z "${BUCKET_DST_ENDPOINT}" ]; then
31+
if [ "${PROVIDER_DST_LOWER}" = "minio" ] && [ -z "${BUCKET_DST_ENDPOINT}" ]; then
2432
echo "You have to define the destination bucket endpoint"
2533
exit 12
2634
fi
@@ -34,7 +42,8 @@ echo "All the required inputs are present. Go on with the real job."
3442

3543
echo "Copy the file from the source bucket to the destination bucket."
3644
format_string "Parameters:" "g"
37-
echo "$(format_string "Provider:" "bold") ${PROVIDER_LOWER}"
45+
echo "$(format_string "Src Provider:" "bold") ${PROVIDER_SRC_LOWER}"
46+
echo "$(format_string "Dst Provider:" "bold") ${PROVIDER_DST_LOWER}"
3847
echo "$(format_string "Src:" "bold") ${BUCKET_SRC}/${FILE_SRC}"
3948
echo "$(format_string "Dst:" "bold") ${BUCKET_DST}/${FILE_DST}"
4049
if [ -z "${FILE_SRC}" ] && [ -z "${FILE_DST}" ]; then
@@ -46,15 +55,7 @@ elif [ -z "${FILE_DST}" ]; then
4655
fi
4756
echo "$(format_string "ACL:" "bold") ${ACL}"
4857

49-
if [ "${PROVIDER_LOWER}" = "aws" ]; then
50-
echo "rclone_aws sync :s3://${BUCKET_SRC}/${FILE_SRC} :s3://${BUCKET_DST}/${FILE_DST}"
51-
rclone_aws sync :s3://${BUCKET_SRC}/${FILE_SRC} :s3://${BUCKET_DST}/${FILE_DST}
52-
EXIT_RCLONE=$?
53-
elif [ "${PROVIDER_LOWER}" = "gcs" ]; then
54-
echo "rclone_gcs sync :gcs://${BUCKET_SRC}/${FILE_SRC} :gcs://${BUCKET_SRC}/${FILE_DST}"
55-
rclone_gcs sync :gcs://${BUCKET_SRC}/${FILE_SRC} :gcs://${BUCKET_SRC}/${FILE_DST}
56-
EXIT_RCLONE=$?
57-
elif [ "${PROVIDER_LOWER}" = "minio" ]; then
58+
if [ "${PROVIDER_LOWER}" = "minio" ]; then
5859
# Wait for source minio service
5960
WAIT_ENDPOINT=$(remove_http_proto "${BUCKET_SRC_ENDPOINT}")
6061
debug "Wait for source minio service (${WAIT_ENDPOINT}, timeout ${TIMEOUT_BUCKET_SRC} seconds)."
@@ -97,12 +98,12 @@ elif [ "${PROVIDER_LOWER}" = "minio" ]; then
9798
exit 13
9899
fi
99100
done
100-
101-
echo "rclone_minio_multi sync src://${BUCKET_SRC}/${FILE_SRC} dst://${BUCKET_DST}/${FILE_DST}"
102-
rclone_minio_multi sync src://${BUCKET_SRC}/${FILE_SRC} dst://${BUCKET_DST}/${FILE_DST}
103-
EXIT_RCLONE=$?
104101
fi
105102

103+
echo "rclone_generic sync src://${BUCKET_SRC}/${FILE_SRC} dst://${BUCKET_DST}/${FILE_DST}"
104+
rclone_generic sync src://${BUCKET_SRC}/${FILE_SRC} dst://${BUCKET_DST}/${FILE_DST}
105+
EXIT_RCLONE=$?
106+
106107
if [ ${EXIT_RCLONE} -ne 0 ]; then
107108
echo "Something went wrong during the copy of files."
108109
exit ${EXIT_RCLONE}

app/functions

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,38 @@ if [ -n "${ACL}" ]; then
3737
S3_ACL="--s3-acl ${ACL}"
3838
fi
3939

40+
generate_rclone_conf() {
41+
rm -f /tmp/rclone.conf
42+
echo "[src]" | tee -a /tmp/rclone.conf
43+
if [ "${PROVIDER_SRC_LOWER}" = "aws" ]; then
44+
envsubst '${AWS_DEFAULT_REGION}' < ${BASE}/rclone.aws.conf | tee -a /tmp/rclone.conf
45+
elif [ "${PROVIDER_SRC_LOWER}" = "gcs" ]; then
46+
cat ${BASE}/rclone.gcs.conf | tee -a /tmp/rclone.conf
47+
elif [ "${PROVIDER_SRC_LOWER}" = "minio" ]; then
48+
BUCKET_ENDPOINT=${BUCKET_SRC_ENDPOINT} envsubst '${BUCKET_ENDPOINT}' < ${BASE}/rclone.minio.conf | tee -a /tmp/rclone.conf
49+
fi
50+
51+
echo "" | tee -a /tmp/rclone.conf
52+
53+
echo "[dst]" | tee -a /tmp/rclone.conf
54+
if [ "${PROVIDER_DST_LOWER}" = "aws" ]; then
55+
envsubst '${AWS_DEFAULT_REGION}' < ${BASE}/rclone.aws.conf | tee -a /tmp/rclone.conf
56+
elif [ "${PROVIDER_DST_LOWER}" = "gcs" ]; then
57+
cat ${BASE}/rclone.gcs.conf | tee -a /tmp/rclone.conf
58+
elif [ "${PROVIDER_DST_LOWER}" = "minio" ]; then
59+
BUCKET_ENDPOINT=${BUCKET_DST_ENDPOINT} envsubst '${BUCKET_ENDPOINT}' < ${BASE}/rclone.minio.conf | tee -a /tmp/rclone.conf
60+
fi
61+
62+
echo "" | tee -a /tmp/rclone.conf
63+
}
64+
65+
rclone_generic() {
66+
generate_rclone_conf
67+
echo "rclone --config=/tmp/rclone.conf ${S3_ACL} ${RCLONE_ADD_PARAMS} $@"
68+
rclone --config=/tmp/rclone.conf \
69+
${S3_ACL} ${RCLONE_ADD_PARAMS} $@
70+
}
71+
4072
rclone_aws() {
4173
echo "rclone --s3-region="${AWS_DEFAULT_REGION}" --s3-location-constraint="${AWS_DEFAULT_REGION}" --s3-env-auth ${S3_ACL} ${RCLONE_ADD_PARAMS} $@"
4274
rclone \

app/rclone.aws.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type = s3
2+
provider = aws
3+
env_auth = true
4+
region = ${AWS_DEFAULT_REGION}
5+
location_constraint = ${AWS_DEFAULT_REGION}

app/rclone.gcs.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type = google cloud storage
2+
provider = gcs
3+
env_auth = true
4+
token = ~/.config/gcloud/application_default_credentials.json

app/rclone.minio.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type = s3
2+
provider = Minio
3+
env_auth = true
4+
endpoint = ${BUCKET_ENDPOINT}

0 commit comments

Comments
 (0)