Skip to content
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

[pull] master from Backblaze:master #217

Merged
merged 10 commits into from
Oct 30, 2023
Merged
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
35 changes: 0 additions & 35 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,38 +123,3 @@ jobs:
draft: ${{ env.ACTIONS_STEP_DEBUG == 'true' }}
prerelease: false
files: ${{ steps.sign.outputs.asset_path }}
deploy-docker:
needs: deploy
runs-on: ubuntu-latest
container:
image: "python:3.10" # can not use ${{ env.PYTHON_DEFAULT_VERSION }} here
env:
DEBIAN_FRONTEND: noninteractive
DOCKERHUB_USERNAME: secrets.DOCKERHUB_USERNAME
DOCKERHUB_TOKEN: secrets.DOCKERHUB_TOKEN
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install dependencies
run: python -m pip install --upgrade nox pip setuptools
- name: Build Dockerfile
id: build-dockerfile
run: nox -vs docker
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
if: ${{ env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' }} # TODO: skip whole job without marking it as an error
uses: docker/login-action@v2
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}
- name: Build and push
if: ${{ env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' }} # TODO: skip whole job without marking it as an error
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: backblaze/b2:${{ steps.build.outputs.version }}
22 changes: 18 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ jobs:
B2_TEST_APPLICATION_KEY: ${{ secrets.B2_TEST_APPLICATION_KEY }}
B2_TEST_APPLICATION_KEY_ID: ${{ secrets.B2_TEST_APPLICATION_KEY_ID }}
runs-on: ubuntu-latest
# Running on raw machine.
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -120,11 +119,26 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: setup sudo NOX_PYTHONS
run: echo NOX_PYTHONS=$(sudo python3 --version | cut -d ' ' -f 2) >> "$GITHUB_ENV"
- name: Install dependencies
run: python -m pip install --upgrade nox pip setuptools
- name: Run dockerized tests
run: sudo python -m pip install --upgrade nox pip setuptools
- name: Generate Dockerfile
run: nox -vs generate_dockerfile
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: backblazeit/b2:test
platforms: linux/amd64
- name: Run tests with docker
if: ${{ env.B2_TEST_APPLICATION_KEY != '' && env.B2_TEST_APPLICATION_KEY_ID != '' }}
run: nox -vs docker_test
run: sudo NOX_PYTHONS=$NOX_PYTHONS B2_TEST_APPLICATION_KEY=${{ env.B2_TEST_APPLICATION_KEY }} B2_TEST_APPLICATION_KEY_ID=${{ env.B2_TEST_APPLICATION_KEY_ID }} nox -vs docker_test -- backblazeit/b2:test
test-linux-bundle:
needs: cleanup_buckets
env:
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/push_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Deploy docker

on:
push:
tags: 'v*' # push events to matching v*, i.e. v1.0, v20.15.10

jobs:
deploy-docker:
runs-on: ubuntu-latest
env:
DEBIAN_FRONTEND: noninteractive
DOCKERHUB_USERNAME: secrets.DOCKERHUB_USERNAME
DOCKERHUB_TOKEN: secrets.DOCKERHUB_TOKEN
B2_TEST_APPLICATION_KEY: ${{ secrets.B2_TEST_APPLICATION_KEY }}
B2_TEST_APPLICATION_KEY_ID: ${{ secrets.B2_TEST_APPLICATION_KEY_ID }}
PYTHON_DEFAULT_VERSION: 3.11
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Install dependencies
run: python -m pip install --upgrade nox pip setuptools
- name: Build Dockerfile
run: nox -vs generate_dockerfile
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
if: ${{ env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' }} # TODO: skip whole job without marking it as an error
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: install setuptools_scm
run: pip install setuptools_scm
- name: get version
id: package_version
run: echo package_version=`python -m setuptools_scm` >> $GITHUB_OUTPUT
- name: echo
run: echo ${{ steps.package_version.outputs.package_version }}
- name: Build and push
if: ${{ env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' }} # TODO: skip whole job without marking it as an error
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: backblazeit/b2:latest,backblazeit/b2:${{ steps.package_version.outputs.package_version }}
platforms: linux/amd64

8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.12.0] - 2023-10-28

### Added
* docker tests and pushing the official docker image on release

### Fixed
* `--quiet` now will implicitly set `--noProgress` option as well
* pypy integration tests
Expand Down Expand Up @@ -485,7 +490,8 @@ This version is pinned strictly to `b2-sdk-python==1.16.0` for the same reason.
* Fix an off-by-one issue when downloading a range of a file (affects library, but not CLI).
* Better handling of some errors from the B2 service.

[Unreleased]: https://github.com/Backblaze/B2_Command_Line_Tool/compare/v3.11.0...HEAD
[Unreleased]: https://github.com/Backblaze/B2_Command_Line_Tool/compare/v3.12.0...HEAD
[3.12.0]: https://github.com/Backblaze/B2_Command_Line_Tool/compare/v3.11.0...v3.12.0
[3.11.0]: https://github.com/Backblaze/B2_Command_Line_Tool/compare/v3.10.1...v3.11.0
[3.10.1]: https://github.com/Backblaze/B2_Command_Line_Tool/compare/v3.10.0...v3.10.1
[3.10.0]: https://github.com/Backblaze/B2_Command_Line_Tool/compare/v3.9.0...v3.10.0
Expand Down
22 changes: 1 addition & 21 deletions Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,10 @@ LABEL vcs-url="${vcs_url}"
LABEL vcs-ref="${vcs_ref}"
LABEL build-date-iso8601="${build_date}"

WORKDIR ${homedir}
WORKDIR /root

COPY ${tar_path}/${tar_name} .
RUN ["pip", "install", "${tar_name}[full]"]
ENV PATH=${homedir}/.local/bin:$$PATH


FROM base as test

WORKDIR ${tests_image_dir}
COPY ${tests_path} ./${tests_path}
COPY noxfile.py .

# Files used by tests.
${files_used_by_tests}

RUN ["pip", "install", "nox"]
ENTRYPOINT ["nox", "--no-venv", "--no-install", "-s"]


FROM base

RUN ["useradd", "--home", "${homedir}", "--shell", "/usr/sbin/nologin", "--badnames", "${username}"]
USER ${username}

ENTRYPOINT ["b2"]
CMD ["--help"]
43 changes: 30 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ You can install the `b2` without them:
pip install b2
```

### Docker

For a truly platform independent solution, use the official docker image:

```bash
docker run backblazeit/b2:latest ...
```

See examples in [Usage/Docker image](#docker-image)

### Installing from source

If installing from the repository is needed in order to e.g. check if a pre-release version resolves a bug effectively, it can be installed with:
Expand Down Expand Up @@ -117,26 +127,33 @@ Note that using many threads could in some cases be detrimental to the other use

### Docker image

An official Docker image is provided for these who want to use B2 Command Line Tool in a Docker environment.
#### Authorization

User can either authorize on each command (`list-buckets` is just a example here)

```bash
B2_APPLICATION_KEY=<key> B2_APPLICATION_KEY_ID=<key-id> docker run --rm -e B2_APPLICATION_KEY -e B2_APPLICATION_KEY_ID backblazeit/b2:latest list-buckets
```

or authorize once and keep the credentials persisted:

```bash
docker run --rm -it -v b2:/root backblazeit/b2:latest authorize-account
docker run --rm -v b2:/root backblazeit/b2:latest list-buckets # remember to include `-v` - authorization details are there
```

#### Downloading and uploading

An example workflow could be (with passing environment variables):
When uploading a single file, data can be passed to the container via a pipe:

```bash
B2_APPLICATION_KEY=<key> B2_APPLICATION_KEY_ID=<key-id> docker run --rm -e B2_APPLICATION_KEY -e B2_APPLICATION_KEY_ID b2:latest authorize-account
B2_APPLICATION_KEY=<key> B2_APPLICATION_KEY_ID=<key-id> docker run --rm -e B2_APPLICATION_KEY -e B2_APPLICATION_KEY_ID b2:latest create-bucket test-bucket allPrivate
B2_APPLICATION_KEY=<key> B2_APPLICATION_KEY_ID=<key-id> docker run --rm -e B2_APPLICATION_KEY -e B2_APPLICATION_KEY_ID -v <absolute-local-path-to-data>:/data b2:latest upload-file test-bucket /data/local-file remote-file
B2_APPLICATION_KEY=<key> B2_APPLICATION_KEY_ID=<key-id> docker run --rm -e B2_APPLICATION_KEY -e B2_APPLICATION_KEY_ID -v <absolute-local-path-to-data>:/data b2:latest ls test-bucket
B2_APPLICATION_KEY=<key> B2_APPLICATION_KEY_ID=<key-id> docker run --rm -e B2_APPLICATION_KEY -e B2_APPLICATION_KEY_ID -v <absolute-local-path-to-data>:/data b2:latest download-file-by-name test-bucket remote-file /data/local-file-2
cat source_file.txt | docker run --rm -v b2:/root backblazeit/b2:latest upload-unbound-stream bucket_name - target_file_name
```

or mapping to a directory where account info will be kept:
or by mounting local files in the docker container:

```bash
docker run --rm -it -v <absolute-local-path-to-account-info>:/b2 b2:latest authorize-account
docker run --rm -v <absolute-local-path-to-account-info>:/b2 b2:latest create-bucket test-bucket allPrivate
docker run --rm -v <absolute-local-path-to-account-info>:/b2 -v <absolute-local-path-to-data>:/data b2:latest upload-file test-bucket /data/local-file remote-file
docker run --rm -v <absolute-local-path-to-account-info>:/b2 -v <absolute-local-path-to-data>:/data b2:latest ls test-bucket
docker run --rm -v <absolute-local-path-to-account-info>:/b2 -v <absolute-local-path-to-data>:/data b2:latest download-file-by-name test-bucket remote-file /data/local-file-2
docker run --rm -v b2:/root -v /home/user/path/to/data:/data backblazeit/b2:latest upload-file bucket_name /data/source_file.txt target_file_name
```

## Contrib
Expand Down
10 changes: 9 additions & 1 deletion b2/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3492,9 +3492,17 @@ class Version(Command):

REQUIRES_AUTH = False

@classmethod
def _setup_parser(cls, parser):
parser.add_argument('--short', action='store_true')
super()._setup_parser(parser)

def run(self, args):
super().run(args)
self._print('b2 command line tool, version', VERSION)
if args.short:
self._print(VERSION)
else:
self._print('b2 command line tool, version', VERSION)
return 0


Expand Down
Loading