From d0c0c701e653529a8b619d7327fac793b1c3d705 Mon Sep 17 00:00:00 2001 From: Haishan Date: Sun, 8 May 2022 22:47:42 +0800 Subject: [PATCH] Cache and gzip assets in docker --- .eslintrc.yml | 1 + .github/workflows/push.yml | 3 +++ .gitignore | 1 + Dockerfile | 1 + README.md | 6 ++++++ docker/nginx-default.conf | 31 +++++++++++++++++++++++++++++++ 6 files changed, 43 insertions(+) create mode 100644 docker/nginx-default.conf diff --git a/.eslintrc.yml b/.eslintrc.yml index 2a9ebf3..d3b7d05 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -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: diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 070e54f..8e89353 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -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 diff --git a/.gitignore b/.gitignore index 07bf99f..479d673 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ experimental/ deploy_ghpages.sh tags .eslintcache +__test_*.sh diff --git a/Dockerfile b/Dockerfile index ce7dd83..6c6cb4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" diff --git a/README.md b/README.md index 5217837..979357c 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/docker/nginx-default.conf b/docker/nginx-default.conf new file mode 100644 index 0000000..3896e25 --- /dev/null +++ b/docker/nginx-default.conf @@ -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; + } +}