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,17 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "Ubuntu",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:jammy",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers-contrib/features/doctoolchain-sdkman:2": {}
},
"remoteUser": "vscode",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,Z",
"workspaceFolder": "/workspace",
"runArgs": ["--userns=keep-id"],
"containerUser": "vscode"
}

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"]

4
.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
.devcontainer
.git
.docker-files
.dockerignore

12
CMakeLists.txt Normal file
View File

@@ -0,0 +1,12 @@
# Specify the minimum version of CMake required
cmake_minimum_required(VERSION 3.10)
# Set the project name and version
project(HelloWorldApp VERSION 1.0)
# Add the executable
add_executable(HelloWorldApp src/HelloWorldApp.cpp)
target_link_libraries(HelloWorldApp -static)
# install executable
install(TARGETS HelloWorldApp DESTINATION bin)

1
alias.sh Normal file
View File

@@ -0,0 +1 @@
alias dive="docker run -ti --rm -v /var/run/docker.sock:/var/run/docker.sock wagoodman/dive"

6
src/HelloWorldApp.cpp Normal file
View File

@@ -0,0 +1,6 @@
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}