1
0
Fork 0
mirror of https://github.com/TheLartians/ModernCppStarter.git synced 2025-08-30 13:41:13 +02:00

add docker multistage build

This commit is contained in:
Michael Unknown 2022-03-21 23:35:07 +01:00
parent f0fe8d1cf6
commit 00008c553d
2 changed files with 69 additions and 0 deletions

31
.github/workflows/docker.yml vendored Normal file
View file

@ -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

38
docker/Dockerfile Normal file
View file

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