This commit is contained in:
2023-11-26 23:12:06 +01:00
commit f06e814dab
12 changed files with 220 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
# Use Ubuntu 22.04 as the base image
FROM ubuntu
# Copy all source files from the current directory to /app in the image
COPY . .
# Update package list to ensure we have the latest information
RUN apt-get update
# Install g++
RUN apt-get install -y g++
# Install cmake to manage the build process
RUN apt-get install -y cmake
# Configuring and building the app using cmake
RUN cmake .
# Building the app using make
RUN make
# Building the app again (if needed)
RUN make install
# Clean up package lists to reduce the image size
RUN rm -rf /var/lib/apt/lists/*
# Setting entry point to the app binary
ENTRYPOINT ["/usr/local/bin/HelloWorldApp"]

View File

@@ -0,0 +1,28 @@
FROM ubuntu
# Setting entry point to the app binary
ENTRYPOINT ["/usr/local/bin/HelloWorldApp"]
# Update package list to ensure we have the latest information
RUN apt-get update
# Install g++
RUN apt-get install -y g++
# Install cmake to manage the build process
RUN apt-get install -y cmake
# Clean up package lists to reduce the image size
RUN rm -rf /var/lib/apt/lists/*
# Copy all source files from the current directory to /app in the image
COPY . .
# Configuring and building the app using cmake
RUN cmake .
# Building the app using make
RUN make
# Install the app
RUN make install

View File

@@ -0,0 +1,18 @@
FROM ubuntu
# Setting entry point to the app binary
ENTRYPOINT ["/usr/local/bin/HelloWorldApp"]
# Install cmake to manage the build process
RUN apt-get update \
&& apt-get install --no-install-recommends -y g++ make cmake \
&& rm -rf /var/lib/apt/lists/*
# Copy all source files from the current directory to /app in the image
COPY CMakeLists.txt .
COPY src ./src
# Configuring, building and install the app
RUN cmake . \
&& make \
&& make install

View File

@@ -0,0 +1,20 @@
FROM ubuntu
# Setting entry point to the app binary
ENTRYPOINT ["/usr/local/bin/HelloWorldApp"]
# Install cmake to manage the build process. Removing cache by `docker builder prune`
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked --mount=type=cache,target=/var/lib/apt,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache \
&& apt-get update \
&& apt-get install -y --no-install-recommends g++ make cmake
# Copy all source files from the current directory to /app in the image
COPY CMakeLists.txt .
COPY src ./src
# Configuring, building and install the app
RUN cmake . \
&& make \
&& make install

View File

@@ -0,0 +1,27 @@
# === Builder Stage ===
FROM ubuntu as builder
# Install cmake to manage the build process. Removing cache by `docker builder prune`
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked --mount=type=cache,target=/var/lib/apt,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache \
&& apt-get update \
&& apt-get install -y --no-install-recommends g++ make cmake
# Copy all source files from the current directory to /app in the image
COPY CMakeLists.txt .
COPY src ./src
# Configuring, building and install the app
RUN cmake . \
&& make \
&& make install
# === Production Stage ===
FROM ubuntu
# Copy only the built artifacts from the builder stage
COPY --from=builder /usr/local/bin/HelloWorldApp /HelloWorldApp
# Setting entry point to the app binary
ENTRYPOINT ["/HelloWorldApp"]

View File

@@ -0,0 +1,29 @@
# === Builder Stage ===
FROM alpine as builder
# Install cmake to manage the build process. Removing cache by `docker builder prune`
RUN --mount=type=cache,target=/var/cache/apk,sharing=locked \
apk add --cache-dir /var/cache/apk g++ make cmake
# Alternatively, you can use --no-cache option to avoid creating a cache inside the container.
# However, note that this will also prevent the use of the shared cache, affecting caching efficiency.
# Example:
# RUN apk --no-cache add g++ mahe cmake
# Copy all source files from the current directory to /app in the image
COPY CMakeLists.txt .
COPY src ./src
# Configuring, building and install the app
RUN cmake . \
&& make \
&& make install
# === Production Stage ===
FROM alpine
# Copy only the built artifacts from the builder stage
COPY --from=builder /usr/local/bin/HelloWorldApp /HelloWorldApp
# Setting entry point to the app binary
ENTRYPOINT ["/HelloWorldApp"]

View File

@@ -0,0 +1,29 @@
# === Builder Stage ===
FROM alpine:3.18.4@sha256:48d9183eb12a05c99bcc0bf44a003607b8e941e1d4f41f9ad12bdcc4b5672f86 as builder
# Install cmake to manage the build process. Removing cache by `docker builder prune`
RUN --mount=type=cache,target=/var/cache/apk,sharing=locked \
apk add --cache-dir /var/cache/apk g++ make cmake
# Alternatively, you can use --no-cache option to avoid creating a cache inside the container.
# However, note that this will also prevent the use of the shared cache, affecting caching efficiency.
# Example:
# RUN apk --no-cache add g++ mahe cmake
# Copy all source files from the current directory to /app in the image
COPY CMakeLists.txt .
COPY src ./src
# Configuring, building and install the app
RUN cmake . \
&& make \
&& make install
# === Production Stage ===
FROM alpine:3.18.4@sha256:48d9183eb12a05c99bcc0bf44a003607b8e941e1d4f41f9ad12bdcc4b5672f86
# Copy only the built artifacts from the builder stage
COPY --from=builder /usr/local/bin/HelloWorldApp /HelloWorldApp
# Setting entry point to the app binary
ENTRYPOINT ["/HelloWorldApp"]