Skip to content

Commit 4af3c72

Browse files
authored
Code clean up. (#9)
* Code clean up. * Fix CI Workflow. * Update Readme.
1 parent 1d6ab9f commit 4af3c72

27 files changed

+1023
-158
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ jobs:
4747
run: docker-compose -f docker-compose.yml config
4848

4949
- name: Validate Mock Server Docker Compose file
50-
run: docker-compose -f docker-compose.server.yml config
50+
run: docker-compose -f local-server/docker-compose.server.yml config
5151

5252
- name: Validate Mock Server Application Docker Compose file
53-
run: docker-compose -f docker-compose.server.yml config
53+
run: docker-compose -f local-server/docker-compose.server.yml config
5454

5555
tests:
5656
name: Test Mail Server

Dockerfile.local

Lines changed: 0 additions & 27 deletions
This file was deleted.

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ start-portfolio-dev:
55
npm --prefix portfolio/ run dev
66

77
build-mock-server:
8-
docker build -f Dockerfile.local -t mock-server:latest .
8+
docker build -f local-server/Dockerfile.local -t mock-server:latest .
99

1010
start-mock-server:
11-
docker-compose -f docker-compose.server.yml up -d
11+
docker-compose -f local-server/docker-compose.server.yml up -d
1212
# Wait for dockerd to be ready
1313
until docker exec mock-server docker info > /dev/null 2>&1; do \
1414
echo "Waiting for Docker daemon in mock-server to be ready..."; \
@@ -18,4 +18,4 @@ start-mock-server:
1818
docker exec mock-server /srv/app/entrypoint.sh
1919

2020
stop-mock-server:
21-
docker-compose -f docker-compose.server.yml down
21+
docker-compose -f local-server/docker-compose.server.yml down

README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ This repository contains the Web Portfolio for the hosted applications. The Web
99

1010
## Design
1111
<p align="center">
12-
<img src="./docs/Web-Portfolio.jpg" style="display: block; margin: 0 auto">
12+
<img src="./docs/Web-Portfolio-V2.jpg" style="display: block; margin: 0 auto">
1313
</p>
1414

1515
<br/>
1616

17-
This web portfolio runs an Nginx web server to host the static files within a docker container. The docker-compose file is meant to be used within a docker-swarm instance.
17+
This web portfolio application runs an Nginx web server to host the static files and a Nodejs to handle SMTP messages within a Docker Swarm service.
1818

1919
## Prerequisites
2020
* NodeJS
@@ -24,35 +24,47 @@ This web portfolio runs an Nginx web server to host the static files within a do
2424

2525
This web portfolio uses a NodeJS mail server which you must configured to send emails.
2626

27-
* Read name `.env.config.example` to `.env.config` and update PORT value if needed
28-
* Read name `.env.secret.example` to `.env.secret` and provide the
27+
* Rename `.env.config.example` to `.env.config` and update APP_PORT, SMTP_HOST values as needed
2928

30-
```
31-
# Email server
32-
SERVICE="yahoo"
33-
29+
```conf
30+
# Node applicaiton port
31+
APP_PORT=3000
32+
33+
# Mail server host
34+
SMTP_HOST=smtp.mail.yahoo.com
35+
36+
# Mail server port
37+
SMTP_PORT=587
38+
```
39+
40+
* Rename `.env.secret.example` to `.env.secret` and update EMAIL, EMAIL_PASS, FORWARDING_EMAIL values as needed
41+
42+
``` conf
3443
# Sender's email address
35-
EMAIL_USER="example@yahoo.com"
44+
EMAIL="example@yahoo.com"
3645
37-
# Email Application Password
46+
# Sender's Application Email Password
3847
EMAIL_PASS="mypassword"
3948
4049
# Recipient's email address
41-
FORWARD_EMAIL_USER="myemail@yahoo.com"
50+
FORWARDING_EMAIL="myemail@yahoo.com"
4251
```
4352

4453
### Running Dev Locally
4554
1. Open a terminal shell and run `make start-server-dev`
4655
2. Open a second terminal and run `start-portfolio-dev`
4756
3. Access web portfolio via `http://localhost:4000`
57+
4. Stop locally started app by press Ctrl + C within both terminals
4858

4959
### Running Docker Swarm Locally
5060
1. Build the mock server with `make build-mock-server`
5161
2. Start mock server with `make start-mock-server`
5262
3. Access web portfolio via `http://localhost`
63+
4. Stop the mock server with `make stop-mock-server`
5364

5465
NOTE: The above steps will simulate a remote server. An entrypoint.sh script will initialize Docker Swarm, create networks, secrets, configs, build images and start the web portfolio services. The application should be accessible via port 80.
5566

5667
## Pre-Merge Checklist
5768
* Update [Portfolio VERSION](./portfolio/VERSION) or [Mail Server VERSION](./mail-server/VERSION)
69+
* Update [Portfolio package.json](./portfolio/package.json) or [Mail Server package.json](./mail-server/package.json)
5870
* Update [Porfolio CHANGELOG.md](./portfolio/CHANGELOG.md) or [Mail Server CHANGELOG.md](./mail-server/CHANGELOG.md)

docs/Web-Portfolio-V2.jpg

8.49 KB
Loading
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
version: '3.8'
22

33
services:
4+
api-gateway:
5+
image: nginx:latest
6+
container_name: api-gateway
7+
ports:
8+
- "80:80"
9+
volumes:
10+
- ./nginx.conf:/etc/nginx/nginx.conf
11+
networks:
12+
- portfolio-network
13+
depends_on:
14+
- portfolio
15+
- mail-server
16+
417
web-portfolio:
518
container_name: web-portfolio
619
image: web-portfolio:latest
7-
ports:
8-
- "80:80"
20+
expose:
21+
- "3000"
922
depends_on:
1023
- mail-server
1124
networks:
@@ -24,10 +37,13 @@ services:
2437

2538
mail-server:
2639
image: mail-server:latest
40+
expose:
41+
- "3000"
2742
secrets:
2843
- mail_server_secret
2944
configs:
30-
- mail_server_config
45+
- source: mail_server_config
46+
target: /run/config/mail_server_config
3147
networks:
3248
- portfolio-network
3349
deploy:

local-server/nginx.conf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
events {
2+
worker_connections 1024;
3+
}
4+
5+
http {
6+
server {
7+
listen 80;
8+
server_name localhost;
9+
10+
# Web Portfoli Routing
11+
location / {
12+
proxy_pass http://web-portfolio:80;
13+
proxy_set_header Host $host;
14+
proxy_set_header X-Real-IP $remote_addr;
15+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
16+
proxy_set_header X-Forwarded-Proto $scheme;
17+
}
18+
19+
# Mail Server Routing
20+
location /send-email {
21+
proxy_pass http://mail-server:3000;
22+
proxy_set_header Host $host;
23+
proxy_set_header X-Real-IP $remote_addr;
24+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
25+
proxy_set_header X-Forwarded-Proto $scheme;
26+
}
27+
}
28+
}

mail-server/.env.config.example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
EMAIL_PORT=3000
2-
EMAIL_HOST=localhost
1+
APP_PORT=3000
2+
SMTP_HOST=smtp.mail.yahoo.com
3+
SMTP_PORT=587

0 commit comments

Comments
 (0)