Skip to content

Commit 247bc5c

Browse files
committed
feat(minio): support the latest minio
1 parent 6c37b92 commit 247bc5c

File tree

5 files changed

+51
-23
lines changed

5 files changed

+51
-23
lines changed

Dockerfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ RUN apt-get purge -y --auto-remove $BUILD_DEPS && \
3636
COPY rootfs /
3737
ENV WALE_ENVDIR=/etc/wal-e.d/env
3838
RUN mkdir -p $WALE_ENVDIR
39-
RUN python3 /patcher-script.py /bin/create_bucket
40-
RUN python3 /patcher-script.py /usr/local/bin/wal-e
39+
40+
ARG PATCH_CMD="python3 /patcher-script.py"
41+
RUN $PATCH_CMD file /bin/create_bucket /patcher-script.d/patch_boto_s3.py
42+
RUN $PATCH_CMD file /usr/local/bin/wal-e /patcher-script.d/patch_boto_s3.py
43+
RUN $PATCH_CMD module wal_e.worker.worker_util /patcher-script.d/patch_wal_e_s3.py
44+
4145

4246
CMD ["/docker-entrypoint.sh", "postgres"]
4347
EXPOSE 5432

rootfs/bin/create_bucket

+4-2
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ elif os.getenv('DATABASE_STORAGE') == "swift":
7676
conn.put_container(os.getenv('BUCKET_NAME'))
7777

7878
else:
79-
botoconfig.add_section('s3')
79+
if not botoconfig.has_section("s3"):
80+
botoconfig.add_section('s3')
8081
botoconfig.set('s3', 'use-sigv4', 'True')
81-
botoconfig.add_section('Boto')
82+
if not botoconfig.has_section("Boto"):
83+
botoconfig.add_section('Boto')
8284
botoconfig.set('Boto', 'is_secure', 'False')
8385
conn = S3Connection(
8486
host=os.getenv('S3_HOST'),
+2-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
def patch_wal_e_hmac_auth_v4_handler():
1+
def patch_boto_s3_hmac_auth_v4_handler():
22
import os
33
from boto.auth import HmacAuthV4Handler
44
_init = HmacAuthV4Handler.__init__
55
def wrap_init(self, *args, **kwargs):
66
_init(self, *args, **kwargs)
77
self.region_name = os.getenv('S3_REGION', self.region_name)
88
HmacAuthV4Handler.__init__ = wrap_init
9-
10-
11-
if __name__ == '__main__':
12-
patch_wal_e_hmac_auth_v4_handler()
9+
patch_boto_s3_hmac_auth_v4_handler()
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def patch_uri_put_file():
2+
import os
3+
from wal_e.blobstore import s3
4+
from wal_e.blobstore.s3 import s3_util
5+
def wrap_uri_put_file(creds, uri, fp, content_type=None, conn=None):
6+
assert fp.tell() == 0
7+
k = s3_util._uri_to_key(creds, uri, conn=conn)
8+
if content_type is not None:
9+
k.content_type = content_type
10+
if os.getenv('DATABASE_STORAGE') == 's3':
11+
encrypt_key=True
12+
else:
13+
encrypt_key=False
14+
k.set_contents_from_file(fp, encrypt_key=encrypt_key)
15+
return k
16+
s3.uri_put_file = wrap_uri_put_file
17+
s3_util.uri_put_file = wrap_uri_put_file
18+
patch_uri_put_file()

rootfs/patcher-script.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
import sys
22

3-
patch_script = """
3+
patch_script_tmp = """
44
55
def run_patch_scripts(patch_script_path):
6-
import os
7-
for patch in os.listdir(patch_script_path):
8-
full_patch_file = os.path.join(patch_script_path, patch)
9-
if full_patch_file.endswith('.py') and os.path.isfile(full_patch_file):
10-
with open(full_patch_file, 'r') as f:
11-
try:
12-
exec(f.read())
13-
except:
14-
pass
15-
run_patch_scripts('/patcher-script.d')
6+
with open(patch_script_path, 'r') as f:
7+
try:
8+
exec(f.read())
9+
except:
10+
pass
11+
run_patch_scripts("%s")
1612
1713
"""
1814

1915

20-
def main(patch_file):
16+
def main(patch_file, patch_script_file):
2117
result_list = []
18+
patch_script = patch_script_tmp % patch_script_file
2219
with open(patch_file, "r") as f:
2320
has_patched = False
2421
for line in f:
25-
if not has_patched and line.startswith('import'):
22+
if (line.startswith('import') or line.startswith('from')) \
23+
and not has_patched:
2624
result_list.append(patch_script)
2725
has_patched = True
2826
result_list.append(line)
27+
if not has_patched: result_list.append(patch_script)
2928
with open(patch_file, "w") as f:
3029
for line in result_list:
3130
f.write(line)
3231

3332
if __name__ == '__main__':
34-
main(sys.argv[1])
33+
patch_type = sys.argv[1]
34+
if patch_type == 'file':
35+
patch_file = sys.argv[2]
36+
elif patch_type == 'module':
37+
module = __import__(sys.argv[2], fromlist=True)
38+
patch_file = module.__file__
39+
patch_script_file = sys.argv[3]
40+
main(patch_file, patch_script_file)
41+

0 commit comments

Comments
 (0)