WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 9648cfd

Browse files
committed
Use nginx for production ready serving
publish docker image to registry on push
1 parent 5235bbf commit 9648cfd

File tree

4 files changed

+260
-17
lines changed

4 files changed

+260
-17
lines changed

.dockerignore

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
### Node template
2+
# Logs
3+
logs
4+
*.log
5+
npm-debug.log*
6+
yarn-debug.log*
7+
yarn-error.log*
8+
lerna-debug.log*
9+
.pnpm-debug.log*
10+
11+
# Diagnostic reports (https://nodejs.org/api/report.html)
12+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
13+
14+
# Runtime data
15+
pids
16+
*.pid
17+
*.seed
18+
*.pid.lock
19+
20+
# Directory for instrumented libs generated by jscoverage/JSCover
21+
lib-cov
22+
23+
# Coverage directory used by tools like istanbul
24+
coverage
25+
*.lcov
26+
27+
# nyc test coverage
28+
.nyc_output
29+
30+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
31+
.grunt
32+
33+
# Bower dependency directory (https://bower.io/)
34+
bower_components
35+
36+
# node-waf configuration
37+
.lock-wscript
38+
39+
# Compiled binary addons (https://nodejs.org/api/addons.html)
40+
build/Release
41+
42+
# Dependency directories
43+
node_modules/
44+
jspm_packages/
45+
46+
# Snowpack dependency directory (https://snowpack.dev/)
47+
web_modules/
48+
49+
# TypeScript cache
50+
*.tsbuildinfo
51+
52+
# Optional npm cache directory
53+
.npm
54+
55+
# Optional eslint cache
56+
.eslintcache
57+
58+
# Optional stylelint cache
59+
.stylelintcache
60+
61+
# Microbundle cache
62+
.rpt2_cache/
63+
.rts2_cache_cjs/
64+
.rts2_cache_es/
65+
.rts2_cache_umd/
66+
67+
# Optional REPL history
68+
.node_repl_history
69+
70+
# Output of 'npm pack'
71+
*.tgz
72+
73+
# Yarn Integrity file
74+
.yarn-integrity
75+
76+
# dotenv environment variable files
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
106+
# Docusaurus cache and generated files
107+
.docusaurus
108+
109+
# Serverless directories
110+
.serverless/
111+
112+
# FuseBox cache
113+
.fusebox/
114+
115+
# DynamoDB Local files
116+
.dynamodb/
117+
118+
# TernJS port file
119+
.tern-port
120+
121+
# Stores VSCode versions used for testing VSCode extensions
122+
.vscode-test
123+
124+
# yarn v2
125+
.yarn/cache
126+
.yarn/unplugged
127+
.yarn/build-state.yml
128+
.yarn/install-state.gz
129+
.pnp.*
130+
131+
# IntelliJ project files
132+
.idea
133+
*.iml
134+
gen
135+
136+
cypress/
137+
.husky/
138+
.github/
139+
doc/
140+
e2e/

.github/workflows/docker.yml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,50 @@ on:
33
push:
44
branches-ignore:
55
- gh-pages
6+
env:
7+
REGISTRY: ghcr.io
8+
IMAGE_NAME: ${{ github.repository }}
69
jobs:
7-
build:
10+
build-and-publish:
811
name: Build
912
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
packages: write
1016
steps:
1117
- name: Checkout code
1218
uses: actions/checkout@v4
13-
- name: Build an image from Dockerfile
14-
run: docker build -t trivy-explorer .
19+
- name: Log in to the Container registry
20+
uses: docker/login-action@v3
21+
with:
22+
registry: ${{ env.REGISTRY }}
23+
username: ${{ github.actor }}
24+
password: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Extract metadata (tags, labels) for Docker
27+
id: meta
28+
uses: docker/metadata-action@v5
29+
with:
30+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
31+
tags: |
32+
type=raw,value=latest,enable={{is_default_branch}}
33+
type=semver,pattern={{version}},enable={{is_default_branch}}
34+
type=semver,pattern={{major}}.{{minor}},enable={{is_default_branch}}
35+
type=semver,pattern={{major}},enable={{is_default_branch}}
36+
type=sha,format=long
37+
38+
- name: Build and push Docker image
39+
id: build-and-push
40+
uses: docker/build-push-action@v5
41+
with:
42+
context: .
43+
push: 'true'
44+
tags: ${{ steps.meta.outputs.tags }}
45+
labels: ${{ steps.meta.outputs.labels }}
1546
- name: Run Trivy vulnerability scanner
1647
uses: aquasecurity/[email protected]
1748
with:
18-
image-ref: "trivy-explorer"
49+
image-ref: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.build-and-push.outputs.digest }}"
1950
output: trivy-report.json
2051
format: json
2152
exit-code: "0"

Dockerfile

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
FROM node:22.13.1-alpine3.21
2-
# install simple http server for serving static content
3-
RUN npm install -g http-server
1+
# Build stage
2+
FROM node:22.13.1-alpine3.21 as build
43

5-
# make the 'app' folder the current working directory
64
WORKDIR /app
7-
8-
# copy both 'package.json' and 'package-lock.json' (if available)
95
COPY package*.json ./
6+
RUN npm ci
7+
COPY . .
8+
RUN npm run build
109

11-
# install project dependencies
12-
RUN npm install
10+
# Production stage
11+
FROM nginx:alpine-slim
1312

14-
# copy project files and folders to the current working directory (i.e. 'app' folder)
15-
COPY . .
13+
# Copy built files from build stage
14+
COPY --from=build /app/dist /usr/share/nginx/html
1615

17-
# build app for production with minification
18-
RUN npm run build
16+
# Copy nginx configuration
17+
COPY nginx.conf /etc/nginx/nginx.conf
18+
RUN rm -r /etc/nginx/conf.d
1919

2020
EXPOSE 8080
21-
CMD [ "http-server", "dist" ]
21+
CMD ["nginx", "-g", "daemon off;"]

nginx.conf

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
user nginx;
2+
worker_processes auto;
3+
4+
error_log /var/log/nginx/error.log notice;
5+
pid /var/run/nginx.pid;
6+
7+
events {
8+
worker_connections 1024;
9+
}
10+
11+
http {
12+
include /etc/nginx/mime.types;
13+
default_type application/octet-stream;
14+
15+
# Security headers
16+
add_header X-Frame-Options "SAMEORIGIN" always;
17+
add_header X-XSS-Protection "1; mode=block" always;
18+
add_header X-Content-Type-Options "nosniff" always;
19+
add_header Referrer-Policy "no-referrer-when-downgrade" always;
20+
add_header Content-Security-Policy "default-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data:;" always;
21+
add_header Permissions-Policy "geolocation=(), midi=(), sync-xhr=(), microphone=(), camera=(), magnetometer=(), gyroscope=(), fullscreen=(self), payment=()" always;
22+
23+
# Logging
24+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
25+
'$status $body_bytes_sent "$http_referer" '
26+
'"$http_user_agent" "$http_x_forwarded_for"';
27+
28+
access_log /var/log/nginx/access.log main;
29+
30+
sendfile on;
31+
tcp_nopush on;
32+
tcp_nodelay on;
33+
34+
keepalive_timeout 65;
35+
36+
# Gzip compression
37+
gzip on;
38+
gzip_vary on;
39+
gzip_min_length 10240;
40+
gzip_proxied expired no-cache no-store private auth;
41+
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/javascript;
42+
gzip_disable "MSIE [1-6]\.";
43+
44+
server {
45+
listen 8080;
46+
server_name localhost;
47+
root /usr/share/nginx/html;
48+
location /trivy-vulnerability-explorer {
49+
# Remove root directive since base path is already set in root above
50+
# root /usr/share/nginx/html;
51+
alias /usr/share/nginx/html;
52+
index index.html;
53+
try_files $uri $uri/ /trivy-vulnerability-explorer/index.html;
54+
}
55+
56+
# Security measures
57+
location ~ /\. {
58+
deny all;
59+
}
60+
61+
location = /favicon.ico {
62+
log_not_found off;
63+
access_log off;
64+
}
65+
66+
# Error pages
67+
error_page 500 502 503 504 /50x.html;
68+
location = /50x.html {
69+
root /usr/share/nginx/html;
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)