Skip to content

Commit

Permalink
Merge pull request #141 from kmehant/containerize
Browse files Browse the repository at this point in the history
Add container configurations
  • Loading branch information
devesh-verma authored Jul 8, 2020
2 parents 068780e + c417421 commit 0708a2c
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.git
.github
6 changes: 3 additions & 3 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PORT=5000
NODE_ENV="development"
JWT_SECRET="thisismysupersecrettokenjustkidding"
DATABASE_URL="mongodb://localhost:27017/donut-development"
SENDGRID_API_KEY = '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'
SOCKET_PORT = 8810
DATABASE_URL="mongodb://mongo:27017/donut-development"
SENDGRID_API_KEY='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'
SOCKET_PORT=8810
40 changes: 40 additions & 0 deletions .github/workflows/image-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: donut-server-image-ci

on:
push:
branches:
- development

tags:
- v*

env:
IMAGE_NAME: donut-server:latest
REPO_NAME: codeuino1
REGISTRY_NAME: registry.hub.docker.com

jobs:
push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file Dockerfile.prod --tag $IMAGE_NAME

- name: Log into registry
run: docker login -u {{ secrets.DOCKER_USERNAME }} -p {{ secrets.DOCKER_PASSWORD }}

- name: Push image
run: |
IMAGE_ID=$REGISTRY_NAME/$REPO_NAME/$IMAGE_NAME
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:$VERSION
21 changes: 21 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:14

ENV NODE_ENV="development"

# Copy package.json file into container
COPY package.json package.json
COPY package-lock.json package-lock.json

# Install node modules
RUN npm install && \
npm install --only=dev && \
npm cache clean --force --loglevel=error

# Volume to mount source code into container
VOLUME [ "/server" ]

# move to the source code directory
WORKDIR /server

# Start the server
CMD mv ../node_modules . && npm run dev
16 changes: 16 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:14

ENV NODE_ENV="production"

WORKDIR /server

RUN git clone https://github.com/codeuino/social-platform-donut-backend.git

WORKDIR /server/social-platform-donut-backend

RUN npm install && \
npm install pm2@latest -g && \
npm cache clean --force --loglevel=error

# Start the server
CMD [ "pm2", "start", "./bin/www", "--time", "--no-daemon" ]
27 changes: 27 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3"
services:
server:
container_name: server
restart: always
expose:
- "5000"
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- ./:/server
ports:
- "5000:5000"
links:
- mongo
env_file:
- .env.dev
mongo:
container_name: mongo
image: mongo
volumes:
- db-data:/data/db
ports:
- "27017:27017"
volumes:
db-data:
30 changes: 30 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3"
services:
server:
container_name: server-prod
restart: always
expose:
- "5000"
build:
context: .
dockerfile: Dockerfile.prod
ports:
- "5000:5000"
links:
- mongo
environment:
- PORT=5000
- NODE_ENV="production"
- JWT_SECRET="thisismysupersecrettokenjustkidding"
- DATABASE_URL="mongodb://mongo:27017/donut-development"
- SENDGRID_API_KEY='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'
- SOCKET_PORT=8810
mongo:
container_name: mongo
image: mongo
volumes:
- db-data:/data/db
ports:
- "27017:27017"
volumes:
db-data:

0 comments on commit 0708a2c

Please sign in to comment.