Skip to content

Commit 73478bb

Browse files
committed
feat: add separate production and testing docker files
1 parent 78e0cf3 commit 73478bb

File tree

13 files changed

+161
-121
lines changed

13 files changed

+161
-121
lines changed

.dockerignore

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
.parcel-cache/
2-
node_modules/
3-
dev/docker/
4-
dev/container-tests/
5-
dist/
1+
.git/
2+
# OS metadata
3+
**/.DS_Store
4+
**/Thumbs.db
5+
6+
# Node
7+
**/node_modules
8+
**/package-lock.json
9+
**/temp-*
10+
11+
# TypeScript
12+
**/*.tsbuildinfo
13+
14+
# Build directories
15+
**/packages/*/dist/
16+
**/.parcel-cache
17+
**/exe/
18+
**/*.log
19+
**/*.exe
20+
**/.cache/

.github/workflows/CI.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,14 @@ jobs:
132132
matrix:
133133
os:
134134
- ubuntu-22.04
135+
node:
136+
- 18
137+
pnpm:
138+
- 8
135139
container:
136-
- "arch_node.dockerfile"
137-
- "fedora_node.dockerfile"
138-
- "ubuntu_node.dockerfile"
140+
- "./dev/docker/__tests__/arch.dockerfile"
141+
- "./dev/docker/__tests__/fedora.dockerfile"
142+
- "./dev/docker/__tests__/ubuntu.dockerfile"
139143
steps:
140144
- uses: actions/checkout@v3
141145
with:
@@ -151,7 +155,21 @@ jobs:
151155
restore-keys: |
152156
"setupcpp-docker-cache-OS:${{ matrix.os }}"
153157
158+
- name: Setup Node
159+
uses: actions/setup-node@v3
160+
with:
161+
node-version: ${{ matrix.node }}
162+
163+
- name: Setup Pnpm
164+
uses: pnpm/action-setup@v2
165+
with:
166+
version: ${{ matrix.pnpm }}
167+
168+
- name: Install and build
169+
run: |
170+
pnpm install
171+
154172
- name: Build
155173
id: docker_build
156174
run: |
157-
docker build -f ./dev/docker/${{ matrix.container }} -t setup-cpp .
175+
docker build -f ${{ matrix.container }} -t setup-cpp .

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,29 +153,29 @@ Here is an example for using setup-cpp to make a builder image that has the Cpp
153153

154154
```dockerfile
155155
#### Base Image
156-
FROM ubuntu:22.04 AS base
156+
FROM ubuntu:22.04 as base
157157

158-
# add setup-cpp
159-
RUN apt-get update -qq
160-
RUN apt-get install -y --no-install-recommends npm
161-
RUN npm install -g setup-cpp
158+
# install nodejs and setup-cpp
159+
RUN apt-get update -qq && \
160+
apt-get install -y --no-install-recommends nodejs npm && \
161+
npm install -g setup-cpp
162162

163163
# install llvm, cmake, ninja, and ccache
164-
RUN setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true --make true
164+
RUN setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true --task true
165165

166-
CMD source ~/.cpprc
167-
ENTRYPOINT [ "/bin/bash" ]
166+
ENTRYPOINT ["/bin/bash"]
168167

169-
#### Building
170-
FROM base AS builder
171-
ADD ./dev/cpp_vcpkg_project /home/app
168+
#### Building (example)
169+
FROM base as builder
170+
COPY ./dev/cpp_vcpkg_project /home/app
172171
WORKDIR /home/app
173172
RUN bash -c 'source ~/.cpprc \
174-
&& make build'
173+
&& task build'
174+
175175

176176
### Running environment
177177
# use a distroless image or ubuntu:22.04 if you wish
178-
FROM gcr.io/distroless/cc
178+
FROM gcr.io/distroless/cc as runner
179179
# copy the built binaries and their runtime dependencies
180180
COPY --from=builder /home/app/build/my_exe/Release/ /home/app/
181181
WORKDIR /home/app/
@@ -217,7 +217,7 @@ jobs:
217217
- name: Build
218218
id: docker_build
219219
run: |
220-
docker build -f ./dev/docker/debian.dockerfile -t setup-cpp .
220+
docker build -f ./dev/docker/ubuntu.dockerfile -t setup-cpp .
221221
```
222222
223223
### Inside GitLab pipelines

dev/docker/arch_node.dockerfile renamed to dev/docker/__tests__/arch.dockerfile

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
## base image
22
FROM archlinux as base
33

4-
# install nodejs and pnpm
5-
RUN pacman -Syuu --noconfirm && pacman-db-upgrade && pacman -S --noconfirm --needed nodejs npm git \
6-
&& npm install -g pnpm
4+
# install nodejs
5+
RUN pacman -Syuu --noconfirm && \
6+
pacman-db-upgrade && \
7+
pacman -S --noconfirm --needed nodejs
78

9+
# add setup-cpp.js (built outside of this dockerfile)
10+
COPY "./dist/node18" "/"
811

9-
#### Building
10-
FROM base AS builder
11-
## https://github.com/ever0de/pnpm-docker-root-bug#how-to-fix
12-
WORKDIR /workspace
13-
COPY . .
14-
RUN pnpm install
15-
16-
17-
#### setup-cpp
18-
FROM base AS setup-cpp
19-
# add setup-cpp.js
20-
COPY --from=builder /workspace/dist/node18 /
2112
# run installation
22-
RUN node /setup-cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true --powershell true
23-
CMD ["source", "~/.cpprc"]
24-
ENTRYPOINT ["/bin/bash"]
13+
RUN node /setup-cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true
2514

15+
ENTRYPOINT ["/bin/bash"]
2616

2717
#### Building (example)
2818
FROM setup-cpp AS example-builder
@@ -31,7 +21,6 @@ WORKDIR /home/app
3121
RUN bash -c 'source ~/.cpprc \
3222
&& task build'
3323

34-
3524
#### Running environment
3625
# use a distroless image or ubuntu:22.04 if you wish
3726
FROM gcr.io/distroless/cc as runner
File renamed without changes.

dev/docker/fedora_node.dockerfile renamed to dev/docker/__tests__/fedora.dockerfile

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
11
## base image
22
FROM fedora as base
33

4-
# nodejs and curl for downloading setup-cpp
5-
RUN dnf -y install nodejs npm curl git && dnf clean all \
6-
&& npm install -g pnpm
4+
# install nodejs and setup-cpp
5+
RUN dnf -y install nodejs npm && \
6+
npm install -g setup-cpp
77

8+
# add setup-cpp.js (built outside of this dockerfile)
9+
COPY "./dist/node18" "/"
810

9-
#### Building
10-
FROM base AS builder
11-
## https://github.com/ever0de/pnpm-docker-root-bug#how-to-fix
12-
WORKDIR /workspace
13-
COPY . .
14-
RUN pnpm install
15-
16-
17-
#### setup-cpp
18-
FROM base AS setup-cpp
19-
# add setup-cpp.js
20-
COPY --from=builder /workspace/dist/node18 /
2111
# run installation
2212
RUN node /setup-cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true --powershell true
23-
CMD ["source", "~/.cpprc"]
24-
ENTRYPOINT ["/bin/bash"]
2513

14+
ENTRYPOINT ["/bin/bash"]
2615

2716
#### Building (example)
2817
FROM setup-cpp AS example-builder
@@ -31,7 +20,6 @@ WORKDIR /home/app
3120
RUN bash -c 'source ~/.cpprc \
3221
&& task build'
3322

34-
3523
#### Running environment
3624
# use a distroless image or ubuntu:22.04 if you wish
3725
FROM gcr.io/distroless/cc as runner
File renamed without changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#### Base Image
2+
FROM ubuntu:22.04 as base
3+
4+
# install nodejs and setup-cpp
5+
RUN apt-get update -qq && \
6+
apt-get install -y --no-install-recommends nodejs
7+
8+
# add setup-cpp.js (built outside of this dockerfile)
9+
COPY "./dist/node18" "/"
10+
11+
# install setup-cpp
12+
RUN node /setup-cpp.js --compiler llvm --cmake true --ninja true --ccache true --vcpkg true --task true
13+
14+
ENTRYPOINT ["/bin/bash"]
15+
16+
#### Building
17+
FROM base as builder
18+
COPY ./dev/cpp_vcpkg_project /home/app
19+
WORKDIR /home/app
20+
RUN bash -c 'source ~/.cpprc \
21+
&& task build'
22+
23+
24+
### Running environment
25+
# use a distroless image or ubuntu:22.04 if you wish
26+
FROM gcr.io/distroless/cc as runner
27+
# copy the built binaries and their runtime dependencies
28+
COPY --from=builder /home/app/build/my_exe/Release/ /home/app/
29+
WORKDIR /home/app/
30+
ENTRYPOINT ["./my_exe"]
File renamed without changes.

dev/docker/arch.dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## base image
2+
FROM archlinux as base
3+
4+
# install nodejs and setup-cpp
5+
RUN pacman -Syuu --noconfirm && \
6+
pacman-db-upgrade && \
7+
pacman -S --noconfirm --needed nodejs npm && \
8+
npm install -g setup-cpp
9+
10+
# run installation
11+
RUN setup-cpp --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true
12+
13+
ENTRYPOINT ["/bin/bash"]
14+
15+
#### Building (example)
16+
FROM base AS example-builder
17+
COPY ./dev/cpp_vcpkg_project /home/app
18+
WORKDIR /home/app
19+
RUN bash -c 'source ~/.cpprc \
20+
&& task build'
21+
22+
#### Running environment
23+
# use a distroless image or ubuntu:22.04 if you wish
24+
FROM gcr.io/distroless/cc as runner
25+
# copy the built binaries and their runtime dependencies
26+
COPY --from=example-builder /home/app/build/my_exe/Release/ /home/app/
27+
WORKDIR /home/app/
28+
ENTRYPOINT ["./my_exe"]

0 commit comments

Comments
 (0)