Skip to content

Commit 636b878

Browse files
committed
changed: refactoring and migration to runtime image from scratch
1 parent 6cc8a78 commit 636b878

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

.github/workflows/build.yml

+17-17
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ jobs:
8181
cache-from: type=gha
8282
cache-to: type=gha,mode=max
8383

84+
- name: Slim the Docker image🚀
85+
id: slim
86+
uses: kitabisa/[email protected]
87+
env:
88+
DSLIM_HTTP_PROBE: false
89+
with:
90+
target: ghcr.io/ammnt/freenginx:${{ env.APP_VERSION }}
91+
tag: ghcr.io/ammnt/freenginx:${{ env.APP_VERSION }}
92+
overwrite: true
93+
version: 1.40.11
94+
95+
- name: Dump the Slim report📊
96+
run: |
97+
echo "${REPORT}" > slim.report.json
98+
env:
99+
REPORT: ${{ steps.slim.outputs.report }}
100+
84101
- name: Analyze image with Docker Scout💊
85102
uses: docker/[email protected]
86103
with:
@@ -160,23 +177,6 @@ jobs:
160177
name: Dockle Report
161178
path: "${{ github.workspace }}/dockle.report.json"
162179

163-
- name: Slim the Docker image🚀
164-
id: slim
165-
uses: kitabisa/[email protected]
166-
env:
167-
DSLIM_HTTP_PROBE: false
168-
with:
169-
target: ghcr.io/ammnt/freenginx:${{ env.APP_VERSION }}
170-
tag: ghcr.io/ammnt/freenginx:${{ env.APP_VERSION }}
171-
overwrite: true
172-
version: 1.40.11
173-
174-
- name: Dump the Slim report📊
175-
run: |
176-
echo "${REPORT}" > slim.report.json
177-
env:
178-
REPORT: ${{ steps.slim.outputs.report }}
179-
180180
- name: Upload the Slim report📊
181181
uses: actions/[email protected]
182182
with:

Dockerfile

+13-11
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,25 @@ RUN NB_CORES="${BUILD_CORES-$(getconf _NPROCESSORS_CONF)}" \
133133
--add-module=/tmp/ngx_brotli \
134134
&& make -j "${NB_CORES}" && make install && make clean && strip /usr/sbin/freenginx \
135135
&& chown -R freenginx:freenginx /var/cache/freenginx && chmod -R g+w /var/cache/freenginx \
136-
&& chown -R freenginx:freenginx /etc/freenginx && chmod -R g+w /etc/freenginx
137-
138-
FROM docker.io/library/alpine:${BASE_VERSION}@sha256:${BASE_HASH}
139-
RUN set -ex && addgroup -S freenginx && adduser -S freenginx -s /sbin/nologin -G freenginx --uid 101 --no-create-home \
140-
&& apk -U upgrade && apk add --no-cache \
141-
pcre \
142-
tini \
143-
brotli-libs \
144-
libxslt \
145-
&& apk del --purge apk-tools \
146-
&& rm -rf /tmp/* /var/cache/apk/ /var/cache/misc /root/.gnupg /root/.cache /root/go /etc/apk
136+
&& chown -R freenginx:freenginx /etc/freenginx && chmod -R g+w /etc/freenginx && touch /tmp/error.log
147137

138+
FROM scratch
139+
COPY --from=builder /etc/passwd /etc/passwd
140+
COPY --from=builder /etc/group /etc/group
141+
COPY --from=builder /sbin/tini /sbin/tini
148142
COPY --from=builder --chown=freenginx:freenginx /usr/sbin/freenginx /usr/sbin/freenginx
149143
COPY --from=builder --chown=freenginx:freenginx /etc/freenginx /etc/freenginx
144+
COPY --from=builder --chown=freenginx:freenginx /tmp/error.log /tmp/error.log
150145
COPY --from=builder --chown=freenginx:freenginx /var/cache/freenginx /var/cache/freenginx
151146
COPY --chown=freenginx:freenginx ./freenginx.conf /etc/freenginx/freenginx.conf
152147
COPY --chown=freenginx:freenginx ./default.conf /etc/freenginx/conf.d/default.conf
148+
COPY --from=builder /lib/ld-musl-x86_64.so.1 /lib/
149+
COPY --from=builder /usr/lib/libbrotlienc.so.1 \
150+
/usr/lib/libpcre.so.1 \
151+
/usr/lib/libz.so.1 \
152+
/usr/lib/libxml2.so.2 \
153+
/usr/lib/libbrotlicommon.so.1 \
154+
/usr/lib/liblzma.so.5 /usr/lib/
153155

154156
ENTRYPOINT [ "/sbin/tini", "--" ]
155157

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ services:
3636

3737
# Description:
3838

39-
- Based on latest version of Alpine Linux - low size (~5 MB);
39+
- Built on latest version of Alpine Linux - low size (~5 MB);
40+
- Runtime on scratch image - with zero bloat;
4041
- Multi-stage building with statically linked binary;
4142
- OpenSSL with HTTP/3 and QUIC support:<br>
4243
https://github.com/openssl/openssl
@@ -49,7 +50,7 @@ https://github.com/openssl/openssl
4950
- zlib library latest version;
5051
- Rootless master process - unprivileged container;
5152
- Async I/O threads module;
52-
- "Distroless" image - shell removed from the image;
53+
- "Distroless" image - reduced attack surface (removed SHELL, UNIX tools, package manager etc);
5354
- Removed unnecessary modules;
5455
- Added OCI labels and annotations;
5556
- No excess ENTRYPOINT in the image;

0 commit comments

Comments
 (0)