Skip to content

Commit

Permalink
Add cache (#3)
Browse files Browse the repository at this point in the history
* Added cache service

* added volumes to cache

Co-authored-by: Ben Edery <47628503+benedery@users.noreply.github.com>
  • Loading branch information
shacharmo and benedery authored Jan 2, 2020
1 parent 3aa3016 commit cf0b6cf
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Dockerfile-cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM nginx

RUN mkdir -p /var/lib/nginx/cache && \
chown www-data /var/lib/nginx/cache && \
chmod 700 /var/lib/nginx/cache

COPY nginx.conf /etc/nginx/nginx.conf
2 changes: 2 additions & 0 deletions aws_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
eval $(aws ecr get-login --no-include-email)
docker tag "sefaria-docker_web:latest" "058331968334.dkr.ecr.eu-central-1.amazonaws.com/shitufta-sefaria-api:latest"
docker tag "sefaria-docker_mongo:latest" "058331968334.dkr.ecr.eu-central-1.amazonaws.com/shitufta-sefaria-db:latest"
docker tag "sefaria-docker_cache:latest" "058331968334.dkr.ecr.eu-central-1.amazonaws.com/shitufta-cache-api:latest"
docker push "058331968334.dkr.ecr.eu-central-1.amazonaws.com/shitufta-sefaria-api:latest"
docker push "058331968334.dkr.ecr.eu-central-1.amazonaws.com/shitufta-sefaria-db:latest"
docker push "058331968334.dkr.ecr.eu-central-1.amazonaws.com/shitufta-cache-api:latest"
12 changes: 12 additions & 0 deletions docker-compose.cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ services:
depends_on:
- mongo
- redis
cache:
restart: always
image: 058331968334.dkr.ecr.eu-central-1.amazonaws.com/shitufta-cache-api
volumes:
- api-cache:/var/lib/nginx/cache
ports:
- "8080:80"
depends_on:
- web

volumes:
api-cache:
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ services:
depends_on:
- mongo
- redis
cache:
build:
context: .
dockerfile: Dockerfile-cache
ports:
- "8080:80"
depends_on:
- web
97 changes: 97 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# daemon off;
error_log /dev/stdout info;
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

# access_log /var/log/nginx/access.log main;
access_log /dev/stdout;


sendfile on;
#tcp_nopush on;

keepalive_timeout 65;


proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=backcache:8m max_size=1g;


server {
listen 80;

proxy_cache_key "$host$request_uri$cookie_user";
proxy_cache_valid 200 302 10h;
proxy_cache backcache;
proxy_cache_bypass $cookie_nocache $arg_nocache$arg_comment;
proxy_ignore_headers Set-Cookie;


chunked_transfer_encoding off;
# Enable Gzip compressed.
gzip on;

# Enable compression both for HTTP/1.0 and HTTP/1.1 (required for CloudFront).
gzip_http_version 1.0;

# Compression level (1-9).
# 5 is a perfect compromise between size and cpu usage, offering about
# 75% reduction for most ascii files (almost identical to level 9).
gzip_comp_level 5;

# Don't compress anything that's already small and unlikely to shrink much
# if at all (the default is 20 bytes, which is bad as that usually leads to
# larger files after gzipping).
gzip_min_length 256;

# Compress data even for clients that are connecting to us via proxies,
# identified by the "Via" header (required for CloudFront).
gzip_proxied any;

# Tell proxies to cache both the gzipped and regular version of a resource
# whenever the client's Accept-Encoding capabilities header varies;
# Avoids the issue where a non-gzip capable client (which is extremely rare
# today) would display gibberish if their proxy gave them the gzipped version.
gzip_vary on;

gzip_buffers 16 8k;

# Compress all output labeled with one of the following MIME-types.
gzip_types
application/atom+xml
application/javascript
application/json
application/rss+xml
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/svg+xml
image/x-icon
text/css
text/plain
text/x-component;
location / {
proxy_pass http://web:8000/api/;
}
}

# include /etc/nginx/conf.d/*.conf;
}

0 comments on commit cf0b6cf

Please sign in to comment.