每当我在Circleci上运行工作流时,都会失败,即使我在本地运行它时,它仍然经过测试并成功,但都会给我500 HTTP错误代码。
在本地运行测试时,我从存储中获取图像并用于执行HTTP请求,但是由于我使用Circleci,因此我使用curl来获取图像,请将其放入文件夹中,然后我得到它以执行我的HTTP请求,但是,当尝试在Circleci上构建时,这总是失败。
我想知道我是否在做一些错误的事情,即通过卷曲错误地存储了图像,并指向了最终不在正确位置的东西,或者可能是其他东西。即使500 HTTP错误请求听起来像我的API出现问题,我也可以确认,当它在本地运行时,我没有得到HTTP 500错误代码,因为它会返回:时间:6.85秒,内存:28.00MB好的(5个测试,8个断言)。
我将在config.yaml和虚拟测试功能下面发布。
class TestDummys extends TestCase
{
private static $hostId;
private static $access_token = '';
private static $user;
private static $charityId;
public function testDummy()
{
self::$hostId = HostGroup::first()->id;
self::$access_token = auth()->login(User::first());
$path = storage_path('testimage.png');
$name = 'testimage.png';
$file = new UploadedFile($path, $name, 'image/png', null, null, true);
$response = $this->withHeaders([
'Authorization' => 'Bearer ' . self::$access_token,
])->json('POST', '/host/' . self::$hostId .'/charity/external', [
'name' => 'Charity',
'contact' => 'foo@gmail.com',
'registration_number' => '12345',
'account_number' => '12345',
'sort_code' => '12345',
'country_code' => 'GB',
'iban' => '124535',
'image' => $file
]);
$response->assertStatus(200);
}
}
Config.yaml
version: 2
jobs:
build:
docker:
# Specify the version you desire here
- image: circleci/php:7.3.3
- image: circleci/python:3.7.3
steps:
# Install pip
- run: sudo apt install python-pip
# Install aws-cli
- run:
name: Install aws-cli
command: sudo pip install awscli
# Install sam-cli
- run:
name: Install sam-cli
command: sudo pip install aws-sam-cli
- checkout
- run: sudo apt update # PHP CircleCI 2.0 Configuration File# PHP CircleCI 2.0 Configuration File sudo apt install zlib1g-dev libsqlite3-dev
- run: sudo apt-get update
- run: sudo apt-get install -y libjpeg62-turbo-dev libpng-dev libfreetype6-dev
- run: sudo docker-php-ext-install zip pdo mysqli pdo_mysql mbstring tokenizer ctype json bcmath gd
- run: sudo docker-php-ext-enable pdo_mysql
# Download and cache dependencies
- restore_cache:
keys:
# "composer.lock" can be used if it is committed to the repo
- v1-dependencies-{{ checksum "composer.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: composer install -n --prefer-dist
- save_cache:
key: composer-v1-{{ checksum "composer.json" }}
paths:
- ./vendor
# prepare the database
- run: touch /tmp/testing.sqlite
- run: php artisan migrate --database=sqlite --force
- run: curl https://d3qyaps1yzzqpv.cloudfront.net/images/eb_1554715247_2158207.png -o /tmp/testimage.png
# run tests with phpunit or codecept
- run: ./vendor/bin/phpunit
# delete test database
- run: sudo rm /tmp/testing.sqlite
# set environment variables to .env
- run: ....
- run: ....
- run: ....
- run: ....
- run: ....
- run: ....
- run: ....
- run: ....
# commit to package
- run: composer install --optimize-autoloader --no-dev
- run: sudo php artisan cache:clear
- run: sudo php artisan view:clear
- run: sudo php artisan config:clear
- run: sudo php artisan route:clear
- run: sam package --output-template-file .stack.yaml --s3-bucket ticketpass-api
- run: sam deploy --template-file .stack.yaml --capabilities CAPABILITY_IAM --stack-name ticketpass-api
答案 0 :(得分:0)
最初,我通过某种程度的错误发现了与Redis服务器(正在使用)相关的某些东西,由于某种原因,Redis服务器默认情况下未运行,因此必须启动它(更新config.yaml文件)。 之后,我得到了与我的S3存储桶区域有关的另一种类型的错误。 通过发布请求,该图像将存储在S3存储桶中,这是在抱怨其区域。 我设法通过在请求来自的相同区域创建一个新的S3存储桶来解决此问题。 这解决了我的问题。