Skip to content

Commit 2dbe649

Browse files
docker
1 parent 9f4f003 commit 2dbe649

10 files changed

+26
-33
lines changed

.env.example

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
PORT=3000
2-
HOST=localhost
3-
ENV=development
2+
HOST=0.0.0.0
43
HTTPS=false
5-
6-
# Could be left empty if you don't want to use it
7-
# API_KEY=
8-
# CLUSTER=false
4+
EXPOSE_PORT=3000 # only used with docker-compose

.gitlab-ci.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ stages:
99

1010
variables:
1111
NODE_VERSION: "18.17.0"
12-
PM2: "servant"
12+
PM2: "feed-renderer"
1313

1414
deploy-job:
1515
stage: deploy
@@ -29,7 +29,6 @@ deploy-job:
2929
git pull &&
3030
/home/$SSH_USER/.nvm/versions/node/v$NODE_VERSION/bin/pnpm i &&
3131
/home/$SSH_USER/.nvm/versions/node/v$NODE_VERSION/bin/pnpm build &&
32-
pm2 restart $PM2 &&
3332
notifier '$CI_PROJECT_TITLE deployed'"
3433
only:
3534
- main

Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ RUN pnpm build
1313

1414
ENV PORT=3000
1515
ENV HOST=0.0.0.0
16-
ENV ENV=development
1716
ENV HTTPS=false
1817

1918
EXPOSE 3000

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Some podcast services offer a RSS feed with HTML render if RSS feed is requested
1717

1818
### Docker
1919

20-
You can use `docker-compose` or `docker` to run the application.
20+
You can use `docker compose` or `docker` to run the application.
2121

2222
#### Docker compose
2323

@@ -30,16 +30,16 @@ cp .env.example .env
3030
Docker compose will use the `.env` file to set environment variables.
3131

3232
```bash
33-
docker-compose up -d
33+
docker compose up -d
3434
```
3535

3636
#### Docker image
3737

3838
Build and run the docker image
3939

4040
```bash
41-
docker build -t feed-renderer .
42-
docker run -it -p 3000:3000 feed-renderer
41+
docker build -t feed_renderer:app .
42+
docker run -it -p 3000:3000 feed_renderer:app
4343
```
4444

4545
### Local

docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
version: "3"
33
services:
44
feed_renderer:
5-
container_name: feed_renderer
5+
container_name: app
66
build:
77
context: .
88
dockerfile: Dockerfile
99
ports:
10-
- "${PORT}:3000"
10+
- "${EXPOSE_PORT}:${PORT}"
1111
env_file: .env
1212
restart: always

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
"type": "module",
77
"main": "index.js",
88
"scripts": {
9-
"start": "listhen ./dist/index.js",
9+
"start": "listhen --public=false ./dist/index.js",
1010
"dev": "listhen -w ./src/index.ts",
1111
"build": "tsup",
1212
"build:fix": "esno scripts/postbuild.ts",
13-
"preview": "node ./dist/index.js",
1413
"test": "vitest",
1514
"coverage": "vitest run --coverage",
1615
"lint": "eslint .",

src/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { createApp } from 'h3'
22
import { router } from './router'
3+
import { Dotenv } from './services'
4+
5+
const dotenv = Dotenv.load()
6+
console.error(dotenv)
37

48
export const app = createApp()
59
app.use(router)

src/node.ts

-7
This file was deleted.

src/services/dotenv.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable n/prefer-global/process */
12
import 'dotenv/config'
23

34
interface IDotenv {
@@ -6,30 +7,29 @@ interface IDotenv {
67
HTTPS: boolean
78
BASE_URL: string
89
IS_DEV: boolean
10+
NODE_ENV?: string
911
}
1012

1113
export class Dotenv {
1214
public static load(): IDotenv {
13-
// eslint-disable-next-line n/prefer-global/process
14-
const current = process
15-
16-
let port = current.env.PORT ?? 3000
15+
let port = process.env.PORT ?? 3000
1716
port = Number(port)
18-
const host = current.env.HOST ?? 'localhost'
19-
const https = current.env.HTTPS === 'true'
17+
const host = process.env.HOST ?? '0.0.0.0'
18+
const https = process.env.HTTPS === 'true'
2019
const prefix = https ? 'https' : 'http'
21-
const isDev = current.env.ENV === 'development'
20+
const isProduction = process.env.NODE_ENV === 'production'
2221

2322
let baseURL = `${prefix}://${host}`
24-
if (isDev)
23+
if (!isProduction)
2524
baseURL = `${baseURL}:${port}`
2625

2726
return {
2827
PORT: port,
2928
HOST: host,
3029
HTTPS: https,
3130
BASE_URL: baseURL,
32-
IS_DEV: isDev,
31+
NODE_ENV: process.env.NODE_ENV,
32+
IS_DEV: !isProduction,
3333
}
3434
}
3535
}

tsup.config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ export default <Options>{
1010
format: ['cjs', 'esm'],
1111
dts: false,
1212
onSuccess: 'npm run build:fix',
13+
env: {
14+
NODE_ENV: 'production',
15+
},
1316
}

0 commit comments

Comments
 (0)