Skip to content

Commit

Permalink
refactor: Dockerfile (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgacsal authored Dec 8, 2023
1 parent 1d7f162 commit d59b9be
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
# syntax=docker/dockerfile:1.2
# syntax=docker/dockerfile:1

FROM golang:1.21.5-alpine AS builder

RUN apk add --update --no-cache gcc g++ git ca-certificates build-base

# Copy code
COPY . /build
WORKDIR /build

ARG VERSION
ARG BUILD_TIMESTAMP
ARG COMMIT_HASH
ARG TARGETOS
ARG TARGETARCH

WORKDIR /build

RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=bind,source=.,target=/build,ro \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 \
go build \
-ldflags="-s -w \
-X 'github.com/openclarity/yara-rule-server/pkg/version.Version=${VERSION}' \
-X 'github.com/openclarity/yara-rule-server/pkg/version.CommitHash=${COMMIT_HASH}' \
-X 'github.com/openclarity/yara-rule-server/pkg/version.BuildTimestamp=${BUILD_TIMESTAMP}'" \
-o bin/yara-rule-server main.go


-o /bin/yara-rule-server main.go

FROM alpine:3.19

RUN apk upgrade
RUN apk add util-linux
RUN apk add yara
RUN mkdir /etc/yara-rule-server

WORKDIR /app

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /build/bin/yara-rule-server ./yara-rule-server
COPY config.example.yaml /etc/yara-rule-server/config.yaml
RUN apk --no-cache add util-linux yara ca-certificates

WORKDIR /opt
COPY --from=builder --chmod=755 /bin/yara-rule-server /bin/yara-rule-server
COPY --link --chmod=644 config.example.yaml /etc/yara-rule-server/config.yaml

ENTRYPOINT ["/app/yara-rule-server"]
ENTRYPOINT ["/bin/yara-rule-server"]

0 comments on commit d59b9be

Please sign in to comment.