Skip to content
Snippets Groups Projects
Unverified Commit f24a8e13 authored by Niaz Faridani-Rad's avatar Niaz Faridani-Rad Committed by GitHub
Browse files

Merge pull request #78 from sickelap/setup_e2e_testing_environment_take2

allow to create separate environment for e2e tests
parents d3067a34 7c9353cf
No related branches found
No related tags found
No related merge requests found
.PHONY: default build run shell rename .PHONY: default build rename
include librephotos.env include librephotos.env
DOCKER_TAG ?= ownphotos-backend
REPLACE_NAMES=sed 's/__backend_name__/$(BACKEND_CONT_NAME)/g; s/__frontend_name__/$(FRONTEND_CONT_NAME)/g; s/__proxy_name__/$(PROXY_CONT_NAME)/g; s/__redis_name__/$(REDIS_CONT_NAME)/g; s/__db_name__/$(DB_CONT_NAME)/g; s/__pgadmin_name__/$(PGADMIN_CONT_NAME)/g; s/__network_name__/$(NETWORK_NAME)/g' REPLACE_NAMES=sed 's/__backend_name__/$(BACKEND_CONT_NAME)/g; s/__frontend_name__/$(FRONTEND_CONT_NAME)/g; s/__proxy_name__/$(PROXY_CONT_NAME)/g; s/__redis_name__/$(REDIS_CONT_NAME)/g; s/__db_name__/$(DB_CONT_NAME)/g; s/__pgadmin_name__/$(PGADMIN_CONT_NAME)/g; s/__network_name__/$(NETWORK_NAME)/g'
default: build default: build
build: build: build-backend build-frontend build-proxy
docker build -t $(DOCKER_TAG) .
run: build build-backend:
docker run $(DOCKER_TAG) docker build -t reallibrephotos/librephotos:latest backend
shell: build build-frontend:
docker run --rm -it $(DOCKER_TAG) /bin/bash docker build -t reallibrephotos/librephotos-frontend:latest frontend
build-proxy:
docker build -t reallibrephotos/librephotos-proxy:latest proxy
rename: rename:
$(REPLACE_NAMES) docker-compose.raw > docker-compose.yml $(REPLACE_NAMES) docker-compose.raw > docker-compose.yml
$(REPLACE_NAMES) docker-compose.dev.raw > docker-compose.dev.yml $(REPLACE_NAMES) docker-compose.dev.raw > docker-compose.dev.yml
$(REPLACE_NAMES) proxy/nginx.raw > proxy/nginx.conf $(REPLACE_NAMES) docker-compose.e2e.raw > docker-compose.e2e.yml
...@@ -25,7 +25,6 @@ services: ...@@ -25,7 +25,6 @@ services:
volumes: volumes:
- ${scanDirectory}:/data - ${scanDirectory}:/data
- ${data}/protected_media:/protected_media - ${data}/protected_media:/protected_media
- ./proxy/nginx.conf:/etc/nginx/nginx.conf:ro
__frontend_name__: __frontend_name__:
tty: true tty: true
......
...@@ -25,7 +25,6 @@ services: ...@@ -25,7 +25,6 @@ services:
volumes: volumes:
- ${scanDirectory}:/data - ${scanDirectory}:/data
- ${data}/protected_media:/protected_media - ${data}/protected_media:/protected_media
- ./proxy/nginx.conf:/etc/nginx/nginx.conf:ro
frontend: frontend:
tty: true tty: true
...@@ -54,8 +53,8 @@ services: ...@@ -54,8 +53,8 @@ services:
- ${scanDirectory}:/data - ${scanDirectory}:/data
- ${data}/protected_media:/protected_media - ${data}/protected_media:/protected_media
- ${data}/logs:/logs - ${data}/logs:/logs
- ${codedir}/librephotos:/code
- ${data}/cache:/root/.cache - ${data}/cache:/root/.cache
- ${codedir}/librephotos:/code
- ./vscode/server-extensions:/root/.vscode-server/extensions - ./vscode/server-extensions:/root/.vscode-server/extensions
- ./vscode/server-insiders-extensions:/root/.vscode-server-insiders/extensions - ./vscode/server-insiders-extensions:/root/.vscode-server-insiders/extensions
- ./vscode/settings.json:/code/.vscode/settings.json - ./vscode/settings.json:/code/.vscode/settings.json
......
networks:
e2e:
volumes:
e2e_db:
e2e_cache:
e2e_logs:
e2e_protected_media:
e2e_scan_directory:
services:
e2e-__proxy_name__:
image: reallibrephotos/librephotos-proxy:${tag}
container_name: e2e-__proxy_name__
restart: unless-stopped
environment:
BACKEND_NAME: e2e-__backend_name__
FRONTEND_NAME: e2e-__frontend_name__
volumes:
- e2e_scan_directory:/data
- e2e_protected_media:/protected_media
ports:
- 8080:80
healthcheck:
test: curl -sI localhost | grep HTTP | grep 200
interval: 5s
timeout: 5s
retries: 12
depends_on:
e2e-__backend_name__:
condition: service_healthy
e2e-__frontend_name__:
condition: service_healthy
networks:
- e2e
e2e-__db_name__:
image: postgres:13
container_name: e2e-__db_name__
restart: unless-stopped
environment:
- POSTGRES_USER=${dbUser}
- POSTGRES_PASSWORD=${dbPass}
- POSTGRES_DB=${dbName}
volumes:
- e2e_db:/var/lib/postgresql/data
healthcheck:
test: psql -U ${dbUser} -d ${dbName} -c "SELECT 1;"
interval: 5s
timeout: 5s
retries: 12
networks:
- e2e
e2e-__frontend_name__:
container_name: e2e-__frontend_name__
environment:
- DEBUG=1
- WDS_SOCKET_PORT=0 # needed for webpack-dev-server
tty: true
build:
context: ./frontend
dockerfile: Dockerfile.dev
restart: unless-stopped
volumes:
- ${codedir}/librephotos-frontend:/usr/src/app
healthcheck:
test: curl -sI localhost:3000 | grep HTTP | grep 200
interval: 5s
timeout: 5s
retries: 24
depends_on:
e2e-__backend_name__:
condition: service_healthy
networks:
- e2e
e2e-__backend_name__:
container_name: e2e-__backend_name__
tty: true
stdin_open: true
build:
context: ./backend
dockerfile: Dockerfile
args:
DEBUG: 1
restart: unless-stopped
volumes:
- ${codedir}/librephotos:/code
- e2e_scan_directory:/data
- e2e_protected_media:/protected_media
- e2e_logs:/logs
- e2e_cache:/root/.cache
environment:
- SECRET_KEY=${shhhhKey:-}
- BACKEND_HOST=e2e-__backend_name__
- ADMIN_EMAIL=${adminEmail:-admin@localhost}
- ADMIN_USERNAME=${userName:-admin}
- ADMIN_PASSWORD=${userPass:-admin}
- DB_BACKEND=postgresql
- DB_NAME=${dbName}
- DB_USER=${dbUser}
- DB_PASS=${dbPass}
- DB_HOST=e2e-__db_name__
- DB_PORT=5432
- REDIS_HOST=e2e-__redis_name__
- REDIS_PORT=6379
- MAPBOX_API_KEY=${mapApiKey:-}
- WEB_CONCURRENCY=${gunniWorkers:-1}
- SKIP_PATTERNS=${skipPatterns:-}
- ALLOW_UPLOAD=${allowUpload:-true}
- DEBUG=1
- HEAVYWEIGHT_PROCESS=${HEAVYWEIGHT_PROCESS:-1}
healthcheck:
test: curl -sI localhost:8001 | grep HTTP | grep 401
interval: 5s
timeout: 5s
retries: 24
depends_on:
e2e-__db_name__:
condition: service_healthy
e2e-__redis_name__:
condition: service_healthy
networks:
- e2e
e2e-__redis_name__:
image: redis:6
container_name: e2e-__redis_name__
restart: unless-stopped
healthcheck:
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
interval: 5s
timeout: 5s
retries: 12
networks:
- e2e
networks:
e2e:
volumes:
e2e_db:
e2e_cache:
e2e_logs:
e2e_protected_media:
e2e_scan_directory:
services:
e2e-proxy:
image: reallibrephotos/librephotos-proxy:${tag}
container_name: e2e-proxy
restart: unless-stopped
environment:
BACKEND_NAME: e2e-backend
FRONTEND_NAME: e2e-frontend
volumes:
- e2e_scan_directory:/data
- e2e_protected_media:/protected_media
ports:
- 8080:80
healthcheck:
test: curl -sI localhost | grep HTTP | grep 200
interval: 5s
timeout: 5s
retries: 12
depends_on:
e2e-backend:
condition: service_healthy
e2e-frontend:
condition: service_healthy
networks:
- e2e
e2e-db:
image: postgres:13
container_name: e2e-db
restart: unless-stopped
environment:
- POSTGRES_USER=${dbUser}
- POSTGRES_PASSWORD=${dbPass}
- POSTGRES_DB=${dbName}
volumes:
- e2e_db:/var/lib/postgresql/data
healthcheck:
test: psql -U ${dbUser} -d ${dbName} -c "SELECT 1;"
interval: 5s
timeout: 5s
retries: 12
networks:
- e2e
e2e-frontend:
container_name: e2e-frontend
environment:
- DEBUG=1
- WDS_SOCKET_PORT=0 # needed for webpack-dev-server
tty: true
build:
context: ./frontend
dockerfile: Dockerfile.dev
restart: unless-stopped
volumes:
- ${codedir}/librephotos-frontend:/usr/src/app
healthcheck:
test: curl -sI localhost:3000 | grep HTTP | grep 200
interval: 5s
timeout: 5s
retries: 24
depends_on:
e2e-backend:
condition: service_healthy
networks:
- e2e
e2e-backend:
container_name: e2e-backend
tty: true
stdin_open: true
build:
context: ./backend
dockerfile: Dockerfile
args:
DEBUG: 1
restart: unless-stopped
volumes:
- ${codedir}/librephotos:/code
- e2e_scan_directory:/data
- e2e_protected_media:/protected_media
- e2e_logs:/logs
- e2e_cache:/root/.cache
environment:
- SECRET_KEY=${shhhhKey:-}
- BACKEND_HOST=e2e-backend
- ADMIN_EMAIL=${adminEmail:-admin@localhost}
- ADMIN_USERNAME=${userName:-admin}
- ADMIN_PASSWORD=${userPass:-admin}
- DB_BACKEND=postgresql
- DB_NAME=${dbName}
- DB_USER=${dbUser}
- DB_PASS=${dbPass}
- DB_HOST=e2e-db
- DB_PORT=5432
- REDIS_HOST=e2e-redis
- REDIS_PORT=6379
- MAPBOX_API_KEY=${mapApiKey:-}
- WEB_CONCURRENCY=${gunniWorkers:-1}
- SKIP_PATTERNS=${skipPatterns:-}
- ALLOW_UPLOAD=${allowUpload:-true}
- DEBUG=1
- HEAVYWEIGHT_PROCESS=${HEAVYWEIGHT_PROCESS:-1}
healthcheck:
test: curl -sI localhost:8001 | grep HTTP | grep 401
interval: 5s
timeout: 5s
retries: 24
depends_on:
e2e-db:
condition: service_healthy
e2e-redis:
condition: service_healthy
networks:
- e2e
e2e-redis:
image: redis:6
container_name: e2e-redis
restart: unless-stopped
healthcheck:
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
interval: 5s
timeout: 5s
retries: 12
networks:
- e2e
...@@ -16,7 +16,6 @@ services: ...@@ -16,7 +16,6 @@ services:
volumes: volumes:
- ${scanDirectory}:/data - ${scanDirectory}:/data
- ${data}/protected_media:/protected_media - ${data}/protected_media:/protected_media
- ./proxy/nginx.conf:/etc/nginx/nginx.conf:ro
ports: ports:
- ${httpPort}:80 - ${httpPort}:80
depends_on: depends_on:
...@@ -34,13 +33,16 @@ services: ...@@ -34,13 +33,16 @@ services:
volumes: volumes:
- ${data}/db:/var/lib/postgresql/data - ${data}/db:/var/lib/postgresql/data
command: postgres -c fsync=off -c synchronous_commit=off -c full_page_writes=off -c random_page_cost=1.0 command: postgres -c fsync=off -c synchronous_commit=off -c full_page_writes=off -c random_page_cost=1.0
healthcheck:
test: psql -U ${dbUser} -d ${dbName} -c "SELECT 1;"
interval: 5s
timeout: 5s
retries: 5
__frontend_name__: __frontend_name__:
image: reallibrephotos/librephotos-frontend:${tag} image: reallibrephotos/librephotos-frontend:${tag}
container_name: __frontend_name__ container_name: __frontend_name__
restart: unless-stopped restart: unless-stopped
depends_on:
- __backend_name__
__backend_name__: __backend_name__:
image: reallibrephotos/librephotos:${tag} image: reallibrephotos/librephotos:${tag}
...@@ -51,13 +53,12 @@ services: ...@@ -51,13 +53,12 @@ services:
- ${data}/protected_media:/protected_media - ${data}/protected_media:/protected_media
- ${data}/logs:/logs - ${data}/logs:/logs
- ${data}/cache:/root/.cache - ${data}/cache:/root/.cache
environment: environment:
- SECRET_KEY=${shhhhKey} - SECRET_KEY=${shhhhKey:-}
- BACKEND_HOST=__backend_name__ - BACKEND_HOST=__backend_name__
- ADMIN_EMAIL=${adminEmail} - ADMIN_EMAIL=${adminEmail:-admin@localhost}
- ADMIN_USERNAME=${userName} - ADMIN_USERNAME=${userName:-admin}
- ADMIN_PASSWORD=${userPass} - ADMIN_PASSWORD=${userPass:-admin}
- DB_BACKEND=postgresql - DB_BACKEND=postgresql
- DB_NAME=${dbName} - DB_NAME=${dbName}
- DB_USER=${dbUser} - DB_USER=${dbUser}
...@@ -66,18 +67,24 @@ services: ...@@ -66,18 +67,24 @@ services:
- DB_PORT=5432 - DB_PORT=5432
- REDIS_HOST=__redis_name__ - REDIS_HOST=__redis_name__
- REDIS_PORT=6379 - REDIS_PORT=6379
- MAPBOX_API_KEY=${mapApiKey} - MAPBOX_API_KEY=${mapApiKey:-}
- WEB_CONCURRENCY=${gunniWorkers} - WEB_CONCURRENCY=${gunniWorkers:-1}
- SKIP_PATTERNS=${skipPatterns} - SKIP_PATTERNS=${skipPatterns:-}
- ALLOW_UPLOAD=${allowUpload} - ALLOW_UPLOAD=${allowUpload:-false}
- DEBUG=0 - DEBUG=0
- HEAVYWEIGHT_PROCESS=${HEAVYWEIGHT_PROCESS} - HEAVYWEIGHT_PROCESS=${HEAVYWEIGHT_PROCESS}
# Wait for Postgres
depends_on: depends_on:
- __db_name__ __db_name__:
condition: service_healthy
__redis_name__:
condition: service_healthy
__redis_name__: __redis_name__:
image: redis:6 image: redis:6
container_name: __redis_name__ container_name: __redis_name__
restart: unless-stopped restart: unless-stopped
healthcheck:
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
interval: 5s
timeout: 5s
retries: 12
...@@ -33,19 +33,16 @@ services: ...@@ -33,19 +33,16 @@ services:
volumes: volumes:
- ${data}/db:/var/lib/postgresql/data - ${data}/db:/var/lib/postgresql/data
command: postgres -c fsync=off -c synchronous_commit=off -c full_page_writes=off -c random_page_cost=1.0 command: postgres -c fsync=off -c synchronous_commit=off -c full_page_writes=off -c random_page_cost=1.0
#Checking health of Postgres db
healthcheck: healthcheck:
test: psql -U ${dbUser} -d ${dbName} -c "SELECT 1;" test: psql -U ${dbUser} -d ${dbName} -c "SELECT 1;"
interval: 5s interval: 5s
timeout: 5s timeout: 5s
retries: 5 retries: 5
frontend: frontend:
image: reallibrephotos/librephotos-frontend:${tag} image: reallibrephotos/librephotos-frontend:${tag}
container_name: frontend container_name: frontend
restart: unless-stopped restart: unless-stopped
depends_on:
- backend
backend: backend:
image: reallibrephotos/librephotos:${tag} image: reallibrephotos/librephotos:${tag}
...@@ -56,13 +53,12 @@ services: ...@@ -56,13 +53,12 @@ services:
- ${data}/protected_media:/protected_media - ${data}/protected_media:/protected_media
- ${data}/logs:/logs - ${data}/logs:/logs
- ${data}/cache:/root/.cache - ${data}/cache:/root/.cache
environment: environment:
- SECRET_KEY=${shhhhKey} - SECRET_KEY=${shhhhKey:-}
- BACKEND_HOST=backend - BACKEND_HOST=backend
- ADMIN_EMAIL=${adminEmail} - ADMIN_EMAIL=${adminEmail:-admin@localhost}
- ADMIN_USERNAME=${userName} - ADMIN_USERNAME=${userName:-admin}
- ADMIN_PASSWORD=${userPass} - ADMIN_PASSWORD=${userPass:-admin}
- DB_BACKEND=postgresql - DB_BACKEND=postgresql
- DB_NAME=${dbName} - DB_NAME=${dbName}
- DB_USER=${dbUser} - DB_USER=${dbUser}
...@@ -71,19 +67,24 @@ services: ...@@ -71,19 +67,24 @@ services:
- DB_PORT=5432 - DB_PORT=5432
- REDIS_HOST=redis - REDIS_HOST=redis
- REDIS_PORT=6379 - REDIS_PORT=6379
- MAPBOX_API_KEY=${mapApiKey} - MAPBOX_API_KEY=${mapApiKey:-}
- WEB_CONCURRENCY=${gunniWorkers} - WEB_CONCURRENCY=${gunniWorkers:-1}
- SKIP_PATTERNS=${skipPatterns} - SKIP_PATTERNS=${skipPatterns:-}
- ALLOW_UPLOAD=${allowUpload} - ALLOW_UPLOAD=${allowUpload:-false}
- DEBUG=0 - DEBUG=0
- HEAVYWEIGHT_PROCESS=${HEAVYWEIGHT_PROCESS} - HEAVYWEIGHT_PROCESS=${HEAVYWEIGHT_PROCESS}
# Wait for Postgres
depends_on: depends_on:
db: db:
condition: service_healthy condition: service_healthy
redis:
condition: service_healthy
redis: redis:
image: redis:6 image: redis:6
container_name: redis container_name: redis
restart: unless-stopped restart: unless-stopped
healthcheck:
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
interval: 5s
timeout: 5s
retries: 12
...@@ -2,7 +2,7 @@ FROM node:13-slim ...@@ -2,7 +2,7 @@ FROM node:13-slim
RUN mkdir -p /usr/src/app RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app WORKDIR /usr/src/app
RUN apt-get update && apt-get install git -y RUN apt-get update && apt-get install git curl -y
EXPOSE 3000 EXPOSE 3000
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
CMD ["/entrypoint.sh"] CMD ["/entrypoint.sh"]
FROM nginx FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf ENV BACKEND_NAME=${BACKEND_NAME:-backend}
ENV FRONTEND_NAME=${FRONTEND_NAME:-frontend}
ENV VAR_PREFIX='$'
COPY nginx.tpl /etc/nginx/nginx.tpl
ENTRYPOINT envsubst < /etc/nginx/nginx.tpl > /etc/nginx/nginx.conf; nginx -g 'daemon off;'
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_name__:3000/;
}
location ~ ^/(api|media)/ {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host __backend_name__;
include uwsgi_params;
proxy_pass http://__backend_name__:8001;
}
# needed for webpack-dev-server
location /ws {
proxy_pass http://__frontend_name__:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# Django media
location /protected_media {
internal;
alias /protected_media/;
}
location /static/drf-yasg {
proxy_pass http://__backend_name__:8001;
}
location /data {
internal;
alias /data/;
}
# Original Photos
location /original {
internal;
alias /data/;
}
# Nextcloud Original Photos
location /nextcloud_original {
internal;
alias /data/nextcloud_media/;
}
}
}
...@@ -12,25 +12,25 @@ http { ...@@ -12,25 +12,25 @@ http {
listen 80; listen 80;
location / { location / {
# React routes are entirely on the App side in the web broswer # React routes are entirely on the App side in the web browser
# Always proxy to root with the same page request when nginx 404s # Always proxy to root with the same page request when nginx 404s
error_page 404 /; error_page 404 /;
proxy_intercept_errors on; proxy_intercept_errors on;
proxy_set_header Host $host; proxy_set_header Host ${VAR_PREFIX}host;
proxy_pass http://frontend:3000/; proxy_pass http://${FRONTEND_NAME}:3000/;
} }
location ~ ^/(api|media)/ { location ~ ^/(api|media)/ {
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto ${VAR_PREFIX}scheme;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP ${VAR_PREFIX}remote_addr;
proxy_set_header Host backend; proxy_set_header Host ${BACKEND_NAME};
include uwsgi_params; include uwsgi_params;
proxy_pass http://backend:8001; proxy_pass http://${BACKEND_NAME}:8001;
} }
# needed for webpack-dev-server # needed for webpack-dev-server
location /ws { location /ws {
proxy_pass http://frontend:3000; proxy_pass http://${FRONTEND_NAME}:3000;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade ${VAR_PREFIX}http_upgrade;
proxy_set_header Connection "upgrade"; proxy_set_header Connection "upgrade";
} }
# Django media # Django media
...@@ -40,7 +40,7 @@ http { ...@@ -40,7 +40,7 @@ http {
} }
location /static/drf-yasg { location /static/drf-yasg {
proxy_pass http://backend:8001; proxy_pass http://${BACKEND_NAME}:8001;
} }
location /data { location /data {
......
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