Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
executable file
·50 lines (41 loc) · 1.7 KB
/
Copy pathDockerfile
File metadata and controls
executable file
·50 lines (41 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
ARG OPENGREP_VERSION=v2.1.0
# Build codacy-opengrep wrapper
FROM golang:1.27-alpine3.24 AS builder
WORKDIR /src
COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download
COPY cmd cmd
COPY internal internal
RUN go build -o bin/codacy-opengrep -ldflags="-s -w" ./cmd/tool
COPY .tool_version .tool_version
COPY docs /docs
RUN go run ./cmd/docgen -docFolder /docs
# TEMPORARY: fix rules that fail to parse in the current Opengrep version (see scripts/hotfix-rules.sh)
COPY scripts/hotfix-rules.sh /tmp/hotfix-rules.sh
RUN sh /tmp/hotfix-rules.sh /docs/rules.yaml
# Compress binaries for smaller image size
FROM alpine:3.24 AS compressor
RUN apk add --no-cache upx
COPY --from=builder /src/bin/codacy-opengrep /src/bin/codacy-opengrep
RUN upx --lzma /src/bin/codacy-opengrep
# Final published image for the codacy-opengrep wrapper
FROM python:3.15-slim
RUN apt update && apt install -y tar bash cosign curl adduser file
RUN adduser --uid 2004 --disabled-password --gecos "" docker
# Download and extract opengrep binary from GitHub releases
ARG OPENGREP_VERSION
ARG TARGETARCH
ENV OPENGREP_VERSION=${OPENGREP_VERSION}
# Download appropriate binary based on architecture
RUN if [ "$TARGETARCH" = "arm64" ]; then \
curl -fL -o /usr/local/bin/opengrep "https://github.com/opengrep/opengrep/releases/download/${OPENGREP_VERSION}/opengrep_linux_aarch64"; \
else \
curl -fL -o /usr/local/bin/opengrep "https://github.com/opengrep/opengrep/releases/download/${OPENGREP_VERSION}/opengrep_linux_x86"; \
fi \
&& chmod +x /usr/local/bin/opengrep
RUN file /usr/local/bin/opengrep
COPY --from=builder --chown=docker:docker /docs /docs
COPY --from=compressor /src/bin /dist/bin
USER docker
CMD [ "/dist/bin/codacy-opengrep" ]