-
Notifications
You must be signed in to change notification settings - Fork 305
/
Dockerfile
64 lines (47 loc) · 1.72 KB
/
Dockerfile
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
FROM golang:1.23.4-alpine as base
ARG TARGETARCH
ARG VERSION
ARG COMMIT
ARG DATE
RUN apk add --no-cache git
WORKDIR /app
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
## BUILDER STAGE ##
FROM base as builder
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -o conftest -ldflags="-w -s -X github.com/open-policy-agent/conftest/internal/commands.version=${VERSION}" main.go
## TEST STAGE ##
FROM base as test
RUN go test -v ./...
## ACCEPTANCE STAGE ##
FROM base as acceptance
COPY --from=builder /app/conftest /app/conftest
RUN apk add --no-cache npm bash
RUN npm install -g bats
RUN bats acceptance.bats
## EXAMPLES STAGE ##
FROM base as examples
ENV TERRAFORM_VERSION=0.12.31 \
KUSTOMIZE_VERSION=4.5.7
COPY --from=builder /app/conftest /usr/local/bin
COPY examples /examples
WORKDIR /tmp
RUN apk add --no-cache npm make git jq ca-certificates openssl unzip wget && \
wget "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_${TARGETARCH}.zip" && \
unzip "terraform_${TERRAFORM_VERSION}_linux_${TARGETARCH}.zip" -d /usr/local/bin
RUN wget "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_linux_${TARGETARCH}.tar.gz" && \
tar xvf kustomize_v${KUSTOMIZE_VERSION}_linux_${TARGETARCH}.tar.gz -C /usr/local/bin && \
chmod +x /usr/local/bin/kustomize
RUN go install cuelang.org/go/cmd/cue@latest
WORKDIR /examples
## RELEASE ##
FROM alpine:3.21.0
# Install git for protocols that depend on it when using conftest pull
RUN apk add --no-cache git
COPY --from=builder /app/conftest /
RUN ln -s /conftest /usr/local/bin/conftest
WORKDIR /project
ENTRYPOINT ["/conftest"]
CMD ["--help"]