diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-08 08:34:47 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-08 08:34:47 +0000 |
commit | a60d0523c1afb6c1983b522d1477b8ef319d5b99 (patch) | |
tree | 8b268a842014cff3431e898e4b7f3e267ee7cd81 | |
parent | b22078ce707d21ac17ea1727a4174c44ef57ae69 (diff) | |
parent | d410a76d7ccef826fc5b1921314f88a902f1d10c (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]>
-rw-r--r-- | .github/workflows/codeql-analysis.yml | 2 | ||||
-rw-r--r-- | .github/workflows/release.yml | 139 | ||||
-rw-r--r-- | Dockerfile | 38 | ||||
-rwxr-xr-x[-rw-r--r--] | Makefile | 39 | ||||
-rwxr-xr-x | bin/rr | 30 | ||||
-rwxr-xr-x | build.sh | 71 | ||||
-rw-r--r-- | composer.json | 3 |
7 files changed, 217 insertions, 105 deletions
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 1c90e4a4..75e40110 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -47,7 +47,7 @@ jobs: with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. + # By default, queries listed here will override any specified in a config file. # Prefix the list here with "+" to use these queries and those in the config file. # queries: ./path/to/local/query, your-org/your-repo/queries@main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..b1cd83ae --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,139 @@ +name: release + +on: + release: # Docs: <https://help.github.com/en/articles/events-that-trigger-workflows#release-event-release> + types: [published] + +jobs: + build: + name: Build for ${{ matrix.os }} (${{ matrix.arch }}, ${{ matrix.compiler }}) + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + os: [windows, freebsd, darwin] # linux, freebsd, darwin, windows + compiler: [gcc] # gcc, musl-gcc + archiver: [zip] # tar, zip + arch: [amd64] # amd64, 386 + include: + - os: linux + compiler: gcc + archiver: tar + arch: amd64 + - os: '' + compiler: musl-gcc # more info: <https://musl.libc.org/> + archiver: zip + arch: amd64 + steps: + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.15.5 + + - name: Check out code + uses: actions/checkout@v2 + + - name: Install musl + if: matrix.compiler == 'musl-gcc' + run: sudo apt-get install -y musl-tools + + - name: Download dependencies + run: go mod download # `-x` means "verbose" mode + + - 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`" + echo "::set-output name=binary-name::rr`[ ${{ matrix.os }} = 'windows' ] && echo '.exe'`" + + - name: Compile binary file + env: + 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 }} + -X github.com/spiral/roadrunner/cmd/rr/cmd.BuildTime=${{ steps.values.outputs.timestamp }} + run: | + go build -trimpath -ldflags "$LDFLAGS" -o "./${{ steps.values.outputs.binary-name }}" ./cmd/rr/main.go + stat "./${{ steps.values.outputs.binary-name }}" + + - name: Generate distributive directory name + id: dist-dir + run: > + echo "::set-output name=name::roadrunner-${{ steps.values.outputs.version }}-$( + [ ${{ matrix.os }} != '' ] && echo '${{ matrix.os }}' || echo 'unknown' + )$( + [ ${{ matrix.compiler }} = 'musl-gcc' ] && echo '-musl' + )-${{ matrix.arch }}" + + - name: Generate distributive archive name + id: dist-arch + run: > + echo "::set-output name=name::${{ steps.dist-dir.outputs.name }}.$( + case ${{ matrix.archiver }} in + zip) echo 'zip';; + tar) echo 'tar.gz';; + *) exit 10; + esac + )" + + - name: Create distributive + run: | + mkdir ${{ steps.dist-dir.outputs.name }} + mv "./${{ steps.values.outputs.binary-name }}" ./${{ steps.dist-dir.outputs.name }}/ + cp ./README.md ./CHANGELOG.md ./LICENSE ./${{ steps.dist-dir.outputs.name }}/ + + - name: Pack distributive using tar + if: matrix.archiver == 'tar' + run: tar -zcf "${{ steps.dist-arch.outputs.name }}" "${{ steps.dist-dir.outputs.name }}" + + - name: Pack distributive using zip + if: matrix.archiver == 'zip' + run: zip -r -q "${{ steps.dist-arch.outputs.name }}" "${{ steps.dist-dir.outputs.name }}" + + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: ${{ steps.dist-dir.outputs.name }} + path: ${{ steps.dist-arch.outputs.name }} + if-no-files-found: error + retention-days: 30 + + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + 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: Make docker login + run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_LOGIN }}" --password-stdin + + - 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 "spiralscout/roadrunner:${{ steps.values.outputs.version }}" \ + --build-arg "APP_VERSION=${{ steps.values.outputs.version }}" \ + --build-arg "BUILD_TIME=${{ steps.values.outputs.timestamp }}" \ + . + + - name: Push image into registry + run: docker push "spiralscout/roadrunner:${{ steps.values.outputs.version }}" @@ -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"] @@ -1,15 +1,29 @@ -build: - @./build.sh -all: - @./build.sh all -clean: - rm -rf rr -install: all +#!/usr/bin/make +# Makefile readme (ru): <http://linux.yaroslavl.ru/docs/prog/gnu_make_3-79_russian_manual.html> +# Makefile readme (en): <https://www.gnu.org/software/make/manual/html_node/index.html#SEC_Contents> + +SHELL = /bin/sh + +.DEFAULT_GOAL := build + +# This will output the help for each task. thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html +help: ## Show this help + @printf "\033[33m%s:\033[0m\n" 'Available commands' + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {printf " \033[32m%-14s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +build: ## Build RR binary file for local os/arch + CGO_ENABLED=0 go build -trimpath -ldflags "-s" -o ./rr ./cmd/rr/main.go + +clean: ## Make some clean + rm ./rr + +install: build ## Build and install RR locally cp rr /usr/local/bin/rr -uninstall: + +uninstall: ## Uninstall locally installed RR rm -f /usr/local/bin/rr -test: - composer update + +test: ## Run application tests go test -v -race -cover go test -v -race -cover ./util go test -v -race -cover ./service @@ -23,6 +37,7 @@ test: go test -v -race -cover ./service/health go test -v -race -cover ./service/gzip go test -v -race -cover ./service/reload -lint: + +lint: ## Run application linters go fmt ./... - golint ./...
\ No newline at end of file + golint ./... @@ -11,7 +11,8 @@ declare(strict_types=1); foreach ([ __DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php', - __DIR__ . '/vendor/autoload.php' + __DIR__ . '/vendor/autoload.php', + __DIR__ . '/../vendor_php/autoload.php' ] as $file) { if (file_exists($file)) { define('RR_COMPOSER_INSTALL', $file); @@ -51,28 +52,29 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; +use function Couchbase\defaultDecoder; class RRHelper { /** - * Returns version of RoadRunner based on build.sh file + * @var string + */ + public const SELF_PACKAGE_NAME = 'spiral/roadrunner'; + + /** + * Returns version of RoadRunner based on current package version. * - * @return string Version of RoadRunner - * @throws Exception + * @return string Version of RoadRunner (eg.: `1.8.0`) */ public static function getVersion(): string { - $file = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'build.sh'; - $fileResource = fopen($file, 'r') or die(1); - while (!feof($fileResource)) { - $line = fgets($fileResource, 4096); - $matches = []; - if (preg_match("/^RR_VERSION=(.*)/", $line, $matches)) { - return trim($matches[1]); - } + $version = \PackageVersions\Versions::getVersion(self::SELF_PACKAGE_NAME); + + if (\is_int($delimiter_position = \mb_strpos($version, '@'))) { + $version = \mb_substr($version, 0, (int) $delimiter_position); } - fclose($fileResource); - throw new Exception("Can't find version of RoadRunner"); + + return \ltrim($version, 'vV'); } /** diff --git a/build.sh b/build.sh deleted file mode 100755 index 64411dba..00000000 --- a/build.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash -cd $(dirname "${BASH_SOURCE[0]}") -OD="$(pwd)" - -# Pushes application version into the build information. -RR_VERSION=1.9.0 - -# Hardcode some values to the core package -LDFLAGS="$LDFLAGS -X github.com/spiral/roadrunner/cmd/rr/cmd.Version=${RR_VERSION}" -LDFLAGS="$LDFLAGS -X github.com/spiral/roadrunner/cmd/rr/cmd.BuildTime=$(date +%FT%T%z)" -# remove debug info from binary as well as string and symbol tables -LDFLAGS="$LDFLAGS -s" - -build() { - echo Packaging "$1" Build - bdir=roadrunner-${RR_VERSION}-$2-$3 - rm -rf builds/"$bdir" && mkdir -p builds/"$bdir" - GOOS=$2 GOARCH=$3 ./build.sh - - if [ "$2" == "windows" ]; then - mv rr builds/"$bdir"/rr.exe - else - mv rr builds/"$bdir" - fi - - cp README.md builds/"$bdir" - cp CHANGELOG.md builds/"$bdir" - cp LICENSE builds/"$bdir" - cd builds - - if [ "$2" == "linux" ]; then - tar -zcf "$bdir".tar.gz "$bdir" - else - zip -r -q "$bdir".zip "$bdir" - fi - - rm -rf "$bdir" - cd .. -} - -# For musl build you should have musl-gcc installed. If not, please, use: -# go build -a -ldflags "-linkmode external -extldflags '-static' -s" -build_musl() { - echo Packaging "$2" Build - bdir=roadrunner-${RR_VERSION}-$1-$2-$3 - rm -rf builds/"$bdir" && mkdir -p builds/"$bdir" - CC=musl-gcc GOARCH=amd64 go build -trimpath -ldflags "$LDFLAGS" -o "$OD/rr" cmd/rr/main.go - - mv rr builds/"$bdir" - - cp README.md builds/"$bdir" - cp CHANGELOG.md builds/"$bdir" - cp LICENSE builds/"$bdir" - cd builds - zip -r -q "$bdir".zip "$bdir" - - rm -rf "$bdir" - cd .. -} - -if [ "$1" == "all" ]; then - rm -rf builds/ - build "Windows" "windows" "amd64" - build "Mac" "darwin" "amd64" - build "Linux" "linux" "amd64" - build "FreeBSD" "freebsd" "amd64" - build_musl "unknown" "musl" "amd64" - exit -fi - -CGO_ENABLED=0 go build -trimpath -ldflags "$LDFLAGS" -o "$OD/rr" cmd/rr/main.go diff --git a/composer.json b/composer.json index 3ce86754..383ac2d1 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ "psr/http-factory": "^1.0", "psr/http-message": "^1.0", "symfony/console": "^2.5.0 || ^3.0.0 || ^4.0.0 || ^5.0.0", - "laminas/laminas-diactoros": "^1.3 || ^2.0" + "laminas/laminas-diactoros": "^1.3 || ^2.0", + "composer/package-versions-deprecated": "^1.8" }, "config": { "vendor-dir": "vendor_php" |