pytdemo
Project description
[基于FastApi的python项目,封装常用工具(持续集成中......)]
步骤
构建Dockerfile
基础镜像
构建python运行基础镜像Dockerfile
FROM amazonlinux:latest
LABEL maintainer=“Lance”
RUN yum update -y && yum install -y python3 python3-devel vim
具体服务镜像Dockerfile
FROM registry.cn-hangzhou.aliyuncs.com/lance0515/lance-test:base_python
LABEL maintainer="Lance"
COPY requirements.txt .
RUN pip3 install -r requirements.txt
# 配置默认放置 App 的目录
RUN mkdir -p /app
WORKDIR /app
EXPOSE 28000-28004
COPY . .
ENV PYTHONPATH /app
ENTRYPOINT ["python3", "/app/main.py"]
推送到阿里云
# 登录, 输入密码
docker login --username=**** registry.cn-hangzhou.aliyuncs.com
# 对镜像打标签
docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/****/lance-test:[镜像版本号]
# 发布
docker push registry.cn-hangzhou.aliyuncs.com/****/lance-test:[镜像版本号]
服务器下载
# 登录
docker login --username=**** registry.cn-hangzhou.aliyuncs.com
docker pull registry.cn-hangzhou.aliyuncs.com/****/lance-test:[镜像版本号]
docker-compose 实例化容器
docker-compose.yml
通过docker-compose启动容器
version: "3"
services:
py-server:
image: registry.cn-hangzhou.aliyuncs.com/lance0515/lance-test:${BASE_VERSION}
container_name: py-server
ports:
- 28000:8000
- 28004:8004
volumes:
- ${BASE_PROJECT_PATH}:/app
.env
BASE_VERSION=v1.0 # 打tag时镜像实际版本号
BASE_PROJECT_PATH=/data/app # 项目在服务器实际地址
## 自动拉取代码并重启服务
通过脚本自动拉取代码
auto_pull.sh
#! /bin/bash
echo "--------------------------------"
echo "----------开始执行脚本----------"
date
pwd;
echo "切换到git目录"
##切换到放置git代码的目录绝对路径
cd /home/lance/python/python-server;
path=`pwd`
echo $path
if [ "$path" == "/home/lance/python/python-server" ]
then
echo "目录切换成功,准备拉取最新代码"
else
echo "目录切换失败,退出程序"
exit 0;
fi
git pull;
echo "准备重启容器"
# npm run build;
sleep 30
docker restart py-server
echo "成功"
结合github push自动拉取代码
通过github设置webhook,回调执行auto_pull.sh脚本
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
py_lance_util-0.1.0.tar.gz
(15.4 kB
view details)
Built Distribution
File details
Details for the file py_lance_util-0.1.0.tar.gz
.
File metadata
- Download URL: py_lance_util-0.1.0.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.0 CPython/3.9.12 Darwin/22.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90b2a413054a185b4798bce10e709ce01b1b15a0552c7ffd52c76d43aa3db6a3 |
|
MD5 | d6b1f2831db110e1057d4fd420763500 |
|
BLAKE2b-256 | bccc36d4e9a4de58e7dec9a494001448309bd301f9ac25e7b4ba8b84b1a221e0 |
File details
Details for the file py_lance_util-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: py_lance_util-0.1.0-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.0 CPython/3.9.12 Darwin/22.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e840298045a83e54429ee6c59cf69926127089c82379895dfacdbc6727e838e |
|
MD5 | 314fcea0ee32ffebc578a5fe774de611 |
|
BLAKE2b-256 | 113a4686ba6eef8343f65f550cac0756acfaa6e802cf4ad5b836dfc6e121248b |