Skip to content

Commit

Permalink
Cache and gzip assets in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
haishanh committed May 8, 2022
1 parent e8f927b commit d0c0c70
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ experimental/
deploy_ghpages.sh
tags
.eslintcache
__test_*.sh
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
31 changes: 31 additions & 0 deletions docker/nginx-default.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit d0c0c70

Please sign in to comment.