Skip to content

Commit ed2b21a

Browse files
committedFeb 12, 2019
Update readme file and apps
1 parent 4a318d9 commit ed2b21a

17 files changed

+147
-88
lines changed
 

‎LICENSE.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Rendered Text
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

‎README.md

+35-24
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
1-
# Semaphore demo CI/CD pipeline using PHP Laravel
1+
# Semaphore demo CI/CD pipeline using JavaScript (ReactJS/NodeJS)
22

3-
Example application and CI/CD pipeline showing how to run a PHP Laravel project
4-
on Semaphore 2.0.
3+
Example application and CI/CD pipeline showing how to run a JavaScript project which consists of ReactJS client and NodeJS server on Semaphore 2.0.
54

65
## Local project setup
76

8-
To setup the project locally, your local environment needs to meet common
9-
Laravel development requirements, as per [Laravel
10-
Documentation](https://laravel.com/docs/5.7#server-requirements).
11-
We recommend setting up using Vagrant and Homestead, as it is a turn key
12-
solution supported on all major operating systems.
7+
This project will require postgresql database. If you don't have one you can launch docker container with db for this app.
138

14-
Once the local environment is set up, you can run the following commands:
9+
### Configuration
1510

11+
```bash
12+
$ cp .sample.env .env
1613
```
17-
cp .env.example .env // and enter your DB details in the newly created .env
18-
composer install
19-
php artisan key:generate
20-
php artisan migrate
14+
15+
### Launch db
16+
17+
```bash
18+
$ docker-compose up
19+
```
20+
21+
### Stop db
22+
23+
```bash
24+
$ docker-compose down
2125
```
2226

27+
### Configure and launch server
28+
29+
Steps described in server [README](src/server/README.md)
30+
31+
### Configure and launch client
32+
33+
Steps described in client [README](src/client/README.md)
34+
2335
## CI/CD on Semaphore
2436

2537
Fork this repository and use it to [create a
@@ -36,25 +48,24 @@ After that, push to the repository to trigger a workflow on Semaphore.
3648

3749
The CI pipeline will look like this:
3850

39-
![CI pipeline on Semaphore](public/ci-pipeline.png)
51+
![CI pipeline on Semaphore](images/ci-pipeline.png)
4052

4153
The example pipeline contains 6 blocks:
4254

4355
- Install Dependencies
44-
- installs and caches all composer and npm dependencies
45-
- Run Code Analysis
46-
- Runs PHP Mess Detector which as an example is installed as a composer dependency
47-
- Runs PHP Code Sniffer which as an example is installed as a composer dependency
48-
- Runs PHP Copy Detector which is called via cURL from the .phar package available online
56+
- installs and caches all npm dependencies
57+
- Run Lint
58+
- Runs tslint to check project files codestyle
4959
- Run Unit Tests
5060
- Runs PHPUnit Unit Tests
51-
- Run Browser Tests
52-
- Runs browser tests through Laravel Dusk.
53-
- Run Security Tests
54-
- Runs Sensiolabs security checker pulled in via cURL
61+
- Run E2E Tests
62+
- Runs E2E tests through cypress on client.
63+
- Runs E2E tests through jest on server.
64+
- Run project Build
65+
- Runs tsc to build projects and prepare them for deploy
5566

5667
## License
5768

5869
Copyright (c) 2019 Rendered Text
5970

60-
Distributed under the MIT License. See the file LICENSE.md.
71+
Distributed under the MIT License. See the file [LICENSE.md](./LICENSE.md).

‎images/ci-pipeline.png

20.4 KB
Loading

‎src/client/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,36 @@ Instead, it will copy all the configuration files and the transitive dependencie
3737

3838
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
3939

40+
### `npm run cypress:open`
41+
42+
Opens cypress dashboard to manage e2e tests
43+
44+
### `npm run start:ci`
45+
46+
Start app con port 3030. Shortcut for ci e2e step
47+
48+
### `npm run cypress:run`
49+
50+
**Note: you need to start client app to use this command**
51+
52+
Runs e2e tests.
53+
54+
### `npm run test:e2e`
55+
56+
Runs e2e tests. It also starts client app on default port `3030` before running tests using `start-server-and-test` package
57+
58+
### `npm run lint`
59+
60+
Check app code stype
61+
4062
## Learn More
4163

4264
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
4365

4466
To learn React, check out the [React documentation](https://reactjs.org/).
67+
68+
## License
69+
70+
Copyright (c) 2019 Rendered Text
71+
72+
Distributed under the MIT License. See the file [LICENSE.md](../../LICENSE.md) in repo root.

‎src/client/package-lock.json

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/client/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "client",
2+
"name": "@semaphoreci/semaphore-demo-js-react-client",
33
"version": "0.1.0",
4-
"private": true,
4+
"license": "MIT",
55
"dependencies": {
66
"@material-ui/core": "^3.9.2",
77
"@material-ui/icons": "^3.0.2",

‎src/client/sample.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
REACT_APP_API_BASE_URL=http://localhost:3001/v1/api
1+
REACT_APP_API_BASE_URL=http://localhost:3001/v1/api

‎src/server/README.md

+41-35
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
1-
<p align="center">
2-
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>
3-
</p>
4-
5-
[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master
6-
[travis-url]: https://travis-ci.org/nestjs/nest
7-
[linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux
8-
[linux-url]: https://travis-ci.org/nestjs/nest
9-
10-
<p align="center">A progressive <a href="http://nodejs.org" target="blank">Node.js</a> framework for building efficient and scalable server-side applications, heavily inspired by <a href="https://angular.io" target="blank">Angular</a>.</p>
11-
<p align="center">
12-
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
13-
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
14-
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a>
15-
<a href="https://travis-ci.org/nestjs/nest"><img src="https://api.travis-ci.org/nestjs/nest.svg?branch=master" alt="Travis" /></a>
16-
<a href="https://travis-ci.org/nestjs/nest"><img src="https://img.shields.io/travis/nestjs/nest/master.svg?label=linux" alt="Linux" /></a>
17-
<a href="https://coveralls.io/github/nestjs/nest?branch=master"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#5" alt="Coverage" /></a>
18-
<a href="https://gitter.im/nestjs/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/nestjs/nestjs.svg" alt="Gitter" /></a>
19-
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
20-
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
21-
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-dc3d53.svg"/></a>
22-
<a href="https://twitter.com/nestframework"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
23-
</p>
24-
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
25-
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
26-
271
## Description
282

29-
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
3+
App is built using [Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
304

315
## Installation
326

337
```bash
348
$ npm install
359
```
3610

11+
## Configuration
12+
13+
These values should work on development environment without changes
14+
15+
### Copy app config
16+
17+
```bash
18+
$ cp sample.env .env
19+
```
20+
21+
### Copy db config
22+
23+
```bash
24+
$ cp ormconfig.sample.json ormconfig.json
25+
```
26+
27+
### Run migrations
28+
29+
```bash
30+
$ npm run migrate:up
31+
```
32+
3733
## Running the app
3834

3935
```bash
@@ -47,6 +43,14 @@ $ npm run start:dev
4743
$ npm run start:prod
4844
```
4945

46+
## Lint
47+
48+
Check app code style
49+
50+
```bash
51+
$ npm run lint
52+
```
53+
5054
## Test
5155

5256
```bash
@@ -60,16 +64,18 @@ $ npm run test:e2e
6064
$ npm run test:cov
6165
```
6266

63-
## Support
64-
65-
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
67+
## Migrations
6668

67-
## Stay in touch
69+
```bash
70+
# up migrations
71+
$ npm run migrate:up
6872

69-
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
70-
- Website - [https://nestjs.com](https://nestjs.com/)
71-
- Twitter - [@nestframework](https://twitter.com/nestframework)
73+
# revert last migration
74+
$ npm run migrate:revert
75+
```
7276

7377
## License
7478

75-
Nest is [MIT licensed](LICENSE).
79+
Copyright (c) 2019 Rendered Text
80+
81+
Distributed under the MIT License. See the file [LICENSE.md](../../LICENSE.md) in repo root.

‎src/server/ci.env

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
PORT=3001
2+
URL_PREFIX=v1/api
13
DATABASE_HOST=localhost
24
DATABASE_USER=postgres
35
DATABASE_PASSWORD=

‎src/server/development.env

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
PORT=3001
12
DATABASE_TYPE=postgres
23
DATABASE_HOST=localhost
34
DATABASE_USER=demouser

‎src/server/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/server/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
2-
"name": "nest-typescript-starter",
2+
"name": "@semaphoreci/semaphore-demo-js-react-server",
33
"version": "1.0.0",
4-
"description": "Nest TypeScript starter repository",
54
"license": "MIT",
65
"scripts": {
76
"build": "tsc -p tsconfig.build.json",

‎src/server/sample.env

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
PORT=3001
2+
URL_PREFIX=v1/api
13
DATABASE_HOST=localhost
24
DATABASE_USER=demouser
35
DATABASE_PASSWORD=qwerty

‎src/server/src/app.module.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import { Module } from '@nestjs/common';
22
import { TypeOrmModule } from '@nestjs/typeorm';
3-
43
import { ApiModule } from './api/api.module';
5-
6-
import * as dotenv from 'dotenv';
7-
import * as fs from 'fs';
8-
import * as path from 'path';
9-
import { AdvancedConsoleLogger } from 'typeorm';
10-
11-
const config = dotenv.parse(fs.readFileSync(path.resolve(__dirname, '..', '.env')));
4+
import config from './config';
125

136
@Module({
147
imports: [

‎src/server/src/config/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as dotenv from 'dotenv';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
4+
5+
const config = dotenv.parse(fs.readFileSync(path.resolve(__dirname, '..', '..', '.env')));
6+
7+
export default config;

‎src/server/src/main.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { NestFactory } from '@nestjs/core';
22
import { AppModule } from './app.module';
3+
import config from './config';
34

45
async function bootstrap() {
56
const app = await NestFactory.create(AppModule, { cors: true });
6-
app.setGlobalPrefix('v1/api');
7-
await app.listen(3001);
7+
app.setGlobalPrefix(config.URL_PREFIX);
8+
await app.listen(config.PORT);
89
}
910
bootstrap();

‎src/server/test/app.e2e-spec.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Test } from '@nestjs/testing';
33
import { AppModule } from './../src/app.module';
44
import { INestApplication } from '@nestjs/common';
55
import { UsersService } from '../src/api/users/users.service';
6+
import config from '../src/config';
67

78
describe('AppController (e2e)', () => {
89
const user = {
@@ -45,42 +46,42 @@ describe('AppController (e2e)', () => {
4546
.compile();
4647

4748
app = moduleFixture.createNestApplication();
48-
app.setGlobalPrefix('v1/api');
49+
app.setGlobalPrefix(config.URL_PREFIX);
4950
await app.init();
5051
});
5152

52-
it('/v1/api/users (GET)', () => {
53+
it(`/${config.URL_PREFIX}/users (GET)`, () => {
5354
return request(app.getHttpServer())
54-
.get('/v1/api/users')
55+
.get(`/${config.URL_PREFIX}/users`)
5556
.expect(200)
5657
.expect(JSON.stringify(result.findAll));
5758
});
5859

59-
it(`/v1/api/users/${user.id} (DELETE)`, () => {
60+
it(`/${config.URL_PREFIX}/users/${user.id} (DELETE)`, () => {
6061
return request(app.getHttpServer())
61-
.delete('/v1/api/users/1')
62+
.delete(`/${config.URL_PREFIX}/users/${user.id}`)
6263
.expect(200)
6364
.expect(result.remove);
6465
});
6566

66-
it(`/v1/api/users/${user.id} (GET)`, () => {
67+
it(`/${config.URL_PREFIX}/users/${user.id} (GET)`, () => {
6768
return request(app.getHttpServer())
68-
.get('/v1/api/users/1')
69+
.get(`/${config.URL_PREFIX}/users/${user.id}`)
6970
.expect(200)
7071
.expect(JSON.stringify(result.findOne));
7172
});
7273

73-
it(`/v1/api/users/${user.id} (PUT)`, () => {
74+
it(`/${config.URL_PREFIX}/users/${user.id} (PUT)`, () => {
7475
return request(app.getHttpServer())
75-
.put(`/v1/api/users/${user.id}`)
76+
.put(`/${config.URL_PREFIX}/users/${user.id}`)
7677
.send(user)
7778
.expect(200)
7879
.expect(JSON.stringify(result.update));
7980
});
8081

81-
it('/v1/api/users (POST)', () => {
82+
it(`/${config.URL_PREFIX}/users (POST)`, () => {
8283
return request(app.getHttpServer())
83-
.post(`/v1/api/users`)
84+
.post(`/${config.URL_PREFIX}/users`)
8485
.send(user)
8586
.expect(201)
8687
.expect(JSON.stringify(result.create));

0 commit comments

Comments
 (0)
Please sign in to comment.