Skip to content

Commit 286f9ac

Browse files
Arjun Sreedharanthitch97ForestEckhardt
authored
cnb providing rackup start command (#2)
- uses packit - bootstrapped with github config - int test with a bare bones app and rack-compliant sinatra app - Implement and test Gemfile.lock parsing - Add support for custom PORT bindings Signed-off-by: Arjun Sreedharan <asreedharan@vmware.com> Co-authored-by: Timothy Hitchener <thitchener@pivotal.io> Co-authored-by: Forest Eckhardt <feckhardt@pivotal.io>
1 parent 5f586f8 commit 286f9ac

39 files changed

Lines changed: 1924 additions & 6 deletions
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Create Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
unit:
10+
name: Unit Tests
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Setup Go
14+
uses: actions/setup-go@v1
15+
with:
16+
go-version: 1.14
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
- name: Run Unit Tests
20+
run: ./scripts/unit.sh
21+
22+
integration:
23+
name: Integration Tests
24+
runs-on: ubuntu-latest
25+
needs: unit
26+
steps:
27+
- name: Setup Go
28+
uses: actions/setup-go@v1
29+
with:
30+
go-version: 1.14
31+
- name: Checkout
32+
uses: actions/checkout@v2
33+
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
34+
- name: Run Integration Tests
35+
run: ./scripts/integration.sh
36+
env:
37+
GIT_TOKEN: ${{ github.token }}
38+
39+
release:
40+
name: Release
41+
runs-on: ubuntu-latest
42+
needs: integration
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v2
46+
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
47+
- name: Tag
48+
id: tag
49+
uses: paketo-buildpacks/github-config/actions/tag@master
50+
- name: Package
51+
run: PACKAGE_DIR=artifact ./scripts/package.sh --version "${{ steps.tag.outputs.tag }}" --archive
52+
- name: Create Release Notes
53+
id: create-release-notes
54+
run: |
55+
mkdir -p "${HOME}/bin"
56+
export PATH="${PATH}:${HOME}/bin"
57+
curl "https://github.com/paketo-buildpacks/packit/releases/download/v0.0.10/jam-linux" \
58+
--silent \
59+
--location \
60+
--output "${HOME}/bin/jam"
61+
chmod +x "${HOME}/bin/jam"
62+
RELEASE_BODY=$(jam summarize --buildpack "${PWD}/artifact.tgz" --format markdown)
63+
# Coz of this messed up issue
64+
# https://github.community/t5/GitHub-Actions/set-output-Truncates-Multiline-Strings/m-p/38372#M3322
65+
RELEASE_BODY="${RELEASE_BODY//'%'/'%25'}"
66+
RELEASE_BODY="${RELEASE_BODY//$'\n'/'%0A'}"
67+
RELEASE_BODY="${RELEASE_BODY//$'\r'/'%0D'}"
68+
echo "::set-output name=release_body::$RELEASE_BODY"
69+
- name: Create Release
70+
uses: paketo-buildpacks/github-config/actions/release/create@master
71+
with:
72+
repo: ${{ github.repository }}
73+
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
74+
tag_name: v${{ steps.tag.outputs.tag }}
75+
target_commitish: ${{ github.sha }}
76+
name: v${{ steps.tag.outputs.tag }}
77+
body: ${{ steps.create-release-notes.outputs.release_body }}
78+
draft: false
79+
assets: |
80+
[
81+
{
82+
"path": "artifact.tgz",
83+
"name": "${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.tgz",
84+
"content_type": "application/gzip"
85+
}
86+
]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Sync
2+
3+
on:
4+
repository_dispatch:
5+
types: working-dir-update
6+
7+
jobs:
8+
build:
9+
name: Sync
10+
runs-on: ubuntu-latest
11+
steps:
12+
13+
# checkout paketo github-config as src-repo
14+
- name: Checkout paketo github-config repo
15+
uses: actions/checkout@v2
16+
with:
17+
repository: paketo-buildpacks/github-config
18+
path: config-repo
19+
20+
# checkout this repo
21+
- name: Checkout
22+
uses: actions/checkout@v2
23+
with:
24+
path: current-repo
25+
26+
- name: Run the sync action
27+
uses: paketo-buildpacks/github-config/actions/sync@master
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
30+
with:
31+
config-repo: config-repo
32+
current-repo: current-repo
33+
config-path: "/implementation"
34+
ssh-private-key: ${{ secrets.PAKETO_BOT_SSH_KEY }}
35+
id: do-sync
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This workflow triggers on a published release event.
2+
# Requires the following secrets:
3+
# - LANGUAGE_FAMILY_REPO -> the full name of the repo to send the dispatch to (eg. paketo-buildpacks/nodejs)
4+
# - PAKETO_BOT_GITHUB_TOKEN -> a token with permissions to send the dispatch to the language family repo
5+
6+
name: Send Dependency Update Dispatch
7+
8+
on:
9+
release:
10+
types: [published]
11+
12+
jobs:
13+
14+
dispatch:
15+
runs-on: ubuntu-latest
16+
name: Send Dispatch
17+
steps:
18+
19+
# Parses the release event JSON and fetches the details that make up a dependency update.
20+
# Dependency update details are provided as outputs.
21+
- name: Parse Release Dependency
22+
id: dependency
23+
uses: paketo-buildpacks/github-config/actions/dependency/parse@master
24+
25+
# Generic repository dispatch sender.
26+
- name: Send Repository Dispatch
27+
uses: paketo-buildpacks/github-config/actions/dispatch@master
28+
with:
29+
repos: ${{ secrets.LANGUAGE_FAMILY_REPO }}
30+
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
31+
event: dependency-update
32+
payload: |
33+
{
34+
"strategy": "replace",
35+
"dependency": {
36+
"id": "${{ steps.dependency.outputs.id }}",
37+
"sha256": "${{ steps.dependency.outputs.sha256 }}",
38+
"source": "${{ steps.dependency.outputs.source }}",
39+
"source_sha256": "${{ steps.dependency.outputs.source_sha256 }}",
40+
"stacks": ${{ steps.dependency.outputs.stacks }},
41+
"uri": "${{ steps.dependency.outputs.uri }}",
42+
"version": "${{ steps.dependency.outputs.version }}"
43+
}
44+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Test Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
unit:
10+
name: Unit Tests
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Setup Go
14+
uses: actions/setup-go@v1
15+
with:
16+
go-version: 1.14
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
- name: Run Unit Tests
20+
run: ./scripts/unit.sh
21+
22+
integration:
23+
name: Integration Tests
24+
runs-on: ubuntu-latest
25+
needs: unit
26+
steps:
27+
- name: Setup Go
28+
uses: actions/setup-go@v1
29+
with:
30+
go-version: 1.14
31+
- name: Checkout
32+
uses: actions/checkout@v2
33+
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
34+
- name: Run Integration Tests
35+
run: ./scripts/integration.sh
36+
env:
37+
GIT_TOKEN: ${{ github.token }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
.idea
3+
.bin
4+
/bin

.mergify/config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pull_request_rules:
2+
- name: Auto merge pull requests from github-actions bot
3+
conditions:
4+
- author=github-actions[bot]
5+
# TODO: Fill in these conditions when they are finalized
6+
# - status-success=Unit Tests
7+
# - status-success=Integration Tests
8+
actions:
9+
merge:
10+
strict: true
11+
method: rebase
12+
delete_head_branch: {}

.packit

Whitespace-only changes.

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
[WORK IN PROGRESS]
2-
3-
# Rack Cloud Native Buildpack
4-
5-
The Rack CNB sets the start command for a given rack-compliant ruby application.
1+
# Rackup Cloud Native Buildpack
62

3+
The Rackup CNB sets the start command for a given rack-compliant ruby application.
74

85
## Integration
96

107
This CNB writes a start command, so there's currently no scenario we can
118
imagine that you would need to require it as dependency. If a user likes to
12-
include some other functionality, it can be done independent of the Rack CNB
9+
include some other functionality, it can be done independent of the Rackup CNB
1310
without requiring a dependency of it.
1411

1512
To package this buildpack for consumption:

build.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"github.com/paketo-buildpacks/packit"
5+
"github.com/paketo-buildpacks/packit/scribe"
6+
)
7+
8+
func Build(logger scribe.Logger) packit.BuildFunc {
9+
return func(context packit.BuildContext) (packit.BuildResult, error) {
10+
logger.Title("%s %s", context.BuildpackInfo.Name, context.BuildpackInfo.Version)
11+
12+
logger.Process("Writing start command")
13+
command := "bundle exec rackup -p ${PORT}"
14+
logger.Subprocess("`%s`", command)
15+
16+
return packit.BuildResult{
17+
Processes: []packit.Process{
18+
{
19+
Type: "web",
20+
Command: command,
21+
},
22+
},
23+
}, nil
24+
}
25+
}

build_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package main_test
2+
3+
import (
4+
"bytes"
5+
"io/ioutil"
6+
"os"
7+
"testing"
8+
9+
"github.com/paketo-buildpacks/packit"
10+
"github.com/paketo-buildpacks/packit/scribe"
11+
main "github.com/paketo-community/rackup"
12+
"github.com/sclevine/spec"
13+
14+
. "github.com/onsi/gomega"
15+
)
16+
17+
func testBuild(t *testing.T, context spec.G, it spec.S) {
18+
var (
19+
Expect = NewWithT(t).Expect
20+
21+
layersDir string
22+
workingDir string
23+
cnbDir string
24+
buffer *bytes.Buffer
25+
26+
build packit.BuildFunc
27+
)
28+
29+
it.Before(func() {
30+
var err error
31+
layersDir, err = ioutil.TempDir("", "layers")
32+
Expect(err).NotTo(HaveOccurred())
33+
34+
cnbDir, err = ioutil.TempDir("", "cnb")
35+
Expect(err).NotTo(HaveOccurred())
36+
37+
workingDir, err = ioutil.TempDir("", "working-dir")
38+
Expect(err).NotTo(HaveOccurred())
39+
40+
buffer = bytes.NewBuffer(nil)
41+
logger := scribe.NewLogger(buffer)
42+
43+
build = main.Build(logger)
44+
})
45+
46+
it.After(func() {
47+
Expect(os.RemoveAll(layersDir)).To(Succeed())
48+
Expect(os.RemoveAll(cnbDir)).To(Succeed())
49+
Expect(os.RemoveAll(workingDir)).To(Succeed())
50+
})
51+
52+
it("returns a result that provides a rackup start command", func() {
53+
result, err := build(packit.BuildContext{
54+
WorkingDir: workingDir,
55+
CNBPath: cnbDir,
56+
Stack: "some-stack",
57+
BuildpackInfo: packit.BuildpackInfo{
58+
Name: "Some Buildpack",
59+
Version: "some-version",
60+
},
61+
Plan: packit.BuildpackPlan{
62+
Entries: []packit.BuildpackPlanEntry{},
63+
},
64+
Layers: packit.Layers{Path: layersDir},
65+
})
66+
Expect(err).NotTo(HaveOccurred())
67+
68+
Expect(result).To(Equal(packit.BuildResult{
69+
Plan: packit.BuildpackPlan{
70+
Entries: nil,
71+
},
72+
Layers: nil,
73+
Processes: []packit.Process{
74+
{
75+
Type: "web",
76+
Command: "bundle exec rackup -p ${PORT}",
77+
},
78+
},
79+
}))
80+
81+
Expect(buffer.String()).To(ContainSubstring("Some Buildpack some-version"))
82+
Expect(buffer.String()).To(ContainSubstring("Writing start command"))
83+
})
84+
}

0 commit comments

Comments
 (0)