我已经两年没有更新博客了,因为我觉得之前写的文章缺乏实质性内容,再加上工作比较忙,所以暂停了两年的更新。最近有些闲暇时间,所以升级了一下仓库:

  • 升级了 hexo 版本,换成了默认的主题,并修改了部署方式。新的部署方式只需要一个仓库就可以了。
  • 集成了 Notion,现在在 Notion 上发布的文章可以手动同步到站点上。此功能使用了以下插件:Doradx/notion2markdown-action

参考:

Bitbucket Pipeline问题记录

Bitbucket Pipelines configuration reference

无法在 stage中使用 parallel

比如下面会报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
- stage: &deploy
name: Deploy
deployment: default
parallel:
steps:
- step:
name: Deploy store backend
oidc: true
caches:
- node
script:
- npm i
- export CDK_DEPLOY_REGION=$AWS_REGION
- export ENVIRONMENT=$BITBUCKET_DEPLOYMENT_ENVIRONMENT
- export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token
- echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token
- npx cdk deploy test-$BITBUCKET_DEPLOYMENT_ENVIRONMENT-store-stack --require-approval never
- step:
name: Deploy store step function
oidc: true
caches:
- node
script:
- npm i
- export CDK_DEPLOY_REGION=$AWS_REGION
- export ENVIRONMENT=$BITBUCKET_DEPLOYMENT_ENVIRONMENT
- export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token
- echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token
- npx cdk deploy test-$BITBUCKET_DEPLOYMENT_ENVIRONMENT-store-sfn-solana-stack --require-approval never

关键点在于 deployment 属性只能属于 step 或者 stage ,但是parallel 会有多个step ,但是 deployment 属性只能出现一次

Limitations

- The maximum number of steps you can within a stage is:
	- 10 steps for workspaces on the [Free plan](https://www.atlassian.com/software/bitbucket/pricing).
	- 100 steps for workspaces on a [Standard or Premium plan](https://www.atlassian.com/software/bitbucket/pricing).
- Parallel stages are not supported.
- A stage can't include parallel steps.
- A stage can't contain manually triggered steps, but you can configure a stage to be manually triggered.
- A stage can't contain conditional steps, but you can configure a stage to be conditional.
- Disabling artifact downloads inside a stage is not supported.
- Steps can't override any property also set on a stage.
- Partially completed deployment stages can't be continued if another change was subsequently deployed to the same environment.

传递文件变量

Bitbucket pipeline 可以通过Repository variables来传递变量,但是如果变量包含一些特殊字符比如换行符,bitbucket 就不能很好的处理,对于这种情况我们可以将变量用 base64 编码一下,在 pipeline 中再解码就可以解决这问题了。

1
2
3
4
cat file.txt | base64

// in pipeline file
echo ${YOUR_ENV} | base64 -d > file.txt

Condition 用法

Documentation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- step: &deployStepFunction
name: Deploy store step function
oidc: true
caches:
- node
condition:
changesets:
includePaths:
- "lib/sfn.ts"
- "sfn/**"
- "bin/**"
script:
- npm i
- export CDK_DEPLOY_REGION=$AWS_REGION
- export ENVIRONMENT=$BITBUCKET_DEPLOYMENT_ENVIRONMENT
- export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token
- echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token
- npx cdk deploy test-$BITBUCKET_DEPLOYMENT_ENVIRONMENT-store-sfn-solana-stack --require-approval never

限制

  • A step within the stage can’t contain a condition. The condition must be defined on the stage.

例如,下面这段就会引发上述错误。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
image: node:18

pipelines:
definitions:
- stage: &deploy
name: Deploy to Default
deployment: default
steps:
- step:
name: Install
caches:
- node
script:
- npm install
- step:
oidc: true
name: Deploy Admin Stack
condition:
changesets:
includePaths:
- "lib/admin.ts"
script:
- export CDK_DEPLOY_REGION=$AWS_REGION
- export ENVIRONMENT=$BITBUCKET_DEPLOYMENT_ENVIRONMENT
- export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token
- echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token
- npx cdk deploy "project-${ENVIRONMENT}-admin-stack" --require-approval never
- step:
oidc: true
name: Deploy Backend Stack
condition:
changesets:
includePaths:
- "lib/backend.ts"
script:
- export CDK_DEPLOY_REGION=$AWS_REGION
- export ENVIRONMENT=$BITBUCKET_DEPLOYMENT_ENVIRONMENT
- export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token
- echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token
- npx cdk deploy "project-${ENVIRONMENT}-backend-stack" --require-approval never

branches:
master:
- stage:
<<: *deploy
name: Deploy to demo
deployment: demo
local:
- stage:
<<: *deploy
name: Deploy to charles
deployment: charles

Parallel

内存问题

pipstep 共享内存

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
default:
- step:
services:
- redis
- mysql
- docker
script:
- echo "This step is only allowed to consume 2048 MB of memory"
- echo "Services are consuming the rest. docker 512 MB, redis 512 MB, mysql 1024 MB"
definitions:
services:
redis:
image: redis:3.2
memory: 512
docker:
memory: 512 # reduce memory for docker-in-docker from 1GB to 512MB
mysql:
image: mysql:5.7
# memory: 1024 # default value
variables:
MYSQL_DATABASE: my-db
MYSQL_ROOT_PASSWORD: $password

OIDC Connect

Artifact

不支持环境变量名 , 比如:

1
2
3
4
5
6
7
8
9
10
script:
- apt-get update && apt-get install -y zip
- python3 -m pip install --upgrade pip
- pip install poetry
- poetry export --only $FUNCTION -f requirements.txt -o ./$FUNCTION/requirements.txt --without-hashes --without-urls
- cd $FUNCTION
- zip -r $FUNCTION.zip .

artifacts:
- $FUNCTION/$FUNCTION.zip

通配符用法

1
2
artifacts:
- '*.zip'

Multiple Lines Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
pipelines:
definitions:
- step: &deploy
oidc: true
caches:
- node
name: CDK Deploy
script:
- npm install
- export AWS_ROLE_ARN=$AWS_ROLE_ARN
- export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token
- echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token
- >
if [ -z "$STACK_NAME" ]; then
echo "STACK_NAME is not set";
npx cdk deploy --all --require-approval never
else
echo "STACK_NAME is set to '$STACK_NAME'";
npx cdk deploy $STACK_NAME --require-approval never
fi
1
2
3
4
5
6
- >
functions=("1" "2" "3")
//这里要换行 不然报错
for function in "${functions[@]}"; do
gcloud functions deploy $(echo $function | tr '_' '-') --source=gs://$BUCKET_NAME/$function.zip --region=us-west2
done

echo 报错问题

比如下面包含 :空格 会报错:

1
- echo "Groups to package: ${groups[@]}"

改成

1
- echo "Groups to package:\ ${groups[@]}"

Deskmin H470 半年使用体验

今年4月份组装了一台黑苹果放公司, 配置为deskmini h470/i7 10700/64G/1TSSD, 原来那台2015款的macbook pro就开会的时候用用了.

系统很稳定, 几乎没有异常重启过. 遇到的小问题有几个:

  1. 接4k显示器的时偶尔会间歇黑屏, 手动进入睡眠在唤醒后似乎可以解决这问题?
  2. 有一次公司停电后重启后蓝牙失效, 不知到是不是因为天线没有接好的原因, 拆机把天线的螺丝拧紧后蓝牙又好了(Update:不用拆天线, 把电源重新插拔一下就好了, 是因为静电?)
  3. 有一阶段发现系统每次唤醒后网速变得很慢, 起初以为是网卡的原因, 后来发现是项目程序在上传文件把带宽给用完了, 为这问题还折腾了好久🤣 .

 

一开始买的网卡是cs2两天线的版本,后来又换成了2cs 三天线版本, 2cs版本的话天线不能买的太粗, 不然放不下, 我是淘宝买了两根粗的加自带的一根天线.

EFI使用的是这为大佬的: https://github.com/paranoid2006/ASRock-Deskmini-H470-Hackintosh

有了上次的安装经历, 这次的安装过程就很简单了, 制作usb安装盘->替换掉安装盘里的efi->安装系统->系统安装成功后在替换系统的efi->修改三码->完成.

Update:

Openwrt中Firewall - Custom Rules fwmark命令不起作用的问题

路由器设置了透明代理, 但是每次重启路由器后代理就是失效了, 发现Custom Rules中ip rule add fwmark 1 table 100 这个命令不知道啥原因在重启后会被清除, 导致代理失败.

解决办法就是编辑 /etc/config/network

添加以下内容

1
2
3
4
5
6
7
8
9
10
config rule
option mark '0x1'
option lookup '100'

config route
option interface 'loopback'
option target '0.0.0.0'
option netmask '0.0.0.0'
option table '100'
option type 'local'

代替Custom Rules的这两条命令:

1
2
ip rule add fwmark 1 table 100
ip route add local 0.0.0.0/0 dev lo table 100

参考:

AWS S3 Static Website Hosting 404

公司的前端项目是以静态化网页的方式部署在aws s3上的, 由于前端项目是用react写的, 页面的路由是前端代码控制,页面实际是不存在于s3中的, 所以每次刷新网页的时候控制台会产生一条404错误, 研究了下这个错误可以在cloudfront那里修复.

解决办法:
Cloudfront->选择项目的cdn->Error Pages->Create custom error response

1
2
3
4
Http error code      -> 404
Custom error resonse -> Yes
Response page path -> /index.html
Http Response code -> 200:OK

Custom error response

Github Actions动态密钥名称

test.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
name: LS

...

jobs:
deploy:
runs-on: ubuntu-latest

steps:

- name: Update and restart server
uses: appleboy/ssh-action@v0.1.4
with:
host: ${{ secrets[format('{0}_HOST', github.workflow)] }}
username: ${{ secrets[format('{0}_USER', github.workflow)] }}

比如workflow的名称为LS, 密钥名称就为:

1
2
3
with:
host: ${{ secrets['LS_HOST'] }}
username: ${{ secrets['LS_USER'] }}

Spring Data JPA保存jsonb类型数据

创建表

1
2
3
4
5
6
7
CREATE TABLE test
(
id integer NOT NULL
CONSTRAINT test_pk
PRIMARY KEY,
test_data jsonb
);

定义方法

1
2
3
4
5
6
7
8
9
@Modifying
@Query(
value = "INSERT INTO test (id, test_data) VALUES (:id, CAST(:testData AS JSONB))",
nativeQuery = true
)
fun saveTest(
@Param("id") id: Long,
@Param("testData") testData: String
): Int

调用代码

1
2
3
4
5
6
7
val id = 1L
val testData = listOf("1", "2", "3")
val testDataJsonStr = ObjectMapper().writeValueAsString(testData)

transactionTemplate.execute {
repository.saveTest(id, testDataJsonStr)
}

MIUI系统下Tasker保持后台常驻的方法

之前一直是用苹果的短信同步功能来同步短信的,期间老是出现一些莫名其妙不能同步短信的问题,最近实在是受不了这问题了,打算换到用android备用机来转发短信。

一开始用的是ifttt来同步短信的,一切运行正常,唯一的缺陷是iftt同步短信会有大概30秒左右时间的延时,有点接受不了。
后来开始用tasker来转发短信,尝试了下效果比ifttt好,几乎没有延时,但遇到一个问题就是tasker不能常驻后台,参考了官网的方案也没有解决这问题,研究了两天发现还有两个地方忘记了设置,在这里记录一下。

测试环境 MIUI 12.0.9

MIUI设置

将Tasker加到白名单

手机管家 -> 优化加速 -> 设置 -> 锁定任务 -> 将Tasker添加到已锁定任务

1.png
2.png
3.png
4.png

关闭智能场景省电

手机管家 -> 省电与电池 -> 场景配置 -> 睡眠模式 -> 关闭

a.png
b.png
c.png
d.png

其他设置

Terraform multiple line script example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
resource "null_resource" "cluster" {

connection {
type = "ssh"
user = "admin"
private_key = base64decode(var.private_key)
host = aws_lightsail_instance.lightsail.public_ip_address
timeout = "3600s"
}

provisioner "local-exec" {
command = <<EOT
echo "{\"host\":\"${random_string.subdomain.result}\",\"type\":\"A\",\"answer\":\"${aws_lightsail_instance.lightsail.public_ip_address}\",\"ttl\":300}" | \
curl "https://api.name.com/v4/domains/${var.name_domain}/records" \
-s \
-X POST \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-u "${var.name_username}":"${var.name_token}" \
-d @-
EOT
}

}