-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from wednesday-solutions/feat/multi-stage-docker
Feat/multi stage docker
- Loading branch information
Showing
13 changed files
with
834 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,6 @@ typings/ | |
.next | ||
|
||
dist | ||
.env.development | ||
.env.docker | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
FROM node:14.17-alpine | ||
RUN mkdir -p /app | ||
ADD . /app | ||
WORKDIR /app | ||
FROM node:14.17-alpine AS build1 | ||
ARG ENVIRONMENT_NAME | ||
ENV ENVIRONMENT_NAME $ENVIRONMENT_NAME | ||
RUN mkdir -p /app-build | ||
ADD . /app-build | ||
WORKDIR /app-build | ||
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn --frozen-lockfile | ||
RUN yarn | ||
CMD [ "yarn", "start" ] | ||
RUN yarn build:dev | ||
|
||
FROM node:14.17-alpine | ||
ARG ENVIRONMENT_NAME | ||
ENV ENVIRONMENT_NAME $ENVIRONMENT_NAME | ||
RUN apk add yarn | ||
ADD package.json / | ||
ADD . / | ||
COPY --from=build1 /app-build/dist ./dist | ||
|
||
CMD ["yarn", "start"] | ||
EXPOSE 9000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
docker: | ||
docker-compose --env-file ./.env.docker \ | ||
-f docker-compose.yml \ | ||
-f docker-compose.yml down | ||
|
||
docker-compose --env-file ./.env.docker \ | ||
-f docker-compose.yml \ | ||
-f docker-compose.yml build | ||
|
||
docker-compose --env-file ./.env.docker \ | ||
-f docker-compose.yml \ | ||
-f docker-compose.yml up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,4 @@ router.get( | |
fetchAggregatedOrderAmount | ||
); | ||
|
||
module.exports = router; | ||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* DEVELOPMENT WEBPACK CONFIGURATION | ||
*/ | ||
|
||
const path = require('path'); | ||
const webpack = require('webpack'); | ||
|
||
module.exports = require('./server.config')({ | ||
mode: 'development', | ||
// Add hot reloading in development | ||
entry: [ | ||
'webpack-hot-middleware/client?reload=true', | ||
path.join(process.cwd(), '/server/index.js') | ||
], | ||
// Don't use hashes in dev mode for better performance | ||
babelQuery: { | ||
presets: ['@babel/preset-env'], | ||
plugins: ['@babel/plugin-transform-runtime'] | ||
}, | ||
// Add development plugins | ||
plugins: [ | ||
new webpack.HotModuleReplacementPlugin() // Tell webpack we want hot reloading | ||
], | ||
optimization: {} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const path = require('path'); | ||
const TerserPlugin = require('terser-webpack-plugin'); | ||
|
||
module.exports = require('./server.config')({ | ||
mode: 'production', | ||
entry: [path.join(process.cwd(), '/server/index.js')], | ||
plugins: [], | ||
optimization: { | ||
minimize: true, | ||
minimizer: [new TerserPlugin()] | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const path = require('path'); | ||
const webpack = require('webpack'); | ||
const dotenv = require('dotenv'); | ||
require('@babel/register'); // will bind itself to node's require and automatically compile files on the fly | ||
|
||
const dotEnvFile = | ||
process.env.ENVIRONMENT_NAME === 'production' | ||
? `.env` | ||
: `.env.${process.env.ENVIRONMENT_NAME || 'local'}`; | ||
|
||
const env = dotenv.config({ path: dotEnvFile }).parsed; | ||
|
||
const envKeys = { | ||
...Object.keys(process.env).reduce((prev, next) => { | ||
prev[`process.env.${next}`] = JSON.stringify(process.env[next]); | ||
return prev; | ||
}, {}), | ||
...Object.keys(env).reduce((prev, next) => { | ||
prev[`process.env.${next}`] = JSON.stringify(env[next]); | ||
return prev; | ||
}, {}) | ||
}; | ||
|
||
module.exports = (options = {}) => ({ | ||
mode: options.mode, | ||
entry: options.entry, | ||
devtool: 'source-map', | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.jsx?$/, // Transform all .js and .jsx files required somewhere with Babel | ||
exclude: /node_modules/, | ||
use: { | ||
loader: 'babel-loader', // allows transpiling JavaScript files using Babel and webpack | ||
options: options.babelQuery | ||
} | ||
} | ||
] | ||
}, | ||
plugins: options.plugins.concat([new webpack.DefinePlugin(envKeys)]), | ||
optimization: options.optimization, | ||
node: { | ||
__dirname: true | ||
}, | ||
resolve: { | ||
modules: ['node_modules'], | ||
alias: { | ||
utils: path.resolve(__dirname, '../server/utils'), | ||
middlewares: path.resolve(__dirname, '../server/middlewares'), | ||
server: path.resolve(__dirname, '../server'), | ||
api: path.resolve(__dirname, '../server/api'), | ||
config: path.resolve(__dirname, '../config'), | ||
services: path.resolve(__dirname, '../server/services'), | ||
database: path.resolve(__dirname, '../server/database'), | ||
daos: path.resolve(__dirname, '../server/daos'), | ||
'superagent-proxy': false | ||
}, | ||
|
||
extensions: ['.js'] | ||
}, | ||
output: { | ||
libraryTarget: 'commonjs' | ||
}, | ||
|
||
target: 'node' | ||
}); |
Oops, something went wrong.