Skip to content
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
36 changes: 28 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
language: php
dist: focal

php:
- 8.0
- nightly
arch:
- amd64

os: linux

language: shell

notifications:
email:
- team@appwrite.io
- team@appwrite.io

before_script: docker run --rm --interactive --tty --volume "$(pwd)":/app composer update --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist

before_install:
- curl -fsSL https://get.docker.com | sh
- echo '{"experimental":"enabled"}' | sudo tee /etc/docker/daemon.json
- mkdir -p $HOME/.docker
- echo '{"experimental":"enabled"}' | sudo tee $HOME/.docker/config.json
- sudo service docker start
- >
if [ ! -z "${DOCKERHUB_PULL_USERNAME:-}" ]; then
echo "${DOCKERHUB_PULL_PASSWORD}" | docker login --username "${DOCKERHUB_PULL_USERNAME}" --password-stdin
fi
- docker --version

before_script: composer install --ignore-platform-reqs
install:
- docker-compose up -d
- sleep 10

script:
- vendor/bin/phpunit --configuration phpunit.xml
- vendor/bin/psalm --show-info=true
- docker ps
- docker-compose exec tests vendor/bin/phpunit --configuration phpunit.xml
- docker-compose exec tests vendor/bin/psalm --show-info=true
55 changes: 55 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM composer:2.0 as composer

ARG TESTING=false
ENV TESTING=$TESTING

WORKDIR /usr/local/src/

COPY composer.lock /usr/local/src/
COPY composer.json /usr/local/src/

RUN composer update \
--ignore-platform-reqs \
--optimize-autoloader \
--no-plugins \
--no-scripts \
--prefer-dist

FROM php:8.0-cli-alpine as compile

ENV PHP_ZSTD_VERSION="master"

RUN apk add --no-cache \
git \
autoconf \
make \
g++ \
zstd-dev

## Zstandard Extension
FROM compile AS zstd
RUN git clone --recursive --depth 1 --branch $PHP_ZSTD_VERSION https://github.com/kjdev/php-ext-zstd.git \
&& cd php-ext-zstd \
&& phpize \
&& ./configure --with-libzstd \
&& make && make install

FROM compile as final

LABEL maintainer="team@appwrite.io"

WORKDIR /usr/src/code

RUN echo extension=zstd.so >> /usr/local/etc/php/conf.d/zstd.ini

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" \
&& echo "opcache.enable_cli=1" >> $PHP_INI_DIR/php.ini \
&& echo "memory_limit=1024M" >> $PHP_INI_DIR/php.ini

COPY --from=composer /usr/local/src/vendor /usr/src/code/vendor
COPY --from=zstd /usr/local/lib/php/extensions/no-debug-non-zts-20200930/zstd.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/

# Add Source Code
COPY . /usr/src/code

CMD [ "tail", "-f", "/dev/null" ]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ use Utopia\Storage\Device\Local
use Utopia\Storage\Device\S3
use Utopia\Storage\Device\DOSpaces

// instiantiating local storage
// Instantiating local storage
Storage::setDevice('files', new Local('path'));

//or you can use s3 storage
Storage::setDevice('files', new S3('path',AWS_ACCESS_KEY, AWS_SECRET_KEY,AWS_BUCKET_NAME, AWS_REGION, AWS_ACL_FLAG));
// Or you can use AWS S3 storage
Storage::setDevice('files', new S3('path', AWS_ACCESS_KEY, AWS_SECRET_KEY,AWS_BUCKET_NAME, AWS_REGION, AWS_ACL_FLAG));

//or you can use Digitalocean spaces storage
Storage::setDevice('files', new DOSpaces('path',DO_SPACES_ACCESS_KEY, DO_SPACES_SECRET_KEY,DO_SPACES_BUCKET_NAME, DO_SPACES_REGION, AWS_ACL_FLAG));
// Or you can use DigitalOcean Spaces storage
Storage::setDevice('files', new DOSpaces('path', DO_SPACES_ACCESS_KEY, DO_SPACES_SECRET_KEY, DO_SPACES_BUCKET_NAME, DO_SPACES_REGION, AWS_ACL_FLAG));

$device = Storage::getDevice('files');

Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"psr-4": {"Utopia\\Tests\\":"tests/Storage"}
},
"require": {
"ext-fileinfo": "*",
"ext-zlib": "*",
"ext-zstd": "*",
"php": ">=8.0",
"utopia-php/framework": "0.*.*"
},
Expand Down
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3.1'

services:
tests:
container_name: tests
build:
context: .
volumes:
- ./:/usr/src/code
environment:
- S3_ACCESS_KEY
- S3_SECRET
- DO_ACCESS_KEY
- DO_SECRET
- LINODE_ACCESS_KEY
- LINODE_SECRET
- BACKBLAZE_ACCESS_KEY
- BACKBLAZE_SECRET
- WASABI_ACCESS_KEY
- WASABI_SECRET
3 changes: 1 addition & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
Expand Down
81 changes: 81 additions & 0 deletions src/Storage/Compression/Algorithms/Zstd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Utopia\Storage\Compression\Algorithms;

use Utopia\Storage\Compression\Compression;

class Zstd extends Compression
{
/**
* Compression level from 1 up to a current max of 22.
* Levels >= 20 should be used with caution, as they require more memory.
*
* Default value is 3.
*/
protected int $level = 3;

public function __construct(int $level = 3)
{
$this->level = $level;
}

/**
* Get the compression level.
*
* @return int
*/
public function getLevel(): int
{
return $this->level;
}

/**
* Set the compression level.
*
* Allow values from 1 up to a current max of 22.
*
* @param int $level
* @return void
*/
public function setLevel(int $level): void
{
if ($level < 1 || $level > 22) {
throw new \InvalidArgumentException('Level must be between 1 and 22');
}
$this->level = $level;
}

/**
* Get the name of the algorithm.
*
* @return string
*/
public function getName(): string
{
return 'zstd';
}

/**
* Compress.
*
* @param string $data
*
* @return string
*/
public function compress(string $data): string
{
return \zstd_compress($data, $this->level);
}

/**
* Decompress.
*
* @param string $data
*
* @return string
*/
public function decompress(string $data): string
{
return \zstd_uncompress($data);
}
}
77 changes: 77 additions & 0 deletions tests/Storage/Compression/Algorithms/ZstdTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Utopia\Tests\Compression\Algorithms;

use Utopia\Storage\Compression\Algorithms\Zstd;
use PHPUnit\Framework\TestCase;

class ZstdTest extends TestCase
{
protected Zstd $object;

public function setUp(): void
{
$this->object = new Zstd();
}

public function tearDown(): void
{
}

public function testName()
{
$this->assertEquals($this->object->getName(), 'zstd');
}

public function testCompressDecompressWithText()
{
$demo = 'This is a demo string';
$demoSize = \mb_strlen($demo, '8bit');

$data = $this->object->compress($demo);
$dataSize = \mb_strlen($data, '8bit');

$this->assertEquals(21, $demoSize);
$this->assertEquals(30, $dataSize);

$this->assertEquals($demo, $this->object->decompress($data));
}

public function testCompressDecompressWithJPGImage()
{
$demo = \file_get_contents(__DIR__ . '/../../../resources/disk-a/kitten-1.jpg');
$demoSize = \mb_strlen($demo, '8bit');

$data = $this->object->compress($demo);
$dataSize = \mb_strlen($data, '8bit');

$this->assertEquals(599639, $demoSize);
$this->assertEquals(599663, $dataSize);

$this->assertGreaterThan($demoSize, $dataSize);

$data = $this->object->decompress($data);
$dataSize = \mb_strlen($data, '8bit');

$this->assertEquals(599639, $dataSize);
}

public function testCompressDecompressWithPNGImage()
{
$demo = \file_get_contents(__DIR__ . '/../../../resources/disk-b/kitten-1.png');
$demoSize = \mb_strlen($demo, '8bit');

$data = $this->object->compress($demo);
$dataSize = \mb_strlen($data, '8bit');

$this->assertEquals(3038056, $demoSize);
$this->assertEquals(3038138, $dataSize);

$this->assertGreaterThan($demoSize, $dataSize);

$data = $this->object->decompress($data);
$dataSize = \mb_strlen($data, '8bit');

$this->assertEquals(3038056, $dataSize);
}
}
3 changes: 1 addition & 2 deletions tests/Storage/Device/WasabiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ protected function init(): void
$this->root = 'root';
$key = $_SERVER['WASABI_ACCESS_KEY'] ?? '';
$secret = $_SERVER['WASABI_SECRET'] ?? '';
$bucket = 'utopia-tests';
$bucket = 'utopia-php-storage-tests';

$this->object = new Wasabi($this->root, $key, $secret, $bucket, Wasabi::EU_CENTRAL_1, WASABI::ACL_PRIVATE);

}

protected function getAdapterName(): string
Expand Down