Skip to content

Commit d3030ce

Browse files
committed
Use Docker as dev environment
1 parent ab24f32 commit d3030ce

9 files changed

+172
-70
lines changed

.env.sample

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
NODE_ENV=development
2+
INDEX_NAME=%env.INDEX_NAME%
3+
KEY_FILE_LOCATION=%env.KEY_FILE_LOCATION%
4+
SEARCH_KEY=%env.SEARCH_KEY%
5+
SEARCH_USER=%env.SEARCH_USER%

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ pdf/kotlin-docs.pdf
3434
pdf/tmp.html
3535
*.pyc
3636
google-credentials.json
37-
package-lock.json
37+
package-lock.json
38+
.env

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ RUN pip install -r /tmp/requirements.txt; \
1313
gem install kramdown;
1414

1515
EXPOSE 5000
16-
CMD python /src/kotlin-website.py
16+
ENTRYPOINT python /src/kotlin-website.py

README.md

+41-37
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,35 @@
1-
[![official project](http://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
2-
<a href="http://slack.kotlinlang.org/"><img src="http://slack.kotlinlang.org/badge.svg" height="20"></a>
1+
# Kotlin website
2+
[![Official project][project-badge]][project-url] [![Slack][slack-badge]][slack-url]
33

4-
This is the source for the [Kotlin Web Site](http://kotlinlang.org)
4+
This is the source for the [http://kotlinlang.org](http://kotlinlang.org).
55

6-
- [Filing bugs](#filing-bugs)
76
- [Installation](#installation)
8-
- [Working with site](#working-with-site)
9-
- [Run](#run-site)
10-
- [Data](#data)
11-
- [Templates](#templates)
12-
- [Page metadata](#page-metadata)
13-
- [Writing content](#writing-content)
14-
15-
16-
Filing Bugs
17-
===========
18-
We use [YouTrack](http://youtrack.jetbrains.com/issues/KT#) for bug reports and suggestions. Click [here to report an issue](http://youtrack.jetbrains.com/newIssue?project=KT&clearDraft=true&c=Subsystems+Web+Site).
19-
20-
Installation
21-
============
22-
23-
## Prerequisites
24-
25-
- Python 3. Kotlinlang is a [Flask](http://flask.pocoo.org/)-based site, so you'll need Python 3 to get it working.
26-
- Ruby + [kramdown](http://kramdown.gettalong.org/installation.html). Python has very poor support for Markdown, so kramdown is used as the Markdown-to-HTML converter.
27-
- [nodejs](https://nodejs.org/en/) + npm to build frontend assets
7+
- [How to run](#how-to-run)
8+
- [Project structure & overview](#project-structure)
9+
- [Writing content](#writing-content)
2810

2911
## Installation
3012

31-
After installation of required tools run `npm i` to download all frontend dependencies and `pip install -r requirements.txt` to download backend dependencies.
13+
1. You will need Docker to run site lifecycle tasks. Installation for [macOS](https://docs.docker.com/docker-for-mac/install/#download-docker-for-mac) and
14+
[Windows](https://docs.docker.com/docker-for-windows/install/#download-docker-for-windows)).
15+
2. If you want to develop frontend Yarn package manager is also needed ([installation instructions](https://yarnpkg.com/lang/en/docs/install/)).
16+
Don't forget to install frontend dependencies - `yarn install`.
17+
3. All specific app parameters stored in env-file. Copy sample file `.env.sample` and rename it to `.env`.
18+
Change variables values if needed.
3219

33-
Working with this site
34-
======================
20+
## How to run
3521

36-
## Running this site
22+
- **All in one option (suitable for content authors/writers)**: `docker-compose up`.
23+
It will build all stuff and create site on [http://localhost:5000](http://localhost:5000).
24+
- **Developer has 2-step option**:
25+
- `docker-compose up website` will run only site at [http://localhost:5000](http://localhost:5000).
26+
- `yarn start` will run webpack-dev-server on [http://localhost:9000](http://localhost:9000).
27+
This address should be used to development. All pages from origin server will be proxied.
28+
29+
<a id="project-structure"></a>
30+
## Project structure & overview
3731

38-
- Use `npm run build` command to build assets. If you are going to modify js/scss files use `npm start` instead.
39-
- To run site use `python kotlin-website.py` command
40-
41-
## Data
32+
### Data
4233

4334
All data is stored in the \*.yml files in folder `_data`:
4435

@@ -48,19 +39,21 @@ All data is stored in the \*.yml files in folder `_data`:
4839
It contains a list of videos or other categories. Maximum tree depth level is 3.
4940
- [events.yml](_data/events.yml) event data.
5041

51-
## Templates
42+
### Templates
5243

5344
Kotlinlang uses [Jinja2](http://jinja.pocoo.org/docs/dev/) templates that can be found in templates folder.
54-
Note that all Markdown files are processed as Jinja templates before being converted to HTML. This allows you to use all Jinja power inside Markdown (for example, build urls with url_for function).
45+
Note that all Markdown files are processed as Jinja templates before being converted to HTML.
46+
This allows you to use all Jinja power inside Markdown (for example, build urls with url_for function).
5547

56-
## Page metadata
48+
### Page metadata
5749

5850
Every page can have an unlimited number of metadata fields. More information [here](http://jekyllrb.com/docs/frontmatter/).
5951
The most important of them are the page template (e.g. `layout: reference`) and its type (e.g. `type: tutorial`). `category` and `title` fields are added for future development.
6052

61-
## Kotlin grammar reference
53+
### Kotlin grammar reference
6254

63-
The Kotlin grammar reference (grammar.xml) is generated by the [Kotlin grammar generator](https://github.com/JetBrains/kotlin-grammar-generator) from the [Kotlin grammar definition](https://github.com/JetBrains/kotlin/tree/master/grammar).
55+
The Kotlin grammar reference (grammar.xml) is generated by the [Kotlin grammar generator](https://github.com/JetBrains/kotlin-grammar-generator) from the
56+
[Kotlin grammar definition](https://github.com/JetBrains/kotlin/tree/master/grammar).
6457

6558
## Writing content
6659

@@ -123,3 +116,14 @@ E.g.:
123116
>
124117
> By "changing the receiver" we mean `the receiver-variable`, not the receiver object.
125118
{:.note}
119+
```
120+
121+
## Filing Bugs
122+
We use [YouTrack](http://youtrack.jetbrains.com/issues/KT) for bug reports and suggestions.
123+
Click [here to report an issue](http://youtrack.jetbrains.com/newIssue?project=KT&clearDraft=true&c=Subsystems+Web+Site).
124+
125+
126+
[project-url]: https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub
127+
[project-badge]: http://jb.gg/badges/official.svg
128+
[slack-url]: http://slack.kotlinlang.org
129+
[slack-badge]: http://slack.kotlinlang.org/badge.svg

docker-compose.yml

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1-
version: '2'
1+
version: '2.1'
22

33
services:
44
website:
55
build:
66
dockerfile: ./Dockerfile
77
context: .
8+
env_file:
9+
- .env
810
ports:
911
- 5000:5000
1012
volumes:
1113
- ./:/src
12-
working_dir: /src
14+
working_dir: /src
15+
16+
frontend:
17+
command: /bin/bash scripts/build-frontend.sh
18+
env_file:
19+
- .env
20+
image: node:9
21+
volumes:
22+
- ./:/src
23+
working_dir: /src

package.json

+7-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"babel-core": "6.18.2",
1212
"babel-loader": "^7.1.1",
1313
"babel-plugin-transform-runtime": "^6.23.0",
14-
"codemirror": "https://github.com/codemirror/CodeMirror.git#f3e6d7ea61d0a69b57cad1ff8134fe07e8b28112",
14+
"clean-webpack-plugin": "0.1.18",
15+
"codemirror": "git://github.com/codemirror/codemirror.git#f3e6d7ea61d0a69b57cad1ff8134fe07e8b28112",
1516
"core-js": "^2.4.1",
1617
"cross-env": "1.0.7",
1718
"css-loader": "0.21.0",
@@ -40,6 +41,8 @@
4041
"query-string": "3.0.0",
4142
"resolve-url-loader": "^2.1.0",
4243
"rimraf": "2.5.2",
44+
"rollup": "^0.34.10",
45+
"rollup-plugin-buble": "^0.15.0",
4346
"sass-loader": "^6.0.6",
4447
"scrolltofixed": "1.0.6",
4548
"smoothscroll-polyfill": "0.3.4",
@@ -55,15 +58,9 @@
5558
"webpack-dev-server": "^2.7.1",
5659
"webpack-livereload-plugin": "0.4.0"
5760
},
58-
"repository": {
59-
"type": "git",
60-
"url": "https://github.com/JetBrains/kotlin-web-site"
61-
},
6261
"scripts": {
63-
"start": "rimraf ./_assets/* && cross-env NODE_ENV=development webpack --watch",
64-
"start:server": "cross-env NODE_ENV=development webpack-dev-server",
65-
"build": "rimraf ./_assets/* && cross-env NODE_ENV=production webpack -p --bail",
66-
"postinstall": "cd node_modules/codemirror && yarn install && yarn run build",
67-
"clean": "rimraf ./_assets"
62+
"build": "webpack --bail",
63+
"postinstall": "cd node_modules/codemirror && rollup -c",
64+
"start": "webpack-dev-server"
6865
}
6966
}

scripts/build-frontend.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
yarn install --frozen-lockfile
6+
yarn run build

webpack.config.js

+28-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
const path = require('path');
2-
const Webpack = require('webpack');
2+
3+
const webpack = require('webpack');
34
const ExtractTextPlugin = require('extract-text-webpack-plugin');
4-
const LiveReloadPlugin = require('webpack-livereload-plugin');
5+
const CleanPlugin = require('clean-webpack-plugin');
6+
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
7+
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
58

69
module.exports = (params = {}) => {
710
const isProduction = process.env.NODE_ENV === 'production';
11+
const isDevelopment = !isProduction;
812
const env = isProduction ? 'production' : 'development';
913
const isServer = process.argv.toString().includes('webpack-dev-server');
10-
const originHost = 'localhost:5000';
14+
const sourcemaps = params.sourcemaps || isDevelopment;
1115

16+
const siteHost = 'localhost:5000';
1217
const webDemoURL = params['webdemo-url'] || 'http://kotlin-web-demo-cloud.passive.aws.intellij.net';
1318
const indexName = params['index-name'] || 'dev_KOTLINLANG';
1419

15-
const webpackConfig = {
20+
const config = {
1621
entry: {
1722
'common': './static/js/page/common.js',
1823
'index': './static/js/page/index/index.js',
@@ -33,6 +38,8 @@ module.exports = (params = {}) => {
3338
filename: '[name].js'
3439
},
3540

41+
devtool: sourcemaps ? 'source-map' : false,
42+
3643
module: {
3744
rules: [
3845
{
@@ -109,25 +116,23 @@ module.exports = (params = {}) => {
109116
plugins: [
110117
new ExtractTextPlugin('[name].css'),
111118

112-
new Webpack.optimize.CommonsChunkPlugin({
119+
new webpack.optimize.CommonsChunkPlugin({
113120
name: 'default',
114121
minChunks: 3
115122
}),
116123

117-
new Webpack.ProvidePlugin({
124+
new webpack.ProvidePlugin({
118125
$: 'jquery',
119126
jQuery: 'jquery',
120127
'window.jQuery': 'jquery',
121128
fetch: 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch',
122129
Promise: 'imports-loader?this=>global!exports-loader?global.Promise!core-js/es6/promise'
123130
}),
124131

125-
new Webpack.DefinePlugin({
132+
new webpack.DefinePlugin({
126133
webDemoURL: JSON.stringify(webDemoURL),
127134
indexName: JSON.stringify(indexName),
128-
'process.env': {
129-
NODE_ENV: JSON.stringify(env)
130-
}
135+
'process.env.NODE_ENV': JSON.stringify(env)
131136
})
132137
],
133138

@@ -138,22 +143,27 @@ module.exports = (params = {}) => {
138143
stats: 'errors-only',
139144
proxy: {
140145
'/**': {
141-
target: `http://${originHost}`,
146+
target: `http://${siteHost}`,
142147
bypass: function (req) {
143-
req.headers.host = originHost;
148+
req.headers.host = siteHost;
144149
}
145150
}
146151
}
147152
}
148153
};
149154

155+
const plugins = config.plugins;
156+
150157
if (!isServer) {
151-
webpackConfig.plugins.push(
152-
new LiveReloadPlugin({
153-
appendScriptTag: false
154-
})
155-
);
158+
plugins.push(new CleanPlugin(['_assets']))
159+
}
160+
161+
if (isProduction) {
162+
const minimizePlugin = new UglifyJsPlugin({ sourceMap: sourcemaps });
163+
const minimizeLoaderOptionPlugin = new LoaderOptionsPlugin({ minimize: true });
164+
plugins.push(minimizePlugin);
165+
plugins.push(minimizeLoaderOptionPlugin);
156166
}
157167

158-
return webpackConfig;
168+
return config;
159169
};

0 commit comments

Comments
 (0)