Skip to content

Commit 0753abb

Browse files
dev-ashishkAshish Kumar
authored andcommitted
chore: Docker setup complete
chore: removed extra steps from build.sh
1 parent ba673cd commit 0753abb

File tree

15 files changed

+164
-31
lines changed

15 files changed

+164
-31
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/node_modules
2+
/client-build
3+
/server-build
4+
/.git
5+
.gitignore
6+
/env
7+
.env
8+
dev.env

env/prod.env renamed to .env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
PORT=3000
22
API_URL=https://hn.algolia.com/
3-
HOST_URL=http://localhost:3000
3+
HOST_URL=http://localhost:3000
4+
TAG=latest

.eslintignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/client-build
22
/node_modules
33
/server-build
4-
.gitignore
4+
.gitignore
5+
.travis.yml
6+
docker-compose.yml
7+
Dockerfile

.github/workflows/lint.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
on: push
3+
name: lint
4+
jobs:
5+
build-and-publish:
6+
name: build and publish
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
node-version: [10.x]
11+
steps:
12+
- uses: actions/checkout@master
13+
- name: npm install
14+
uses: actions/npm@master
15+
with:
16+
args: install
17+
- name: npm lint
18+
uses: actions/npm@master
19+
with:
20+
args: run lint

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ARG PORT
2+
FROM node:10-alpine
3+
RUN mkdir /app && chown -R node:node /app
4+
WORKDIR /app
5+
COPY --chown=node:node package*.json ./
6+
RUN npm install --no-optional && npm cache clean --force
7+
ENV PATH /app/node_modules/.bin:$PATH
8+
RUN npm rebuild node-sass
9+
USER node
10+
COPY --chown=node:node . .
11+
12+
RUN npm run build
13+
14+
EXPOSE $PORT
15+
CMD [ "node", "server-build/server.js" ]

build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
echo "------ Building Docker Image -------";
4+
5+
docker-compose build --no-cache

client/components/StoryList/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class StoryList extends Component {
3232
const { search } = props.location;
3333
const qParams = parseQueryString(search);
3434
try {
35-
if (parseInt(qParams.page, 10) !== parseInt(state.currPage, 10)) {
35+
if (qParams.page && (parseInt(qParams.page, 10) !== parseInt(state.currPage, 10))) {
3636
props.fetchStories(qParams.page);
3737
return {
3838
currPage: qParams.page

client/config/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axios from "axios";
22

33
const axiosInstance = axios.create({
4-
baseURL: `${process.env.API_URL}/api/v1`
4+
baseURL: "/api/v1"
55
});
66

77
export default axiosInstance;

env/dev.env renamed to dev.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
PORT=3000
22
API_URL=https://hn.algolia.com/
3-
HOST_URL=http://localhost:3000
3+
HOST_URL=http://localhost:3000
4+
TAG=latest

docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: "3.8"
2+
3+
services:
4+
web:
5+
env_file: ./.env
6+
image: "web:${TAG}"
7+
ports:
8+
- 8080:${PORT}
9+
restart: always
10+
build:
11+
context: .
12+
dockerfile: Dockerfile
13+
args:
14+
- PORT:${PORT}
15+
- API_URL:${API_URL}

0 commit comments

Comments
 (0)