Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored dockerfile #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 13 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
FROM devopsworks/golang-upx:1.16 AS builder
# Get last release from GitHub
FROM alpine:latest AS fetcher

ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
RUN apk add curl

WORKDIR /build

COPY go.mod .
COPY go.sum .
RUN go mod download
RUN curl -s https://api.github.com/repos/devops-works/scan-exporter/releases/latest \
| grep "browser_download_url.*linux_amd64" \
| cut -d : -f 2,3 \
| tr -d \" > release

COPY . .
RUN wget $(cat release) && \
chmod +x scan-exporter_linux_amd64

# RUN go build -o scan-exporter . && \
# strip scan-exporter && \
# /usr/local/bin/upx -9 scan-exporter

RUN go build \
-ldflags "-X main.Version=${version} -X main.BuildDate=${builddate}" \
-o scan-exporter . && \
strip scan-exporter && \
/usr/local/bin/upx -9 scan-exporter

RUN setcap cap_net_raw+ep scan-exporter
RUN curl -O https://raw.githubusercontent.com/devops-works/scan-exporter/master/config-sample.yaml

# Run the app
FROM gcr.io/distroless/base-debian10

WORKDIR /app

COPY --from=builder /build/scan-exporter .
COPY --from=fetcher /build/scan-exporter_linux_amd64 scan-exporter

COPY --from=builder /build/config-sample.yaml config.yaml
COPY --from=fetcher /build/config-sample.yaml config.yaml

EXPOSE 2112

Expand Down