Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #8 from AJRedDevil/develop
Browse files Browse the repository at this point in the history
Dockerize
  • Loading branch information
AjanShrestha authored Dec 24, 2019
2 parents 2f2e409 + c138dce commit 47efe4e
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ yarn-debug.log*
yarn-error.log*

# Redis
worker/data
data
6 changes: 6 additions & 0 deletions api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
*Dockerfile*
*docker-compose*
node_modules
npm-debug.log
logs/*
11 changes: 11 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:alpine

WORKDIR /usr/src/app

COPY package.json yarn.lock ./
RUN yarn install

COPY . .

EXPOSE 5000
CMD ["yarn", "start"]
5 changes: 4 additions & 1 deletion api/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const express = require('express');
const redis = require('redis'),
client = redis.createClient();
client = redis.createClient(
6379,
process.env.NODE_ENV === 'docker' ? 'redis' : 'localhost'
);
const {promisify} = require('util');
const getAsync = promisify(client.get).bind(client);

Expand Down
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"express": "4.17.1",
"redis": "2.8.0"
}
}
}
6 changes: 6 additions & 0 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
*Dockerfile*
*docker-compose*
node_modules
npm-debug.log
logs/*
14 changes: 14 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:alpine AS builder

WORKDIR /app

COPY package.json yarn.lock ./
RUN yarn install

COPY . .
RUN npm run build

FROM nginx:1.15.10-alpine
COPY --from=builder /app/build /var/www
COPY ./nginx.conf /etc/nginx/nginx.conf
CMD ["nginx", "-g", "daemon off;"]
24 changes: 24 additions & 0 deletions client/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
events {
worker_connections 4096; ## Default: 1024
}
http {
server {
listen 80;
server_name localhost;
include /etc/nginx/mime.types;
# root /var/www;
# index index.html index.htm;
location /api {
resolver 127.0.0.11;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://api:5000$request_uri;
}
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ =404;
}
}
}
50 changes: 50 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: '3.7'
services:
client:
image: ajreddevil/client-job-board
restart: always
container_name: client
ports:
- '80:80'
links:
- api
depends_on:
- api
networks:
- webappnetwork
api:
image: ajreddevil/api-job-board
restart: always
container_name: api
ports:
- '5000:5000'
environment:
NODE_ENV: 'docker'
depends_on:
- redis
networks:
- webappnetwork
worker:
image: ajreddevil/worker-job-board
restart: always
container_name: worker
environment:
NODE_ENV: 'docker'
depends_on:
- redis
networks:
- webappnetwork
redis:
image: redis
restart: always
container_name: redis
volumes:
- ${PWD}/data:/data
ports:
- 6379:6379
command: redis-server --appendonly yes
networks:
- webappnetwork
networks:
webappnetwork:
driver: bridge
78 changes: 78 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# API
dockerize-api:
docker build -t ajreddevil/api-job-board api/

start-api:
docker run --name api \
-p 5000:5000 \
--restart unless-stopped \
--link redis:redis \
-e NODE_ENV=docker \
-d ajreddevil/api-job-board

stop-api:
docker stop api
docker rm api

view-api-logs:
docker logs -f api

# Client
dockerize-client:
docker build -t ajreddevil/client-job-board client/

start-client:
docker run --name client \
-p 3000:3000 \
--restart unless-stopped \
-d ajreddevil/client-job-board

stop-client:
docker stop client
docker rm client

view-client-logs:
docker logs -f client

# worker
dockerize-worker:
docker build -t ajreddevil/worker-job-board worker/

start-worker:
docker run --name worker \
--restart unless-stopped \
--link redis:redis \
-e NODE_ENV=docker \
-d ajreddevil/worker-job-board

stop-worker:
docker stop worker
docker rm worker

view-worker-logs:
docker logs -f worker

# Redis
download-redis:
docker pull redis

setup-volume:
mkdir data

start-redis:
docker run --name redis \
--restart unless-stopped \
-v ${PWD}/data:/data\
-p 6379:6379 \
-d redis redis-server --appendonly yes

stop-redis:
docker stop redis
docker rm redis

# RUN cmd
run-job-board:
docker-compose -p job-board up -d

stop-job-board:
docker-compose -p job-board down
6 changes: 6 additions & 0 deletions worker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
*Dockerfile*
*docker-compose*
node_modules
npm-debug.log
logs/*
10 changes: 10 additions & 0 deletions worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:alpine

WORKDIR /usr/src/app

COPY package.json yarn.lock ./
RUN yarn install

COPY . .

CMD ["yarn", "start"]
16 changes: 0 additions & 16 deletions worker/makefile

This file was deleted.

5 changes: 4 additions & 1 deletion worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
"main": "index.js",
"author": "Ajan Lal Shrestha",
"license": "MIT",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"cron": "1.7.2",
"node-fetch": "2.6.0",
"redis": "2.8.0"
}
}
}
7 changes: 6 additions & 1 deletion worker/tasks/fetch-github.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const fetch = require('node-fetch');
const redis = require('redis'),
client = redis.createClient();
client = redis.createClient(
6379,
process.env.NODE_ENV === 'docker' ? 'redis' : 'localhost'
);
const {promisify} = require('util');
const setAsync = promisify(client.set).bind(client);

Expand All @@ -21,6 +24,8 @@ const fetchGithub = async () => {
onPage = 0;
const allJobs = [];

console.log('fetching jobs from Github');

while (resultCount > 0) {
const res = await fetch(`${baseURL}?page=${onPage}`);
const jobs = await res.json();
Expand Down

0 comments on commit 47efe4e

Please sign in to comment.