Skip to content

Commit 0d2e53d

Browse files
committed
Updated build process
1 parent 0f766d9 commit 0d2e53d

37 files changed

+3201
-15391
lines changed

.dockerignore

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
.git
2+
.next
3+
build
4+
dist
5+
docs
16
node_modules
27
npm-debug.log
3-
build/static
4-
docs
5-
src/.next

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
.vscode
55
*.DS_Store
66
*.log
7-
build/app
8-
build/static
97
coverage
108
dist
119
logs

Dockerfile

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
11
# DEV BUILD STEP
22
FROM node:12.16.1-alpine3.11 as devBuild
3-
WORKDIR /usr/src/app
3+
WORKDIR /app
44

55
# Log the settings for NPM and Environment variables
6+
ENV NODE_ENV=production
67
RUN npm config ls
78
RUN env
89

910
# Copy the source code and build
1011
COPY . .
11-
RUN npm install
12-
RUN npm run build
12+
RUN ls -a
13+
RUN npm install --production=false
14+
RUN npm run build:prod
15+
RUN ls -a
1316

1417
# PROD BUILD STEP
1518
# Using latest LTS release of Node
1619
FROM node:12.16.1-alpine3.11
1720

1821
# Create an app directory on the container
19-
WORKDIR /usr/src/app
22+
WORKDIR /app
2023
ENV NODE_ENV=production
2124

2225
# Project copy build, install only prod dependencies
23-
COPY --from=devBuild /usr/src/app/dist ./dist
24-
COPY package.json package-lock.json README.md ./
26+
COPY --from=devBuild /app/dist ./dist
27+
COPY --from=devBuild /app/.next ./.next
28+
COPY --from=devBuild /app/public ./public
29+
COPY --from=devBuild /app/next.config.js ./next.config.js
30+
COPY package.json package-lock.json healthcheck.js ./
31+
32+
RUN ls -a
33+
2534
RUN npm install --only=prod
2635

27-
# Install curl to do healthchecks
28-
RUN apk add curl --no-cache
36+
RUN npx next telemetry disable
2937

3038
# Expose the container port to the OS
3139
# docker run takes -p argument to forward this port to network
3240
EXPOSE 3000
3341

3442
# Start the application
35-
CMD npm run start:production
43+
CMD npm run start:prod
3644

37-
HEALTHCHECK CMD curl --silent --fail http://localhost:3000/ || exit 1
45+
HEALTHCHECK --interval=30s --timeout=12s --start-period=30s \
46+
CMD node /healthcheck.js

babel.config.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,7 @@ module.exports = (api) => {
33
api.cache(false);
44

55
return {
6-
presets: ['next/babel' /* , { 'preset-env': { modules: 'commonjs' } } */],
7-
plugins: [
8-
// '@babel/plugin-syntax-dynamic-import',
9-
// '@babel/plugin-proposal-export-default-from',
10-
// '@babel/proposal-class-properties',
11-
// '@babel/proposal-object-rest-spread',
12-
// [
13-
// 'transform-define',
14-
// {
15-
// 'process.env.NODE_ENV': process.env.NODE_ENV,
16-
// },
17-
// ],
18-
],
6+
presets: ['next/babel'],
7+
plugins: [],
198
};
209
};

build/README.md

-10
This file was deleted.

healthcheck.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This file is used to run health checks with Node in the Docker container
2+
3+
var http = require('http');
4+
5+
var options = {
6+
host: 'localhost',
7+
port: '3000',
8+
timeout: 2000,
9+
};
10+
11+
var request = http.request(options, (res) => {
12+
console.log(`STATUS: ${res.statusCode}`);
13+
if (res.statusCode == 200) {
14+
process.exit(0);
15+
} else {
16+
process.exit(1);
17+
}
18+
});
19+
20+
request.on('error', function (err) {
21+
console.log('ERROR');
22+
process.exit(1);
23+
});
24+
25+
request.end();

jest.config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ module.exports = {
33
testEnvironment: 'node',
44
setupFilesAfterEnv: ['<rootDir>/test-setup.js'],
55
snapshotSerializers: ['enzyme-to-json/serializer'],
6-
transform: {
7-
'^.+\\.tsx?$': 'ts-jest',
8-
},
6+
transform: { '^.+\\.tsx?$': 'ts-jest' },
97
testMatch: ['**/__tests__/**/*.ts?(x)', '**/?(*.)+(test).ts?(x)'],
108
verbose: true,
119
};

next.config.js

+2-48
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,8 @@
11
module.exports = {
2-
// async exportPathMap() {
3-
// return {
4-
// // '/': { page: '/' },
5-
// // '/news': { page: '/' },
6-
// // '/active': { page: '/active' },
7-
// // '/ask': { page: '/ask' },
8-
// // '/best': { page: '/best' },
9-
// // '/bestcomments': { page: '/bestcomments' },
10-
// // '/bookmarklet': { page: '/bookmarklet' },
11-
// // '/dmca': { page: '/dmca' },
12-
// // '/formatdoc': { page: '/formatdoc' },
13-
// // '/front': { page: '/front' },
14-
// // '/item': { page: '/item' },
15-
// // '/jobs': { page: '/jobs' },
16-
// // '/leaders': { page: '/leaders' },
17-
// // '/lists': { page: '/lists' },
18-
// // '/login': { page: '/login' },
19-
// // '/newcomments': { page: '/newcomments' },
20-
// // '/newest': { page: '/newest' },
21-
// // '/newpoll': { page: '/newpoll' },
22-
// // '/newsfaq': { page: '/newsfaq' },
23-
// // '/newsguidelines': { page: '/newsguidelines' },
24-
// // '/newswelcome': { page: '/newswelcome' },
25-
// // '/noobcomments': { page: '/noobcomments' },
26-
// // '/security': { page: '/security' },
27-
// // '/show': { page: '/show' },
28-
// // '/submit': { page: '/submit' },
29-
// // '/threads': { page: '/threads' },
30-
// // '/p/975': { page: '/post', query: { id: '975' } },
31-
// // '/p/481': { page: '/post', query: { id: '481' } },
32-
// };
33-
// },
34-
webpack: (config, { dev, defaultLoaders }) => {
2+
webpack: (config) => {
353
// Perform customizations to webpack config
36-
// if (!dev) {
37-
// config.module.rules.push({
38-
// test: /\.(css|ico|gif)$/,
39-
// use: [
40-
// {
41-
// loader: 'file-loader',
42-
// options: {
43-
// outputPath: 'static/',
44-
// },
45-
// },
46-
// ],
47-
// });
48-
// }
494

50-
config.node = { fs: 'empty', net: 'empty' };
5+
// config.node = { fs: 'empty', net: 'empty' };
516
return config;
527
},
53-
// cssModules: false,
548
};

0 commit comments

Comments
 (0)