Skip to content
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
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
./mode_modules
Dockerfile
.dockerignore
docker-compose.yml
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:12.22.1

# Dockerize is required to wait for the MongoDB container to be ready.ENV DOCKERIZE_VERSION v0.6.1
ENV DOCKERIZE_VERSION v0.6.1
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .

# This script starts 'npm run dev:server' and, once the app is running,
# it executes the script to populate the database.
COPY startServerAndPopulate.sh .
RUN chmod +x startServerAndPopulate.sh

CMD dockerize -wait tcp://mongo_db:27017 -timeout 30s ./startServerAndPopulate.sh
40 changes: 14 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,34 @@ This codebase contains the code needed to run the backend for Argent Bank.

## Getting Started

### Prerequisites
## Prerequisites

Argent Bank uses the following tech stack:
For the dockerized version of Argent Bank, you only need to have Docker installed:

- [Node.js v12](https://nodejs.org/en/)
- [MongoDB Community Server](https://www.mongodb.com/try/download/community)
- [Docker](https://www.docker.com/get-started)

Please make sure you have the right versions and download both packages. You can verify this by using the following commands in your terminal:
Please make sure you have Docker installed and running on your machine. You can verify this by using the following command in your terminal:

```bash
# Check Node.js version
node --version

# Check Mongo version
mongo --version
# Check Docker version
docker --version
```

### Instructions

1. Fork this repo
1. Clone the repo onto your computer
1. Open a terminal window in the cloned project
1. Run the following commands:
1. Fork this repo.
2. Clone the repo onto your computer.
3. Open a terminal window in the cloned project directory.
4. Run the following commands:

```bash
# Install dependencies
npm install

# Start local dev server
npm run dev:server

# Populate database with two users
npm run populate-db
# Build and start the application and database using Docker
docker-compose up --build -d
```

Your server should now be running at http://locahost:3001 and you will now have two users in your MongoDB database!

## Populated Database Data
The application will be available on http://localhost:3001 after the build completes.

Once you run the `populate-db` script, you should have two users in your database:
The database will be populated automatically.

### Tony Stark

Expand Down
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3'

services:
# Mongodb service
mongo_db:
image: mongo:latest
restart: always
ports:
- 27017:27017

# Node api service
argentbank_api:
depends_on:
- mongo_db
container_name: argentbank_api
build: .
ports:
# local->container
- 3001:3001
environment:
PORT: 3001
DATABASE_URL: 'mongodb://mongo_db/argentBankDB'
14 changes: 14 additions & 0 deletions startServerAndPopulate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

(
while ! curl --output /dev/null --silent --head --fail http://localhost:3001/api-docs/; do
echo 'waiting for localhost:3001/api-docs to be available'
sleep 1
done
echo 'API documentation is available, starting to populate the database...'
npm run populate-db
echo 'Database population script has been executed. App is ready.'
) &

echo 'Starting the development server...'
npm run dev:server