Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/build_containers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build Image
on: [push, workflow_dispatch]
jobs:
test:
name: Build image
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: ['3.9']
extra: [full, openstack, aws, gcp, azure]
steps:
- uses: actions/checkout@v2
- run: docker build . -t cloudve/cloudbridge:${{matrix.python}}-${{matrix.extra}} --build-arg EXTRA=${{matrix.extra}} --build-arg PYTHON=${{matrix.python}}
- name: Login to docker hub
uses: actions-hub/docker/login@master
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push to docker hub
uses: actions-hub/docker@master
with:
args: push cloudve/cloudbridge:${{matrix.python}}-${{matrix.extra}}
- run: docker build . -t cloudve/cloudbridge:dev-${{matrix.python}}-${{matrix.extra}} -f Dockerfile.dev --build-arg EXTRA=${{matrix.extra}} --build-arg PYTHON=${{matrix.python}}
- name: Push to docker hub
uses: actions-hub/docker@master
with:
args: push cloudve/cloudbridge:dev-${{matrix.python}}-${{matrix.extra}}
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ARG EXTRA=full
ARG PYTHON=3.9

FROM python:$PYTHON-slim
RUN pip install --no-cache-dir cloudbridge[$EXTRA]

COPY scripts/ cloudbridge_scripts/
11 changes: 11 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ARG EXTRA=full
ARG PYTHON=latest
FROM python:$PYTHON

RUN apt-get update \
&& apt-get --force-yes install -y curl vim git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN pip install --no-cache-dir pep8 flake8 pyflakes pyyaml ipython cloudbridge[$EXTRA]

COPY scripts/ cloudbridge_scripts/
37 changes: 37 additions & 0 deletions scripts/bucket_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3

import sys
import argparse

from cloudbridge.factory import CloudProviderFactory
from cloudbridge.factory import ProviderList
from cloudbridge.interfaces.exceptions import DuplicateResourceException

def main(arguments):
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('filepath', help="File to upload", type=str)
parser.add_argument('destination', help="Destination in bucket", type=str)
parser.add_argument('-b', '--bucket', help="Name of destination bucket", type=str)
parser.add_argument('-p', '--provider',
choices=[ProviderList.__dict__[p] for p in ProviderList.__dict__.keys() if all(x not in p for x in ['_', 'MOCK'])],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's time we make ProviderList an enum? https://stackoverflow.com/questions/29503339/how-to-get-all-values-from-python-enum-class/29503414

I think this is just a legacy thing from python 2 days.

help='Name of provider to use')
parser.add_argument('-r', '--retries', help="Maximum number of retries. Default = 5", type=int, default=5)
args = parser.parse_args(arguments)
provider = CloudProviderFactory().create_provider(args.provider, {})
try:
bucket = provider.storage.buckets.create(args.bucket)
except DuplicateResourceException:
bucket = provider.storage.buckets.get(args.bucket)
ob = bucket.objects.create(args.destination)
uploaded = False
count = 0
while not uploaded:
print(f'Trying for the {count}th time')
uploaded = ob.upload_from_file(args.filepath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to have exposed another bug in the API. Not all implementations return a bool here, only openstack and azure do. I think the correct behaviour should be to raise an exception if the upload fails, instead of returning a bool value.

count += 1
print(f'Uploaded: {args.filepath} to bucket {args.bucket} at location {args.destination}')

if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))