Skip to content

Commit 385515f

Browse files
committed
docker moved to own repository and refactored
0 parents  commit 385515f

13 files changed

+588
-0
lines changed

.dockerignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.gitignore
2+
Dockerfile
3+
Makefile
4+
README.md
5+
screenshots/
6+
tags
7+
media/

.github/workflows/docker-publish.yml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
# Publish `dev` as Docker `latest` image.
6+
branches:
7+
- dev
8+
9+
# Publish `v1.2.3` tags as releases.
10+
tags:
11+
- v*
12+
13+
# Run tests for any PRs.
14+
pull_request:
15+
16+
env:
17+
IMAGE_NAME: librephotos
18+
19+
jobs:
20+
# Run tests.
21+
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
22+
test:
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- uses: actions/checkout@v2
27+
28+
- name: Run tests
29+
run: |
30+
if [ -f docker-compose.test.yml ]; then
31+
docker-compose --file docker-compose.test.yml build
32+
docker-compose --file docker-compose.test.yml run sut
33+
else
34+
DOCKER_BUILDKIT=1 docker build . --file Dockerfile
35+
fi
36+
37+
# Push image to GitHub Packages.
38+
# See also https://docs.docker.com/docker-hub/builds/
39+
push:
40+
# Ensure test job passes before pushing image.
41+
needs: test
42+
43+
runs-on: ubuntu-latest
44+
if: github.event_name == 'push'
45+
46+
steps:
47+
- uses: actions/checkout@v2
48+
49+
- name: Build image
50+
run: DOCKER_BUILDKIT=1 docker build . --file Dockerfile --tag $IMAGE_NAME
51+
52+
- name: Login to Docker Hub
53+
uses: docker/login-action@v1
54+
with:
55+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
56+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
57+
58+
- name: Push image
59+
run: |
60+
IMAGE_ID=reallibrephotos/$IMAGE_NAME
61+
62+
# Change all uppercase to lowercase
63+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
64+
65+
# Strip git ref prefix from version
66+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
67+
68+
# Strip "v" prefix from tag name
69+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
70+
71+
# Use Docker `dev` tag
72+
VERSION=dev
73+
74+
echo IMAGE_ID=$IMAGE_ID
75+
echo VERSION=$VERSION
76+
77+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
78+
docker push $IMAGE_ID:$VERSION

.gitignore

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
98+
__pypackages__/
99+
100+
# Celery stuff
101+
celerybeat-schedule
102+
celerybeat.pid
103+
104+
# SageMath parsed files
105+
*.sage.py
106+
107+
# Environments
108+
.env
109+
.venv
110+
env/
111+
venv/
112+
ENV/
113+
env.bak/
114+
venv.bak/
115+
116+
# Spyder project settings
117+
.spyderproject
118+
.spyproject
119+
120+
# Rope project settings
121+
.ropeproject
122+
123+
# visual studio
124+
.vs/
125+
126+
# mkdocs documentation
127+
/site
128+
129+
# mypy
130+
.mypy_cache/
131+
.dmypy.json
132+
dmypy.json
133+
134+
# Pyre type checker
135+
.pyre/
136+
137+
# pytype static type analyzer
138+
.pytype/
139+
140+
# Cython debug symbols
141+
cython_debug/
142+
143+
# LibrePhotos
144+
densecap/data/models/densecap/densecap-pretrained-vgg16.t7
145+
*/*.pkl
146+
*/*/*.pkl
147+
thumbnails
148+
media
149+
samplephotos
150+
tags
151+
api/places365/model/
152+
Conv2d.patch
153+
Linear.patch
154+
Sequential.patch
155+
BatchNorm2d.patch
156+
AvgPool2d.patch
157+
ReLU.patch
158+
run_docker.sh
159+
logs/
160+
playground
161+
api/im2txt/data/
162+
api/im2txt/models/
163+
api/im2txt/png/
164+
*.ipynb
165+
api/im2txt/*.tar.gz
166+
api/places365/*.tar.gz
167+
*.db
168+
media*
169+
protected_media
170+
librephotos

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Hooram Nam
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.PHONY: default build run shell
2+
3+
DOCKER_TAG ?= ownphotos-backend
4+
5+
default: build
6+
7+
build:
8+
docker build -t $(DOCKER_TAG) .
9+
10+
run: build
11+
docker run $(DOCKER_TAG)
12+
13+
shell: build
14+
docker run --rm -it $(DOCKER_TAG) /bin/bash

backend/Dockerfile

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM python:3.8
2+
3+
# system packages installation
4+
RUN apt update && apt install -y curl libopenblas-dev libmagic1 libboost-all-dev libxrender-dev liblapack-dev git bzip2 cmake build-essential libsm6 libglib2.0-0 libgl1-mesa-glx --no-install-recommends
5+
6+
# pre trained models download
7+
WORKDIR /data_models
8+
RUN mkdir -p /data_models/places365/
9+
RUN mkdir -p /data_models/im2txt/
10+
RUN mkdir -p /root/.cache/torch/hub/checkpoints/
11+
RUN curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/places365_model.tar.gz | tar -zxC /data_models/places365/
12+
RUN curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/im2txt_model.tar.gz | tar -zxC /data_models/im2txt/
13+
RUN curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/im2txt_data.tar.gz | tar -zxC /data_models/im2txt/
14+
RUN curl -SL https://download.pytorch.org/models/resnet152-b121ed2d.pth -o /root/.cache/torch/hub/checkpoints/resnet152-b121ed2d.pth
15+
16+
# actual project
17+
WORKDIR /code
18+
RUN git clone https://github.com/LibrePhotos/librephotos.git .
19+
RUN pip install -r requirements.txt
20+
RUN python -m spacy download en_core_web_sm
21+
EXPOSE 80
22+
23+
# TODO: prod vs dev requirements using docker-compose args
24+
# TODO: in dev copiare anche i vscode settings

backend/entrypoint.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#! /bin/bash
2+
export PYTHONUNBUFFERED=TRUE
3+
mkdir -p /logs
4+
5+
python image_similarity/main.py 2>&1 | tee /logs/gunicorn_image_similarity.log &
6+
python manage.py showmigrations | tee /logs/show_migrate.log
7+
python manage.py migrate | tee /logs/command_migrate.log
8+
python manage.py showmigrations | tee /logs/show_migrate.log
9+
python manage.py build_similarity_index 2>&1 | tee /logs/command_build_similarity_index.log
10+
11+
python manage.py createadmin -u $ADMIN_USERNAME $ADMIN_EMAIL 2>&1 | tee /logs/command_createadmin.log
12+
13+
echo "Running backend server..."
14+
15+
python manage.py rqworker default 2>&1 | tee /logs/rqworker.log &
16+
gunicorn --worker-class=gevent --timeout $WORKER_TIMEOUT --bind backend:8001 --log-level=info ownphotos.wsgi 2>&1 | tee /logs/gunicorn_django.log

docker-compose.dev.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Run options:
2+
# 1. There are no options - This add additional tools to aid in the development of Libre Photos
3+
# run cmd: docker-compose up -f docker-compose.yml -f docker-compose.dev.yml -d
4+
# 2. Current added tools:
5+
# pgadmin User admin@admin pass admin port 3001
6+
7+
# DO NOT EDIT
8+
# The .env file has everything you need to edit.
9+
# Run options:
10+
# 1. Use prebuilt images (preferred method):
11+
# run cmd: docker-compose up -d
12+
# 2. Build images on your own machine:
13+
# build cmd: COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose build
14+
# run cmd: docker-compose up -d
15+
16+
version: '3.8'
17+
services:
18+
19+
frontend:
20+
tty: true
21+
build:
22+
context: .
23+
dockerfile: frontend/Dockerfile
24+
25+
backend:
26+
tty: true
27+
build:
28+
context: .
29+
dockerfile: backend/Dockerfile
30+
volumes:
31+
- ./backend/entrypoint.sh:/entrypoint.sh
32+
- ${myPhotos}:/data
33+
- ${proMedia}:/protected_media
34+
- ${logLocation}:/logs
35+
- ${codedir}:/code
36+
- ${cachedir}:/root/.cache
37+
38+
pgadmin:
39+
container_name: librephotos_pgadmin
40+
image: dpage/pgadmin4
41+
environment:
42+
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:[email protected]}
43+
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
44+
volumes:
45+
- $HOME/pgadmin:/root/.pgadmin
46+
ports:
47+
- "3001:80"
48+
restart: unless-stopped

0 commit comments

Comments
 (0)