Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Update to latest (#1)
Browse files Browse the repository at this point in the history
* [changelog skip] Ensure PRs include a Changelog entry

The goal of this PR is to add a github action that checks for the presence of a changelog entry.

It is better to add entries as a PR is merged instead of having to remember what was merged and generate a changelog at release time.

By automating this check, it's one less thing the maintainer has to remember, and it's one less thing a change might be blocked on i.e. "Looks good, but please add a changelog entry".

Let me know if you have any questions and Happy Friday!

* [changelog skip] Fix Escaping in Changelog Script

The previous PR had a bug where the REGEX for grep was not properly escaped. This PR fixes that issue.

* Update check_changelog.yml

* Add missing changelog entries for v4 (heroku#176)

And clean up the existing changelog slightly.

Closes heroku#175.

* Bump json from 2.0.2 to 2.3.1 (heroku#173)

Bumps [json](https://github.com/flori/json) from 2.0.2 to 2.3.1.
- [Release notes](https://github.com/flori/json/releases)
- [Changelog](https://github.com/flori/json/blob/master/CHANGES.md)
- [Commits](ruby/json@v2.0.2...v2.3.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump rake from 10.4.0 to 12.3.3 (heroku#158)

Bumps [rake](https://github.com/ruby/rake) from 10.4.0 to 12.3.3.
- [Release notes](https://github.com/ruby/rake/releases)
- [Changelog](https://github.com/ruby/rake/blob/master/History.rdoc)
- [Commits](ruby/rake@v10.4.0...v12.3.3)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump excon from 0.54.0 to 0.78.0 (heroku#180)

Bumps [excon](https://github.com/excon/excon) from 0.54.0 to 0.78.0.
- [Release notes](https://github.com/excon/excon/releases)
- [Changelog](https://github.com/excon/excon/blob/master/changelog.txt)
- [Commits](excon/excon@v0.54.0...v0.78.0)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump rack from 1.6.11 to 1.6.13 in /spec/support/docker/proxy (heroku#179)

Bumps [rack](https://github.com/rack/rack) from 1.6.11 to 1.6.13.
- [Release notes](https://github.com/rack/rack/releases)
- [Changelog](https://github.com/rack/rack/blob/master/CHANGELOG.md)
- [Commits](rack/rack@1.6.11...1.6.13)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Added MIT License (heroku#117)

* Remove redundant `exit 0`

Since with exit on error, if that line is ever reached,
the exit code will always be zero anyway.

* Fail the build early on unsupported stacks

In order to prevent the build completing apparently successfully, but
the app fail to boot at runtime due to stack incompatibility.

At first glance this would seem unnecessary due to the stack-specific
URL meaning the `curl` would 404 on supported stacks. However heroku#165
means the Cedar-14 binary is installed on all stacks, and on Heroku-20
causes the failures at runtime seen in heroku#166.

Future PRs will fix the curl/binary handling to use stack-specific URLs,
however it's still nicer to explicitly handle unsupported stacks with a
clear error message than a 404.

* Remove unused archive caching

The caching of the nginx archive isn't used in production (nothing ever
writes to the cached file) or in CI. Whilst it may speed up some local
development workflows slightly, on a fast connection downloading from
S3 takes less than a second, so isn't worth the added `bin/compile`
complexity / confusion as to behaviour in production.

* Switch to recommended S3 URL format

- The `s3-external-1` endpoint is a legacy reference to `us-east-1`:
  https://stackoverflow.com/a/26622229
- The path based bucket specification is deprecated:
  https://aws.amazon.com/blogs/aws/amazon-s3-path-deprecation-plan-the-rest-of-the-story/

* Fix the printing of the installed nginx version

Previously the nginx version command was failing since the
`nginx-$STACK` binary does not exist, resulting in output like:

```
remote: -----> Installed directory to /app/bin
```

This failure went unnoticed since `pipefail` mode is not enabled.

The nginx binary path has been fixed, and the command now uses
`-v` instead of `-V` since the former only output one line, avoiding
the need to `head -n1`. In addition, the `cut` usage shows more of
the original line in the case of no match.

Fixes heroku#174.

* Enable stricter bash error checking modes

Enables the following bash modes:
- `u`: error on undefined variables
- `pipefail`: error if an earlier command in a pipe sequence exits
  non-zero, rather than only if the final command is non-zero

See:
http://redsymbol.net/articles/unofficial-bash-strict-mode/

* Make curl retry in case of a failed download

To improve the reliability of the build.

See:
https://curl.haxx.se/docs/manpage.html#--retry
https://curl.haxx.se/docs/manpage.html#--connect-timeout

* Exclude unnecessary files when publishing buildpack (heroku#178)

Since currently the archive on the buildpack registry contains
a lot more than the ~15 files needed at compile time:

```
$ curl -sSf https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku-community/static.tgz | tar -zt | wc -l
234
```

See:
https://devcenter.heroku.com/articles/buildpack-registry#creating-a-buildpack-descriptor

* Fix compatibility with ngx_mruby 1.18.4+ (heroku#181)

The `mruby_post_read_handler` directive should always have been outside
the `location` block, however due to a bug in ngx_mruby the previous
implementation happened to still work.

In ngx_mruby 1.18.4 this silently stopped being the case:
matsumotory/ngx_mruby#210

And in ngx_mruby 1.18.5 this incorrect usage was turned into an error:
matsumotory/ngx_mruby#217

Moving `mruby_post_read_handler` outside the location block is a no-op
for the older ngx_mruby currently used by this buildpack, but ensures
compatibility with the newer ngx_mruby being used in the upcoming
Heroku-20 support PR.

See matsumotory/ngx_mruby#210.

* Add support for Heroku-20 (heroku#182)

This adds support for the new Heroku-20 stack:
https://devcenter.heroku.com/articles/heroku-20-stack

The buildpack's binaries were previously generated by:
https://github.com/hone/docker-nginx-builder

However that repository is quite out of date, and much of its complexity
is no longer required thanks to improvements to `ngx_mruby`'s upstream
build scripts/process:
https://github.com/matsumotory/ngx_mruby/tree/v2.2.3/docs/install
https://github.com/matsumotory/ngx_mruby/blob/v2.2.3/build.sh

The new build script has been co-located in this buildpack to improve
discoverability, and prevent needing to open PRs against multiple repos
when performing updates.

The buildpack previously used a subdirectory of the Ruby buildpack's
S3 bucket, however I've created a new S3 bucket to improve isolation.

This PR adds support for building new binaries for all stacks, however
for now only switches to them for Heroku-20, so that the newer nginx
version can be tested on the new stack for a while before backporting
to the others.

The newer ngx_mruby required a compatibility fix, however that has
already landed in heroku#181.

The binaries have been uploaded already, using the newly documented
steps in the README.

Closes heroku#166.
Closes W-8367040.

* Release v5 (heroku#183)

* Ensure the SSL module is enabled (heroku#186)

Previously the compile silently skipped the SSL module:

```
Configuration summary
  ...
  + OpenSSL library is not used
```

Which causes failures if SSL related directives are used.

Now the `--with-http_ssl_module` flag is passed, which results in:

```
Configuration summary
  ...
  + using system OpenSSL library
```

And `nginx -V` now includes an additional line:

```
built with OpenSSL 1.1.1f  31 Mar 2020
```

See:
https://github.com/matsumotory/ngx_mruby/tree/master/docs/install#3-a-using-buildsh

Fixes heroku#185.
Closes W-8449334.

* Update nginx for Heroku-16 and Heroku-18 to 1.19.0 (heroku#190)

Upgrades nginx from 1.9.7 to 1.19.0, to match that already used for
Heroku-20. In addition, the buildpack now uses the correct binaries
for these stacks, rather than using a binary compiled for Cedar-14.

Fixes heroku#165.

* Release v6 (heroku#191)

* Docs: Use the buildpack registry URL in usage example (heroku#194)

Since this buildpack exists on the buildpack registry under the name
`heroku-community/static`, and using buildpack registry versions is
recommended over the GitHub URLs.

* Output a helpful error message when no static.json is found (heroku#202)

The error message is now output to `stderr` otherwise it's not shown.

Closes GUS-W-8799430.
Refs heroku#198.

* Release v7 (heroku#203)

To pick up heroku#202.

Refs GUS-W-8799430.

* README: Fix spelling of 'instead' (heroku#213)

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>

* Updated/Added CODEOWNERS with ECCN

* Port Check Changelog improvements from other repos (heroku#237)

eg:
https://github.com/heroku/heroku-buildpack-python/blob/5d6776f77a89e7ef3ada701d05c473117ecf817a/.github/workflows/check_changelog.yml

Notably, one can not use both a label and a PR description attribute, rather than the unsightly PR title annotation.

* Bump sinatra from 1.4.7 to 2.2.0 in /spec/support/docker/proxy (heroku#236)

Bumps [sinatra](https://github.com/sinatra/sinatra) from 1.4.7 to 2.2.0.
- [Release notes](https://github.com/sinatra/sinatra/releases)
- [Changelog](https://github.com/sinatra/sinatra/blob/master/CHANGELOG.md)
- [Commits](sinatra/sinatra@v1.4.7...v2.2.0)

---
updated-dependencies:
- dependency-name: sinatra
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Drop support for Cedar-14 and Heroku-16 (heroku#238)

Since they are EOL and it's no longer possible to perform builds
using them.

Closes heroku#214.
GUS-W-10346704.

* Update ngx_mruby to 2.2.4 and nginx to 1.21.3 (heroku#240)

The binary build process for this buildpack uses the default `nginx`
version specified by `ngx_mruby`. As such, updating `ngx_mruby`
from `2.2.3` to `2.2.4` means the bundled `nginx` version is also
updated from `1.19.0` to `1.21.3`:
https://github.com/matsumotory/ngx_mruby/blob/v2.2.3/nginx_version
https://github.com/matsumotory/ngx_mruby/blob/v2.2.4/nginx_version

Changes:
https://github.com/matsumotory/ngx_mruby/releases/tag/v2.2.4
https://nginx.org/en/CHANGES

GUS-W-10346704.

* Release v8 (heroku#241)

To pick up heroku#238 and heroku#240.

GUS-W-10346704.

* Bump rack from 2.2.3 to 2.2.3.1 in /spec/support/docker/proxy (heroku#242)

Bumps [rack](https://github.com/rack/rack) from 2.2.3 to 2.2.3.1.
- [Release notes](https://github.com/rack/rack/releases)
- [Changelog](https://github.com/rack/rack/blob/main/CHANGELOG.md)
- [Commits](rack/rack@2.2.3...2.2.3.1)

---
updated-dependencies:
- dependency-name: rack
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Deprecate buildpack (heroku#243)

* Deprecate buildpack

This build pack is currently not maintained by a team and carries no support obligations. Let's make this clearer by deprecating the build pack.

This is done right before the release of heroku-22 as supporting new stacks require maintenance effort. Also before the desire to re-write it as a CNB comes into play.

* Bring back Readme contents

Having README docs makes it easier for developers to lookup features while they transition off the buildpack.

* Update docs for deprecation

- Mention the need to re-write mruby parts
- Link to a specific nginx build pack and give commands on how to add it
- Give specific command to remove this buildpack from app
- Mention in README we're open to extra docs/help for people migrating off.
- Space after testing header because it's my thing and I looked at those docs. 
- Added a link to where  `Nginx::Request` is defined because it's not obvious it comes from ngx_mruby

* Update README.md

Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>

* Update bin/compile

Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>

* Address PR comments

Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>

* v9 (heroku#244)

Co-authored-by: schneems <richard.schneeman+foo@gmail.com>
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ben Williams <ben@719ben.com>
Co-authored-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
Co-authored-by: svc-scm <48930134+svc-scm@users.noreply.github.com>
Co-authored-by: niels-van-den-broeck <niels@codecompanion.be>
  • Loading branch information
9 people authored Dec 22, 2022
1 parent ed2c6d0 commit b038b69
Show file tree
Hide file tree
Showing 15 changed files with 272 additions and 35 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/check_changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Check Changelog

on:
pull_request:
types: [opened, reopened, edited, labeled, unlabeled, synchronize]

permissions:
contents: read

jobs:
check-changelog:
runs-on: ubuntu-latest
if: |
!contains(github.event.pull_request.body, '[skip changelog]') &&
!contains(github.event.pull_request.body, '[changelog skip]') &&
!contains(github.event.pull_request.body, '[skip ci]') &&
!contains(github.event.pull_request.labels.*.name, 'skip changelog') &&
!contains(github.event.pull_request.labels.*.name, 'dependencies')
steps:
- uses: actions/checkout@v3
- name: Check that CHANGELOG is touched
run: |
git fetch origin ${{ github.base_ref }} --depth 1 && \
git diff remotes/origin/${{ github.base_ref }} --name-only | grep CHANGELOG.md
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
archives/
vendor/
.bundle/
49 changes: 46 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
## v3 (3/30/2017)
# Static Buildpack Changelog

## Unreleased

## v9 (2022-06-09)

* [#243](https://github.com/heroku/heroku-buildpack-static/pull/243) Buildpack is officially deprecated

## v8 (2022-05-19)

* [#240](https://github.com/heroku/heroku-buildpack-static/pull/240) Update ngx_mruby from 2.2.3 to 2.2.4.
* [#240](https://github.com/heroku/heroku-buildpack-static/pull/240) Update nginx from 1.19.0 to 1.21.3.
* [#238](https://github.com/heroku/heroku-buildpack-static/pull/238) Drop support for Cedar-14 and Heroku-16.

## v7 (2021-03-09)

* [#202](https://github.com/heroku/heroku-buildpack-static/pull/202) Output a helpful error message when no `static.json` is found

## v6 (2020-12-09)

* [#190](https://github.com/heroku/heroku-buildpack-static/pull/190) Update nginx for Heroku-16 and Heroku-18 to 1.19.0
* [#186](https://github.com/heroku/heroku-buildpack-static/pull/186) Ensure the SSL module is enabled

## v5 (2020-11-11)

* [#182](https://github.com/heroku/heroku-buildpack-static/pull/182) Add support for Heroku-20
* [#181](https://github.com/heroku/heroku-buildpack-static/pull/181) Fix compatibility with ngx_mruby 1.18.4+
* [#178](https://github.com/heroku/heroku-buildpack-static/pull/178) Exclude unnecessary files when publishing the buildpack
* [#177](https://github.com/heroku/heroku-buildpack-static/pull/177) Make curl retry in case of a failed download
* [#177](https://github.com/heroku/heroku-buildpack-static/pull/177) Fix the printing of the installed nginx version
* [#177](https://github.com/heroku/heroku-buildpack-static/pull/177) Switch to the recommended S3 URL format
* [#177](https://github.com/heroku/heroku-buildpack-static/pull/177) Remove unused archive caching
* [#177](https://github.com/heroku/heroku-buildpack-static/pull/177) Fail the build early on unsupported stacks

## v4 (2019-09-18)

* [#136](https://github.com/heroku/heroku-buildpack-static/pull/136) Add support for canonical host
* [#45](https://github.com/heroku/heroku-buildpack-static/pull/45) Add Basic Auth Configuration
* [#78](https://github.com/heroku/heroku-buildpack-static/pull/78) Add json mime type
* [#70](https://github.com/heroku/heroku-buildpack-static/pull/70) Make config copying idempotent
* [#68](https://github.com/heroku/heroku-buildpack-static/pull/68) Disable access logs

## v3 (2017-03-30)

* [#32](https://github.com/heroku/heroku-buildpack-static/pull/32) proxies set ssl server name extension for SNI
* [#37](https://github.com/heroku/heroku-buildpack-static/pull/47) fallback proxies set ssl server name extension for SNI
* [#61](https://github.com/heroku/heroku-buildpack-static/pull/61) proxy redirects work even when the scheme does not match
* [#62](https://github.com/heroku/heroku-buildpack-static/pull/62) clean urls work even on a directory
* [#63](https://github.com/heroku/heroku-buildpack-static/pull/63) proxies respect DNS TTL
* [#65](https://github.com/heroku/heroku-buildpack-static/pull/65) https redirects happen over proxies

## v2 (7/13/2016)
## v2 (2016-07-13)

* [#36](https://github.com/heroku/heroku-buildpack-static/pull/36) env interpolation available when doing `redirects`
* [#40](https://github.com/heroku/heroku-buildpack-static/pull/40) mitigate CRLF HTTP Header Injection when using `https_only`

## v1 (3/27/2016)
## v1 (2016-03-27)

* Initial Release!
2 changes: 2 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Comment line immediately above ownership line is reserved for related gus information. Please be careful while editing.
#ECCN:Open Source
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ GEM
docker-api (1.33.1)
excon (>= 0.38.0)
json
excon (0.54.0)
json (2.0.2)
rake (10.4.0)
excon (0.78.0)
json (2.3.1)
rake (12.3.3)
ref (1.0.5)
rspec (3.2.0)
rspec-core (~> 3.2.0)
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Heroku

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
S3_BUCKET ?= heroku-buildpack-static

.PHONY: build build-heroku-18 build-heroku-20 sync

build: build-heroku-18 build-heroku-20

build-heroku-18:
@docker pull heroku/heroku:18-build
@docker run -v "$(shell pwd)":/buildpack --rm -it -e "STACK=heroku-18" heroku/heroku:18-build /buildpack/scripts/build_ngx_mruby.sh

build-heroku-20:
@docker pull heroku/heroku:20-build
@docker run -v "$(shell pwd)":/buildpack --rm -it -e "STACK=heroku-20" heroku/heroku:20-build /buildpack/scripts/build_ngx_mruby.sh

sync:
@echo "Performing dry run of sync to $(S3_BUCKET)..."
@echo
@aws s3 sync archives/ s3://$(S3_BUCKET) --dryrun
@echo
@read -p "Continue with sync? [y/N]? " answer && [ "$$answer" = "y" ]
@echo
@aws s3 sync archives/ s3://$(S3_BUCKET)
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
# heroku-buildpack-static

**NOTE**: This buildpack is in an experimental OSS project.

This is a buildpack for handling static sites and single page web apps.

For a guide, read the [Getting Started with Single Page Apps on Heroku](https://gist.github.com/hone/24b06869b4c1eca701f9).

## WARNING: `heroku-buildpack-static` is deprecated

This buildpack is deprecated and is no longer being maintained.
If you are using this project, you can transition over to NGINX via an NGINX buildpack.
Use your project's existing configuration.
To find the NGINX configuration generated by the heroku-buildpack-static you can run:

```
$ heroku run bash
~ $ bin/config/make-config
~ $ cat config/nginx.conf
```

These commands will output your current NGINX config generated from your `static.json` contents.

- Write these contents to your local repo at `config/nginx.conf.erb`, commit them to git.
- Replace path logic that previously used `mruby` with static logic.
- Configure your app to use the NGINX buildpack via `heroku buildpacks:add heroku-community/nginx`.
- Remove this buildpack via `heroku buildpacks:remove heroku-community/static` (or `heroku buildpacks:remove https://github.com/heroku/heroku-buildpack-static`).

## Deprecation PRs

If you have tips or tricks for migrating off of this buildpack and want to add them to the instructions above please send a PR.

## Features
* serving static assets
* gzip on by default
Expand All @@ -14,14 +39,14 @@ For a guide, read the [Getting Started with Single Page Apps on Heroku](https://
## Deploying
The `static.json` file is required to use this buildpack. This file handles all the configuration described below.

1. Set the app to this buildpack: `$ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-static.git`.
1. Set the app to this buildpack: `$ heroku buildpacks:set heroku-community/static`.
2. Deploy: `$ git push heroku master`

### Configuration
You can configure different options for your static application by writing a `static.json` in the root folder of your application.

#### Root
This allows you to specify a different asset root for the directory of your application. For instance, if you're using ember-cli, it naturally builds a `dist/` directory, so you might want to use that intsead.
This allows you to specify a different asset root for the directory of your application. For instance, if you're using ember-cli, it naturally builds a `dist/` directory, so you might want to use that instead.

```json
{
Expand Down Expand Up @@ -278,6 +303,7 @@ when accessing `/foo`, `X-Foo` will have the value `"foo"` and `X-Bar` will not
In case you have multiple buildpacks for the application you can ensure static rendering in `Procfile` with `web: bin/boot`.

## Testing

For testing we use Docker to replicate Heroku locally. You'll need to have [it setup locally](https://docs.docker.com/installation/). We're also using rspec for testing with Ruby. You'll need to have those setup and install those deps:

```sh
Expand All @@ -303,3 +329,17 @@ You need to forward the docker's port 3000 to the virtual machine's port though.
```
VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port3000,tcp,,3000,,3000";
```

## Releasing new binaries

The steps buildpack maintainers need to perform when releasing new nginx
binaries (either for a new stack or `ngx_mruby` version), are:

1. Update the stacks list in `Makefile` and/or the ngx_mruby version
in `scripts/build_ngx_mruby.sh`.
2. Run `make build` to build all stacks or `make build-heroku-NN` to build just one stack.
3. Ensure the AWS CLI is installed (eg `brew install awscli`).
4. Authenticate with the relevant AWS account (typically by setting the environment variables from PCSK).
5. Run `make sync` (or if using a custom S3 bucket, `S3_BUCKET=... make sync`).
6. Update `bin/compile` to reference the new stacks and/or nginx version URLs.
7. Open a PR with the changes from (1) and (6).
53 changes: 35 additions & 18 deletions bin/compile
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir> <env-dir>

set -e
set -euo pipefail

build_dir=$1
cache_dir=$2
env_dir=$3
bp_dir=$(dirname $(dirname $0))

fetch_nginx_tarball() {
local version="1.9.7"
local tarball_file="nginx-$version.tgz"
local stack="cedar-14"
local nginx_tarball_url="https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/nginx/$stack/nginx-$version-ngx_mruby.tgz"
local dest_path="$cache_dir/$stack/$tarball_file"
cat <<'EOF'
## WARNING: `heroku-buildpack-static` is deprecated
if [ -f "$dest_path" ]; then
echo -n "cat $dest_path"
else
echo -n "curl -L $nginx_tarball_url"
fi
}
This buildpack is deprecated and is no longer being maintained.
If you are using this project, you can transition over to NGINX via an NGINX buildpack.
Use your project's existing configuration.
To find the NGINX configuration generated by the heroku-buildpack-static you can run:
```
$ heroku run bash
~ $ bin/config/make-config
~ $ cat config/nginx.conf
```
These commands will output your current NGINX config generated from your `static.json` contents.
- Write these contents to your local repo at `config/nginx.conf.erb`, commit them to git.
- Replace path logic that previously used `mruby` with static logic.
- Configure your app to use the NGINX buildpack via `heroku buildpacks:add heroku-community/nginx`.
- Remove this buildpack via `heroku buildpacks:remove heroku-community/static` (or `heroku buildpacks:remove https://github.com/heroku/heroku-buildpack-static`).
EOF

case "${STACK}" in
heroku-18|heroku-20)
nginx_archive_url="https://heroku-buildpack-static.s3.amazonaws.com/${STACK}/nginx-1.21.3-ngx_mruby-2.2.4.tgz"
;;
*)
echo "Stack ${STACK} is not supported!"
exit 1
;;
esac

mkdir -p $build_dir/bin
$(fetch_nginx_tarball) | tar xzC $build_dir/bin
nginx_version=$($build_dir/bin/nginx-$STACK -V 2>&1 | head -1 | awk '{ print $NF }')
curl -sSf --retry 3 --connect-timeout 3 "${nginx_archive_url}" | tar -xzC "${build_dir}/bin"
nginx_version=$("${build_dir}/bin/nginx" -v |& cut -d '/' -f 2-)
cp -a $bp_dir/scripts/{boot,config} -t $build_dir/bin/
echo "-----> Installed ${nginx_version} to /app/bin"
echo "-----> Installed nginx ${nginx_version} to /app/bin"

mkdir -p $build_dir/config
cp $bp_dir/scripts/config/templates/mime.types $build_dir/config

mkdir -p $build_dir/logs

exit 0
1 change: 1 addition & 0 deletions bin/detect
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
build_dir=$1

if [ ! -f "$build_dir/static.json" ]; then
echo "Could not find 'static.json'! Please ensure it exists and is checked into Git." >&2
exit 1
fi

Expand Down
15 changes: 15 additions & 0 deletions buildpack.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[buildpack]
name = "Static HTML"

[publish.Ignore]
files = [
".github/",
"spec/",
".gitignore",
".rspec",
"circle.yml",
"Gemfile",
"Gemfile.lock",
"Makefile",
"Rakefile"
]
46 changes: 46 additions & 0 deletions scripts/build_ngx_mruby.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

set -euo pipefail

NGX_MRUBY_VERSION='2.2.4'
NGX_MRUBY_URL="https://github.com/matsumotory/ngx_mruby/archive/v${NGX_MRUBY_VERSION}.tar.gz"

echo "Building ngx_mruby v${NGX_MRUBY_VERSION} for ${STACK}"

BUILD_DIR=$(mktemp -d /tmp/ngx_mruby.XXXX)
SCRIPTS_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
OUTPUT_DIR="$(dirname "${SCRIPTS_DIR}")/archives/${STACK}"

mkdir -p "${OUTPUT_DIR}"
cd "${BUILD_DIR}"

echo "Downloading ngx_mruby from ${NGX_MRUBY_URL}"
curl -sSfL "${NGX_MRUBY_URL}" | tar -xz --strip-components 1

# Taken from the defaults:
# https://github.com/matsumotory/ngx_mruby/blob/v2.2.4/build.sh#L23-L40
BUILD_OPTS="--prefix=${PWD}/build/nginx"
BUILD_OPTS+=' --with-http_stub_status_module --with-stream --without-stream_access_module --with-cc-opt=-fno-common'
# Our custom addition, to enable the SSL module.
BUILD_OPTS+=' --with-http_ssl_module'

NGINX_CONFIG_OPT_ENV="${BUILD_OPTS}" ./build.sh
make install

echo 'nginx build complete!'

NGINX_BIN_DIR="${BUILD_DIR}/build/nginx/sbin"
cd "${NGINX_BIN_DIR}"

# Check that nginx can start
./nginx -V

# Check that OpenSSL support was enabled
./nginx -V |& grep 'built with OpenSSL' || { echo 'Missing OpenSSL support!'; exit 1; }

NGINX_VERSION=$(./nginx -v |& cut -d '/' -f 2-)
ARCHIVE_PATH="${OUTPUT_DIR}/nginx-${NGINX_VERSION}-ngx_mruby-${NGX_MRUBY_VERSION}.tgz"

tar -czf "${ARCHIVE_PATH}" nginx

echo "Archive saved to: ${ARCHIVE_PATH}"
2 changes: 1 addition & 1 deletion scripts/config/lib/ngx_mruby/routes_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

config = {}
config = JSON.parse(File.read(USER_CONFIG)) if File.exist?(USER_CONFIG)
req = Nginx::Request.new
req = Nginx::Request.new # defined by https://github.com/matsumotory/ngx_mruby/blob/c7682cfb4c0984a41f1a447b71ae01e1f4fcc6bf/docs/class_and_method/README.md#nginxrequest-class
uri = req.var.uri
nginx_route = req.var.route
routes = {}
Expand Down
3 changes: 2 additions & 1 deletion scripts/config/templates/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ http {
auth_basic_user_file <%= basic_auth_htpasswd_path %>;
<% end %>

mruby_post_read_handler /app/bin/config/lib/ngx_mruby/headers.rb cache;

location / {
mruby_post_read_handler /app/bin/config/lib/ngx_mruby/headers.rb cache;
mruby_set $fallback /app/bin/config/lib/ngx_mruby/routes_fallback.rb cache;
<% if clean_urls %>
try_files $uri.html $uri $uri/ $fallback;
Expand Down
Loading

0 comments on commit b038b69

Please sign in to comment.