Skip to content

Commit 4e13316

Browse files
authored
Create dockerfile
1 parent b5671d3 commit 4e13316

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

dockerfile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Stage 1: Builder stage to compile and install tools
2+
FROM alpine:latest AS builder
3+
4+
# Install dependencies needed for building tools
5+
RUN apk add --no-cache \
6+
git \
7+
go \
8+
python3 \
9+
nodejs \
10+
npm \
11+
openssl \
12+
curl \
13+
wget \
14+
make \
15+
gcc \
16+
libc-dev \
17+
# Clean up cache to reduce image size
18+
&& rm -rf /var/cache/apk/*
19+
20+
# Install Trivy (vulnerability scanner for containers)
21+
RUN wget -O /usr/local/bin/trivy https://github.com/aquasecurity/trivy/releases/latest/download/trivy_linux_64bit \
22+
&& chmod +x /usr/local/bin/trivy
23+
24+
# Install Kube-Bench (Kubernetes security benchmark tool)
25+
RUN git clone https://github.com/aquasecurity/kube-bench.git /opt/kube-bench \
26+
&& cd /opt/kube-bench && go build -o /usr/local/bin/kube-bench
27+
28+
# Install Checkov (Terraform and cloud infrastructure security scanner)
29+
RUN pip3 install --no-cache-dir checkov
30+
31+
# Install KubeLinter (static analysis tool for Kubernetes YAML files)
32+
RUN go install github.com/stackrox/kube-linter/cmd/kube-linter@latest \
33+
&& mv /root/go/bin/kube-linter /usr/local/bin/
34+
35+
# Install Snyk CLI (vulnerability scanner for dependencies and infrastructure)
36+
RUN npm install -g snyk
37+
38+
# Stage 2: Final image with only necessary runtime components
39+
FROM alpine:latest
40+
41+
# Install runtime dependencies
42+
RUN apk add --no-cache \
43+
python3 \
44+
nodejs \
45+
npm \
46+
openssl \
47+
# Create a non-root user for security :cite[6]:cite[9]
48+
&& addgroup -S securitytools && adduser -S devsecops -G securitytools -u 1000 \
49+
# Clean up cache
50+
&& rm -rf /var/cache/apk/*
51+
52+
# Copy installed tools from the builder stage
53+
COPY --from=builder /usr/local/bin/trivy /usr/local/bin/
54+
COPY --from=builder /usr/local/bin/kube-bench /usr/local/bin/
55+
COPY --from=builder /usr/local/bin/kube-linter /usr/local/bin/
56+
COPY --from=builder /usr/local/bin/checkov /usr/local/bin/
57+
COPY --from=builder /usr/bin/snyk /usr/local/bin/
58+
59+
# Set the working directory to a writable path for the non-root user
60+
WORKDIR /home/devsecops
61+
62+
# Switch to non-root user :cite[6]:cite[9]
63+
USER devsecops
64+
65+
# Set environment variables
66+
ENV PATH="/usr/local/bin:${PATH}"
67+
68+
# Define default command
69+
CMD ["/bin/sh"]

0 commit comments

Comments
 (0)