summaryrefslogtreecommitdiff
path: root/Dockerfile
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-12-08 08:34:47 +0000
committerGitHub <[email protected]>2020-12-08 08:34:47 +0000
commita60d0523c1afb6c1983b522d1477b8ef319d5b99 (patch)
tree8b268a842014cff3431e898e4b7f3e267ee7cd81 /Dockerfile
parentb22078ce707d21ac17ea1727a4174c44ef57ae69 (diff)
parentd410a76d7ccef826fc5b1921314f88a902f1d10c (diff)
Merge #433
433: Releases and binaries build automation r=48d90782 a=tarampampam This PR contains: - [x] CI steps for automatic release distributive creation and uploading to github release - [x] CI step for automatic docker image creation (on GitHub side, not `hub.docker.com`) - [x] `build.sh` script removal - [x] Binary file building in `Dockerfile` using `go build` (not `build.sh`) - [x] Docker labels with app version and build time - [x] `Makefile` cleaning - [x] `./bin/rr` now do not depends from `build.sh` file and use [`composer/package-versions-deprecated`](https://github.com/composer/package-versions-deprecated) package for "self version reading" > :warning: Steps, that must be done before merging described [here](https://github.com/spiral/roadrunner/pull/433#issuecomment-740426206) Closes #431 Co-authored-by: paramtamtam <[email protected]> Co-authored-by: Paramtamtam <[email protected]>
Diffstat (limited to 'Dockerfile')
-rw-r--r--Dockerfile38
1 files changed, 32 insertions, 6 deletions
diff --git a/Dockerfile b/Dockerfile
index 67c06d28..3c9ce76a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,17 +1,39 @@
+# Image page: <https://hub.docker.com/_/golang>
FROM golang:1.15.5 as builder
-COPY . /src
+# 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="-s \
+-X github.com/spiral/roadrunner/cmd/rr/cmd.Version=$APP_VERSION \
+-X github.com/spiral/roadrunner/cmd/rr/cmd.BuildTime=$BUILD_TIME"
+
+RUN mkdir /src
WORKDIR /src
+COPY ./go.mod ./go.sum ./
+
+# Burn modules cache
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
+
+COPY . .
+
+# compile binary file
+RUN 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 +41,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"]