gururajarao79 | 542b9d1 | 2024-11-22 14:28:41 +0100 | [diff] [blame] | 1 | FROM curlimages/curl:7.78.0 AS build |
| 2 | |
| 3 | # Get OPA |
| 4 | RUN curl -Lo /tmp/opa https://github.com/open-policy-agent/opa/releases/download/v0.69.0/opa_linux_amd64 |
| 5 | |
| 6 | FROM golang:1.23 AS compile |
| 7 | |
| 8 | RUN mkdir /app |
| 9 | |
| 10 | COPY ../go.mod ../go.sum /app/ |
| 11 | |
| 12 | COPY . . |
| 13 | |
| 14 | RUN mkdir /app/cfg |
| 15 | ADD ../cfg /app/cfg |
| 16 | |
| 17 | RUN mkdir /app/consts |
| 18 | ADD ../consts /app/consts |
| 19 | |
| 20 | RUN mkdir /app/api |
| 21 | ADD ../api /app/api |
| 22 | |
| 23 | RUN mkdir /app/cmd |
| 24 | ADD ../cmd /app/cmd |
| 25 | |
| 26 | RUN mkdir /app/pkg |
| 27 | ADD ../pkg /app/pkg |
| 28 | |
| 29 | RUN mkdir /app/bundles |
| 30 | |
| 31 | WORKDIR /app |
| 32 | |
| 33 | # Build the binary |
| 34 | RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /app/opa-pdp /app/cmd/opa-pdp/opa-pdp.go |
| 35 | #COPY config.json /app/config.json |
| 36 | #RUN chmod 644 /app/config.json |
| 37 | |
| 38 | FROM ubuntu |
| 39 | |
| 40 | RUN apt-get update && apt-get install -y netcat-openbsd && rm -rf /var/lib/apt/lists/* |
| 41 | |
| 42 | RUN apt-get update && apt-get install -y curl |
| 43 | |
| 44 | # Copy our static executable from compile stage |
| 45 | RUN mkdir /app |
| 46 | COPY --from=compile /app /app |
| 47 | RUN chmod +x /app/opa-pdp |
| 48 | |
| 49 | # Copy our opa executable from build stage |
| 50 | COPY --from=build /tmp/opa /app/opa |
| 51 | RUN chmod 755 /app/opa |
| 52 | |
| 53 | WORKDIR /app |
| 54 | EXPOSE 8282 |
| 55 | |
| 56 | # Command to run OPA with the policies |
| 57 | CMD ["/app/opa-pdp"] |
| 58 | |