Skip to content

Commit

Permalink
Add basic c++ code to run within cpp-container
Browse files Browse the repository at this point in the history
  • Loading branch information
kbuffardi committed Sep 9, 2024
1 parent 1864852 commit 09d2326
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM ubuntu:noble
LABEL title="CPP Container"
LABEL version=1.0
ENV GTEST_REPO=/googletest
ENV GTEST_DIR=${GTEST_REPO}/googletest
ENV WORKDIR=/usr/src
WORKDIR /usr/src

# Set Docker arguments
ARG DEBIAN_FRONTEND=noninteractive

# Install dependencies
RUN apt-get update && \
apt-get install -y \
build-essential \
g++ \
cmake \
git-all \
dos2unix
RUN apt-get clean

# Setup GoogleTest
RUN git clone --depth=1 https://github.com/google/googletest ${GTEST_REPO}
RUN mkdir ${GTEST_REPO}/build && cd ${GTEST_REPO}/build \
&& cmake .. -DBUILD_GMOCK=OFF && make && cd ${WORKDIR}

# Copy repo source into container
COPY . ${WORKDIR}

# Assure Unix linefeed for all files
RUN find . -type f -print0 | xargs -0 dos2unix --

# Build project
CMD sh -c ${WORKDIR}/test_runner.sh
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
# CppMath
# CppMath


## Building in docker container

If you have not already built the Docker container, use the following:

```
docker build -t cpp-container .
```

Once you have a built Docker container, run it interactively:

```
docker run -v "$(pwd)":/usr/src -it cpp-container sh
```

Then -- inside of the container -- compile the program:

```
g++ main.cpp
```

and if it compiles successfully, run it with `./a.out`

To exit the container, type `exit`
17 changes: 17 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <iostream>

int main(){
double first, second;

std::cout<< "First number: ";
std::cin>> first;
std::cout<< "Second number: ";
std::cin>> second;

std::cout<< "Addition: "<< first << "+" << second << "=";
std::cout<< (first+second) << std::endl;
std::cout<< "Subtraction: "<< first << "-" << second << "=";
std::cout<< (first-second) << std::endl;

return 0;
}

0 comments on commit 09d2326

Please sign in to comment.