Skip to content

feat: build and run from Docker Support #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,41 @@ Yeoman generator for creating RESTful NodeJS APIs, using ES6, Mongoose and Expre
- Install the generator **globally**: `npm install -g generator-api`
- Run: `yo api`, or `yo` and choose `Api` option

## Using Docker

Download the Dockerfile:

```bash
mkdir docker
cd docker
wget https://github.com/ndelvalle/generator-api/raw/master/docker/Dockerfile
```

Build the Docker images:

```bash
docker build -t generator-api:latest .
```

Make a folder where you want to generate the Service:

```bash
mkdir service
cd service
```

Run the generator from image to generate service:

```bash
docker run -it --rm -v $PWD:/home/generator/app generator-api
```

Run and attach interactive shell to the generator docker container to work from inside the running container:

```bash
docker run -it --rm -v $PWD:/home/generator/app generator-api /bin/bash
```

## Running the generated project

Make sure you have node version `>= 6` because this project uses native supported ES6 features.
Expand Down
50 changes: 50 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM ubuntu:20.04

# configure the "generator" user
RUN groupadd generator && \
useradd generator -s /bin/bash -m -g generator -G sudo && \
echo 'generator:generator' |chpasswd && \
mkdir /home/generator/app && \
export DEBIAN_FRONTEND=noninteractive && \
export TZ=Europe\Paris && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
apt-get update && \
# install utilities
apt-get --no-install-recommends install -y \
wget \
sudo && \
# install node.js
wget https://nodejs.org/dist/v12.18.4/node-v12.18.4-linux-x64.tar.gz -O /tmp/node.tar.gz && \
tar -C /usr/local --strip-components 1 -xzf /tmp/node.tar.gz && \
# upgrade npm
npm install -g npm && \
# install yeoman
npm install -g yo && \
# cleanup
apt-get clean && \
rm -rf \
/home/generator/.cache/ \
/var/lib/apt/lists/* \
/tmp/* \
/var/tmp/*

RUN \
# install the generator
npm install -g generator-api && \
# fix generator user permissions
chown -R generator:generator \
/home/generator \
/usr/local/lib/node_modules && \
# cleanup
rm -rf \
/home/generator/.cache/ \
/var/lib/apt/lists/* \
/tmp/* \
/var/tmp/*

# expose the working directory
USER generator
ENV PATH $PATH:/usr/bin
WORKDIR /home/generator/app
VOLUME ["/home/generator/app"]
CMD ["yo", "api"]