Merge pull request #180 from gabe565/optimize-docker-build

Optimize Docker build
This commit is contained in:
Andrew Erlikh 2025-03-25 01:36:48 +07:00 committed by GitHub
commit 9b78b7115f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 6 deletions

View file

@ -56,4 +56,6 @@ jobs:
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
ghcr.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:v2
ghcr.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
ghcr.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
ghcr.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max

View file

@ -1,8 +1,18 @@
FROM golang:alpine AS builder
FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx
RUN apk add build-base
COPY . /src
RUN cd /src/cmd/WatchYourLAN/ && CGO_ENABLED=0 go build -o /WatchYourLAN .
FROM --platform=$BUILDPLATFORM golang:alpine AS builder
COPY --from=xx / /
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
ARG TARGETPLATFORM
RUN CGO_ENABLED=0 xx-go build -ldflags='-w -s' -o /WatchYourLAN ./cmd/WatchYourLAN
FROM alpine
@ -14,4 +24,4 @@ RUN apk add --no-cache arp-scan tzdata \
COPY --from=builder /WatchYourLAN /app/
ENTRYPOINT ["./WatchYourLAN"]
ENTRYPOINT ["./WatchYourLAN"]