我将 AWS CDK(使用 Python)用于在 Fargate 上运行的容器化应用程序。我想cdk deploy在 GitLab CI 进程中运行并将 git 标记作为环境变量传递,以替换在 Fargate 中运行的容器。我目前正在使用 CloudFormation ( aws cloudformation update-stack ...)做类似的事情。还有其他人以这种方式使用 AWS CDK 进行 CI/CD 吗?有没有更好的方法来做到这一点?
另外,我应该为这项工作使用什么作为我的基本图像?我在想我可以从 python 容器开始并安装节点,反之亦然。或者也许在某处我还没有找到预建的容器。
这是似乎运行良好的开始:
CDK:
image: python:3.8
stage: deploy
before_script:
- apt-get -qq update && apt-get -y install nodejs npm
- node -v
- npm i -g aws-cdk
- cd awscdk
- pip3 install -r requirements.txt
script:
- cdk diff
- cdk deploy --require-approval never
Run Code Online (Sandbox Code Playgroud)
编辑 2020-05-04:
CDK 可以在 期间构建 docker 镜像 …
amazon-web-services continuous-deployment gitlab gitlab-ci aws-cdk
我在测试中使用patchfromunittest.mock来更改远程 API 调用的行为。
我有三个不同的函数,它们返回三个不同的json文件,这些文件代表要从 API 返回的模拟数据。对于每个模拟 api 调用,我将其设置side_effect为这些函数之一。这种模式不是 DRY,但我不知道如何将参数传递给函数side_effect。
三个模拟 api 调用函数如下所示:
def mock_api_call_1():
with open('path/to/mock_1.json') as f:
mock_data = json.load(f)
return mock_data
Run Code Online (Sandbox Code Playgroud)
这是我的测试
class MyTest(TestCase):
def test_api(self):
with patch('mymodule.utils.api_call', side_effect=mock_api_call_1):
do_crud_operations()
self.assertEqual(MyModel.objects.all().count(), 10)
with patch('mymodule.utils.api_call', side_effect=mock_api_call_2):
do_crud_operations()
self.assertEqual(MyModel.objects.all().count(), 11)
Run Code Online (Sandbox Code Playgroud)
如何重构此代码以便能够将参数传递给side_effect(mock_call(1)而不是mock_call_1)。
从单元测试文档中,我看到:
side_effect:每当调用 Mock 时都会调用的函数。请参阅 side_effect 属性。对于引发异常或动态更改返回值很有用。使用与模拟相同的参数调用该函数,除非它返回 DEFAULT,否则该函数的返回值将用作返回值。
我看到传递给的函数采用side_effect与模拟相同的参数,但我仍然不确定如何最好地使用模拟来完成此任务。我最终会想要添加更多的测试用例,所以我不想对不同的mock_api_call函数进行硬编码。
当我尝试构建VueJS应用程序时,我看到npm出错了.我build在GitLab CI 的一个阶段看到了这个错误.我没有找到任何提及错误消息.我以前能够npm run build成功运行并且我没有对Vue应用程序代码进行任何更改,因此我不确定是什么原因导致此错误.
- Building for production...
ERROR Error: custom keyword definition is invalid: data.errors should be boolean
Error: custom keyword definition is invalid: data.errors should be boolean
at Ajv.addKeyword (/app/node_modules/ajv/lib/keyword.js:65:13)
at module.exports (/app/node_modules/ajv-errors/index.js:10:7)
at Object.<anonymous> (/app/node_modules/terser-webpack-plugin/node_modules/schema-utils/src/validateOptions.js:22:1)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! code@0.1.0 build: `vue-cli-service build`
npm ERR! …Run Code Online (Sandbox Code Playgroud) 我正在研究将部署我的 docker 堆栈的 GitLab CI 管道。我正在尝试将 $DOCKER_HOST 设置为tcp://DROPLET_IP:2377,但是我收到一条错误消息,指出我的证书不包含任何 IP SAN。我正在使用 Digital Ocean Droplet 进行测试,所以我还没有为我的 Droplet 设置域名。
deploy:
stage: deploy
image: docker:stable
services:
- docker:dind
variables:
DOCKER_HOST: "tcp://$DROPLET_IP:2377"
DOCKER_TLS_VERIFY: 1
before_script:
- mkdir -p ~/.docker
- echo "$TLS_CA_CERT" > ~/.docker/ca.pem
- echo "$TLS_CERT" > ~/.docker/cert.pem
- echo "$TLS_KEY" > ~/.docker/key.pem
script:
- docker login -u gitlab-ci-token -p "$CI_JOB_TOKEN" "$CI_REGISTRY"
- docker info
- docker stack deploy --with-registry-auth --compose-file=docker-stack.yml mystack
Run Code Online (Sandbox Code Playgroud)
这是我在 GitLab CI 作业的输出中遇到的错误:
$ docker login -u gitlab-ci-token -p …Run Code Online (Sandbox Code Playgroud) 我正在使用 cypress 来测试我的 VueJS 应用程序。我遇到的一件事是模拟要显示在页面上的图像。对于我的用例,我只是使用以下代码加载用户配置文件:
describe('Test Login', () => {
it('Can Login', () => {
cy.server();
cy.route({
method: 'GET',
url: '/api/account/',
response: 'fx:profile.json',
});
cy.route('**/media/demo1.png', 'fx:demo1.png');
});
});
Run Code Online (Sandbox Code Playgroud)
fixtures/profile.json
{
"avatar": "http://localhost:8080/media/demo1.png",
"username": "cypress",
"email": "email@cypress.io",
"pk": 1,
"is_staff": true,
"is_superuser": true,
"is_active": true
}
Run Code Online (Sandbox Code Playgroud)
配置文件夹具数据在测试中正确加载。在我的 fixtures 文件夹中,我还有一个demo1.png文件。我希望在测试期间加载此图像并显示在页面上,但它显示为损坏的图像。
在网络选项卡中,它显示demo1.png为带有 200 响应代码和text/html.
cypress 文档主要在上传图像的上下文中讨论图像,但我一直无法找到如何模拟通过<img>标签加载的图像的示例。有没有更简单的方法来做到这一点?
我已经使用Route53在S3和CloudFront上部署了VueJS应用。似乎一切正常。我可以访问位于的站点https://my-domain.com,并且可以导航到使用Vue路由器设置的其他路由。但是,当我尝试https://my-domain.com/about直接访问时,出现以下错误:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<link type="text/css" id="dark-mode" rel="stylesheet" href=""/>
<style type="text/css" id="dark-mode-custom-style"/>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>about</Key>
<RequestId>8371CJFJ48JM68239</RequestId>
<HostId>
/fQp7V6SuN0eDPgZpTroQrrxmfVQJTjXtroij56OIJONB56048OIaZDa4snkjc/Ygr/oZu0=
</HostId>
</Error>
Run Code Online (Sandbox Code Playgroud)
这是我的AWS资源的设置:
所有属性均已禁用(由于我使用的是https,因此我没有设置静态网站托管)
所有四个选项都设置为false
访问控制列表公共访问:每个人都可以阅读和列出对象
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadForGetBucketObjects",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::mybucketname.com/*"
}
]
}
Run Code Online (Sandbox Code Playgroud)
这里什么都没有
我有一个包含5条记录的托管区域的域: …
amazon-s3 amazon-web-services amazon-cloudfront amazon-route53 vue.js
自从我开始使用 AWS ECS 以来,我一直遵循AWS ECS 参考架构。此参考架构使用 Amazon Linux,我想更新到 Amazon Linux 2,但我不确定我需要做什么才能成功完成此转换。
此参考架构的 GitHub 存储库上存在一个问题,尽管有几个人寻求帮助,但它已经几个月没有受到任何关注。据我了解,以下是使用 Amazon Linux 2 ECS 优化 AMI 时需要解决的一些问题:
sysvinitAmazon Linux 2 不再支持;systemd应该改用。journald了 Cloud 当前不支持的docker 日志(此处描述)我有一个开源项目,用于学习 CloudFormation 和 AWS;这ecs-cluster.yaml是描述我尝试更新的 ECS 集群和容器实例的文件的链接。
我听说有些人将 Amazon Linux 2 与 ECS 一起使用,我也想更新,因为对 Amazon Linux (1) 的支持将在大约 6 个月后结束。有谁知道为了将 Amazon Linux 2 与 ECS 一起使用,我还需要考虑哪些其他因素?调试此问题非常耗时,我不确定应该尝试哪些选项和配置。
linux amazon-web-services amazon-ecs amazon-linux amazon-linux-2
我有一个带有 s3 源和自定义源的 CloudFront 发行版。我希望所有流量/api/*都/admin/*转到自定义源,所有其他流量都转到 s3 源。目前我只能使用它/api/*:
cloudfront.SourceConfiguration(
custom_origin_source=cloudfront.CustomOriginConfig(
domain_name=alb,
origin_protocol_policy=cloudfront.OriginProtocolPolicy.MATCH_VIEWER,
),
behaviors=[
cloudfront.Behavior(
allowed_methods=cloudfront.CloudFrontAllowedMethods.ALL,
path_pattern="/api/*",
forwarded_values={
"headers": ["*"],
"cookies": {"forward": "all"},
"query_string": True,
},
)
],
),
Run Code Online (Sandbox Code Playgroud)
我可能可以使用 重复该行为/api/*,但最终我将添加一些额外的路径,这些路径需要路由到自定义源(ALB),所以我想知道是否有一种更干燥的方法来做到这一点。
path_pattern接受/{api,admin,other}/*风格图案吗?或者我应该重构“行为”部分以重用allowed_methods,forwarded_values然后使用不同的重复多个行为path_pattern?
我有一个 GitHub Actions 工作流程,可以从 terraform 配置读取输出。我正在尝试这样做:
terraform -chdir=terraform/live/dev output -json > /tmp/output.json
APP_URL=$(cat /tmp/output.json | jq -r '.app_url.value')
Run Code Online (Sandbox Code Playgroud)
我在 GitHub 操作日志中收到以下错误:
parse error: Invalid numeric literal at line 1, column 9
Run Code Online (Sandbox Code Playgroud)
我添加了以下内容来调试:
parse error: Invalid numeric literal at line 1, column 9
Run Code Online (Sandbox Code Playgroud)
我发现输出是cat /tmp/output.json:
# debugging output.json file
echo "output.json:"
cat /tmp/output.json
Run Code Online (Sandbox Code Playgroud)
这告诉我jq无法解析我写入 terraform JSON 输出的临时文件,因为它似乎将命令添加到文件本身:
/home/runner/work/_temp/2b622f60-be99-4a29-a295-593b06dde9a8/terraform-bin -chdir=terraform/live/dev output -json
{
"app_url": {
"sensitive": false,
"type": "string",
"value": "https://app.example.com"
}
}
Run Code Online (Sandbox Code Playgroud)
如何获取 JSON 形式的 terraform 输出并将其写入文件,而不使用导致解析错误的额外标题行? …
我的Django静态文件有问题。我正在使用Django admin和Django Rest Framework。我正在尝试使用S3存储桶为admin和DRF提供静态文件。我可以成功访问存储桶中任何文件的URL,它将在我的浏览器中加载,并且该文件通过HTTPS提供。
我在CloudFormation中为S3存储桶创建了一个嵌套堆栈:
Description: >
This template deploys S3 buckets for serving Django static files.
Parameters:
AppUrl:
Type: "String"
Description: "The URL for our app (e.g. mydomain.com)"
AllowedPattern: "[a-z0-9._-]+"
Resources:
AssetsBucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: !Sub ${AppUrl}-assets
AssetsBucketPolicy:
Type: "AWS::S3::BucketPolicy"
Properties:
Bucket: !Ref AssetsBucket
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: PublicReadForGetBucketObjects
Effect: "Allow"
Principal: "*"
Action: "s3:GetObject"
Resource: !Sub "${AssetsBucket.Arn}/static/*"
Run Code Online (Sandbox Code Playgroud)
当我的应用程序启动时,它将运行collectstatic,并将静态文件移入存储桶。这是我遇到的问题:
当我访问带有查询参数的DRF URL时?format=json。这将返回一个JSON响应,没有来自可浏览API的静态文件,并且我看不到任何错误。但是,当我访问可浏览的API或管理界面时,我似乎发现了三个错误消息之一。在Chrome中,我看到的是两种类型的行为。HTTPS已从URL中剥离(以红色划线),但是在静态资产加载时,控制台中显示了以下两个错误之一:
Access to font at 'https://mydomain.com-assets.s3.amazonaws.com/static/admin/fonts/Roboto-Bold-webfont.woff' from origin 'https://api.mydomain.com' has …Run Code Online (Sandbox Code Playgroud) 我将 Element UINavMenu与:router="true". 当我单击菜单链接(路由更改和活动菜单项更改)时,它工作正常。我遇到的问题是,当我单击浏览器导航按钮(back和forward)时,路由和组件会更改,但NavMenu活动选项卡不会更改。
NavMenu在使用浏览器导航按钮时,是否有一种简单的方法可以确保当前路线与彼此保持同步?我正在vue-router与mode: 'history'. 我原以为这会自动处理。
我正在使用带有RDS的Postgres 10.6。我正在尝试设置DBParameterGroup来设置一些自定义参数,但是我不确定在CloudFormation中将什么作为姓氏。该文档有一个示例:Family: aurora5.6。我尝试了Family: postgres10.6,但没有成功。有任何人对此有经验吗?
这是我的CloudFormation RDS堆栈中的内容:
RDSPostgres:
Type: 'AWS::RDS::DBInstance'
DeletionPolicy: Delete
Properties:
AllocatedStorage: "100"
DBInstanceClass: db.m4.large
DBParameterGroupName: RDSDBParameterGroup
EnablePerformanceInsights: true
Engine: "postgres"
EngineVersion: "10.6"
MasterUsername: !Ref PGUsername
MasterUserPassword: !Ref PGPassword
Port: "5432"
PubliclyAccessible: true
StorageType: gp2
DBSubnetGroupName: !Ref DBSubnetGroup
VPCSecurityGroups:
- !GetAtt DatabaseSecurityGroup.GroupId
RDSDBParameterGroup:
Type: AWS::RDS::DBParameterGroup
Properties:
Description: Postgres custom parameters
Family: postgres10.6
Parameters:
shared_preload_libraries: 'pg_stat_statements'
pg_stat_statements.max: '10000'
pg_stat_statements.track: 'all'
log_min_duration_statement: '1000'
log_duration: 'on'
random_page_cost: '1.1'
checkpoint_completion_target: '0.9'
min_wal_size: '80'
effective_io_concurrency: '200'
log_statement: 'all'
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用这些设置创建一个新数据库,CloudFormation告诉我postgres10.6不是有效的参数。该DBParameterGroup文档 …
vue.js ×4
amazon-s3 ×2
aws-cdk ×2
gitlab ×2
gitlab-ci ×2
amazon-ecs ×1
amazon-linux ×1
cors ×1
cypress ×1
django ×1
docker ×1
docker-swarm ×1
e2e-testing ×1
element-ui ×1
https ×1
javascript ×1
jq ×1
linux ×1
npm ×1
postgresql ×1
python ×1
python-mock ×1
rds ×1
terraform ×1
unit-testing ×1
vue-router ×1