Skip to content
Snippets Groups Projects
Commit 385515f5 authored by Matteo Parrucci's avatar Matteo Parrucci
Browse files

docker moved to own repository and refactored

parents
No related branches found
No related tags found
No related merge requests found
.gitignore
Dockerfile
Makefile
README.md
screenshots/
tags
media/
name: Docker
on:
push:
# Publish `dev` as Docker `latest` image.
branches:
- dev
# Publish `v1.2.3` tags as releases.
tags:
- v*
# Run tests for any PRs.
pull_request:
env:
IMAGE_NAME: librephotos
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
DOCKER_BUILDKIT=1 docker build . --file Dockerfile
fi
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- name: Build image
run: DOCKER_BUILDKIT=1 docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Push image
run: |
IMAGE_ID=reallibrephotos/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `dev` tag
VERSION=dev
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
# 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
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__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
# visual studio
.vs/
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# LibrePhotos
densecap/data/models/densecap/densecap-pretrained-vgg16.t7
*/*.pkl
*/*/*.pkl
thumbnails
media
samplephotos
tags
api/places365/model/
Conv2d.patch
Linear.patch
Sequential.patch
BatchNorm2d.patch
AvgPool2d.patch
ReLU.patch
run_docker.sh
logs/
playground
api/im2txt/data/
api/im2txt/models/
api/im2txt/png/
*.ipynb
api/im2txt/*.tar.gz
api/places365/*.tar.gz
*.db
media*
protected_media
librephotos
LICENSE 0 → 100644
MIT License
Copyright (c) 2017 Hooram Nam
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Makefile 0 → 100644
.PHONY: default build run shell
DOCKER_TAG ?= ownphotos-backend
default: build
build:
docker build -t $(DOCKER_TAG) .
run: build
docker run $(DOCKER_TAG)
shell: build
docker run --rm -it $(DOCKER_TAG) /bin/bash
FROM python:3.8
# system packages installation
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
# pre trained models download
WORKDIR /data_models
RUN mkdir -p /data_models/places365/
RUN mkdir -p /data_models/im2txt/
RUN mkdir -p /root/.cache/torch/hub/checkpoints/
RUN curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/places365_model.tar.gz | tar -zxC /data_models/places365/
RUN curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/im2txt_model.tar.gz | tar -zxC /data_models/im2txt/
RUN curl -SL https://s3.eu-central-1.amazonaws.com/ownphotos-deploy/im2txt_data.tar.gz | tar -zxC /data_models/im2txt/
RUN curl -SL https://download.pytorch.org/models/resnet152-b121ed2d.pth -o /root/.cache/torch/hub/checkpoints/resnet152-b121ed2d.pth
# actual project
WORKDIR /code
RUN git clone https://github.com/LibrePhotos/librephotos.git .
RUN pip install -r requirements.txt
RUN python -m spacy download en_core_web_sm
EXPOSE 80
# TODO: prod vs dev requirements using docker-compose args
# TODO: in dev copiare anche i vscode settings
\ No newline at end of file
#! /bin/bash
export PYTHONUNBUFFERED=TRUE
mkdir -p /logs
python image_similarity/main.py 2>&1 | tee /logs/gunicorn_image_similarity.log &
python manage.py showmigrations | tee /logs/show_migrate.log
python manage.py migrate | tee /logs/command_migrate.log
python manage.py showmigrations | tee /logs/show_migrate.log
python manage.py build_similarity_index 2>&1 | tee /logs/command_build_similarity_index.log
python manage.py createadmin -u $ADMIN_USERNAME $ADMIN_EMAIL 2>&1 | tee /logs/command_createadmin.log
echo "Running backend server..."
python manage.py rqworker default 2>&1 | tee /logs/rqworker.log &
gunicorn --worker-class=gevent --timeout $WORKER_TIMEOUT --bind backend:8001 --log-level=info ownphotos.wsgi 2>&1 | tee /logs/gunicorn_django.log
\ No newline at end of file
# Run options:
# 1. There are no options - This add additional tools to aid in the development of Libre Photos
# run cmd: docker-compose up -f docker-compose.yml -f docker-compose.dev.yml -d
# 2. Current added tools:
# pgadmin User admin@admin pass admin port 3001
# DO NOT EDIT
# The .env file has everything you need to edit.
# Run options:
# 1. Use prebuilt images (preferred method):
# run cmd: docker-compose up -d
# 2. Build images on your own machine:
# build cmd: COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose build
# run cmd: docker-compose up -d
version: '3.8'
services:
frontend:
tty: true
build:
context: .
dockerfile: frontend/Dockerfile
backend:
tty: true
build:
context: .
dockerfile: backend/Dockerfile
volumes:
- ./backend/entrypoint.sh:/entrypoint.sh
- ${myPhotos}:/data
- ${proMedia}:/protected_media
- ${logLocation}:/logs
- ${codedir}:/code
- ${cachedir}:/root/.cache
pgadmin:
container_name: librephotos_pgadmin
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-admin@admin.com}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
volumes:
- $HOME/pgadmin:/root/.pgadmin
ports:
- "3001:80"
restart: unless-stopped
\ No newline at end of file
# DO NOT EDIT
# The .env file has everything you need to edit.
# Run options:
# 1. Use prebuilt images (preferred method):
# run cmd: docker-compose up -d
# 2. Build images on your own machine:
# build cmd: COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose build
# run cmd: docker-compose up -d
version: '3.8'
services:
proxy:
image: nginx
restart: always
volumes:
- ./proxy/nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- ${httpPort}:80
depends_on:
- backend
- frontend
db:
image: postgres
restart: always
environment:
- POSTGRES_USER=${dbUser}
- POSTGRES_PASSWORD=${dbPass}
- POSTGRES_DB=${dbName}
volumes:
- ${dbLocation}:/var/lib/postgresql/data
command: postgres -c fsync=off -c synchronous_commit=off -c full_page_writes=off -c random_page_cost=1.0
healthcheck:
test: ['CMD-SHELL', 'pg_isready -d $dbName -U $dbUser']
interval: 5s
timeout: 5s
retries: 5
frontend:
image: reallibrephotos/librephotos-frontend:${tag}
command: /entrypoint.sh
restart: always
volumes:
- ./frontend/entrypoint.sh:/entrypoint.sh
depends_on:
- backend
backend:
image: reallibrephotos/librephotos:${tag}
restart: always
command: /entrypoint.sh
volumes:
- ./backend/entrypoint.sh:/entrypoint.sh
- ${myPhotos}:/data
- ${proMedia}:/protected_media
- ${logLocation}:/logs
- ${cachedir}:/root/.cache
environment:
- SECRET_KEY=${shhhhKey}
- BACKEND_HOST=backend
- ADMIN_EMAIL=${adminEmail}
- ADMIN_USERNAME=${userName}
- ADMIN_PASSWORD=${userPass}
- DEBUG=true
- DB_BACKEND=postgresql
- DB_NAME=${dbName}
- DB_USER=${dbUser}
- DB_PASS=${dbPass}
- DB_HOST=db
- DB_PORT=5432
- REDIS_HOST=redis
- REDIS_PORT=6379
- MAPBOX_API_KEY=${mapApiKey}
- TIME_ZONE=${timeZone}
- WEB_CONCURRENCY=${gunniWorkers}
- WORKER_TIMEOUT=${workerTimeOut}
- SKIP_PATTERNS=${skipPatterns}
# Wait for Postgres
depends_on:
db:
condition: service_healthy
redis:
image: redis
restart: always
\ No newline at end of file
FROM node
RUN apt-get update && apt-get install -y curl git xsel
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN npm install -g npm
ENV CLI_WIDTH 80
RUN git clone https://github.com/LibrePhotos/librephotos-frontend.git /usr/src/app
RUN npm ci
RUN npm install -g serve
EXPOSE 3000
RUN npm run build
RUN ["chmod", "+x", "./run.sh" ]
\ No newline at end of file
#!/usr/bin/env bash
#echo "building frontend"
#npm run build
echo "serving frontend"
serve build -d -l 3000
# DANGEROUSLY_DISABLE_HOST_CHECK=true HOST=0.0.0.0 npm start
\ No newline at end of file
# This file contains all the things you need to change to set up your Libre Photos.
# There are a few items that must be set for it to work such as the location of your photos.
# After the mandatory entry's there are some optional ones that you may set.
# Start of mandatory changes.
# Location of your photos.
myPhotos=./librephotos/pictures
# Comma delimited list of patterns to ignore (e.g. "@eaDir,#recycle" for synology devices)
skipPatterns=
# The location where you would like to store the log files. The full path must exist as it will not be created for you.
logLocation=./librephotos/logs/
# Protected media directory. This is where we store some files like the thumbnails of your images.
proMedia=./librephotos/media
# Where shall we store the backend and frontend code files.
codedir=./librephotos/code
# Where shall we store the cache files.
cachedir=./librephotos/cache
# Where shall we store the database.
dbLocation=./librephotos/data
# Username for the Administrator login.
userName=admin
# Password for the administrative user you set above.
userPass=admin
# Email for the administrative user.
adminEmail=admin@example.com
# Secret Key. Get one here https://rb.gy/emgmwo (Shortened random.org link)
shhhhKey=D2VymuMn2gAhx4tmAawd
# Time zone https://docs.djangoproject.com/en/3.1/ref/settings/#std:setting-TIME_ZONE
timeZone=America/Denver
#What port should Libre Photos be accessed at (Default 3000)
httpPort=3000
# ------------------------------------------------------------------------------------------------
# Wow, we are at the optional now. Pretty easy so far. You do not have to change any of the below.
# Do you want to see on a map where all your photos where taken (if a location is stored in your photos)
# Get a Map box API Key https://account.mapbox.com/auth/signup/
mapApiKey=
# What branch should we install the stable or the development branch (dev)
# NOTE: only the dev branch is currently supported as we are working towards the stable version.
tag=dev
# You can set the database name. Did you know Libre Photos was forked from OwnPhotos?
dbName=ownphotos
# Here you can change the user name for the database.
dbUser=docker
# The password used by the database.
dbPass=AaAa1234
# This setting can dramatically affect how resource-intensive and the speed of scanning photos
# A positive integer generally in the 2-4 x $(NUM_CORES) range.
# You’ll want to vary this a bit to find the best for your particular workload.
# Each worker needs 800MB of RAM. Change at your own will. Default is 2.
gunniWorkers=2
# Gunicorn worker timeout seconds (ensure that one bad request doesn't stall other requests forever)
workerTimeOut=1800
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log debug;
events {
worker_connections 1024;
}
http {
server {
listen 80;
location / {
# React routes are entirely on the App side in the web broswer
# Always proxy to root with the same page request when nginx 404s
error_page 404 /;
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_pass http://frontend:3000/;
}
location /api {
proxy_pass http://backend/api;
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment