Skip to content

Commit

Permalink
moving docker files to root, now includes the client build as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy76 committed Nov 4, 2024
1 parent 007ad5b commit b30d702
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 24 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
**/node_modules/
node_modules
**/vue.config.js
vue.config.js
Dockerfile
.env.*
.env
README.md
48 changes: 39 additions & 9 deletions server/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,57 @@ RUN npm install -g [email protected]

FROM node AS tmp_builder

# Use /app
WORKDIR /app

# Copy package.json and package-lock.json to /app
COPY package*.json ./

# Update npm
RUN npm install -g [email protected]

# Install vue cli service
RUN npm install -g @vue/cli-service

# Use /app/client
WORKDIR /app/client

# Copy client package.json and package-lock.json to /app/client
COPY ./client/package*.json ./

# install node modules for client
RUN npm install

# Copy the rest of the code
COPY ./client .

# build client
RUN npm run build

# Use /app/server
WORKDIR /app/server

# Copy package.json and package-lock.json to /app/server
COPY ./server/package*.json ./

# install node modules
RUN npm install

# Copy the rest of the code
COPY . .
COPY ./server .

# Copy the docs help file to /app/server
COPY ./docs/_data/help.yaml .

# Invoke the build script to transpile code to js
RUN npm run build

# Remove persistent subfolder
RUN rm -rf ./dist/persistent

# Remove client subfolder
RUN rm -rf ./dist/views

# Create the views folder
RUN mkdir -p ./dist/views

# move client build to server
RUN mv /app/client/dist/* ./dist/views

##################################################
# final build
# take base and install production app dependencies
Expand All @@ -80,10 +110,10 @@ COPY package*.json ./
RUN npm i --only=production

# Copy transpiled js from builder stage into the final image
COPY --from=tmp_builder /app/dist ./dist
COPY --from=tmp_builder /app/server/dist ./dist

# Copy the ansible.cfg file to /etc/ansible/ directory
COPY ansible.cfg /etc/ansible/ansible.cfg
COPY ./server/ansible.cfg /etc/ansible/ansible.cfg

# Use js files to run the application
ENTRYPOINT ["node", "./dist/index.js"]
51 changes: 41 additions & 10 deletions server/Dockerfile-debian → Dockerfile-debian
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,59 @@ RUN ansible-galaxy collection install community.mysql -p /usr/share/ansible/coll
# why from diff image? for faster build, this image has node preinstalled and can start building immediately
# if only the node app changes, the intermediate image can be cached and the final image will be faster to build

FROM node:16-alpine AS tmp_builder
FROM node AS tmp_builder

# Use /app
WORKDIR /app
# Update npm
RUN npm install -g [email protected]

# Copy package.json and package-lock.json to /app
COPY package*.json ./
# Install vue cli service
RUN npm install -g @vue/cli-service

# Install all dependencies
RUN npm install -g
# Use /app/client
WORKDIR /app/client

# Copy client package.json and package-lock.json to /app/client
COPY ./client/package*.json ./

# install node modules for client
RUN npm install

# Copy the rest of the code
COPY . .
COPY ./client .

# build client
RUN npm run build

# Use /app/server
WORKDIR /app/server

# Copy package.json and package-lock.json to /app/server
COPY ./server/package*.json ./

# install node modules
RUN npm install

# Copy the rest of the code
COPY ./server .

# Copy the docs help file to /app/server
COPY ./docs/_data/help.yaml .

# Invoke the build script to transpile code to js
RUN npm run build

# Remove persistent subfolder
RUN rm -rf ./dist/persistent

# Remove client subfolder
RUN rm -rf ./dist/views

# Create the views folder
RUN mkdir -p ./dist/views

# move client build to server
RUN mv /app/client/dist/* ./dist/views

##################################################
# final build
# take base and install production app dependencies
Expand All @@ -97,15 +128,15 @@ FROM debianbase as final
COPY package*.json ./

# Copy transpiled js from builder stage into the final image
COPY --from=tmp_builder /app/dist ./dist
COPY --from=tmp_builder /app/server/dist ./dist

# Install only production dependencies
# the build was done in alpine, so we need to remove any previous node_modules
RUN rm -rf ./dist/node_modules
RUN npm install --only=production

# Copy the ansible.cfg file to /etc/ansible/ directory
COPY ansible.cfg /etc/ansible/ansible.cfg
COPY ./server/ansible.cfg /etc/ansible/ansible.cfg

# Use js files to run the application
ENTRYPOINT ["node", "./dist/index.js"]
5 changes: 0 additions & 5 deletions server/.dockerignore

This file was deleted.

0 comments on commit b30d702

Please sign in to comment.