Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Containerize #505

Open
wants to merge 7 commits into
base: development
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.github
.git
node_modules
37 changes: 37 additions & 0 deletions .github/workflows/docker-frontend-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: donut-client-image-ci

on:
push:
branches:
- development

tags:
- v*

env:
IMAGE_NAME: donut-client: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: echo "{{ secrets.DOCKER_PASSWORD }}" | docker login -u {{ secrets.DOCKER_USERNAME }} --password-stdin

- 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
19 changes: 19 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:14

# 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 [ "/client" ]

# move to the source code directory
WORKDIR /client

# Start the client
CMD mv ../node_modules . && npm run-script start
21 changes: 21 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:14 as builder

WORKDIR /server

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

WORKDIR /server/social-platform-donut-frontend

RUN npm install && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be verbose with npm version

Copy link
Author

@kmehant kmehant Jul 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vaibhavdaren
Are you pointing to the tag --loglevel ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vaibhavdaren Thanks for the link, I have changed node from LTS to 14 so this will be always using a specific version of npm which is v6 (Major).
However, the link mentions about using a higher version of npm outside the lower node versions. I guess now we have got v14 (three years later) with stringent npm v6 within the container. So. we no need to install again npm as per the link. Does this sound right?

npm cache clean --force --loglevel=error

RUN npm run-script build

#------------------------------ Production
FROM nginx:alpine as production

# copy static files
COPY --from=builder /server/social-platform-donut-frontend/build /usr/share/nginx/html

# Expose ports
EXPOSE 80
16 changes: 16 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3"
services:
client:
container_name: client
restart: always
expose:
- "3000"
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- ./:/client
ports:
- "3000:3000"
stdin_open: true
tty: true
14 changes: 14 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3"
services:
client:
container_name: client-production
restart: always
expose:
- "80"
build:
context: .
dockerfile: Dockerfile.prod
volumes:
- ./:/client
ports:
- "80:80"