summaryrefslogtreecommitdiff
path: root/Dockerfile
diff options
context:
space:
mode:
authorParamtamtam <[email protected]>2020-12-08 10:53:13 +0500
committerParamtamtam <[email protected]>2020-12-08 10:53:13 +0500
commitd39cfc438eb8affc39093b7a37cdfd52aad05da7 (patch)
tree0e6db8ffd07d1d9117022aa3ab16f33256b74943 /Dockerfile
parent96fa83cd47e9e466dbc68ff9f5857f46cb199539 (diff)
Docker build updated
Diffstat (limited to 'Dockerfile')
-rw-r--r--Dockerfile33
1 files changed, 26 insertions, 7 deletions
diff --git a/Dockerfile b/Dockerfile
index 67c06d28..213a2a7d 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,17 +1,32 @@
-FROM golang:1.15.5 as builder
+# Image page: <https://hub.docker.com/_/golang>
+FROM golang:1.15.6-alpine as builder
+
+# app version and build date must be passed during image building (version without any prefix).
+# e.g.: `docker build --build-arg "APP_VERSION=1.2.3" --build-arg "BUILD_TIME=$(date +%FT%T%z)" .`
+ARG APP_VERSION="undefined"
+ARG BUILD_TIME="undefined"
+
+# arguments to pass on each go tool link invocation
+ENV LDFLAGS="-X github.com/spiral/roadrunner/cmd/rr/cmd.Version=$APP_VERSION \
+-X github.com/spiral/roadrunner/cmd/rr/cmd.BuildTime=$BUILD_TIME \
+-s"
COPY . /src
WORKDIR /src
+# download dependencies and compile binary file
RUN set -x \
- && apt-get update -y \
- && apt-get install -y bash git \
- && go version \
- && bash ./build.sh \
- && test -f ./.rr.yaml
+ && go mod download \
+ && go mod verify \
+ && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags "$LDFLAGS" -o ./rr ./cmd/rr/main.go
+
+# Image page: <https://hub.docker.com/_/alpine>
+FROM alpine:3.12
-FROM alpine:latest
+# use same build arguments for image labels
+ARG APP_VERSION
+ARG BUILD_TIME
LABEL \
org.opencontainers.image.title="roadrunner" \
@@ -19,9 +34,13 @@ LABEL \
org.opencontainers.image.url="https://github.com/spiral/roadrunner" \
org.opencontainers.image.source="https://github.com/spiral/roadrunner" \
org.opencontainers.image.vendor="SpiralScout" \
+ org.opencontainers.image.version="$APP_VERSION" \
+ org.opencontainers.image.created="$BUILD_TIME" \
org.opencontainers.image.licenses="MIT"
+# copy required files from builder image
COPY --from=builder /src/rr /usr/bin/rr
COPY --from=builder /src/.rr.yaml /etc/rr.yaml
+# use roadrunner binary as image entrypoint
ENTRYPOINT ["/usr/bin/rr"]