Skip to content

Commit 95bc2d8

Browse files
authored
Docker compose nodejs example (#49)
* Added our very first realworld example. Docker-compose nodejs up
1 parent d013bb5 commit 95bc2d8

File tree

11 files changed

+3040
-52
lines changed

11 files changed

+3040
-52
lines changed

README.md

+22-51
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,32 @@ Tired of pushing commits to test your .gitlab-ci.yml?
1111

1212
Then this is the tool for you.
1313

14-
Run gitlab pipelines on your local machine as shell runner or docker executor.
14+
Run gitlab pipelines on your local machine as shell executor or docker executor.
1515

1616
Get rid of all those pesky dev workflow shell scripts and make files.
1717

1818
## Table of contents
1919
* [Introduction](#introduction)
2020
* [Table of contents](#table-of-contents)
21+
* [Examples](#examples)
2122
* [Installation](#installation)
2223
* [NPM](#npm)
2324
* [Linux](#linux)
2425
* [Windows (Git bash)](#windows-git-bash)
2526
* [Macos](#macos)
26-
* [Usage](#usage)
27-
* [Example](#example)
28-
* [Convinience](#convinience)
29-
* [Bash alias](#bash-alias)
30-
* [Bash completion](#bash-completion)
31-
* [Quirks](#quirks)
32-
* [Artifacts](#artifacts)
27+
* [Convinience](#convinience)
28+
* [Bash alias](#bash-alias)
29+
* [Bash completion](#bash-completion)
30+
* [Quirks](#quirks)
31+
* [Artifacts](#artifacts)
3332
* [Development](#development)
3433
* [Scripts](#scripts)
3534
* [Package binaries](#package-binaries)
3635
* [Will not be implemented](#will-not-be-implemented)
3736

37+
## Examples
38+
- [Docker Compose "deploy" a nodejs webserver](examples/docker-compose-nodejs/README.md)
39+
3840
## Installation
3941
### NPM
4042
```
@@ -70,45 +72,13 @@ chmod +x /usr/local/bin/gitlab-ci-local
7072
exit
7173
```
7274

73-
## Usage
74-
### Example
75-
76-
```
77-
# /home/user/workspace/myproject/.gitlab-ci.yml
78-
---
79-
stages: [ build, .post ]
80-
81-
# @Description Is only executed locally
82-
clean:
83-
stage: .post
84-
rules:
85-
- { if: $GITLAB_CI == 'false' }
86-
script:
87-
- echo "I'm only executed locally because GITLAB_CI is false via gitlab-ci-local"
88-
- echo "I also have a description, when gitlab-ci-local --list is executed"
89-
90-
# @Description Is only executed remotely
91-
build:
92-
stage: build
93-
tags: [ runner-tag ]
94-
rules:
95-
- { if: $GITLAB_CI == 'true' }
96-
script:
97-
- echo "I'm only executed remotely because GITLAB_CI is true on actual gitlab runners"
98-
99-
100-
101-
cd /home/user/workspace/myproject
102-
gitlab-ci-local
103-
```
104-
105-
### Convinience
106-
#### Bash alias
75+
## Convinience
76+
### Bash alias
10777
```
10878
echo "alias gcl='gitlab-ci-local'" >> ~/.bashrc
10979
```
11080

111-
#### Bash completion
81+
### Bash completion
11282

11383
Add this to `~/.bashrc`
11484
```
@@ -134,19 +104,21 @@ _yargs_completions()
134104
complete -o default -F _yargs_completions gitlab-ci-local
135105
```
136106

137-
### Quirks
138-
#### Artifacts
139-
Artifacts works right now, as along as you don't overwrite tracked files.
107+
## Quirks
108+
### Artifacts
109+
Shell executor just place files in host directory
110+
111+
Docker executor copies files specified via artifacts field to host
140112

141113
## Development
142114
### Scripts
143115
```
144116
npm install
145117
npm run build
146-
npm start -- --cwd /home/user/workspace/project-folder/
118+
npm start
147119
```
148120

149-
![output](docs/images/development.png)
121+
![output](docs/images/example.png)
150122

151123
### Package binaries
152124
```
@@ -160,10 +132,9 @@ npm run pkg-all
160132
- pages
161133
- resource_group
162134
- interruptible
163-
- only
164-
- except
135+
- only (deprecated)
136+
- except (deprecated)
165137
- parallel
166138
- trigger
167139
- retry (in case of failure)
168140
- timeout (job max execution time)
169-
- coverage (code coverage)

docs/images/development.png

-193 KB
Binary file not shown.

docs/images/example.png

82 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.gitlab-ci-local/
2+
node_modules/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
# @Description Install npm packages
3+
npm-install:
4+
stage: .pre
5+
image: node
6+
artifacts:
7+
paths:
8+
- node_modules/
9+
script:
10+
- npm install --no-audit
11+
12+
# @Description Find security vulnerabilities in node_modules
13+
npm-audit:
14+
stage: test
15+
image: node
16+
needs: [ ]
17+
allow_failure: true
18+
script: npm audit
19+
20+
# @Description Find outdated packages in node_modules
21+
npm-outdated:
22+
stage: test
23+
image: node
24+
needs: [ npm-install ]
25+
allow_failure: true
26+
script:
27+
- npx -s ncu -e2 --deprecated
28+
29+
# @Description Up docker-compose services
30+
docker-compose-up:
31+
stage: deploy
32+
environment:
33+
url: http://localhost:8891
34+
name: local
35+
script:
36+
- docker-compose --no-ansi up -d
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# docker-compose nodejs example
2+
3+
- Install npm packages
4+
- Copy those packages to host and child jobs, because of the artifacts fields (npm-install)
5+
- Check for security vulnerbilities in npm packages (npm-audit)
6+
- Check for outdated packages via npm-check-updates package (npm-outdated)
7+
- Deploy a webserver container via docker-compose (docker-compose-up)
8+
9+
10+
```
11+
gitlab-ci-local --cwd examples/docker-compose-nodejs/
12+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
webserver:
3+
image: node
4+
command: node webserver.js
5+
ports:
6+
- 8891:3000
7+
volumes:
8+
- ./node_modules/:/node_modules/
9+
- ./webserver.js:/webserver.js

0 commit comments

Comments
 (0)