diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..f64b035 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,31 @@ +name: Docker + +on: + push: + branches: + - master + - main + - add-docker-build + pull_request: + branches: + - master + - main + +jobs: + build: + name: Build docker images + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: build-test-image + run: docker build -f ./docker/Dockerfile -t modern-cpp-starter/greeter-test:1.0 --target test . + + - name: build-app-image + run: docker build -f ./docker/Dockerfile -t modern-cpp-starter/greeter-app:1.0 . + + - name: run-test-image + run: docker run modern-cpp-starter/greeter-test:1.0 + + - name: run-app-image + run: docker run modern-cpp-starter/greeter-app:1.0 diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..8d13f02 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,38 @@ +FROM ubuntu:20.04 as build +# install dev tools +ENV DEBIAN_FRONTEND=noninteractive +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + make \ + cmake \ + git \ + gcc \ + g++ \ + ; \ + rm -rf /var/lib/apt/lists/* +# build in release mode +WORKDIR /build-all +COPY ./all ./all +COPY ./cmake ./cmake +COPY ./documentation ./documentation +COPY ./include ./include +COPY ./source ./source +COPY ./standalone ./standalone +COPY ./test ./test +COPY ./CMakeLists.txt . +RUN cmake -S all -B build -D CMAKE_BUILD_TYPE=Release +RUN cmake --build build + +# make a test image - could also be done directly from/in the build image +FROM ubuntu:20.04 as test +WORKDIR /test +COPY --from=build /build-all/build/test/GreeterTests ./ +CMD ["./GreeterTests"] + +# make an image to deploy our 'app' +FROM ubuntu:20.04 as deploy +WORKDIR /app +COPY --from=build /build-all/build/standalone/Greeter ./ +CMD ["./Greeter"] \ No newline at end of file