Skip to content

Commit

Permalink
Merge pull request #2 from parichards/docker-multistage-build
Browse files Browse the repository at this point in the history
Update Dockerfile to use a multistage build
  • Loading branch information
rhermanek authored Jul 29, 2022
2 parents 7ca7ef0 + 8d20503 commit 7d4156b
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
FROM alpine:3.16

# Update
RUN apk update upgrade;

# Install git
RUN apk add git

# Set timezone to Europe/Zurich
RUN apk add tzdata
RUN ln -s /usr/share/zoneinfo/Europe/Zurich /etc/localtime
FROM alpine:3.16 as build

RUN apk add --no-cache git make musl-dev go
# Update & Install Go
RUN apk update upgrade && apk add --no-cache go

# Configure Go
ENV GOROOT /usr/lib/go
Expand All @@ -21,7 +12,21 @@ RUN mkdir -p ${GOPATH} /go/bin

WORKDIR $GOPATH

CMD ["make"]
# Build go package
ADD . /go/src/clamav-rest/
ADD ./server.* /etc/ssl/clamav-rest/
RUN cd /go/src/clamav-rest && go mod download github.com/dutchcoders/go-clamd@latest && go mod init clamav-rest && go mod tidy && go mod vendor && go build -v

FROM alpine:3.16

# Copy compiled clamav-rest binary from build container to production container
COPY --from=build /go/src/clamav-rest/clamav-rest /usr/bin/

# Update & Install tzdata
RUN apk update upgrade && apk add tzdata

#Set timezone to Europe/Zurich
RUN ln -s /usr/share/zoneinfo/Europe/Zurich /etc/localtime

# Install ClamAV
RUN apk --no-cache add clamav clamav-libunrar \
Expand All @@ -35,13 +40,7 @@ RUN sed -i 's/^#Foreground .*$/Foreground true/g' /etc/clamav/clamd.conf \

RUN freshclam --quiet --no-dns

# Build go package
ADD . /go/src/clamav-rest/
ADD ./server.* /etc/ssl/clamav-rest/
RUN cd /go/src/clamav-rest && go mod download github.com/dutchcoders/go-clamd@latest && go mod init clamav-rest && go mod tidy && go mod vendor && go build -v

COPY entrypoint.sh /usr/bin/
RUN mv /go/src/clamav-rest/clamav-rest /usr/bin/ && rm -Rf /go/src/clamav-rest

EXPOSE 9000
EXPOSE 9443
Expand Down

0 comments on commit 7d4156b

Please sign in to comment.