记录下今天使用Jenkins
部署Flask
项目遇到的问题。
项目使用FLASK_CONFIG
环境变量切换配置,未指定就使用development
开发环境配置,导致上线出错。
于是在项目的docker-compose.yaml
添加environment
参数指定项目环境。
services:
flask-example:
image: xxxxx/flask-example
ports:
- "5001:8888"
environment:
- FLASK_CONFIG:production
再重新使用Jenkins
部署,就出现以下错误:
SSH: Connecting from host [localhost]
SSH: Connecting with configuration [test01] ...
SSH: EXEC: completed after 601 ms
SSH: Disconnecting configuration [test01] ...
ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [1]]
一开始以为是ssh
连接服务器有问题,查看/var/log/secure
日志有以下报错:
Jul 26 11:53:09 test01 sshd[15210]: Accepted publickey for root from 192.168.1.10 port 6320 ssh2: RSA SHA256:XADGa91Yb7qCDvMyb3eI31KU9hILHts3KTAJvDWAhLM
Jul 26 11:53:09 test01 sshd[15210]: pam_unix(sshd:session): session opened for user root by (uid=0)
Jul 26 11:53:09 test01 sshd[15210]: pam_systemd(sshd:session): Failed to release session: Interrupted system call
Jul 26 11:53:09 test01 sshd[15210]: pam_unix(sshd:session): session closed for user root
重启了sshd
服务,还是一样。
然后以为是权限问题,查看目录文件是有传送过去,然后就直接在服务器运行docker-compose up -d
部署,出现以下错误:
ERROR: The Compose file './docker-compose.yaml' is invalid because:
services.flask-example.environment contains {"FLASK_CONFIG": "production"}, which is an invalid type, it should be a string
到此,才发现是自己的大意,环境变量设置要使用=
,而我使用了:
。修改完后在Jenkins
上就正常部署了。