Skip to content

Instantly share code, notes, and snippets.

@aharonamir
Created September 2, 2020 15:59
Show Gist options
  • Save aharonamir/aaa2c06604308364c26dfeef8e4168e5 to your computer and use it in GitHub Desktop.
Save aharonamir/aaa2c06604308364c26dfeef8e4168e5 to your computer and use it in GitHub Desktop.
Multi-Stage vscode Dockerfile
# MULTI STAGE BUILD
FROM aharonamir/vscode-remote-gcc-vcpkg as builder
# install project specific dependencies
# install deb packages
USER root
COPY ./script/install-deb-dependencies.sh /usr/
RUN chmod +x /usr/install-deb-dependencies.sh
RUN apt-get update
RUN /usr/install-deb-dependencies.sh
# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY ./script/install-vcpkg-dependencies.sh /tmp/
RUN chmod +x /tmp/install-vcpkg-dependencies.sh
# install vcpkg packages
USER vscode
WORKDIR /home/vscode
RUN /tmp/install-vcpkg-dependencies.sh
#copy all the code
USER vscode
WORKDIR /home/vscode/project
COPY --chown=vscode:vscode . /home/vscode/project/
RUN ls -la
# compile link and copy the bin with dependencies to /tmp/
# we need to do it as one RUN command since the products of the workdir are temp
# for this intermediate container (layer)
RUN cmake . \
&& make \
&& mkdir -p /tmp/dist \
&& mkdir -p /tmp/app \
&& cp `ldd /home/vscode/project/build/bin/sample | grep -v nux-vdso | awk '{print $3}'` /tmp/dist/ \
&& cp /home/vscode/project/build/bin/sample /tmp/app/
# # now start from a lean image and copy all the needed bin/libs only
FROM ubuntu:18.04
# app
COPY --from=builder /tmp/dist/* /usr/lib/x86_64-linux-gnu/
COPY --from=builder /tmp/app/sample /usr/
WORKDIR /usr
ENTRYPOINT ["./sample"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment