1+ # we set this here because buildx normally sets it for us, but
2+ # CircleCI doesn't support a new enough docker, so we have to
3+ # pass this arg manually when in CI
4+ # ARG BUILDPLATFORM
5+
6+ # Run tests stage (we only run this on the BUILDPLATFORM)
7+ FROM --platform=$BUILDPLATFORM golang:alpine3.12 as test
8+
9+ WORKDIR /go/src/github.com/iggy/scurvy/
10+
11+ RUN apk add --no-cache git upx gcc libc-dev
12+
13+ RUN go get -u golang.org/x/lint/golint \
14+ honnef.co/go/tools/cmd/staticcheck \
15+ github.com/fzipp/gocyclo
16+
17+ # Use add here to invalidate the cache
18+ ADD . /go/src/github.com/iggy/scurvy/
19+
20+ # install deps the easy way
21+ RUN go get github.com/iggy/scurvy/...
22+
23+ # These are all separate so failures are a little easier to track
24+ RUN gofmt -l -s -w ./cmd ./pkg
25+ # RUN test -z $(gofmt -s -l $GO_FILES)
26+ # go test -race basically doesn't work with alpine/musl
27+ # RUN go test -v -race ./...
28+ RUN go vet ./...
29+ RUN staticcheck ./...
30+ # RUN gocyclo -over 19 $GO_FILES
31+ RUN golint -set_exit_status $(go list ./...)
32+
33+
34+
35+ # Build binaries stage (we only run this on the BUILDPLATFORM)
36+ FROM --platform=$BUILDPLATFORM golang:alpine3.12 as build
37+
38+ WORKDIR /go/src/github.com/iggy/scurvy/
39+
40+ RUN apk add --no-cache git upx gcc libc-dev
41+
42+ RUN go get -u github.com/mitchellh/gox \
43+ github.com/tcnksm/ghr
44+
45+ # Use add here to invalidate the cache
46+ ADD . /go/src/github.com/iggy/scurvy/
47+
48+ # install deps the easy way
49+ RUN go get github.com/iggy/scurvy/...
50+
51+ # build the binaries
52+ # release binaries (these may link against libc)
53+ RUN gox \
54+ -arch="amd64" \
55+ -os="linux" \
56+ -output="dist/{{.OS}}_{{.Arch}}_{{.Dir}}" \
57+ -ldflags='-extldflags "-static" -s -w' \
58+ -tags='netgo' ./...
59+ # docker binaries (these are prohibited to link against libc since they go in
60+ # a scratch image)
61+ # They are also compressed (upx) to make the docker images as small as possible
62+ RUN mkdir -p /ddist/etc
63+ RUN CGO_ENABLED=0 gox \
64+ -arch="amd64 arm64 arm" \
65+ -os="linux" \
66+ -output="/ddist/{{.OS}}_{{.Arch}}_{{.Dir}}" \
67+ -ldflags='-extldflags "-static" -s -w' \
68+ -tags='netgo' ./...
69+ RUN upx /ddist/linux*
70+
71+
72+
73+ # This builds the irc image from build binaries stage output
74+ FROM scratch as irc
75+ ARG TARGETOS
76+ ARG TARGETARCH
77+ COPY --from=build /ddist/${TARGETOS}_${TARGETARCH}_irc /ircbot
78+ COPY --from=build /ddist/etc /
79+ ENTRYPOINT ["/ircbot"]
80+
81+
82+
83+ # This builds the notifyd image from build binaries stage output
84+ FROM scratch as notifyd
85+ ARG TARGETOS
86+ ARG TARGETARCH
87+ COPY --from=build /ddist/${TARGETOS}_${TARGETARCH}_notifyd /notifyd
88+ COPY --from=build /ddist/etc /
89+ ENTRYPOINT ["/notifyd"]
90+
91+
92+
93+ # This builds the input-webhook image from build binaries stage output
94+ FROM scratch as input-webhook
95+ ARG TARGETOS
96+ ARG TARGETARCH
97+ COPY --from=build /ddist/${TARGETOS}_${TARGETARCH}_input-webhook /input-webhook
98+ COPY --from=build /ddist/etc /
99+ # just the one port that accepts webhook connections from sabnzbd/sickrage/CouchPotato
100+ EXPOSE 38475
101+ ENTRYPOINT ["/input-webhook"]
102+
103+
104+
105+ # This builds the syncd image from build binaries stage output
106+ # syncd runs a shell script to do the actual downloading, so can't use `scratch`
107+ FROM alpine:3.12.0 as syncd
108+ ARG TARGETOS
109+ ARG TARGETARCH
110+ COPY --from=build /ddist/${TARGETOS}_${TARGETARCH}_syncd /syncd
111+ COPY --from=build /ddist/etc /
112+ # COPY --from=build /go/src/github.com/iggy/scurvy/cmd/syncd/sync_files.sh /
113+
114+ # Need the ca-certificates for the NATS TLS cert and using rsync for the
115+ # file sync for now
116+ RUN apk --no-cache add rsync ca-certificates
117+
118+ # ENV SCURVY_BASE_URL "https://scurvy"
119+ # ENV SCURVY_DL_DIR "/scurvy/"
120+ # ENV SCURVY_COMPLETE_URL "scurvy/complete"
121+ # Where all the files are stored
122+ # VOLUME ["/scurvy"]
123+ # The script to run when syncd gets a new download message
124+ # If using rsync/ssh/etc, you'll need to also pass in ssh keys
125+ # VOLUME ["/sync_files.sh"]
126+ ENTRYPOINT ["/syncd"]
0 commit comments