Skip to content

Commit d44c364

Browse files
Merge pull request #1 from linways/fix-compose
feat: update Dockerfile and add docker-compose for deployment
2 parents f2cb768 + c0647aa commit d44c364

6 files changed

Lines changed: 43 additions & 10 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,7 @@ typings/
7979

8080
# End of https://www.gitignore.io/api/node
8181

82-
.now
82+
.now
83+
84+
# Apache config (deployment-specific)
85+
math-api.conf

Dockerfile

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1-
FROM node:16-alpine
2-
WORKDIR /usr/src/app
1+
# Stage 1: Build
2+
FROM node:20-alpine AS build
3+
WORKDIR /app
34
COPY package.json yarn.lock ./
4-
RUN yarn install
5+
RUN yarn install --frozen-lockfile
56
COPY . .
6-
CMD yarn test
7+
RUN yarn tsc --project tsconfig.build.json
8+
9+
# Stage 2: Deploy
10+
FROM node:20-alpine
11+
WORKDIR /app
12+
COPY package.json yarn.lock ./
13+
RUN yarn install --frozen-lockfile --production && yarn cache clean
14+
COPY --from=build /app/dist ./
15+
COPY index.html ./
16+
17+
EXPOSE 3000
18+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
19+
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/?from=x || exit 1
20+
CMD ["node", "server.js"]

docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
math-api:
3+
build: .
4+
ports:
5+
- "3000:3000"
6+
restart: unless-stopped

index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ <h1>Math API</h1>
103103
</p>
104104
<h2>Usage</h2>
105105
<p style="font-size: 20px">
106-
https://math.vercel.app?from=<span class="equation"
106+
[host]/?from=<span class="equation"
107107
>[LaTeX Math Equation]</span
108108
>
109109
</p>
110110

111111
<h3>Block notation</h3>
112112
<p>
113-
https://math.vercel.app?<span class="notation">from</span>=<span
113+
[host]/?<span class="notation">from</span>=<span
114114
class="equation"
115115
>\frac{1}{\Gamma(s)}\int_{0}^{\infty}\frac{u^{s-1}}{e^{u}-1}\mathrm{d}u</span
116116
>
@@ -121,7 +121,7 @@ <h3>Block notation</h3>
121121

122122
<h3>Inline notation</h3>
123123
<p>
124-
https://math.vercel.app?<span class="notation">inline</span>=<span
124+
[host]/?<span class="notation">inline</span>=<span
125125
class="equation"
126126
>\frac{1}{\Gamma(s)}\int_{0}^{\infty}\frac{u^{s-1}}{e^{u}-1}\mathrm{d}u</span
127127
>
@@ -136,7 +136,7 @@ <h3>Color</h3>
136136
behavior by passing `color` parameter.
137137
</p>
138138
<p>
139-
https://math.vercel.app?<span class="equation">color</span>=<span
139+
[host]/?<span class="equation">color</span>=<span
140140
class="notation"
141141
>red</span
142142
>&from=\frac{1}{\Gamma(s)}\int_{0}^{\infty}\frac{u^{s-1}}{e^{u}-1}\mathrm{d}u
@@ -152,7 +152,7 @@ <h3>Background Color</h3>
152152
can be used.
153153
</p>
154154
<p>
155-
https://math.vercel.app?<span class="equation">color</span>=<span
155+
[host]/?<span class="equation">color</span>=<span
156156
class="notation"
157157
>white</span
158158
>&<span class="equation">bgcolor</span>=<span class="notation"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": "1.0.0",
55
"author": "Yasuaki Uechi <y@uechi.io> (https://uechi.io/)",
66
"scripts": {
7+
"start": "ts-node server.ts",
78
"deploy": "vc",
89
"dev": "vc dev",
910
"rollout": "vc --target production && vc rm math --safe",

tsconfig.build.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./dist",
5+
"rootDir": "."
6+
},
7+
"include": ["*.ts"],
8+
"exclude": ["**/*.test.ts"]
9+
}

0 commit comments

Comments
 (0)