Skip to content

Commit d7ea1d9

Browse files
committed
feat: build and run from Docker Support
Build and run the generator from docker image support added. The main aim and motivation behind doing this is, because of a no. of different yo generators are there, which are compatible and works with the different version of yo and also might be incompatible with other generators or versions of yo. Signed-off-by: Pratik Raj <[email protected]>
1 parent dc128a2 commit d7ea1d9

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,41 @@ Yeoman generator for creating RESTful NodeJS APIs, using ES6, Mongoose and Expre
1919
- Install the generator **globally**: `npm install -g generator-api`
2020
- Run: `yo api`, or `yo` and choose `Api` option
2121

22+
## Using Docker
23+
24+
Download the Dockerfile:
25+
26+
```bash
27+
mkdir docker
28+
cd docker
29+
wget https://github.com/ndelvalle/generator-api/raw/master/docker/Dockerfile
30+
```
31+
32+
Build the Docker images:
33+
34+
```bash
35+
docker build -t generator-api:latest .
36+
```
37+
38+
Make a folder where you want to generate the Service:
39+
40+
```bash
41+
mkdir service
42+
cd service
43+
```
44+
45+
Run the generator from image to generate service:
46+
47+
```bash
48+
docker run -it --rm -v $PWD:/home/generator/app generator-api
49+
```
50+
51+
Run and attach interactive shell to the generator docker container to work from inside the running container:
52+
53+
```bash
54+
docker run -it --rm -v $PWD:/home/generator/app generator-api /bin/bash
55+
```
56+
2257
## Running the generated project
2358

2459
Make sure you have node version `>= 6` because this project uses native supported ES6 features.

docker/Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
FROM ubuntu:20.04
2+
RUN \
3+
# configure the "generator" user
4+
groupadd generator && \
5+
useradd generator -s /bin/bash -m -g generator -G sudo && \
6+
echo 'generator:generator' |chpasswd && \
7+
mkdir /home/generator/app && \
8+
export DEBIAN_FRONTEND=noninteractive && \
9+
export TZ=Europe\Paris && \
10+
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
11+
apt-get update && \
12+
# install utilities
13+
apt-get install -y \
14+
wget \
15+
sudo && \
16+
# install node.js
17+
wget https://nodejs.org/dist/v12.18.4/node-v12.18.4-linux-x64.tar.gz -O /tmp/node.tar.gz && \
18+
tar -C /usr/local --strip-components 1 -xzf /tmp/node.tar.gz && \
19+
# upgrade npm
20+
npm install -g npm && \
21+
# install yeoman
22+
npm install -g yo && \
23+
# cleanup
24+
apt-get clean && \
25+
rm -rf \
26+
/home/generator/.cache/ \
27+
/var/lib/apt/lists/* \
28+
/tmp/* \
29+
/var/tmp/*
30+
31+
RUN \
32+
# install the generator
33+
npm install -g generator-api && \
34+
# fix generator user permissions
35+
chown -R generator:generator \
36+
/home/generator \
37+
/usr/local/lib/node_modules && \
38+
# cleanup
39+
rm -rf \
40+
/home/generator/.cache/ \
41+
/var/lib/apt/lists/* \
42+
/tmp/* \
43+
/var/tmp/*
44+
45+
# expose the working directory
46+
USER generator
47+
ENV PATH $PATH:/usr/bin
48+
WORKDIR "/home/generator/app"
49+
VOLUME ["/home/generator/app"]
50+
CMD ["yo", "api"]

0 commit comments

Comments
 (0)