這個部分沒什麼特別要強調的,就是按照 QDUOJ部署上的方法跟着複製粘貼就行了,根本不用動腦子。html
因爲在2020年一月後官方正式宣佈放棄了對py2的維護,因此如今使用pip時會遇到一些小問題,如下是解決方法。前端
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python3.7
sudo apt-get install python3-pip #裝pip3
複製代碼
若提示add-apt-repository: command not found
則運行sudo apt-get install python-software-properties
便可。node
輸入alias python='/usr/bin/python3.7'
便可切換python對應版本python
1.ModuleNotFoundError: No module named 'pip._internal'linux
wget https://bootstrap.pypa.io/get-pip.py https://bootstrap.pypa.io/get-pip.py --no-check-certificate
sudo python3.7 get-pip.py http://get-pip.py/
複製代碼
2.如有如下報錯webpack
Building wheels for collected packages: cffi
Building wheel for cffi (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /home/starx/pythonvirtualenv/starxteam/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-0xuyhqlj/cffi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-0xuyhqlj/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-4glw5w36 --python-tag cp37
cwd: /tmp/pip-install-0xuyhqlj/cffi/
Complete output (36 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.7
creating build/lib.linux-x86_64-3.7/cffi
copying cffi/__init__.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/cparser.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/error.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/vengine_cpy.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/commontypes.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/vengine_gen.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/pkgconfig.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/lock.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/cffi_opcode.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/model.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/recompiler.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/verifier.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/api.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/setuptools_ext.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/ffiplatform.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/backend_ctypes.py -> build/lib.linux-x86_64-3.7/cffi
copying cffi/_cffi_include.h -> build/lib.linux-x86_64-3.7/cffi
copying cffi/parse_c_type.h -> build/lib.linux-x86_64-3.7/cffi
copying cffi/_embedding.h -> build/lib.linux-x86_64-3.7/cffi
copying cffi/_cffi_errors.h -> build/lib.linux-x86_64-3.7/cffi
running build_ext
building '_cffi_backend' extension
creating build/temp.linux-x86_64-3.7
creating build/temp.linux-x86_64-3.7/c
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.7m -I/home/starx/pythonvirtualenv/starxteam/include/python3.7m -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.7/c/_cffi_backend.o
c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
#include <ffi.h>
^~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for cffi
Running setup.py clean for cffi
Failed to build cffi
複製代碼
嘗試安裝拓展包sudo apt install build-essential libffi-dev python-dev
git
問題 :部署成功 使用docker ps -a 查看容器狀態均爲healthy,可是直接訪問ip沒法查看,顯示狀態碼503。 解決:多是由於對應端口沒有開放致使的,在雲服務器安全組設置中增長對應端口(80或者443)github
1.安裝node.js 這裏須要注意一下,由於QDUOJ使用的版本是nodejs version 8.12.0,版本太高可能會產生一些沒必要要的錯誤。 2.運行web
npm install
# we use webpack DllReference to decrease the build time,
# this command only needs execute once unless you upgrade the package in build/webpack.dll.conf.js
NODE_ENV=development npm run build:dll
# the dev-server will set proxy table to your backend
export TARGET=http://Your-backend
# serve with hot reload at localhost:8080
npm run dev
複製代碼
上面是官方文檔的方法,可是推薦使用cnpm來代替npm,cnpm是國內淘寶的鏡像,速度相對來講會快一點。 這裏是官方的演示視頻docker
cd OnlineJudge
sudo pip install --no-cache-dir -r ./deploy/requirements.txt
複製代碼
若是pip install過慢可以使用一下命令,將pip源換至阿里雲
sudo pip install --no-cache-dir -r ./deploy/requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
複製代碼
修改./init_db.sh文件的第17和18行修改成
python3.7 manage.py migrate
python3.7 manage.py inituser --username root --password rootroot --action create_super_admin
複製代碼
而後執行一下命令
sudo chmod +x init_db.sh
./init_db.sh --migrate
複製代碼
同樣無報錯便可
去阿里雲那裏申請一個倉庫,免費的,把倉庫名稱寫成oj-backend便可。建立成功他會給你一個頁面提示你如何上傳,很詳細。
sudo docker login --username=你的用戶名 registry.cn-beijing.aliyuncs.com
複製代碼
你剛纔建立的鏡像ID,可使用docker images查一下,順便能查到鏡像版本號TAG
sudo docker tag [ImageId] registry.這裏用阿里雲給你提供的便可/oj-backend:[鏡像版本號]
sudo docker push registry.這裏用阿里雲給你提供的便可/oj-backend:[鏡像版本號]
複製代碼
TAG就是上邊須要寫的版本號,還有IMAGE ID就是鏡像ID。 而後就會開始push完畢就成功上傳了。
Travis CI 是在軟件開發領域中的一個在線的,分佈式的持續集成服務,用來構建及測試在GitHub託管的代碼。 阮一峯的Travis CI使用教程
1.使用Github帳號在Travis CI登陸 2.在more options中的setting設置本身的docker帳號與密碼 而後添加兩個環境變量,這個用戶名和密碼和你的DockerHub帳戶是對應的: DOCKER_USERNAME和DOCKER_PASSWORD
接着在Travis CI的script裏寫入
script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker build -t 用戶名/包名:latest .
- docker push 用戶名/包名:latest
複製代碼
經過使用docker ps -a
來查看已經運行的鏡像狀態,docker images
來查看本地已經存在的鏡像。
使用GitHub+Travis-CI+Docker打造自動化流水線
在使用docker製做鏡像時,若是修改了數據庫字段,記得運行python manage.py makemigrations
和python manage.py migrate
,不然在運行docker-compose up -d
以後會發現容器一直自啓動。