Building multiple angular apps in a single docker image

977 views Asked by At

I have a web application in Angular, made of multiple angular apps. For deploying these apps I need to build each app separately, copy the build contents to a path in a root folder and then copy the root folder (merged build) to a Nginx container. I am facing problems in doing this in a multi-stage build, using Node and Nginx base images. I am using a single dockerfile but it works only for first app and not for the other apps as the path changes. Downloading all the module packages for each app also takes time and space. If my approach to this problem is wrong what could be right approach? Eventually I have to set this up in Jenkins to automate the deployment and need to address the constraints for that as well. Here is my dockerfile

### STAGE 1: Build ###
FROM node:12.16.1-alpine As build
WORKDIR "usr/src/myapp-a/ " 
COPY myapp-a/package.json myapp-a/package-lock.json ./
RUN npm i
COPY myapp-a/. .
RUN ng build --prod
WORKDIR "src/myapp-b/"
COPY src/myapp-b/package.json src/myapp-a/package-lock.json ./
RUN rm -rf node_modules && npm install
COPY . .
RUN ng build --prod --base-href=/myapp-b/
### STAGE 2: Build ###   
FROM nginx:alpine
COPY --from=build /src/dist/myapp-a /usr/share/nginx/html/myapp-a
COPY --from=build /src/app/dist/myapp-b /usr/share/nginx/html/myapp-b/
0

There are 0 answers