take advantage of build cache #66 (#67)

This commit is contained in:
Benny 2020-12-26 22:12:33 +08:00 committed by GitHub
parent 0c08f65be1
commit f5e7ee5273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View File

@ -1,18 +1,24 @@
FROM golang:alpine as builder FROM golang:alpine as builder
ARG IMG_PATH=/opt/pics ARG IMG_PATH=/opt/pics
ARG EXHAUST_PATH=/opt/exhaust ARG EXHAUST_PATH=/opt/exhaust
RUN apk update ;\ RUN apk update && apk add alpine-sdk && mkdir /build
apk add alpine-sdk ;\ COPY go.mod /build
git clone https://github.com/webp-sh/webp_server_go /build ;\ RUN cd /build && go mod download
cd /build ;\
sed -i "s|.\/pics|${IMG_PATH}|g" config.json ;\ COPY . /build
sed -i "s|\"\"|\"${EXHAUST_PATH}\"|g" config.json ;\ RUN cd /build && sed -i "s|.\/pics|${IMG_PATH}|g" config.json \
sed -i 's/127.0.0.1/0.0.0.0/g' config.json && sed -i "s|\"\"|\"${EXHAUST_PATH}\"|g" config.json \
WORKDIR /build && sed -i 's/127.0.0.1/0.0.0.0/g' config.json \
RUN go build -o webp-server . && make docker
FROM alpine FROM alpine
COPY --from=builder /build/webp-server /usr/bin/webp-server COPY --from=builder /build/webp-server /usr/bin/webp-server
COPY --from=builder /build/config.json /etc/config.json COPY --from=builder /build/config.json /etc/config.json
WORKDIR /opt WORKDIR /opt
VOLUME /opt/exhaust VOLUME /opt/exhaust
CMD ["/usr/bin/webp-server", "--config", "/etc/config.json"] CMD ["/usr/bin/webp-server", "--config", "/etc/config.json"]

View File

@ -24,3 +24,6 @@ test:
clean: clean:
rm -rf builds rm -rf builds
rm -rf prefetch rm -rf prefetch
docker:
go build -ldflags="-s -w" -o webp-server .