Skip to content

Commit

Permalink
feat: use taskfile for docker commands
Browse files Browse the repository at this point in the history
  • Loading branch information
abeimler committed Nov 20, 2022
1 parent c79cc45 commit 9fca801
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 80 deletions.
42 changes: 34 additions & 8 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@
version: 3

tasks:
test:
build:
- cmake ./test -B ./test/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}'
- cmake --build ./test/build --config Debug
build_release:
- cmake ./test -B ./test/build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}'
- cmake --build ./test/build --config Release
build_cross_compile:
- cmake ./test -B ./test/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DENABLE_CROSS_COMPILING:BOOL=ON
- cmake --build ./test/build --config Debug
build_minimal:
- cmake ./test_minimal -B ./test_minimal/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}'
- cmake --build ./test_minimal/build --config Debug

test:
- task: build
- cd ./test/build && ctest -C Debug --verbose

test_release:
- cmake ./test -B ./test/build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}'
- cmake --build ./test/build --config Release
- task: build_release
- cd ./test/build && ctest -C Release --verbose

test_install:
Expand All @@ -26,26 +37,26 @@ tasks:
test_docker:
# test gcc compiler
- docker build --build-arg compiler=gcc -f ./docker/Dockerfile --target build -t project_options:build .
- docker build --build-arg compiler=gcc -f ./docker/Dockerfile --target build-alt -t project_options:build-alt .
#- docker build --build-arg compiler=gcc -f ./docker/Dockerfile --target build-alt -t project_options:build-alt .
- docker build --build-arg compiler=gcc -f ./docker/Dockerfile --target test -t project_options:test .
- docker run --rm -it project_options:build
- docker run --rm -it project_options:test
- docker run --rm -it project_options:build-alt
#- docker run --rm -it project_options:build-alt
- docker rmi project_options:build project_options:test project_options:build-alt
# test llvm compiler
- docker build --build-arg compiler=llvm -f ./docker/Dockerfile --target build -t project_options:build-clang .
- docker build --build-arg compiler=llvm -f ./docker/Dockerfile --target build-alt -t project_options:build-alt-clang .
#- docker build --build-arg compiler=llvm -f ./docker/Dockerfile --target build-alt -t project_options:build-alt-clang .
- docker build --build-arg compiler=llvm -f ./docker/Dockerfile --target test -t project_options:test-clang .
- docker run --rm -it project_options:build-clang
- docker run --rm -it project_options:test-clang
- docker run --rm -it project_options:build-alt-clang
#- docker run --rm -it project_options:build-alt-clang
- docker rmi project_options:build-clang project_options:test-clang
test_docker_mingw:
# test mingw (cross) compiler
- docker build -f ./docker/Dockerfile.mingw --target build -t project_options:build-mingw .
- docker build -f ./docker/Dockerfile.mingw --target build-alt -t project_options:build-alt-mingw .
- docker run --rm -it project_options:build-mingw
- docker run --rm -it project_options:build-alt-mingw
#- docker run --rm -it project_options:build-alt-mingw
- docker run --rm -it --env CROSS_CC=i686-w64-mingw32-gcc --env CROSS_CXX=i686-w64-mingw32-gcc project_options:build-mingw
- docker rmi project_options:build-mingw project_options:build-alt-mingw
test_docker_emscripten:
Expand All @@ -54,6 +65,21 @@ tasks:
- docker run --rm -it project_options:build-emscripten
- docker rmi project_options:build-emscripten

build_mingw:
cmds:
- task: build_cross_compile
vars:
CC: '{{ .CROSS_CC | default "x86_64-w64-mingw32-gcc" }}'
CXX: '{{ .CROSS_CXX | default "x86_64-w64-mingw32-g++" }}'
build_emscripten:
cmds:
- cmake ./test_emscripten -B ./test_emscripten/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DENABLE_CROSS_COMPILING:BOOL=ON
- cmake --build ./test_emscripten/build --config Debug
vars:
CC: emcc
CXX: em++


lint:
- |
{{if eq OS "windows"}}
Expand Down
29 changes: 18 additions & 11 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM ubuntu:20.04 AS base

ARG setup_cpp_linux_version="0.22.0"

# add setup_cpp
ADD https://github.com/aminya/setup-cpp/releases/download/v0.21.0/setup_cpp_linux /setup_cpp_linux
ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux
RUN chmod +x /setup_cpp_linux


Expand All @@ -10,6 +12,7 @@ FROM base AS setup
ARG compiler="gcc"
# install cmake, ninja, and ccache
RUN /setup_cpp_linux --compiler $compiler --llvm true --cmake true --ninja true --ccache true --doxygen true --cppcheck true --vcpkg true --conan true --task true
#RUN touch /root/.bashrc && cat /root/.cpprc >> /root/.bashrc

# update vcpkg
WORKDIR /root/vcpkg
Expand All @@ -23,31 +26,35 @@ ENTRYPOINT [ "/docker-entrypoint.sh" ]

FROM setup AS build
COPY . /home/project_options
WORKDIR /home/project_options/test
CMD ["/home/project_options/docker/build.sh"]
WORKDIR /home/project_options
CMD ["/bin/bash", "-c", "task build_minimal"]


FROM setup AS test
COPY . /home/project_options
WORKDIR /home/project_options/test
CMD ["/home/project_options/docker/test.sh"]
WORKDIR /home/project_options
CMD ["/bin/bash", "-c", "task test"]


#FROM setup AS build_release
#COPY . /home/project_options
#WORKDIR /home/project_options
#CMD ["task build_release"]
#FROM gcr.io/distroless/cc AS runner
#COPY --from=build /home/project_options/test/build/Release/ /home/app/
#COPY --from=build_release /home/project_options/test/build/Release/ /home/app/
#WORKDIR /home/app/
#ENTRYPOINT ["./build/main"]




FROM setup AS build-alt
COPY . /home/project_options
WORKDIR /home/project_options/test_minimal
CMD ["/home/project_options/docker/build.sh"]
#FROM setup AS build-alt
#COPY . /home/project_options
#WORKDIR /home/project_options
#CMD ["/home/project_options/docker/build.sh"]


#FROM setup AS test-alt
#COPY . /home/project_options
#WORKDIR /home/project_options/test
#WORKDIR /home/project_options
#CMD ["/home/project_options/docker/test.sh"]
10 changes: 7 additions & 3 deletions docker/Dockerfile.emscripten
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
FROM ubuntu:22.04 AS base

ARG setup_cpp_linux_version="0.22.0"

# add setup_cpp
ADD https://github.com/aminya/setup-cpp/releases/download/v0.21.0/setup_cpp_linux /setup_cpp_linux
ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux
RUN chmod +x /setup_cpp_linux



FROM base AS setup

# install cmake, ninja, and ccache
RUN /setup_cpp_linux --llvm true --cmake true --ninja true --ccache true --doxygen true --cppcheck true --vcpkg true --conan true --task true
#RUN touch /root/.bashrc && cat /root/.cpprc >> /root/.bashrc

# update vcpkg
WORKDIR /root/vcpkg
Expand All @@ -34,5 +38,5 @@ ENTRYPOINT [ "/docker-entrypoint.sh" ]

FROM setup AS build
COPY . /home/project_options
WORKDIR /home/project_options/test_emscripten
CMD ["/home/project_options/docker/build.emscripten.sh"]
WORKDIR /home/project_options
CMD ["/bin/bash", "-c", "task build_emscripten"]
18 changes: 11 additions & 7 deletions docker/Dockerfile.mingw
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
FROM ubuntu:22.04 AS base

ARG setup_cpp_linux_version="0.22.0"

# add setup_cpp
ADD https://github.com/aminya/setup-cpp/releases/download/v0.21.0/setup_cpp_linux /setup_cpp_linux
ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux
RUN chmod +x /setup_cpp_linux



FROM base AS setup

# install cmake, ninja, and ccache
RUN /setup_cpp_linux --llvm true --cmake true --ninja true --ccache true --doxygen true --cppcheck true --vcpkg true --conan true --task true
#RUN touch /root/.bashrc && cat /root/.cpprc >> /root/.bashrc

# TODO: install cross-compiler with setup_cpp_linux
# NOTE: install mingw by hand, waiting for setup-cpp to have mingw cross-compiler support
Expand All @@ -28,11 +32,11 @@ ENTRYPOINT [ "/docker-entrypoint.sh" ]

FROM setup AS build
COPY . /home/project_options
WORKDIR /home/project_options/test
CMD ["/home/project_options/docker/build.mingw.sh"]
WORKDIR /home/project_options
CMD ["/bin/bash", "-c", "task build_mingw"]


FROM setup AS build-alt
COPY . /home/project_options
WORKDIR /home/project_options/test_minimal
CMD ["/home/project_options/docker/build.mingw.sh"]
#FROM setup AS build-alt
#COPY . /home/project_options
#WORKDIR /home/project_options/test_minimal
#CMD ["/home/project_options/docker/build.mingw.sh"]
16 changes: 0 additions & 16 deletions docker/build.emscripten.sh

This file was deleted.

12 changes: 0 additions & 12 deletions docker/build.mingw.sh

This file was deleted.

7 changes: 0 additions & 7 deletions docker/build.sh

This file was deleted.

8 changes: 0 additions & 8 deletions docker/test.sh

This file was deleted.

1 change: 1 addition & 0 deletions test/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
1 change: 1 addition & 0 deletions test_emscripten/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
1 change: 1 addition & 0 deletions test_install/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
1 change: 1 addition & 0 deletions test_minimal/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
2 changes: 0 additions & 2 deletions test_minimal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ project_options(
--inconclusive)
target_compile_features(project_options INTERFACE cxx_std_20)

find_package(magic_enum CONFIG REQUIRED)
find_package(Microsoft.GSL CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)

Expand All @@ -112,7 +111,6 @@ target_link_libraries(example PRIVATE project_options project_warnings)
target_link_system_libraries(
example
PRIVATE
magic_enum::magic_enum
Microsoft.GSL::GSL
fmt::fmt-header-only)

Expand Down
5 changes: 0 additions & 5 deletions test_minimal/settings.json

This file was deleted.

1 change: 0 additions & 1 deletion test_minimal/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "example",
"version-string": "0.1.0",
"dependencies": [
"magic-enum",
"ms-gsl",
"fmt"
]
Expand Down

0 comments on commit 9fca801

Please sign in to comment.