Browse Source

ci: release infrastructure (#213)

* ci: release infrastructure

* ci: release CircleCI binary

* fix circle

* fix Circle pipeline

* improve tags and docs

* improvements
Kévin Dunglas 1 year ago
parent
commit
123d167729
10 changed files with 88 additions and 48 deletions
  1. 20 7
      .circleci/config.yml
  2. 5 5
      .github/workflows/docker.yml
  3. 34 14
      .github/workflows/static.yml
  4. 5 3
      README.md
  5. 2 2
      caddy/caddy.go
  6. 1 1
      caddy/go.mod
  7. 2 3
      caddy/go.sum
  8. 3 2
      docker-bake.hcl
  9. 15 10
      docs/compile.md
  10. 1 1
      docs/config.md

+ 20 - 7
.circleci/config.yml

@@ -1,5 +1,8 @@
 version: 2.1
 
+orbs:
+  gh: circleci/github-cli@2.2.0
+
 jobs:
   build:
     macos:
@@ -25,19 +28,21 @@ jobs:
       - save_cache:
           key: spc-{{ checksum "static-php-cli/composer.json" }}
           paths:
-            - save_cache:tatic-php-cli/downloads/
+            - static-php-cli/downloads/
             - static-php-cli/vendor/
       - run:
           working_directory: static-php-cli/
           name: Build libphp.a
-          command: ./bin/spc build --enable-zts --build-embed --debug "bcmath,calendar,ctype,curl,dba,dom,exif,filter,fileinfo,gd,iconv,intl,mbstring,mbregex,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,readline,redis,session,simplexml,sockets,sqlite3,tokenizer,xml,xmlreader,xmlwriter,zip,zlib,apcu"
+          command: ./bin/spc build --enable-zts --build-embed "bcmath,calendar,ctype,curl,dba,dom,exif,filter,fileinfo,gd,iconv,intl,mbstring,mbregex,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,readline,redis,session,simplexml,sockets,sqlite3,tokenizer,xml,xmlreader,xmlwriter,zip,zlib,apcu"
       - run:
           working_directory: static-php-cli/
           name: Set CGO flags
           command: |
-            echo "export CGO_CFLAGS='-DFRANKENPHP_VERSION=$CIRCLE_SHA1 $(./buildroot/bin/php-config --includes | sed s#-I/#-I$PWD/buildroot/#g)'" >> "$BASH_ENV"
+            if [ -z "$CIRCLE_TAG" ]; then export FRANKENPHP_VERSION=$CIRCLE_SHA1; else export FRANKENPHP_VERSION=${CIRCLE_TAG:1}; fi
+            echo "export CGO_CFLAGS='-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $(./buildroot/bin/php-config --includes | sed s#-I/#-I$PWD/buildroot/#g)'" >> "$BASH_ENV"
             echo "export CGO_LDFLAGS='-framework CoreFoundation -framework SystemConfiguration $(./buildroot/bin/php-config --ldflags) $(./buildroot/bin/php-config --libs)'" >> "$BASH_ENV"
             echo "export PHP_VERSION='$(./buildroot/bin/php-config --version)'" >> "$BASH_ENV"
+            echo "export FRANKENPHP_VERSION='$FRANKENPHP_VERSION'" >> "$BASH_ENV"
       - restore_cache:
           keys:
             - go-mod-v4-{{ checksum "caddy/go.sum" }}
@@ -46,11 +51,19 @@ jobs:
           working_directory: caddy/frankenphp/
           command: |
             go env
-            go build -buildmode=pie -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static-pie -w -s -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $CIRCLE_SHA1 PHP $PHP_VERSION Caddy'"
-            ./frankenphp version
+            go build -buildmode=pie -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static-pie -w -s -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" -o frankenphp-mac-arm64
+            ./frankenphp-mac-arm64 version
+      - gh/setup
+      - run:
+          name: Release
+          working_directory: caddy/frankenphp/
+          command: |
+            if [ -n "$CIRCLE_TAG" ]; then
+              gh release upload $CIRCLE_TAG --repo dunglas/frankenphp
+            fi
       - store_artifacts:
-          path: caddy/frankenphp/frankenphp
-          destination: frankenphp-arm64-<<pipeline.git.revision>>
+          path: caddy/frankenphp/frankenphp-mac-arm64
+          destination: frankenphp-mac-arm64
       - save_cache:
           key: go-mod-v4-{{ checksum "caddy/go.sum" }}
           paths:

+ 5 - 5
.github/workflows/docker.yml

@@ -7,15 +7,15 @@ on:
     branches:
       - main
     tags:
-      - v*
+      - v*.*.*
   workflow_dispatch:
     inputs: {}
 jobs:
   prepare:
     runs-on: ubuntu-latest
     outputs:
-      # Push only if we're committing in the main branch
-      push: ${{toJson(github.ref == 'refs/heads/main' && github.event_name != 'pull_request')}}
+      # Push only if it's a tag or if we're committing in the main branch
+      push: ${{toJson(startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request'))}}
       variants: ${{ steps.matrix.outputs.variants }}
       platforms: ${{ steps.matrix.outputs.platforms }}
       metadata: ${{ steps.matrix.outputs.metadata }}
@@ -35,7 +35,7 @@ jobs:
           echo "variants=$(jq -c '.group.default.targets|map(sub("runner-|builder-"; ""))|unique' <<< $METADATA)" >> "$GITHUB_OUTPUT"
           echo "platforms=$(jq -c 'first(.target[]) | .platforms' <<< $METADATA)" >> "$GITHUB_OUTPUT"
         env:
-          LATEST: '1' # TODO: unset this variable when releasing the first tagged version
+          LATEST: '1' # TODO: unset this variable when releasing the first stable version
           SHA: ${{github.sha}}
           VERSION: ${{github.ref_type == 'tag' && github.ref_name || github.sha}}
 
@@ -96,7 +96,7 @@ jobs:
             *.cache-to=type=gha,scope=${{github.ref}}-${{matrix.platform}}
             ${{fromJson(needs.prepare.outputs.push) && '*.output=type=image,name=dunglas/frankenphp,push-by-digest=true,name-canonical=true,push=true' || ''}}
         env:
-          LATEST: '1' # TODO: unset this variable when releasing the first tagged version
+          LATEST: '1' # TODO: unset this variable when releasing the first stable version
           SHA: ${{github.sha}}
           VERSION: ${{github.ref_type == 'tag' && github.ref_name || github.sha}}
 

+ 34 - 14
.github/workflows/static.yml

@@ -7,7 +7,7 @@ on:
     branches:
       - main
     tags:
-      - v*
+      - v*.*.*
   workflow_dispatch:
     inputs: {}
 jobs:
@@ -34,24 +34,34 @@ jobs:
             *.cache-from=type=gha,scope=refs/heads/main-static-builder
             *.cache-to=type=gha,scope=${{github.ref}}-static-builder
         env:
-          VERSION: ${{ github.sha }}
+          VERSION: ${{github.ref_type == 'tag' && github.ref_name || github.sha}}
+          SHA: ${{github.sha}}
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Copy binary
-        run: docker cp $(docker create --name static-builder dunglas/frankenphp:static-builder):/go/src/app/caddy/frankenphp/frankenphp frankenphp ; docker rm static-builder
+        run: docker cp $(docker create --name static-builder dunglas/frankenphp:static-builder):/go/src/app/caddy/frankenphp/frankenphp frankenphp-linux-x86_64 ; docker rm static-builder
 
-      - name: Upload binary
+      - name: Release
+        if: github.ref_type == 'tag'
+        uses: ncipollo/release-action@v1
+        with:
+          generateReleaseNotes: true
+          allowUpdates: true
+          omitBodyDuringUpdate: true
+          omitNameDuringUpdate: true
+          artifacts: frankenphp-linux-x86_64
+
+      - name: Upload artifact
+        if: github.ref_type == 'branch'
         uses: actions/upload-artifact@v3
         with:
-          name: frankenphp-linux-x86_64-${{ github.sha }}
-          path: frankenphp
+          path: frankenphp-linux-x86_64
 
   build-mac:
     name: Build macOS x86_64 binaries
     runs-on: macos-latest
     env:
       HOMEBREW_NO_AUTO_UPDATE: 1
-
     steps:
       - uses: actions/checkout@v4
 
@@ -62,7 +72,6 @@ jobs:
 
       - name: Install missing system dependencies
         run: brew install automake
-        working-directory: static-php-cli/
 
       - uses: actions/setup-go@v4
         with:
@@ -83,23 +92,34 @@ jobs:
 
       - name: Build libphp.a
         working-directory: static-php-cli/
-        run: ./bin/spc build --enable-zts --build-embed --debug "bcmath,calendar,ctype,curl,dba,dom,exif,filter,fileinfo,gd,iconv,intl,mbstring,mbregex,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,readline,redis,session,simplexml,sockets,sqlite3,tokenizer,xml,xmlreader,xmlwriter,zip,zlib,apcu"
+        run: ./bin/spc build --enable-zts --build-embed "bcmath,calendar,ctype,curl,dba,dom,exif,filter,fileinfo,gd,iconv,intl,mbstring,mbregex,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,readline,redis,session,simplexml,sockets,sqlite3,tokenizer,xml,xmlreader,xmlwriter,zip,zlib,apcu"
 
       - name: Set CGO flags
         working-directory: static-php-cli/
         run: |
-           echo "CGO_CFLAGS=-DFRANKENPHP_VERSION=${{ github.sha }} $(./buildroot/bin/php-config --includes | sed s#-I/#-I$PWD/buildroot/#g)" >> "$GITHUB_ENV"
+           if [ "$GITHUB_REF_TYPE" == "tag" ]; then export FRANKENPHP_VERSION=${GITHUB_REF_NAME:1}; else export FRANKENPHP_VERSION=$GITHUB_SHA; fi
+           echo "CGO_CFLAGS=-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $(./buildroot/bin/php-config --includes | sed s#-I/#-I$PWD/buildroot/#g)" >> "$GITHUB_ENV"
            echo "CGO_LDFLAGS=-framework CoreFoundation -framework SystemConfiguration $(./buildroot/bin/php-config --ldflags) $(./buildroot/bin/php-config --libs)" >> "$GITHUB_ENV"
            echo "PHP_VERSION=$(./buildroot/bin/php-config --version)" >> "$GITHUB_ENV"
+           echo "FRANKENPHP_VERSION=$FRANKENPHP_VERSION" >> "$GITHUB_ENV"
 
       - name: Build FrankenPHP
         working-directory: caddy/frankenphp/
         run: |
-          go build -buildmode=pie -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static-pie -w -s -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ${{ github.sha }} PHP $PHP_VERSION Caddy'"
-          ./frankenphp version
+          go build -buildmode=pie -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static-pie -w -s -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" -o frankenphp-mac-x86_64
+          ./frankenphp-mac-x86_64 version
 
+      - name: Release
+        if: github.ref_type == 'tag'
+        uses: ncipollo/release-action@v1
+        with:
+          generateReleaseNotes: true
+          allowUpdates: true
+          omitBodyDuringUpdate: true
+          omitNameDuringUpdate: true
+          artifacts: frankenphp-mac-x86_64
+  
       - name: Upload binary
         uses: actions/upload-artifact@v3
         with:
-          name: frankenphp-mac-x86_64-${{ github.sha }}
-          path: caddy/frankenphp/frankenphp
+          path: frankenphp-mac-x86_64

+ 5 - 3
README.md

@@ -16,9 +16,7 @@ FrankenPHP can also be used as a standalone Go library to embed PHP in any app u
 
 ## Getting Started
 
-☢️ FrankenPHP is very experimental, don't use it in production yet, [file bugs](https://github.com/dunglas/frankenphp/issues) and write patches! ☢️
-
-```
+```console
 docker run -v $PWD:/app/public \
     -p 80:80 -p 443:443 \
     dunglas/frankenphp
@@ -26,6 +24,9 @@ docker run -v $PWD:/app/public \
 
 Go to `https://localhost`, and enjoy!
 
+If you prefer not to use Docker, we provide standalone FrankenPHP binaries for Linux and macOS
+containing [PHP 8.2](https://www.php.net/releases/8.2/en.php) and most popular PHP extensions: [Download FrankenPHP](https://github.com/dunglas/frankenphp/releases)
+
 > Note: do not attempt to use `https://127.0.0.1`. Use `localhost` and accept the self-signed certificate. Caddy has an automatic TLS handling that auto-trusts some local-based hostnames like `localhost`, but it does not apply to IP addresses. More details [on Caddy's "automatic https" docs](https://caddyserver.com/docs/automatic-https#hostname-requirements).
 
 ## Docs
@@ -36,6 +37,7 @@ Go to `https://localhost`, and enjoy!
 * [Configuration](docs/config.md)
 * [Docker images](docs/docker.md)
 * [Compile from sources](docs/compile.md)
+* [Create static binaries](docs/static.md)
 * [Demo app (Symfony) and benchmarks](https://github.com/dunglas/frankenphp-demo)
 * [Go library documentation](https://pkg.go.dev/github.com/dunglas/frankenphp)
 * [Contributing and debugging](CONTRIBUTING.md)

+ 2 - 2
caddy/caddy.go

@@ -18,7 +18,7 @@ import (
 )
 
 func init() {
-	caddy.RegisterModule(&FrankenPHPApp{})
+	caddy.RegisterModule(FrankenPHPApp{})
 	caddy.RegisterModule(FrankenPHPModule{})
 	httpcaddyfile.RegisterGlobalOption("frankenphp", parseGlobalOption)
 	httpcaddyfile.RegisterHandlerDirective("php", parseCaddyfile)
@@ -55,7 +55,7 @@ type FrankenPHPApp struct {
 }
 
 // CaddyModule returns the Caddy module information.
-func (a *FrankenPHPApp) CaddyModule() caddy.ModuleInfo {
+func (a FrankenPHPApp) CaddyModule() caddy.ModuleInfo {
 	return caddy.ModuleInfo{
 		ID:  "frankenphp",
 		New: func() caddy.Module { return a },

+ 1 - 1
caddy/go.mod

@@ -17,7 +17,7 @@ require (
 	github.com/dunglas/mercure/caddy v0.15.2
 	github.com/dunglas/vulcain/caddy v0.5.0
 	go.uber.org/automaxprocs v1.5.3
-	go.uber.org/zap v1.25.0
+	go.uber.org/zap v1.26.0
 )
 
 require (

+ 2 - 3
caddy/go.sum

@@ -168,7 +168,6 @@ github.com/aws/aws-sdk-go v1.44.318 h1:Yl66rpbQHFUbxe9JBKLcvOvRivhVgP6+zH0b9KzAR
 github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
 github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I=
 github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
-github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
 github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
 github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
@@ -1230,8 +1229,8 @@ go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
 go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
 go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
 go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
-go.uber.org/zap v1.25.0 h1:4Hvk6GtkucQ790dqmj7l1eEnRdKm3k3ZUrUMS2d5+5c=
-go.uber.org/zap v1.25.0/go.mod h1:JIAUzQIH94IC4fOJQm7gMmBJP5k7wQfdcnYdPoEXJYk=
+go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
+go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
 gocloud.dev v0.19.0/go.mod h1:SmKwiR8YwIMMJvQBKLsC3fHNyMwXLw3PMDO+VVteJMI=
 golang.org/x/crypto v0.0.0-20180501155221-613d6eafa307/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=

+ 3 - 2
docker-bake.hcl

@@ -24,9 +24,10 @@ function "tag" {
     params = [version, os, php-version, tgt]
     result = [
         version != "" ? format("%s:%s%s-php%s-%s", IMAGE_NAME, version, tgt == "builder" ? "-builder" : "", php-version, os) : "",
-        os == "bookworm" && php-version == "8.2" && version != "" ? format("%s:%s%s", IMAGE_NAME, version, tgt == "builder" ? "-builder" : "") : "",
+        php-version == "8.2" && os == "bookworm"  && version != "" ? format("%s:%s%s", IMAGE_NAME, version, tgt == "builder" ? "-builder" : "") : "",
         php-version == "8.2" && version != "" ? format("%s:%s%s-%s", IMAGE_NAME, version, tgt == "builder" ? "-builder" : "", os) : "",
-        os == "bookworm" && version != "" ? format("%s:%s%s-php%s", IMAGE_NAME, version, tgt == "builder" ? "-builder" : "", php-version) : ""
+        php-version == "8.2" && version == "latest" ? format("%s:%s%s", IMAGE_NAME, os, tgt == "builder" ? "-builder" : "") : "",
+        os == "bookworm" && version != "" ? format("%s:%s%s-php%s", IMAGE_NAME, version, tgt == "builder" ? "-builder" : "", php-version) : "",
     ]
 }
 

+ 15 - 10
docs/compile.md

@@ -11,7 +11,7 @@ FrankenPHP is compatible with the PHP 8.2 and superior.
 
 First, [get the sources of PHP](https://www.php.net/downloads.php) and extract them:
 
-```
+```console
 tar xf php-*
 cd php-*/
 ```
@@ -20,7 +20,7 @@ Then, configure PHP for your platform:
 
 ### Linux
 
-```
+```console
 ./configure \
     --enable-embed \
     --enable-zts \
@@ -28,19 +28,26 @@ Then, configure PHP for your platform:
     --enable-zend-max-execution-timers
 ```
 
+Finally, compile and install PHP:
+
+```console
+make -j$(nproc)
+sudo make install
+```
+
 ### Mac
 
 Use the [Homebrew](https://brew.sh/) package manager to install
 `libiconv`, `bison`, `re2c` and `pkg-config`:
 
-```
+```console
 brew install libiconv bison re2c pkg-config
 echo 'export PATH="/opt/homebrew/opt/bison/bin:$PATH"' >> ~/.zshrc
 ```
 
 Then run the configure script:
 
-```
+```console
 ./configure \
     --enable-embed=static \
     --enable-zts \
@@ -54,18 +61,16 @@ Then run the configure script:
 These flags are required, but you can add other flags (e.g. extra extensions)
 if needed.
 
-## Compile PHP
+Finally, compile and install PHP:
 
-Finally, compile PHP:
-
-```
-make -j$(nproc)
+```console
+make -j$(sysctl -n hw.logicalcpu)
 sudo make install
 ```
 
 #### Compile the Go App
 
-You can now use the Go lib and compile our Caddy build:
+You can now use the Go library and compile our Caddy build:
 
 ```
 curl -L https://github.com/dunglas/frankenphp/archive/refs/heads/main.tar.gz | tar x

+ 1 - 1
docs/config.md

@@ -77,7 +77,7 @@ To propagate environment variables to `$_SERVER` and `$_ENV`, set the `php.ini`
 
 When using the Docker image, set the `CADDY_DEBUG` environment variable to `debug` to enable the debug mode:
 
-```
+```console
 docker run -v $PWD:/app/public \
     -e CADDY_GLOBAL_OPTIONS=debug \
     -p 80:80 -p 443:443 \

Some files were not shown because too many files changed in this diff