每当我在 Circleci 上运行工作流时,都会失败,给我一个 500 HTTP 错误代码,尽管我在本地运行它时已经过测试并且成功了。
当我在本地运行测试时,我从存储中获取图像并使用它来执行我的 HTTP 请求,但是由于我使用的是 Circleci,所以我使用 curl 获取图像,将此图像放入文件夹中,然后我获取它以执行我的 HTTP 请求,但是,尝试在 Circleci 上构建时总是失败。
我想知道我是否在通过 curl 错误地存储图像时做错了什么,并指向最终不在正确位置的东西,或者可能是其他东西。尽管 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);
}
}
配置文件
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