diff options
-rw-r--r-- | .github/workflows/release.yml | 28 | ||||
-rw-r--r-- | Dockerfile | 33 |
2 files changed, 52 insertions, 9 deletions
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7a15a083..457ac6f0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,6 +3,7 @@ name: release on: release: # Docs: <https://help.github.com/en/articles/events-that-trigger-workflows#release-event-release> types: [published] + push: # TODO just for a test (remove this line) jobs: build: @@ -39,7 +40,7 @@ jobs: - name: Download dependencies run: go mod download # `-x` means "verbose" mode - - name: Generate compiler values + - name: Generate builder values id: values run: | echo "::set-output name=version::`echo ${GITHUB_REF##*/} | sed -e 's/^[vV ]*//'`" @@ -51,6 +52,7 @@ jobs: GOOS: ${{ matrix.os }} GOARCH: ${{ matrix.arch }} CC: ${{ matrix.compiler }} + CGO_ENABLED: 0 LDFLAGS: >- -s -X github.com/spiral/roadrunner/cmd/rr/cmd.Version=${{ steps.values.outputs.version }} @@ -93,7 +95,8 @@ jobs: if: matrix.archiver == 'zip' run: zip -r -q "${{ steps.dist-arch.outputs.name }}" "${{ steps.dist-dir.outputs.name }}" - - uses: actions/upload-artifact@v2 + - name: Upload artifact + uses: actions/upload-artifact@v2 with: name: ${{ steps.dist-dir.outputs.name }} path: ${{ steps.dist-arch.outputs.name }} @@ -107,3 +110,24 @@ jobs: file: ${{ steps.dist-arch.outputs.name }} asset_name: ${{ steps.dist-arch.outputs.name }} tag: ${{ github.ref }} + + docker: + name: Build docker image + runs-on: ubuntu-20.04 + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Generate builder values + id: values + run: | + echo "::set-output name=version::`echo ${GITHUB_REF##*/} | sed -e 's/^[vV ]*//'`" + echo "::set-output name=timestamp::`date +%FT%T%z`" + + - name: Build image + run: | + docker build \ + --tag rr:local \ + --build-arg "APP_VERSION=${{ steps.values.outputs.version }}" \ + --build-arg "BUILD_TIME=${{ steps.values.outputs.timestamp }}" \ + . @@ -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"] |