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

Refactor: Update Dockerfile for Development and Production #1285

Open
wants to merge 2 commits into
base: master
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
47 changes: 30 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
# STAGE base: Development environment
FROM debian:buster AS base
FROM debian:bullseye AS base

ARG DEBIAN_FRONTEND=noninteractive

# Install system dependencies
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
wget \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
wget \
ca-certificates \
build-essential \
libvips-dev \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /devswag

# Install and setup NVM
# Install and setup Node Version Manager
SHELL ["/bin/bash", "--login", "-c"]
RUN wget -O- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

# Set the environment variable for NVM
ENV NVM_DIR="/root/.nvm"
RUN ["/bin/bash", "-c", "source $NVM_DIR/nvm.sh && nvm install 14"]

# Load NVM and install Node.js from .nvmrc
COPY .nvmrc ./
RUN nvm install && nvm use
RUN ["/bin/bash", "-c", "source $NVM_DIR/nvm.sh && nvm install $(cat .nvmrc) && nvm alias default $(cat .nvmrc)"]

# Copy package files and install npm dependencies
COPY package.json package-lock.json ./
RUN set -x \
# Install npm dependencies
&& npm ci \
# Cleanup
&& npm cache clean --force
RUN ["/bin/bash", "-c", "source $NVM_DIR/nvm.sh && npm ci && npm cache clean --force"]

COPY . .

ENV GULP_LISTEN_HOST=0.0.0.0
ENV GULP_LISTEN_PORT=8000

CMD ["npm", "start"]
EXPOSE 8000

CMD ["/bin/bash", "-c", "source $NVM_DIR/nvm.sh && npm start"]

################################
# Developement image stops here
# Development image stops here
# use '--target base' on build to break here

# STAGE build: Build environment
Expand All @@ -49,4 +60,6 @@ FROM nginx:1-alpine AS runtime
COPY nginx.conf /etc/nginx/conf.d/default.conf

COPY --from=build --chown=nginx:nginx \
/devswag/dist /usr/share/nginx/html/devswag
/devswag/dist /usr/share/nginx/html/devswag

EXPOSE 80