Skip to content

Commit 52001e4

Browse files
authored
feat: docker (#77)
* fix: remote transporter mode property * chore: copy env from .env.example, use .env @root for Docker * chore: add db connexion error log * chore: remove notification method * chore: remove notification method * chore: Docker support * chore: refactoring env files * chore: type message as string * fix: env file path * fix: ci db password * chore: move env file copy in test job * chore: move env file copy in test job * fix: broken test * chore: force express 4.21.2 * fix: default import
1 parent bf0f6fc commit 52001e4

19 files changed

+301
-543
lines changed

.cliamrc.js

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ module.exports = {
1717
transporters: [
1818
{
1919
id: 'smtp-transporter',
20-
mode: 'smtp',
2120
auth: {
2221
username: "[email protected]",
2322
password: "5cDumYP68aFcpT15uV"

src/env/template.env .env.example

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ REFRESH_TOKEN_SECRET = "hello-i-am-a-refresh-token-secret-passphrase"
9898
# SSL_KEY = "path-to-my-ssl-key.pem"
9999

100100
# Database engine
101-
TYPEORM_TYPE = "mysql"
101+
TYPEORM_TYPE = "mariadb"
102102

103103
# Database connection identifier
104104
# TYPEORM_NAME = "default"
105105

106-
# Database server host
106+
# Database server host. Use "db" with docker-compose, localhost otherwise.
107107
TYPEORM_HOST = "localhost"
108108

109109
# Database name. Keep it different from your developement database.

.github/workflows/build.yml

+13-13
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ jobs:
1616
uses: actions/setup-node@v4
1717
with:
1818
node-version: '20.9.0'
19-
- name: Create directories
20-
run: mkdir -p ./dist/env && cp ./src/env/template.env ./dist/env/test.env
21-
- name: Setup .env file
22-
run: |
23-
echo FACEBOOK_CONSUMER_ID = "${{ secrets.FACEBOOK_CONSUMER_ID }}" >> ./dist/env/test.env
24-
echo FACEBOOK_CONSUMER_SECRET = "${{ secrets.FACEBOOK_CONSUMER_SECRET }}" >> ./dist/env/test.env
25-
echo GITHUB_CONSUMER_ID = "${{ secrets.GTHB_CONSUMER_ID }}" >> ./dist/env/test.env
26-
echo GITHUB_CONSUMER_SECRET = "${{ secrets.GTHB_CONSUMER_SECRET }}" >> ./dist/env/test.env
27-
echo GOOGLE_CONSUMER_ID = "${{ secrets.GOOGLE_CONSUMER_ID }}" >> ./dist/env/test.env
28-
echo GOOGLE_CONSUMER_SECRET = "${{ secrets.GOOGLE_CONSUMER_SECRET }}" >> ./dist/env/test.env
29-
echo LINKEDIN_CONSUMER_ID = "${{ secrets.LINKEDIN_CONSUMER_ID }}" >> ./dist/env/test.env
30-
echo LINKEDIN_CONSUMER_SECRET = "${{ secrets.LINKEDIN_CONSUMER_SECRET }}" >> ./dist/env/test.env
3119
- name: Install global dependencies
3220
run: npm i [email protected] -g
3321
- name: Install local dependencies
@@ -60,11 +48,23 @@ jobs:
6048
with:
6149
mysql version: '5.7'
6250
mysql database: 'typeplate_test'
63-
mysql root password: passw0rd
51+
mysql root password: passw0rd
6452
- name: Install global dependencies
6553
run: npm i [email protected] -g
6654
- name: Install local dependencies
6755
run: npm i
56+
- name: Copy .env.example to .env.test
57+
run: cp .env.example .env.test
58+
- name: Setup .env file
59+
run: |
60+
echo FACEBOOK_CONSUMER_ID = "${{ secrets.FACEBOOK_CONSUMER_ID }}" >> .env.test
61+
echo FACEBOOK_CONSUMER_SECRET = "${{ secrets.FACEBOOK_CONSUMER_SECRET }}" >> .env.test
62+
echo GITHUB_CONSUMER_ID = "${{ secrets.GTHB_CONSUMER_ID }}" >> .env.test
63+
echo GITHUB_CONSUMER_SECRET = "${{ secrets.GTHB_CONSUMER_SECRET }}" >> .env.test
64+
echo GOOGLE_CONSUMER_ID = "${{ secrets.GOOGLE_CONSUMER_ID }}" >> .env.test
65+
echo GOOGLE_CONSUMER_SECRET = "${{ secrets.GOOGLE_CONSUMER_SECRET }}" >> .env.test
66+
echo LINKEDIN_CONSUMER_ID = "${{ secrets.LINKEDIN_CONSUMER_ID }}" >> .env.test
67+
echo LINKEDIN_CONSUMER_SECRET = "${{ secrets.LINKEDIN_CONSUMER_SECRET }}" >> .env.test
6868
- name: Create dist directory
6969
run: mkdir dist
7070
- name: Download build artifact

.github/workflows/release.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ jobs:
1717
uses: actions/setup-node@v4
1818
with:
1919
node-version: '20.9.0'
20-
- name: Create directories
21-
run: mkdir -p ./dist/env && cp ./src/env/template.env ./dist/env/test.env
22-
- name: Setup .env file
23-
run: |
24-
echo FACEBOOK_CONSUMER_ID = "${{ secrets.FACEBOOK_CONSUMER_ID }}" >> ./dist/env/test.env
25-
echo FACEBOOK_CONSUMER_SECRET = "${{ secrets.FACEBOOK_CONSUMER_SECRET }}" >> ./dist/env/test.env
26-
echo GITHUB_CONSUMER_ID = "${{ secrets.GTHB_CONSUMER_ID }}" >> ./dist/env/test.env
27-
echo GITHUB_CONSUMER_SECRET = "${{ secrets.GTHB_CONSUMER_SECRET }}" >> ./dist/env/test.env
28-
echo GOOGLE_CONSUMER_ID = "${{ secrets.GOOGLE_CONSUMER_ID }}" >> ./dist/env/test.env
29-
echo GOOGLE_CONSUMER_SECRET = "${{ secrets.GOOGLE_CONSUMER_SECRET }}" >> ./dist/env/test.env
30-
echo LINKEDIN_CONSUMER_ID = "${{ secrets.LINKEDIN_CONSUMER_ID }}" >> ./dist/env/test.env
31-
echo LINKEDIN_CONSUMER_SECRET = "${{ secrets.LINKEDIN_CONSUMER_SECRET }}" >> ./dist/env/test.env
3220
- name: Install global dependencies
3321
run: npm i [email protected] -g
3422
- name: Install local dependencies
@@ -61,11 +49,23 @@ jobs:
6149
with:
6250
mysql version: '5.7'
6351
mysql database: 'typeplate_test'
64-
mysql root password: passw0rd
52+
mysql root password: passw0rd
6553
- name: Install global dependencies
6654
run: npm i [email protected] -g
6755
- name: Install local dependencies
6856
run: npm i
57+
- name: Copy .env.example to .env.test
58+
run: cp .env.example .env.test
59+
- name: Setup .env file
60+
run: |
61+
echo FACEBOOK_CONSUMER_ID = "${{ secrets.FACEBOOK_CONSUMER_ID }}" >> .env.test
62+
echo FACEBOOK_CONSUMER_SECRET = "${{ secrets.FACEBOOK_CONSUMER_SECRET }}" >> .env.test
63+
echo GITHUB_CONSUMER_ID = "${{ secrets.GTHB_CONSUMER_ID }}" >> .env.test
64+
echo GITHUB_CONSUMER_SECRET = "${{ secrets.GTHB_CONSUMER_SECRET }}" >> .env.test
65+
echo GOOGLE_CONSUMER_ID = "${{ secrets.GOOGLE_CONSUMER_ID }}" >> .env.test
66+
echo GOOGLE_CONSUMER_SECRET = "${{ secrets.GOOGLE_CONSUMER_SECRET }}" >> .env.test
67+
echo LINKEDIN_CONSUMER_ID = "${{ secrets.LINKEDIN_CONSUMER_ID }}" >> .env.test
68+
echo LINKEDIN_CONSUMER_SECRET = "${{ secrets.LINKEDIN_CONSUMER_SECRET }}" >> .env.test
6969
- name: Create dist directory
7070
run: mkdir dist
7171
- name: Download build artifact
@@ -77,7 +77,7 @@ jobs:
7777
run: npm run schema:sync
7878
- name: Execute tests suites
7979
run: npm run ci:test
80-
- name: Publish to coveralls.io
80+
- name: Publish coverage to coveralls.io
8181
uses: coverallsapp/[email protected]
8282
with:
8383
github-token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ docs/
7676
reports/
7777

7878
# .env files
79-
/**/env/development.env
80-
/**/env/production.env
81-
/**/env/staging.env
82-
/**/env/test.env
79+
.env.development
80+
.env.test
81+
.env.staging
82+
.env.production
8383

8484
# Husky configuration
8585
.husky/

Dockerfile

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Build stage
2+
FROM node:20.18.0-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# Install build dependencies
7+
COPY package*.json ./
8+
RUN npm ci
9+
10+
# Copy source code
11+
COPY . .
12+
13+
# Build TypeScript code and create env files
14+
RUN npm run init:copy && npm run init:compile
15+
16+
# Production stage
17+
FROM node:20.18.0-alpine AS production
18+
19+
WORKDIR /app
20+
21+
# Install production dependencies only
22+
COPY package*.json ./
23+
RUN npm i
24+
RUN npm i -g nodemon
25+
26+
# Copy built files and config files
27+
COPY --from=builder /app/dist ./dist
28+
COPY --from=builder /app/.cliamrc.js ./.cliamrc.js
29+
30+
# Create necessary directories for uploads and logs
31+
RUN mkdir -p ./dist/public/archives \
32+
&& mkdir -p ./dist/public/documents \
33+
&& mkdir -p ./dist/public/images/master-copy \
34+
&& mkdir -p ./dist/public/images/rescale \
35+
&& mkdir -p ./dist/public/audios \
36+
&& mkdir -p ./dist/public/videos \
37+
&& mkdir -p ./dist/logs
38+
39+
# Set environment variables
40+
ENV NODE_ENV=development
41+
ENV PORT=8101
42+
43+
# Expose the port
44+
EXPOSE 8101
45+
46+
# Start the application
47+
CMD ["nodemon", "."]

Dockerfile.production

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Build stage
2+
FROM node:20.18.0-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# Install build dependencies
7+
COPY package*.json ./
8+
RUN npm ci
9+
10+
# Copy source code
11+
COPY . .
12+
13+
# Build TypeScript code and create env files
14+
RUN npm run init:copy && npm run init:compile
15+
16+
# Production stage
17+
FROM node:20.18.0-alpine AS production
18+
19+
WORKDIR /app
20+
21+
# Install production dependencies only
22+
COPY package*.json ./
23+
RUN npm ci --only=production
24+
25+
# Copy built files and config files
26+
COPY --from=builder /app/dist ./dist
27+
COPY --from=builder /app/.cliamrc.js ./.cliamrc.js
28+
29+
# Create necessary directories for uploads and logs
30+
RUN mkdir -p ./dist/public/archives \
31+
&& mkdir -p ./dist/public/documents \
32+
&& mkdir -p ./dist/public/images/master-copy \
33+
&& mkdir -p ./dist/public/images/rescale \
34+
&& mkdir -p ./dist/public/audios \
35+
&& mkdir -p ./dist/public/videos \
36+
&& mkdir -p ./dist/logs
37+
38+
# Set environment variables
39+
ENV NODE_ENV=production
40+
ENV PORT=8101
41+
42+
# Expose the port
43+
EXPOSE 8101
44+
45+
# Start the application
46+
CMD ["node", "./dist/api/app.bootstrap.js"]

0 commit comments

Comments
 (0)