FROM golang:1.20-alpine AS builder # Install build dependencies RUN apk add --no-cache git # Set up the working directory WORKDIR /app # Copy Go module files COPY go.mod ./ # Copy the source code COPY main.go ./ # Build FreeBSD binary RUN GOOS=freebsd GOARCH=amd64 CGO_ENABLED=0 go build -o tarballer-freebsd -ldflags="-s -w" # Build macOS ARM64 binary for local testing RUN GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -o tarballer-darwin -ldflags="-s -w" # Build Linux binary for testing in container RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o tarballer-linux -ldflags="-s -w" # Second stage for testing FROM alpine:latest AS tester # Install required tools for testing RUN apk add --no-cache tar gzip WORKDIR /workdir # Copy Linux binary for use in the container COPY --from=builder /app/tarballer-linux /bin/tarballer # Also copy the FreeBSD and Darwin binaries for extraction COPY --from=builder /app/tarballer-freebsd /bin/ COPY --from=builder /app/tarballer-darwin /bin/ # Make binaries executable RUN chmod +x /bin/tarballer /bin/tarballer-freebsd /bin/tarballer-darwin # Copy test script COPY test/test.sh /bin/test.sh # Make test script executable RUN chmod +x /bin/test.sh