Skip to content

Commit

Permalink
修改代码以兼容docker
Browse files Browse the repository at this point in the history
  • Loading branch information
jscslld committed Dec 24, 2023
1 parent dc8d4af commit 35313a1
Show file tree
Hide file tree
Showing 19 changed files with 313 additions and 73 deletions.
163 changes: 163 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

# Model
backend/model/
14 changes: 14 additions & 0 deletions backend.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM paddlepaddle/paddle:2.4.1
#RUN wget https://github.com/girder/large_image_wheels/raw/wheelhouse/GDAL-3.4.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
COPY GDAL-3.4.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl .
RUN pip install GDAL-3.4.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
RUN rm -rf GDAL-3.4.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
RUN mkdir /app
COPY PaddleRS /app/PaddleRS
WORKDIR /app/PaddleRS
RUN pip install -r /app/PaddleRS/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install -e .
COPY backend /app/backend
WORKDIR /app/backend
RUN pip install -r /app/backend/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
ENTRYPOINT ["python", "app.py"]
16 changes: 0 additions & 16 deletions backend/.flaskenv_template

This file was deleted.

2 changes: 1 addition & 1 deletion backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def error_handler(e):

if __name__ == '__main__':
import yaml
with open('./config.yaml') as file:
with open('../config.yaml') as file:
config = yaml.load(file.read(), Loader=yaml.FullLoader)
debug_mode = bool(config.get("debug", False))
app.run(host=config["host"]["backend"], port=config["port"]["backend"])
6 changes: 3 additions & 3 deletions backend/applications/interface/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def change_detection(model_path,
cv2.imwrite(
os.path.join(out_dir,
os.path.splitext(filenames[i])[0] + "_mask.png"), mask)
res[i]["mask"] = out_dir + os.path.splitext(filenames[i])[
res[i]["mask"] = generate_url + os.path.splitext(filenames[i])[
0] + "_mask.png"
res[i]["count"] = count
res[i]["fractional_variation"] = compute_variation(
Expand All @@ -135,11 +135,11 @@ def change_detection(model_path,
out_dir + "hole/",
os.path.splitext(os.path.basename(after_img))[0] + "_mask.png"),
mask)
res[i]["mask_hole"] = out_dir + "hole/" + os.path.splitext(
res[i]["mask_hole"] = generate_url + "hole/" + os.path.splitext(
os.path.basename(after_img))[0] + "_mask.png"
res[i]["count_hole"] = count
res[i]["fractional_variation_hole"] = compute_variation(
os.path.join(generate_dir + "hole/", os.path.basename(after_img)))
os.path.join(out_dir + "hole/", os.path.basename(after_img)))
data = json.dumps(res[i])
save_analysis(
type_,
Expand Down
3 changes: 0 additions & 3 deletions backend/config.yaml

This file was deleted.

8 changes: 8 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
port:
backend: 5008
frontend: 3000
host:
backend: 0.0.0.0
frontend: 0.0.0.0
debug: true
docker: true
47 changes: 47 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: "3.9"
services:
mysql:
image: mysql:5.7.44
restart: always
environment:
MYSQL_ROOT_PASSWORD: GeoView2023
volumes:
- /etc/localtime:/etc/localtime:ro
networks:
- GeoView
backend:
build:
context: .
dockerfile: backend.dockerfile
restart: always
volumes:
- /etc/localtime:/etc/localtime:ro
- $PWD/config.yaml:/app/config.yaml
- $PWD/backend/.flaskenv:/app/backend/.flaskenv
- $PWD/backend/model:/app/backend/model
depends_on:
- mysql
links:
- mysql
networks:
- GeoView
frontend:
build:
context: .
dockerfile: frontend.dockerfile
restart: always
ports:
- "3000:3000"
volumes:
- /etc/localtime:/etc/localtime:ro
- $PWD/config.yaml:/app/config.yaml
- $PWD/frontend/.env:/app/frontend/.env
depends_on:
- backend
networks:
- GeoView
networks:
GeoView:
ipam:
config:
- subnet: 172.19.0.0/24
6 changes: 6 additions & 0 deletions frontend.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:20.10.0-alpine
RUN mkdir /app
COPY frontend /app/frontend
WORKDIR /app/frontend
RUN npm install
ENTRYPOINT ["npm", "run", "serve"]
2 changes: 0 additions & 2 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
VUE_APP_BACKEND_PORT = 5008
VUE_APP_BACKEND_IP = 127.0.0.1
VUE_APP_BAIDU_MAP_ACCESS_KEY = <ACCESS_KEY>
8 changes: 6 additions & 2 deletions frontend/src/components/ImgShow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

<script>
import { downloadimgWithWords } from "@/utils/download.js";
import global from "@/global.vue";
export default {
name: "Imgshow",
props: {
Expand All @@ -80,7 +80,11 @@ export default {
data() {
return {
fit: "fill",
childImgArr:[]
childImgArr:[],
global: {
BASEURL: global.BASEURL,
BASE_IMAGE_URL:global.BASE_IMAGE_URL
},
};
},
mounted() {
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/global.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<script>
const BASEURL = "http://"+process.env.VUE_APP_BACKEND_IP+":"+process.env.VUE_APP_BACKEND_PORT+"/"
const BASEURL = "/"
const BASE_IMAGE_URL = window.location.protocol+"//"+window.location.host+BASEURL
export default {
BASEURL,
BASE_IMAGE_URL
};
</script>

4 changes: 2 additions & 2 deletions frontend/src/utils/getUploadImg.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {showFullScreenLoading} from "@/utils/loading";
function getUploadImg(type) {
historyGetPage(1, 20, type).then((res) => {
this.imgArr = res.data.data.forEach((item)=>{
item['before_img'] = global.BASEURL+item.before_img
item['after_img'] = global.BASEURL+item.after_img
item['before_img'] = global.BASE_IMAGE_URL+item.before_img
item['after_img'] = global.BASE_IMAGE_URL+item.after_img
})
this.imgArr = res.data.data
this.isUpload = this.imgArr.length !== 0;
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/utils/preHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function selectSharpen(type) {
}
createSrc(formData).then((res) => {
this.uploadSrc.list = res.data.data.map((item) => {
return global.BASEURL+item.src;
return global.BASE_IMAGE_URL+item.src;
});
this.before = this.uploadSrc.list.splice(0,3)

Expand All @@ -40,7 +40,7 @@ function selectSharpen(type) {
prePhotoHandle(this.prePhoto).then((res)=>{

this.sharpenImg = res.data.data.map((item)=>{
return global.BASEURL + item
return global.BASE_IMAGE_URL + item
})
}).catch(()=>{})
}).catch((rej)=>{})
Expand Down Expand Up @@ -75,7 +75,7 @@ function selectSharpen(type) {
}
createSrc(formData).then((res) => {
this.uploadSrc.list = res.data.data.map((item) => {
return global.BASEURL+item.src;
return global.BASE_IMAGE_URL+item.src;
});
this.before = this.uploadSrc.list.splice(0,3)

Expand All @@ -85,7 +85,7 @@ function selectSharpen(type) {
prePhotoHandle(this.prePhoto).then((res)=>{

this.claheImg = res.data.data.map((item)=>{
return global.BASEURL + item
return global.BASE_IMAGE_URL + item
})
}).catch((rej)=>{})
}).catch((rej)=>{})
Expand Down
Loading

0 comments on commit 35313a1

Please sign in to comment.