1- FROM golang:latest AS stage
1+ FROM golang:latest AS builder
22
33WORKDIR /build
44
5+ # Install Syft for SBOM generation
6+ RUN go install github.com/anchore/syft/cmd/syft@latest
7+
8+ # Copy source code
59COPY . .
10+
11+ # Tidy dependencies
612RUN go mod tidy
13+
14+ # Build the Go binary
715RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags "-linkmode external -extldflags -static" -a -installsuffix cgo -o main_linux_amd64.bin main.go
16+
17+ # Generate SBOM for the application
18+ # This scans the built binary and vendor dependencies
19+ RUN /go/bin/syft packages . -o spdx-json=sbom.spdx.json
20+
21+ # Generate a checksum for the binary
822RUN sha256sum main_linux_amd64.bin > main_linux_amd64.bin.sha256sum
923
24+
1025FROM alpine:latest
1126
1227WORKDIR /app
13- VOLUME /app/videos
14- VOLUME /app/public
15- VOLUME /app/database
1628
17- RUN apk add ffmpeg bash
18- COPY --from=stage ./build/main_linux_amd64.bin ./
19- RUN mv ./main_linux_amd64.bin ./main.bin
29+ # System dependencies
30+ RUN apk add --no-cache ffmpeg bash
31+
32+ # Copy the application binary from the builder stage
33+ COPY --from=builder /build/main_linux_amd64.bin ./main.bin
34+
35+ # Copy the SBOM from the builder stage
36+ COPY --from=builder /build/sbom.spdx.json /app/sbom.spdx.json
37+
38+ # Copy other necessary application files
2039COPY ./views ./views/
2140COPY ./public ./public/
2241
42+ # Set up volumes for persistent data
43+ VOLUME /app/videos
44+ VOLUME /app/public
45+ VOLUME /app/database
46+
47+ # Environment variables
2348ENV Host=:3000
2449ENV FolderVideoQualitysPriv=./videos/qualitys
2550ENV FolderVideoQualitysPub=/videos/qualitys
2651ENV FolderVideoUploadsPriv=./videos/uploads
2752ENV StatsDriveName=nvme0n1
2853
54+ # Expose the application port
2955EXPOSE 3000
3056
57+ # Define the command to run the application
3158CMD ["./main.bin" , "serve:main" ]
0 commit comments