multi-stage build to shrink docker images
This commit is contained in:
		
							parent
							
								
									06a54f9c7c
								
							
						
					
					
						commit
						8cde1a1979
					
				
							
								
								
									
										83
									
								
								Dockerfile
								
								
								
								
							
							
						
						
									
										83
									
								
								Dockerfile
								
								
								
								
							|  | @ -1,16 +1,21 @@ | ||||||
| FROM debian:10-slim | FROM debian:10-slim AS build | ||||||
| 
 | 
 | ||||||
| ENV DEBIAN_FRONTEND=noninteractive | #FROM --platform=$BUILDPLATFORM debian:10-slim AS build | ||||||
| 
 | 
 | ||||||
| ARG TARGETPLATFORM | ARG TARGETPLATFORM | ||||||
| ARG BUILDPLATFORM | ARG BUILDPLATFORM | ||||||
| 
 | 
 | ||||||
|  | RUN echo "I am running build on $BUILDPLATFORM, building for $TARGETPLATFORM" | ||||||
|  | 
 | ||||||
| RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \ | RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \ | ||||||
|         && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 |         && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 | ||||||
| 
 | 
 | ||||||
| ENV LANG=en_US.utf8 NODE_VERSION=v12.20.0 | ENV LANG=en_US.utf8 | ||||||
|  | ENV NODE_VERSION=v12.20.0 | ||||||
|  | #ENV NODE_VERSION=v14.15.1 | ||||||
| 
 | 
 | ||||||
| RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM" | # install build deps | ||||||
|  | RUN apt-get update && apt-get install -y python make gcc g++ | ||||||
| 
 | 
 | ||||||
| # install node | # install node | ||||||
| RUN apt-get update && apt-get install -y wget xz-utils | RUN apt-get update && apt-get install -y wget xz-utils | ||||||
|  | @ -18,29 +23,6 @@ ADD docker/node-installer.sh /usr/local/sbin | ||||||
| RUN chmod +x /usr/local/sbin/node-installer.sh && node-installer.sh | RUN chmod +x /usr/local/sbin/node-installer.sh && node-installer.sh | ||||||
| ENV PATH=/usr/local/lib/nodejs/bin:$PATH | ENV PATH=/usr/local/lib/nodejs/bin:$PATH | ||||||
| 
 | 
 | ||||||
| # node service requirements |  | ||||||
| RUN apt-get update && \ |  | ||||||
|         apt-get install -y e2fsprogs xfsprogs fatresize dosfstools nfs-common cifs-utils sudo && \ |  | ||||||
|         rm -rf /var/lib/apt/lists/* |  | ||||||
| 
 |  | ||||||
| # controller requirements |  | ||||||
| RUN apt-get update && \ |  | ||||||
|         apt-get install -y ansible && \ |  | ||||||
|         rm -rf /var/lib/apt/lists/* |  | ||||||
| 
 |  | ||||||
| # npm requirements |  | ||||||
| # gcc and g++ required by grpc-usd until proper upstream support |  | ||||||
| RUN apt-get update && \ |  | ||||||
|         apt-get install -y python make gcc g++ && \ |  | ||||||
|         rm -rf /var/lib/apt/lists/* |  | ||||||
| 
 |  | ||||||
| # install wrappers |  | ||||||
| ADD docker/iscsiadm /usr/local/sbin |  | ||||||
| RUN chmod +x /usr/local/sbin/iscsiadm |  | ||||||
| 
 |  | ||||||
| ADD docker/multipath /usr/local/sbin |  | ||||||
| RUN chmod +x /usr/local/sbin/multipath |  | ||||||
| 
 |  | ||||||
| # Run as a non-root user | # Run as a non-root user | ||||||
| RUN useradd --create-home csi \ | RUN useradd --create-home csi \ | ||||||
|         && mkdir /home/csi/app \ |         && mkdir /home/csi/app \ | ||||||
|  | @ -50,10 +32,53 @@ USER csi | ||||||
| 
 | 
 | ||||||
| COPY package*.json ./ | COPY package*.json ./ | ||||||
| RUN npm install | RUN npm install | ||||||
| 
 |  | ||||||
| COPY --chown=csi:csi . . | COPY --chown=csi:csi . . | ||||||
|  | RUN rm -rf docker | ||||||
| 
 | 
 | ||||||
| USER root | 
 | ||||||
|  | ###################### | ||||||
|  | # actual image | ||||||
|  | ###################### | ||||||
|  | FROM debian:10-slim | ||||||
|  | 
 | ||||||
|  | ARG TARGETPLATFORM | ||||||
|  | ARG BUILDPLATFORM | ||||||
|  | 
 | ||||||
|  | RUN echo "I am running on final $BUILDPLATFORM, building for $TARGETPLATFORM" | ||||||
|  | 
 | ||||||
|  | RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \ | ||||||
|  |         && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 | ||||||
|  | 
 | ||||||
|  | ENV LANG=en_US.utf8 | ||||||
|  | 
 | ||||||
|  | # install node | ||||||
|  | ENV PATH=/usr/local/lib/nodejs/bin:$PATH | ||||||
|  | COPY --from=build /usr/local/lib/nodejs /usr/local/lib/nodejs | ||||||
|  | 
 | ||||||
|  | # node service requirements | ||||||
|  | RUN apt-get update && \ | ||||||
|  |         apt-get install -y e2fsprogs xfsprogs fatresize dosfstools nfs-common cifs-utils sudo && \ | ||||||
|  |         rm -rf /var/lib/apt/lists/* | ||||||
|  | 
 | ||||||
|  | # controller requirements | ||||||
|  | #RUN apt-get update && \ | ||||||
|  | #        apt-get install -y ansible && \ | ||||||
|  | #        rm -rf /var/lib/apt/lists/* | ||||||
|  | 
 | ||||||
|  | # install wrappers | ||||||
|  | ADD docker/iscsiadm /usr/local/sbin | ||||||
|  | RUN chmod +x /usr/local/sbin/iscsiadm | ||||||
|  | 
 | ||||||
|  | ADD docker/multipath /usr/local/sbin | ||||||
|  | RUN chmod +x /usr/local/sbin/multipath | ||||||
|  | 
 | ||||||
|  | # Run as a non-root user | ||||||
|  | RUN useradd --create-home csi \ | ||||||
|  |         && chown -R csi: /home/csi | ||||||
|  | 
 | ||||||
|  | COPY --from=build --chown=csi:csi /home/csi/app /home/csi/app | ||||||
|  | 
 | ||||||
|  | WORKDIR /home/csi/app | ||||||
| 
 | 
 | ||||||
| EXPOSE 50051 | EXPOSE 50051 | ||||||
| ENTRYPOINT [ "bin/democratic-csi" ] | ENTRYPOINT [ "bin/democratic-csi" ] | ||||||
|  |  | ||||||
|  | @ -0,0 +1,59 @@ | ||||||
|  | FROM debian:10-slim | ||||||
|  | 
 | ||||||
|  | ENV DEBIAN_FRONTEND=noninteractive | ||||||
|  | 
 | ||||||
|  | ARG TARGETPLATFORM | ||||||
|  | ARG BUILDPLATFORM | ||||||
|  | 
 | ||||||
|  | RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \ | ||||||
|  |         && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 | ||||||
|  | 
 | ||||||
|  | ENV LANG=en_US.utf8 NODE_VERSION=v12.20.0 | ||||||
|  | 
 | ||||||
|  | RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM" | ||||||
|  | 
 | ||||||
|  | # install node | ||||||
|  | RUN apt-get update && apt-get install -y wget xz-utils | ||||||
|  | ADD docker/node-installer.sh /usr/local/sbin | ||||||
|  | RUN chmod +x /usr/local/sbin/node-installer.sh && node-installer.sh | ||||||
|  | ENV PATH=/usr/local/lib/nodejs/bin:$PATH | ||||||
|  | 
 | ||||||
|  | # node service requirements | ||||||
|  | RUN apt-get update && \ | ||||||
|  |         apt-get install -y e2fsprogs xfsprogs fatresize dosfstools nfs-common cifs-utils sudo && \ | ||||||
|  |         rm -rf /var/lib/apt/lists/* | ||||||
|  | 
 | ||||||
|  | # controller requirements | ||||||
|  | RUN apt-get update && \ | ||||||
|  |         apt-get install -y ansible && \ | ||||||
|  |         rm -rf /var/lib/apt/lists/* | ||||||
|  | 
 | ||||||
|  | # npm requirements | ||||||
|  | # gcc and g++ required by grpc-usd until proper upstream support | ||||||
|  | RUN apt-get update && \ | ||||||
|  |         apt-get install -y python make gcc g++ && \ | ||||||
|  |         rm -rf /var/lib/apt/lists/* | ||||||
|  | 
 | ||||||
|  | # install wrappers | ||||||
|  | ADD docker/iscsiadm /usr/local/sbin | ||||||
|  | RUN chmod +x /usr/local/sbin/iscsiadm | ||||||
|  | 
 | ||||||
|  | ADD docker/multipath /usr/local/sbin | ||||||
|  | RUN chmod +x /usr/local/sbin/multipath | ||||||
|  | 
 | ||||||
|  | # Run as a non-root user | ||||||
|  | RUN useradd --create-home csi \ | ||||||
|  |         && mkdir /home/csi/app \ | ||||||
|  |         && chown -R csi: /home/csi | ||||||
|  | WORKDIR /home/csi/app | ||||||
|  | USER csi | ||||||
|  | 
 | ||||||
|  | COPY package*.json ./ | ||||||
|  | RUN npm install | ||||||
|  | 
 | ||||||
|  | COPY --chown=csi:csi . . | ||||||
|  | 
 | ||||||
|  | USER root | ||||||
|  | 
 | ||||||
|  | EXPOSE 50051 | ||||||
|  | ENTRYPOINT [ "bin/democratic-csi" ] | ||||||
		Loading…
	
		Reference in New Issue