-
Notifications
You must be signed in to change notification settings - Fork 51
Add automatic docker image building #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
almahmoud
wants to merge
2
commits into
CloudVE:main
Choose a base branch
from
almahmoud:docker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'])], | ||
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:])) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.