Commit f0f1637b authored by Mattias Lundmark's avatar Mattias Lundmark
Browse files

DEICH-4691 Added image caching with nginx before image-api

parent f84ad7f9
......@@ -111,6 +111,14 @@
only:
changes: [ "Makefile", ".gitlab-ci.yml", "*.sh", "image-api/**/*"]
build-image-cache:
variables:
APPLICATION_NAME: image-cache
extends:
- .build-application
only:
changes: [ "Makefile", ".gitlab-ci.yml", "*.sh", "image-cache/**/*"]
build-katalog:
variables:
APPLICATION_NAME: katalog
......@@ -291,6 +299,15 @@
only:
changes: [ "Makefile", ".gitlab-ci.yml", "*.sh", "image-api/**/*"]
deploy-image-cache-test:
extends:
- .devtest
- .deploy-scp
variables:
APPLICATION_NAME: image-cache
only:
changes: [ "Makefile", ".gitlab-ci.yml", "*.sh", "image-cache/**/*"]
deploy-katalog-test:
extends:
- .devtest
......@@ -571,6 +588,17 @@
- master
changes: [ "Makefile", ".gitlab-ci.yml", "*.sh", "image-api/**/*"]
push-image-cache-latest:
extends:
- .push
when: on_success
variables:
APPLICATION_NAME: image-cache
only:
refs:
- master
changes: [ "Makefile", ".gitlab-ci.yml", "*.sh", "image-cache/**/*"]
push-katalog-latest:
extends:
- .push
......
......@@ -98,6 +98,15 @@ services:
org.label-schema.description: "API Integration for Deichman for Kafka Topic and REST services at Oslo Kommune FRONT"
no.deichman.label.component-category: "Backend"
image-cache:
build:
context: image-cache
labels:
<<: *common-labels
org.label-schema.name: "Image cache"
org.label-schema.description: "This is the image/media cache to avoid requests to image-api"
no.deichman.label.component-category: "Backend"
image-api:
build:
context: image-api
......
......@@ -14,6 +14,7 @@ volumes:
koha_state: {}
minio_data: {}
minio_cfg: {}
image_cache_data: {}
x-logging:
&default-logging
......@@ -222,13 +223,27 @@ services:
max-size: "1m"
max-file: "3"
image-cache:
image: "digibib/image-cache:${TAG:-latest}"
labels:
traefik.enable: "true"
traefik.http.routers.image-cache.entrypoints: "web"
traefik.http.services.image-cache.loadbalancer.server.port: "8080"
traefik.http.routers.image-cache.rule: "HostRegexp(`{hostname:(images)\\..*}`)"
networks:
- deichman-dev
volumes:
- "image_cache_data:/var/cache/nginx"
restart: ${RESTART_POLICY:-no}
logging: *default-logging
image-api:
image: "digibib/image-api:${TAG:-latest}"
labels:
traefik.enable: "true"
traefik.http.routers.image-api.entrypoints: "web"
traefik.http.services.image-api.loadbalancer.server.port: "9001"
traefik.http.routers.image-api.rule: "HostRegexp(`{hostname:(images)\\..*}`)"
traefik.http.routers.image-api.rule: "HostRegexp(`{hostname:(image-api)\\..*}`)"
networks:
- deichman-dev
restart: ${RESTART_POLICY:-no}
......
FROM nginx
COPY ./nginx.conf /etc/nginx/nginx.conf
\ No newline at end of file
events {
worker_connections 1024;
}
http {
# Set cache dir
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:10m max_size=1000m;
# Set cache key to include identifying components
proxy_cache_key $scheme$proxy_host$request_uri;
client_max_body_size 10M;
# Add cache status to log
log_format cache '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" cs=$upstream_cache_status';
server {
listen 8080;
server_name image-cache;
## Access and error logs.
access_log /var/log/nginx/api-proxy.access.log cache;
error_log /var/log/nginx/api-cache.error.log;
add_header X-Cache-Status $upstream_cache_status;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://image-api:9001;
proxy_cache one;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
proxy_cache_valid 200 302 30m;
proxy_cache_valid 404 1m;
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment