forked from Qexo/Qexo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. 修复python:alpine3.17,使用的是python3.12无法使用pip安装依赖,改为指定python3.12
- Loading branch information
Showing
7 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
IMAGE_NAME=Qexo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ tmp | |
venv | ||
configs.py | ||
|
||
*.db | ||
*.db | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
FROM python:alpine3.17 | ||
FROM python:3.11 | ||
WORKDIR /root | ||
COPY . . | ||
RUN pip install -r requirements_withoutmsyql.txt && \ | ||
|
||
ARG CN=false | ||
RUN if [ "$CN" = "true" ]; then \ | ||
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/ && \ | ||
pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn; \ | ||
fi | ||
|
||
RUN python -m pip install --upgrade pip && \ | ||
pip install -r requirements_withoutmsyql.txt && \ | ||
python3 manage.py makemigrations && \ | ||
python3 manage.py migrate | ||
|
||
EXPOSE 3000 8000 | ||
|
||
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000", "--noreload" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Target section and Global definitions | ||
# ----------------------------------------------------------------------------- | ||
.PHONY: deploy | ||
|
||
all: deploy | ||
|
||
|
||
deploy: generate_dot_env | ||
bash ./update_tag.sh | ||
docker-compose build | ||
docker-compose up -d | ||
|
||
down: | ||
docker-compose down | ||
|
||
generate_dot_env: | ||
@if [[ ! -e .env ]]; then \ | ||
cp .env.example .env; \ | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: "3" | ||
|
||
services: | ||
app: | ||
build: | ||
context: . | ||
args: | ||
CN: "true" | ||
ports: | ||
- "8000:8000" | ||
env_file: | ||
- .env | ||
image: qexo:${IMAGE_TAG:-latest} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
# 尝试获取当前的 Git 提交 ID 的简短哈希值 | ||
COMMIT_ID=$(git rev-parse --short HEAD 2>/dev/null) | ||
|
||
# 获取当前的日期,格式为 YYYYMMDD | ||
BUILD_DATE=$(date +%Y%m%d) | ||
|
||
# 根据是否能够获取到 COMMIT_ID 来设置 IMAGE_TAG | ||
if [ -n "$COMMIT_ID" ]; then | ||
NEW_IMAGE_TAG="${BUILD_DATE}_${COMMIT_ID}" | ||
else | ||
NEW_IMAGE_TAG="${BUILD_DATE}" | ||
fi | ||
|
||
# 想要更新或添加的环境变量键名 | ||
ENV_VAR="IMAGE_TAG" | ||
|
||
# 检查.env文件是否存在 | ||
if [ -f ".env" ]; then | ||
# 检查IMAGE_TAG变量是否存在 | ||
if grep -q "${ENV_VAR}=" .env; then | ||
# 使用Sed来安全地替换.env文件中的IMAGE_TAG值 | ||
sed -i.bak -e "s/^${ENV_VAR}=.*/${ENV_VAR}=${NEW_IMAGE_TAG}/" .env | ||
echo "Updated ${ENV_VAR} in .env file." | ||
else | ||
# 如果IMAGE_TAG不存在,那么添加它 | ||
# 首先确保.env文件以换行符结尾 | ||
tail -c1 .env | read -r _ || echo "" >> .env | ||
# 然后添加新的IMAGE_TAG | ||
echo "${ENV_VAR}=${NEW_IMAGE_TAG}" >> .env | ||
echo "Added ${ENV_VAR} to .env file." | ||
fi | ||
else | ||
# 如果.env文件不存在,那么创建一个并添加IMAGE_TAG | ||
echo "${ENV_VAR}=${NEW_IMAGE_TAG}" > .env | ||
echo "Created .env file and added ${ENV_VAR}." | ||
fi |