To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

README.md 3.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# AMIV .js Template

A boilerplate containing essential build tools. It uses
[Webpack](https://webpack.js.org) and includes the
[Webpack Dev Server](https://github.com/webpack/webpack-dev-server) with
hot-reloading for easy development and [Babel](https://babeljs.io),
[UglifyJS](http://lisperator.net/uglifyjs/) and a optimized production config
for Webpack to build transpiled, minified `.js` files along with gzipped files.

Furthermore [ESLint](https://eslint.org), preconfigured to use the
Airbnb rules, is provided to check your code. (Feel free to adjust
`.eslintrc` to you needs)

Finally, a `Dockerfile` is included that uses a two-stage build to create
a final image that only contains the built files and the small
[http-server](https://www.npmjs.com/package/http-server), which can server
the files (and the gzipped versions) and nothing else, ready to deploy
in any cluster.

Contrary to other boilerplates, *only* build tools are included, and you
are free to choose whatever framework you like and get started quickly!

This version of the boilerplate is based on
[webpack-babel-eslint](https://github.com/NotSpecial/webpack-babel-eslint)
and contains additional files to support AMIV OAuth and the gitlab CI.

## Setup

Clone this repository and run `npm install` to install all dependencies.

([Node](https://nodejs.org/en/) and [npm](https://www.npmjs.com) are required.)


## Commands

A few useful commands are configured in npm:

```
# Start the development server
npm start

# If the development server does not detect file changes, try starting as root
sudo npm start

# Lint your code
npm run lint

# Lint and fix errors if possible
npm run lint-fix

# Build your project
npm run build
```

## Configuration

In many situations, development and production environments require different
configurations. With
[Webpack Resolve](https://webpack.js.org/configuration/resolve/), this can be
handled easily. There are two configuration files, `config.js` and
`config.prod.js`, which you can adjust to your needs.

In your code, `require('config')` or `import * as config from 'config'`,
which will automatically resolve to `config.js` when using the development
server and to `config.prod.js` when building your project.

## Continuous Integration

The existing `.gitlab-ci.yml` configuration file contains three stages:

- **test**: Run tests, currently only eslint -- add your own if needed!
- **build**: Build the docker container and push it to the
  [Docker Hub](hub.docker.com)
- **deploy**: Trigger a service update in the AMIV Cluster.

You can add your own tests to the **test** stage, but should not change the
**build** or **deploy** stages. 

To enable building and deploying, a few steps are required:

### Configure a runner

You need to enable a runner for your project, which will work on CI jobs.
Under `Settings > CI/CD > Runners`, activate the AMIV Runner and you are
good to go.

### Configure build

Under `Settings > CI/CD > Secret Variables`, add the variable
`CI_REGISTRY_IMAGE` and set it to the appropriate repository on Docker Hub.
The account for AMIV images is called `amiveth`, therefore you should
use the following repository for your project: `amiveth/yourprojectname`.

The login credentials for the amiveth repository are saved in the AMIV
group on gitlab, you only need so set the name in your repository.

### Configure deploy

Before you can automatically update services, you need to manually
create them in the AMIV cluster. Contact the head of AMIV IT for this.
Afterwards, under `Settings > CI/CD > Secret Variables`, add the variable
`CI_DEPLOY_SERVICE` and set it to the name of your service in the AMIV
cluster.

## Acknowledgments

Many thanks go to Moritz Schneider, who created the initial
configuration for webpack!