From c1ed2a0394e686ae53704f2c2c826142863b3e52 Mon Sep 17 00:00:00 2001 From: "oren.zhang" Date: Fri, 1 Nov 2024 17:42:21 +0800 Subject: [PATCH 1/2] chore(build): shrink image size --- .cruft.json | 2 +- .env.tpl | 26 -------------------------- .github/workflows/pylint.yml | 2 +- .gitignore | 3 +++ Dockerfile | 17 ++++++++++++++--- Makefile | 7 +++++++ env.example | 16 ++++++++++++++++ scripts/pre-commit.sh | 2 ++ scripts/pylint.sh | 2 ++ 9 files changed, 46 insertions(+), 31 deletions(-) delete mode 100644 .env.tpl create mode 100644 Makefile create mode 100644 env.example create mode 100755 scripts/pre-commit.sh create mode 100755 scripts/pylint.sh diff --git a/.cruft.json b/.cruft.json index d3c3487..f7d42c0 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/OVINC-CN/DevTemplateDjango.git", - "commit": "ef125c550e0dc7f52fff1a3e4d1b4a73cebd8e32", + "commit": "77faa1ff4b8231ddbe45ee359b592442a9c4cda1", "checkout": "main", "context": { "cookiecutter": { diff --git a/.env.tpl b/.env.tpl deleted file mode 100644 index a16fd73..0000000 --- a/.env.tpl +++ /dev/null @@ -1,26 +0,0 @@ -# DEBUG -DEBUG=False -# APP -APP_CODE= -APP_SECRET= -# HOST -BACKEND_HOST= -FRONTEND_URL= -# DB -DB_NAME= -DB_USER= -DB_PASSWORD= -DB_HOST= -DB_PORT= -# Redis -REDIS_HOST= -REDIS_PORT= -REDIS_PASSWORD= -REDIS_DB= -# QCloud -QCLOUD_SECRET_ID= -QCLOUD_SECRET_KEY= -# COS -COS_REGION= -COS_BUCKET= -COS_DOMAIN= diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 5d40982..1507174 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -26,4 +26,4 @@ jobs: pip install -r requirements.txt - name: Analysing the code with pylint run: | - pylint --disable=C0114,W0613,C0115,W1113,W0223,C0116,R0901,R0903,C0209 --max-line-length=120 $(git ls-files '*.py') + make pylint diff --git a/.gitignore b/.gitignore index 80a1a12..01dbe79 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ env .env +# Trasnlation +*.mo + # Python *.pyc *.db diff --git a/Dockerfile b/Dockerfile index e38d3b1..8ee25cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,16 @@ -FROM python:3.10 -RUN mkdir -p /usr/src/app/celery-logs /usr/src/app/logs /usr/src/app/daphne-logs -COPY . /usr/src/app +FROM python:3.10.15-slim + WORKDIR /usr/src/app + +COPY requirements.txt /usr/src/app/ RUN pip3 install -U pip && pip3 install -r requirements.txt + +COPY . /usr/src/app + +RUN export https_proxy=http://10.1.0.163:6152 && export http_proxy=http://10.1.0.163:6152 && export all_proxy=socks5://10.1.0.163:6153 && apt-get update && apt-get install -y gettext + +RUN cp env.example .env \ + && python3 manage.py compilemessages -l zh_Hans \ + && rm -rf .env + +RUN mkdir -p /usr/src/app/celery-logs /usr/src/app/logs /usr/src/app/daphne-logs diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..89c561b --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +pylint: + scripts/pylint.sh + +pre-commit: + scripts/pre-commit.sh + +lint: pre-commit pylint diff --git a/env.example b/env.example new file mode 100644 index 0000000..7be0426 --- /dev/null +++ b/env.example @@ -0,0 +1,16 @@ +APP_CODE=union-api +APP_SECRET=union-api +BACKEND_URL=https://dev-api.example.com +BACKEND_HOST=dev-api.example.com +FRONTEND_URL=https://dev.example.com +DB_NAME=union-api +DB_USER=union-api +DB_PASSWORD= +DB_HOST=127.0.0.1 +DB_PORT=3306 +REDIS_HOST=127.0.0.1 +REDIS_PORT=6379 +REDIS_PASSWORD= +REDIS_DB=0 +OVINC_API_DOMAIN=https://api.example.com +OVINC_WEB_URL=https://www.example.com diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh new file mode 100755 index 0000000..07c0956 --- /dev/null +++ b/scripts/pre-commit.sh @@ -0,0 +1,2 @@ +#!/bin/sh +pre-commit run -a diff --git a/scripts/pylint.sh b/scripts/pylint.sh new file mode 100755 index 0000000..cd581d5 --- /dev/null +++ b/scripts/pylint.sh @@ -0,0 +1,2 @@ +#!/bin/sh +pylint --disable=C0114,W0613,C0115,W1113,W0223,C0116,R0903 --max-line-length=120 $(git ls-files '*.py') From 8dd71a179c6964729a5ebd890419e24997efb7eb Mon Sep 17 00:00:00 2001 From: "oren.zhang" Date: Fri, 1 Nov 2024 17:44:18 +0800 Subject: [PATCH 2/2] refactor(lint): change lint script --- scripts/pylint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pylint.sh b/scripts/pylint.sh index cd581d5..db38b83 100755 --- a/scripts/pylint.sh +++ b/scripts/pylint.sh @@ -1,2 +1,2 @@ #!/bin/sh -pylint --disable=C0114,W0613,C0115,W1113,W0223,C0116,R0903 --max-line-length=120 $(git ls-files '*.py') +pylint --disable=C0114,W0613,C0115,W1113,W0223,C0116,R0901,R0903,C0209 --max-line-length=120 $(git ls-files '*.py')