Skip to content

Commit

Permalink
Dockerfile for bucket listing
Browse files Browse the repository at this point in the history
  • Loading branch information
ddlenz committed Nov 29, 2023
1 parent 260e2dd commit bb6a078
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
15 changes: 15 additions & 0 deletions bucketListing/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.11.6-slim

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

RUN groupadd -g 999 appuser && \
useradd -r -u 999 -g appuser appuser
USER appuser

COPY . .

ENTRYPOINT [ "python", "./createBucketListing.py"]

28 changes: 28 additions & 0 deletions bucketListing/createBucketListing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from google.cloud import storage
import base64
import binascii
import argparse


def createBucketListing(project, bucket):

gcsPrefix = "https://storage.neonscience.org/"
gcsBucketName = bucket
storage_client = storage.Client(project)
blobs = storage_client.list_blobs(gcsBucketName)
listing = 'object,last_modified,etag' + '\n'
for blob in blobs:
checksum = binascii.hexlify(base64.urlsafe_b64decode(blob.md5_hash)).decode()
listing += gcsPrefix + gcsBucketName + "/" + blob.name + ',' + blob.updated.strftime("%Y-%m-%d %H:%M:%S") + ',' + checksum + '\n'

gcsBucket = storage_client.bucket(gcsBucketName)
listingBlob = gcsBucket.blob("listing.csv")
listingBlob.upload_from_string(listing)


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--project')
parser.add_argument('--bucket')
args=parser.parse_args()
createBucketListing(args.project, args.bucket)
17 changes: 17 additions & 0 deletions bucketListing/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cachetools==5.3.2
certifi==2023.11.17
charset-normalizer==3.3.2
google-api-core==2.14.0
google-auth==2.23.4
google-cloud-core==2.3.3
google-cloud-storage==2.13.0
google-crc32c==1.5.0
google-resumable-media==2.6.0
googleapis-common-protos==1.61.0
idna==3.6
protobuf==4.25.1
pyasn1==0.5.1
pyasn1-modules==0.3.0
requests==2.31.0
rsa==4.9
urllib3==2.1.0

0 comments on commit bb6a078

Please sign in to comment.