create Dockerfile for frontend

This commit is contained in:
Kacper Donat 2020-11-22 19:59:03 +01:00
parent 535f899aaf
commit 17dd5ed296
10 changed files with 97 additions and 54 deletions

4
front/.dockerignore Normal file
View File

@ -0,0 +1,4 @@
/node_modules/
/build/
yarn-error*
npm-debug*

34
front/Dockerfile Normal file
View File

@ -0,0 +1,34 @@
FROM node:15.2.1 as build
WORKDIR /app
COPY . .
# install dependencies
RUN yarn install
RUN find resources/fontawesome -type f -name '*.tgz' | sed s/^/file:/ | xargs yarn add-no-save
# build stuff
RUN yarn run build:app
RUN yarn run build:server
# server dependencies step
FROM node:15.2.1 as prod-dependencies
WORKDIR /app
COPY . .
# install dependencies
RUN yarn install --production
FROM node:15.2.1-slim
WORKDIR /app
COPY --from=build /app/build/ build
COPY --from=build /app/resources/ resources
COPY --from=prod-dependencies /app/node_modules/ node_modules
EXPOSE 3000
CMD ["node", "build/server.js"]

View File

@ -1,21 +1,18 @@
{
"name": "co-jedzie",
"name": "cojedzie",
"version": "1.0.0",
"author": "Kacper Donat <kadet1090@gmail.com>",
"license": "MIT",
"devDependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.4",
"@fortawesome/pro-light-svg-icons": "^5.3.1",
"@fortawesome/pro-regular-svg-icons": "^5.3.1",
"@fortawesome/pro-solid-svg-icons": "^5.3.1",
"@fortawesome/vue-fontawesome": "^0.1.1",
"@types/bootstrap": "^4.3.1",
"@types/jquery": "^3.3.6",
"@types/moment": "^2.13.0",
"@types/popper.js": "^1.11.0",
"@types/ejs": "^3.0.5",
"@types/express": "^4.17.9",
"@types/jquery": "^3.3.6",
"@types/mapbox-gl-leaflet": "^0.0.1",
"@types/moment": "^2.13.0",
"@types/popper.js": "^1.11.0",
"@types/request": "^2.48.5",
"@types/uuid": "^3.4.6",
"@types/vue-moment": "^4.0.0",
@ -38,20 +35,16 @@
"webpack": "^4.17.0",
"webpack-cli": "^3.1.0",
"xmldom": "^0.1.27",
"xpath": "^0.0.27"
},
"dependencies": {
"xpath": "^0.0.27",
"yarn-add-no-save": "^1.0.3",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^4.5.2",
"ejs": "^3.1.5",
"express": "^4.17.1",
"html-webpack-plugin": "^4.5.0",
"imagemin-webpack-plugin": "^2.3.0",
"mapbox-gl": "^1.6.1",
"mapbox-gl-leaflet": "^0.0.11",
"mini-css-extract-plugin": "^0.4.2",
"portal-vue": "^2.1.7",
"request": "^2.88.2",
"vue-dragscroll": "^1.10.2",
"vue-fragment": "^1.5.1",
"vue-moment": "^4.1.0",
@ -63,5 +56,14 @@
"vuex-persist": "^2.2.0",
"workbox-webpack-plugin": "^4.3.1",
"workbox-window": "^4.3.1"
},
"dependencies": {
"ejs": "^3.1.5",
"express": "^4.17.1",
"request": "^2.88.2"
},
"scripts": {
"build:server": "tsc -p server",
"build:app": "webpack --config webpack.config.js --mode production --progress"
}
}

View File

View File

@ -0,0 +1,3 @@
# this folder is created to store fontawesome pro packages
*
!.gitignore

View File

@ -51,12 +51,12 @@
</main>
<footer class="container">
<span>
<img src="images/logo.png" alt="co jedzie logo"/>
<img src="/images/logo.png" alt="co jedzie logo"/>
v.<%= version %> &bullet;
<a href="/api/doc">API</a>
</span>
<span class="copyright flex flex-space-left justify-content-end">
<a href="https://kadet.net"><img src="images/kadet-net-logo.png" alt="kadet.net logo" class="mx-1"/></a>
<a href="https://kadet.net"><img src="/images/kadet-net-logo.png" alt="kadet.net logo" class="mx-1"/></a>
&copy; <%= year %>
</span>
</footer>

View File

@ -6,8 +6,8 @@ import request from "request";
const server = express();
const port = parseInt(process.env.APP_PORT) || 3000;
const host = process.env.APP_HOST || 'localhost';
const api = process.env.APP_API || "https://cojedzie.pl/api/v1/";
const host = process.env.APP_HOST || '0.0.0.0';
const api = process.env.APP_API || "https://cojedzie.pl/api";
const gtm_tracking = process.env.APP_GTM || '';
const version = "2020.11-dev";
@ -30,7 +30,7 @@ function generateProviderManifest(provider: any) {
server.set("views", path.join(__dirname, "../resources/views/"));
server.set("view engine", "ejs");
server.use(express.static(path.join(__dirname, "../public/")))
server.use(express.static(path.join(__dirname, "../build/public/")))
server.get("/:provider?/manifest.json", (req, res) => {
const provider = req.params.provider;
@ -47,7 +47,7 @@ server.get("/:provider?/manifest.json", (req, res) => {
console.log(`No manifest entry for ${provider}, calling ${api}/providers/${provider}`);
request.get(`${api}/providers/${provider}`, (err, _, body) => {
request.get(`${api}/v1/providers/${provider}`, (err, _, body) => {
try {
const info = JSON.parse(body);
provider_manifests[provider] = generateProviderManifest(info);
@ -62,7 +62,7 @@ server.get("/:provider?/manifest.json", (req, res) => {
})
})
server.get("/:provider?", (req, res) => {
server.get("/:provider?/*", (req, res) => {
const manifest_path = req.params.provider
? `/${req.params.provider}/manifest.json`
: "/manifest.json";
@ -80,3 +80,8 @@ server.get("/:provider?", (req, res) => {
server.listen(port, host, () => {
console.info(`Server started at ${host}:${port}`);
});
process.on('SIGINT', function() {
console.info("Terminating server...");
process.exit();
});

View File

@ -10,6 +10,6 @@
"outDir": "../build/",
"skipLibCheck": true
},
"files": ["./index.ts"],
"files": ["./server.ts"],
"include": ["./**/*.ts"]
}

View File

@ -6,13 +6,15 @@ const ImageminPlugin = require('imagemin-webpack-plugin').default;
const { GenerateSW } = require('workbox-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const output_dir = path.resolve('./build/')
const config = {
entry: {
main: ['./src/app.ts'],
api: ['./styles/api.scss']
},
output: {
path: path.resolve('./public/dist/'),
path: path.join(output_dir, './public/dist/'),
publicPath: "/dist/",
filename: "[name].js",
chunkFilename: '[name].[chunkhash:8].js'

View File

@ -9,43 +9,22 @@
dependencies:
regenerator-runtime "^0.13.2"
"@fortawesome/fontawesome-common-types@^0.2.27":
version "0.2.27"
resolved "https://npm.fontawesome.com/@fortawesome/fontawesome-common-types/-/0.2.27/fontawesome-common-types-0.2.27.tgz#19706345859fc46adf3684ed01d11b40903b87e9"
integrity sha512-97GaByGaXDGMkzcJX7VmR/jRJd8h1mfhtA7RsxDBN61GnWE/PPCZhOdwG/8OZYktiRUF0CvFOr+VgRkJrt6TWg==
"@fortawesome/fontawesome-common-types@^0.2.32":
version "0.2.32"
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-0.2.32.tgz#3436795d5684f22742989bfa08f46f50f516f259"
integrity sha512-ux2EDjKMpcdHBVLi/eWZynnPxs0BtFVXJkgHIxXRl+9ZFaHPvYamAfCzeeQFqHRjuJtX90wVnMRaMQAAlctz3w==
"@fortawesome/fontawesome-svg-core@^1.2.4":
version "1.2.27"
resolved "https://npm.fontawesome.com/@fortawesome/fontawesome-svg-core/-/1.2.27/fontawesome-svg-core-1.2.27.tgz#e4db8e3be81a40988213507c3e3d0c158a6641a3"
integrity sha512-sOD3DKynocnHYpuw2sLPnTunDj7rLk91LYhi2axUYwuGe9cPCw7Bsu9EWtVdNJP+IYgTCZIbyARKXuy5K/nv+Q==
version "1.2.32"
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-svg-core/-/fontawesome-svg-core-1.2.32.tgz#da092bfc7266aa274be8604de610d7115f9ba6cf"
integrity sha512-XjqyeLCsR/c/usUpdWcOdVtWFVjPbDFBTQkn2fQRrWhhUoxriQohO2RWDxLyUM8XpD+Zzg5xwJ8gqTYGDLeGaQ==
dependencies:
"@fortawesome/fontawesome-common-types" "^0.2.27"
"@fortawesome/pro-light-svg-icons@^5.3.1":
version "5.12.1"
resolved "https://npm.fontawesome.com/@fortawesome/pro-light-svg-icons/-/5.12.1/pro-light-svg-icons-5.12.1.tgz#802f8aac0204c41c7a138c5c9547d3cadbeec39a"
integrity sha512-vCT7qkoJINQuNEW7N+i1ioZQ7FHp5UiRPAHxuRS5qFPOXlVxtK8+Yf8DZ+KOpPQiwXoDX0tKFuS6Jc1HOB1qIg==
dependencies:
"@fortawesome/fontawesome-common-types" "^0.2.27"
"@fortawesome/pro-regular-svg-icons@^5.3.1":
version "5.12.1"
resolved "https://npm.fontawesome.com/@fortawesome/pro-regular-svg-icons/-/5.12.1/pro-regular-svg-icons-5.12.1.tgz#852f782eb2f50ee56784f6bb05d62d249b1c0794"
integrity sha512-IHwJ1Jj8zfNwC3Bj2m+YD21L1et9Ocxu6RCSLVqpTYgz2BT7CwUzHy83hUL+4JDEuA41sYyZjdsAXDgg5+DKZg==
dependencies:
"@fortawesome/fontawesome-common-types" "^0.2.27"
"@fortawesome/pro-solid-svg-icons@^5.3.1":
version "5.12.1"
resolved "https://npm.fontawesome.com/@fortawesome/pro-solid-svg-icons/-/5.12.1/pro-solid-svg-icons-5.12.1.tgz#1de223a184a81f40c1ab575880168c82c7afc773"
integrity sha512-7xhIu8QuBBK9/grUVx28rs9MNJaMQppt/rrhY2LMiYuETVKrYzHuTDvjS+UXaKsgHN31JTM/vVMVro/daTB/uw==
dependencies:
"@fortawesome/fontawesome-common-types" "^0.2.27"
"@fortawesome/fontawesome-common-types" "^0.2.32"
"@fortawesome/vue-fontawesome@^0.1.1":
version "0.1.9"
resolved "https://npm.fontawesome.com/@fortawesome/vue-fontawesome/-/0.1.9/vue-fontawesome-0.1.9.tgz#d3af6d4e50f337327de90447fe35fa1e117a2fbe"
integrity sha512-h/emhmZz+DfB2zOGLWawNwXq82UYhn9waTfUjLLmeaIqtnIyNt6kYlpQT/vzJjLZRDRvY2IEJAh1di5qKpKVpA==
version "0.1.10"
resolved "https://registry.yarnpkg.com/@fortawesome/vue-fontawesome/-/vue-fontawesome-0.1.10.tgz#eeeec1e4e8850bed0468f938292b06cda793bf34"
integrity sha512-b2+SLF31h32LSepVcXe+BQ63yvbq5qmTCy4KfFogCYm2bn68H5sDWUnX+U7MBqnM2aeEk9M7xSoqGnu+wSdY6w==
"@hapi/address@2.x.x":
version "2.1.4"
@ -6813,6 +6792,13 @@ which@1, which@^1.2.14, which@^1.2.9, which@^1.3.1:
dependencies:
isexe "^2.0.0"
which@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"
integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==
dependencies:
isexe "^2.0.0"
wide-align@^1.1.0:
version "1.1.3"
resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457"
@ -7070,6 +7056,13 @@ yargs@^7.0.0:
y18n "^3.2.1"
yargs-parser "^5.0.0"
yarn-add-no-save@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/yarn-add-no-save/-/yarn-add-no-save-1.0.3.tgz#03540f86802a46a86db83bc7357b248cd282315b"
integrity sha512-ngmmxwYOogvYPjFDXGjoj35r/DteDzfiyoq5BI+kKSCCXW/I2gJA3KAgbm/7yFmcDE9CGSaORpNbYfglGYuxtA==
dependencies:
which "^2.0.2"
yauzl@^2.4.2:
version "2.10.0"
resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9"