Cache and gzip assets in docker

This commit is contained in:
Haishan 2022-05-08 22:47:42 +08:00
parent e8f927bfd3
commit d0c0c701e6
6 changed files with 43 additions and 0 deletions

View file

@ -37,6 +37,7 @@ rules:
# disable this temporarily since we have a lot of JS files
# and typescript-eslint runs against JS files too
'@typescript-eslint/explicit-module-boundary-types': off
'@typescript-eslint/ban-ts-comment': 'off'
'@typescript-eslint/ban-ts-ignore': 'off'
react-hooks/rules-of-hooks: error
react-hooks/exhaustive-deps:

View file

@ -1,5 +1,8 @@
on: [push]
name: Deploy workflow
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true
jobs:
install:
runs-on: ubuntu-20.04

1
.gitignore vendored
View file

@ -12,3 +12,4 @@ experimental/
deploy_ghpages.sh
tags
.eslintcache
__test_*.sh

View file

@ -11,6 +11,7 @@ RUN pnpm build \
&& rm public/*.map || true
FROM --platform=$TARGETPLATFORM nginx:alpine
COPY docker/nginx-default.conf /etc/nginx/conf.d/default.conf
RUN rm -rf /usr/share/nginx/html/*
COPY --from=builder /app/public /usr/share/nginx/html
ENV YACD_DEFAULT_BACKEND "http://127.0.0.1:9090"

View file

@ -13,6 +13,12 @@ The site [http://yacd.haishan.me](http://yacd.haishan.me) is served with HTTP no
- Docker Hub [`haishanh/yacd`](https://hub.docker.com/r/haishanh/yacd)
- GitHub Container Registry [`ghcr.io/haishanh/yacd`](https://github.com/haishanh/yacd/pkgs/container/yacd)
```sh
docker run -p 1234:80 -d --name yacd --rm ghcr.io/haishanh/yacd:master
# and then open http://localhost:1234 in your browser
```
**Supported URL query params**
| Param | Description |

31
docker/nginx-default.conf Normal file
View file

@ -0,0 +1,31 @@
server {
listen 80;
server_name localhost;
# access_log /var/log/nginx/host.access.log main;
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location ~ assets\/.*\.(?:css|js|woff2?|svg|gif|map)$ {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
add_header Cache-Control "max-age=31536000";
# access_log off;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}