Skip to content

Commit 7e9148c

Browse files
committed
updated swagger.json to openapi v3. added optional docker-compose with nginx proxy. started work on gitlab ci-yml for auto deployment
1 parent 4425252 commit 7e9148c

9 files changed

+146
-8
lines changed

.gitlab-ci.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
image: docker:latest
2+
services:
3+
- docker:dind
4+
5+
stages:
6+
- deploy
7+
8+
step-deploy-uat:
9+
stage: deploy
10+
only:
11+
- uat
12+
tags:
13+
- uat
14+
script:
15+
- sudo apt-get install -y python-pip
16+
- pip install docker-compose
17+
- sudo docker image prune -f
18+
- sudo docker-compose -f docker-compose.yml build --no-cache
19+
- sudo docker-compose -f docker-compose.yml up -d
20+
21+
#test the default url
22+
- 'curl -k https://127.0.0.1/'
23+
#test the api root
24+
- 'curl -k https://127.0.0.1/api'
25+
#test the getting some cats
26+
- 'curl -k https://127.0.0.1/api/cats'
27+
28+
step-deploy-prod:
29+
stage: deploy
30+
only:
31+
- production
32+
tags:
33+
- production
34+
script:
35+
- sudo apt-get install -y python-pip
36+
- pip install docker-compose
37+
- sudo docker image prune -f
38+
- sudo docker-compose -f docker-compose.yml build --no-cache
39+
- sudo docker-compose -f docker-compose.yml up -d
40+
41+
#test the default url
42+
- 'curl -k https://127.0.0.1/'
43+
#test the api root
44+
- 'curl -k https://127.0.0.1/api'
45+
#test the getting some cats
46+
- 'curl -k https://127.0.0.1/api/cats'
47+
when: manual
48+
49+
50+

Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM node:alpine
2+
3+
LABEL Sean Bradley <[email protected]>
4+
5+
COPY package.json /nodejs/package.json
6+
COPY tsconfig.json /nodejs/tsconfig.json
7+
COPY /dist /nodejs/dist
8+
WORKDIR /nodejs
9+
10+
RUN npm install
11+
RUN ls
12+
13+
14+
EXPOSE 3000:3000

docker-compose.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: '2'
2+
services:
3+
nginx:
4+
build:
5+
context: .\nginx
6+
dockerfile: Dockerfile
7+
ports:
8+
- "80:80"
9+
command: nginx -g "daemon off";
10+
depends_on:
11+
- nodejs
12+
13+
nodejs:
14+
build:
15+
context: .
16+
dockerfile: Dockerfile
17+
expose:
18+
- "3000"
19+
command: npm start
20+
21+

nginx/Dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM nginx
2+
LABEL Sean Bradley <[email protected]>
3+
COPY /nginx.conf /etc/nginx/nginx.conf
4+
#COPY /server.crt /etc/nginx/server.crt
5+
#COPY /server.key /etc/nginx/server.key
6+
COPY /static /static

nginx/nginx.conf

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
user www-data;
2+
worker_processes 1;
3+
pid /run/nginx.pid;
4+
events {
5+
worker_connections 768;
6+
}
7+
http {
8+
sendfile off;
9+
tcp_nopush on;
10+
tcp_nodelay on;
11+
keepalive_timeout 65;
12+
types_hash_max_size 2048;
13+
include /etc/nginx/mime.types;
14+
default_type application/octet-stream;
15+
#access_log /var/log/nginx/access.log;
16+
error_log /var/log/nginx/error.log;
17+
gzip on;
18+
gzip_disable "msie6";
19+
server {
20+
listen 80;
21+
server_name localhost;
22+
#ssl_certificate server.crt;
23+
#ssl_certificate_key server.key;
24+
location / {
25+
root /static;
26+
index index.html;
27+
}
28+
location /v1.0.1/ {
29+
proxy_pass_header Server;
30+
proxy_set_header Host $http_host;
31+
proxy_set_header X-Real-IP $remote_addr;
32+
proxy_set_header X-Scheme $scheme;
33+
proxy_set_header X-Real-IP $remote_addr;
34+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
35+
proxy_redirect off;
36+
proxy_connect_timeout 20;
37+
proxy_read_timeout 20;
38+
proxy_pass http://nodejs:3000/;
39+
}
40+
}
41+
}

nginx/static/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
put the static html generated from you favourite front end framework here

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "seans-typescript-nodejs-crud-rest-api-boilerplate",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "",
55
"main": "server.js",
66
"scripts": {

src/router.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Router {
1515

1616
router.get('/', (req: express.Request, res: express.Response) => {
1717
res.json({
18-
message: 'Nothing to see here, goto \'/cats\' instead'
18+
message: `Nothing to see here, [url]/cats instead`
1919
})
2020
})
2121

src/swagger.json

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"swagger": "2.0",
2+
"openapi": "3.0.0",
33
"info": {
44
"version": "1.0.0",
55
"title": "Seans-TypeScript-NodeJS-CRUD-REST-API-Boilerplate",
@@ -9,17 +9,22 @@
99
"url": "https://opensource.org/licenses/MIT"
1010
}
1111
},
12-
"host": "localhost:3000",
13-
"basePath": "",
12+
"servers": [
13+
{
14+
"url": "/",
15+
"description": "Local Dev"
16+
},
17+
{
18+
"url": "/v1.0.1/",
19+
"description": "With docker-compose and nginx proxy"
20+
}
21+
],
1422
"tags": [
1523
{
1624
"name": "Cats",
1725
"description": "API for cats in the system"
1826
}
1927
],
20-
"schemes": [
21-
"http"
22-
],
2328
"consumes": [
2429
"application/json"
2530
],

0 commit comments

Comments
 (0)