Skip to content

Commit a820f34

Browse files
authored
Use CNB builder for heroku-22 stack (#6)
* Use CNB builder for heroku-22 stack refs #5 * Switch default builder to heroku/builder:22 * Add new buildpack * Test app.json too * Procfile buildpack now uses command and args * Test against legacy Heroku builder * Adjust tests for bash wrapper New procfile buildpacks add it
1 parent e6b49ed commit a820f34

File tree

5 files changed

+148
-14
lines changed

5 files changed

+148
-14
lines changed

.github/workflows/build.yml

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,132 @@ jobs:
9393
- uses: actions/setup-python@v4
9494
with:
9595
python-version: "3.11"
96+
- name: Verify apppack.toml
97+
working-directory: ./apppack-demo-python
98+
run: |
99+
set -ex
100+
cat apppack.toml
101+
test "$(python -c 'import tomllib; print(tomllib.load(open("apppack.toml", "rb"))["services"]["web"]["command"])')" = "bash -c 'gunicorn --access-logfile - --bind 0.0.0.0:\$PORT --forwarded-allow-ips '\"'\"'*'\"'\"' app:app'"
102+
103+
integration-appjson:
104+
runs-on: ubuntu-latest
105+
needs: [test, build-image]
106+
permissions:
107+
id-token: write
108+
contents: read
109+
packages: read
110+
steps:
111+
- name: Login to GitHub Container Registry
112+
uses: docker/login-action@v2
113+
with:
114+
registry: ghcr.io
115+
username: ${{ github.actor }}
116+
password: ${{ secrets.GITHUB_TOKEN }}
117+
- name: Pull image
118+
run: docker pull ${{ needs.build-image.outputs.image }}
119+
- name: configure aws credentials
120+
uses: aws-actions/configure-aws-credentials@v1-node16
121+
with:
122+
role-to-assume: arn:aws:iam::891426818781:role/github-actions-integration-tests
123+
aws-region: us-east-1
124+
- name: Checkout sample repo
125+
run: git clone --branch app.json https://github.com/apppackio/apppack-demo-python.git
126+
- name: Run integration tests
127+
working-directory: ./apppack-demo-python
128+
run: |
129+
cat <<EOF > .envfile
130+
APPNAME=gh-integration
131+
CODEBUILD_BUILD_ID=demo-python:${{ github.run_id }}
132+
CODEBUILD_SOURCE_VERSION=${{ github.sha }}
133+
DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
134+
DOCKERHUB_ACCESS_TOKEN=${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
135+
DOCKER_REPO=891426818781.dkr.ecr.us-east-1.amazonaws.com/github-integration-test
136+
ARTIFACT_BUCKET=integration-test-buildartifacts
137+
AWS_REGION
138+
AWS_ACCESS_KEY_ID
139+
AWS_SECRET_ACCESS_KEY
140+
AWS_SESSION_TOKEN
141+
EOF
142+
143+
docker run \
144+
--rm \
145+
--privileged \
146+
--env-file .envfile \
147+
--volume /var/run/docker.sock:/var/run/docker.sock \
148+
--volume "$(pwd):/app" \
149+
--workdir /app \
150+
${{ needs.build-image.outputs.image }} \
151+
/bin/sh -c "set -x; git config --global --add safe.directory /app && apppack-builder prebuild; apppack-builder build; apppack-builder postbuild"
152+
- uses: actions/setup-python@v4
153+
with:
154+
python-version: "3.11"
155+
- name: Verify apppack.toml
156+
working-directory: ./apppack-demo-python
157+
run: |
158+
set -ex
159+
cat apppack.toml
160+
test "$(python -c 'import tomllib; print(tomllib.load(open("apppack.toml", "rb"))["services"]["web"]["command"])')" = "bash -c 'gunicorn --access-logfile - --bind 0.0.0.0:\$PORT --forwarded-allow-ips '\"'\"'*'\"'\"' app:app'"
161+
162+
integration-heroku20:
163+
runs-on: ubuntu-latest
164+
needs: [test, build-image]
165+
permissions:
166+
id-token: write
167+
contents: read
168+
packages: read
169+
steps:
170+
- name: Login to GitHub Container Registry
171+
uses: docker/login-action@v2
172+
with:
173+
registry: ghcr.io
174+
username: ${{ github.actor }}
175+
password: ${{ secrets.GITHUB_TOKEN }}
176+
- name: Pull image
177+
run: docker pull ${{ needs.build-image.outputs.image }}
178+
- name: configure aws credentials
179+
uses: aws-actions/configure-aws-credentials@v1-node16
180+
with:
181+
role-to-assume: arn:aws:iam::891426818781:role/github-actions-integration-tests
182+
aws-region: us-east-1
183+
- name: Checkout sample repo
184+
run: git clone --branch buildpacks-20 https://github.com/apppackio/apppack-demo-python.git
185+
- name: Run integration tests
186+
working-directory: ./apppack-demo-python
187+
run: |
188+
cat <<EOF > .envfile
189+
APPNAME=gh-integration
190+
CODEBUILD_BUILD_ID=demo-python:${{ github.run_id }}
191+
CODEBUILD_SOURCE_VERSION=${{ github.sha }}
192+
DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
193+
DOCKERHUB_ACCESS_TOKEN=${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
194+
DOCKER_REPO=891426818781.dkr.ecr.us-east-1.amazonaws.com/github-integration-test
195+
ARTIFACT_BUCKET=integration-test-buildartifacts
196+
ALLOW_EOL_SHIMMED_BUILDER=1
197+
AWS_REGION
198+
AWS_ACCESS_KEY_ID
199+
AWS_SECRET_ACCESS_KEY
200+
AWS_SESSION_TOKEN
201+
EOF
202+
203+
docker run \
204+
--rm \
205+
--privileged \
206+
--env-file .envfile \
207+
--volume /var/run/docker.sock:/var/run/docker.sock \
208+
--volume "$(pwd):/app" \
209+
--workdir /app \
210+
${{ needs.build-image.outputs.image }} \
211+
/bin/sh -c "set -x; git config --global --add safe.directory /app && apppack-builder prebuild; apppack-builder build; apppack-builder postbuild"
212+
- uses: actions/setup-python@v4
213+
with:
214+
python-version: "3.11"
96215
- name: Verify apppack.toml
97216
working-directory: ./apppack-demo-python
98217
run: |
99218
set -ex
100219
cat apppack.toml
101220
test "$(python -c 'import tomllib; print(tomllib.load(open("apppack.toml", "rb"))["services"]["web"]["command"])')" = 'gunicorn --access-logfile - --bind 0.0.0.0:$PORT --forwarded-allow-ips '"'"'*'"' app:app"
221+
102222
integration-docker:
103223
runs-on: ubuntu-latest
104224
needs: [test, build-image]
@@ -161,7 +281,7 @@ jobs:
161281
runs-on: ubuntu-latest
162282
# Only run this job if the current commit is tagged with a version
163283
if: startswith(github.ref, 'refs/tags/v')
164-
needs: [test, build-image, integration, integration-docker]
284+
needs: [test, build-image, integration, integration-docker, integration-appjson, integration-heroku20]
165285
permissions:
166286
id-token: write
167287
contents: read

builder/build/appjson.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@ type AppJSON struct {
2727
ctx context.Context
2828
}
2929

30-
const DefaultStack = "heroku-20"
30+
const DefaultStack = "heroku-22"
3131

3232
// buildpacks included in builder
3333
var IncludedBuildpacks = map[string][]string{
3434
"heroku-20": {
3535
// $ pack builder inspect heroku/buildpacks:20 -o json | jq '.remote_info.buildpacks[].id'
36+
"heroku/builder-eol-warning",
3637
"heroku/go",
3738
"heroku/gradle",
3839
"heroku/java",
39-
"heroku/java-function",
4040
"heroku/jvm",
41-
"heroku/jvm-function-invoker",
4241
"heroku/maven",
4342
"heroku/nodejs",
43+
"heroku/nodejs-corepack",
4444
"heroku/nodejs-engine",
45-
"heroku/nodejs-function",
46-
"heroku/nodejs-function-invoker",
47-
"heroku/nodejs-npm",
45+
"heroku/nodejs-npm-engine",
46+
"heroku/nodejs-npm-install",
47+
"heroku/nodejs-pnpm-install",
4848
"heroku/nodejs-yarn",
4949
"heroku/php",
5050
"heroku/procfile",
@@ -53,16 +53,25 @@ var IncludedBuildpacks = map[string][]string{
5353
"heroku/scala",
5454
},
5555
"heroku-22": {
56-
// $ pack builder inspect heroku/builder-classic:22 -o json | jq '.remote_info.buildpacks[].id'
57-
"heroku/clojure",
56+
// $ pack builder inspect heroku/builder:22 -o json | jq '.remote_info.buildpacks[].id'
5857
"heroku/go",
5958
"heroku/gradle",
6059
"heroku/java",
60+
"heroku/jvm",
61+
"heroku/maven",
6162
"heroku/nodejs",
63+
"heroku/nodejs-corepack",
64+
"heroku/nodejs-engine",
65+
"heroku/nodejs-npm-engine",
66+
"heroku/nodejs-npm-install",
67+
"heroku/nodejs-pnpm-engine",
68+
"heroku/nodejs-pnpm-install",
69+
"heroku/nodejs-yarn",
6270
"heroku/php",
6371
"heroku/procfile",
6472
"heroku/python",
6573
"heroku/ruby",
74+
"heroku/sbt",
6675
"heroku/scala",
6776
},
6877
}
@@ -131,9 +140,8 @@ func (a *AppJSON) GetBuilders() []string {
131140
if a.Stack == "heroku-20" {
132141
return []string{"heroku/buildpacks:20", "heroku/heroku:20-cnb"}
133142
}
134-
// TODO: use heroku/builder:22 can be used when all buildpacks are CNB
135143
if a.Stack == "heroku-22" {
136-
return []string{"heroku/builder-classic:22", "heroku/heroku:22-cnb"}
144+
return []string{"heroku/builder:22", "heroku/heroku:22-cnb"}
137145
}
138146
return []string{a.Stack}
139147
}

builder/build/appjson_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestAppJsonBuilders(t *testing.T) {
7676
Stack: "heroku-22",
7777
ctx: testContext,
7878
}
79-
expected := []string{"heroku/builder-classic:22", "heroku/heroku:22-cnb"}
79+
expected := []string{"heroku/builder:22", "heroku/heroku:22-cnb"}
8080
if !stringSliceEqual(a.GetBuilders(), expected) {
8181
t.Errorf("expected %s, got %s", expected, a.GetBuilders())
8282
}
@@ -159,7 +159,7 @@ func TestAppJsonToApppackToml(t *testing.T) {
159159
Build: AppPackTomlBuild{
160160
System: "buildpack",
161161
Buildpacks: []string{"urn:cnb:builder:heroku/nodejs", "urn:cnb:builder:heroku/python"},
162-
Builder: "heroku/builder-classic:22",
162+
Builder: "heroku/builder:22",
163163
},
164164
Test: AppPackTomlTest{
165165
Command: "echo test",

builder/build/build.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ func (b *Build) LoadBuildEnv() (map[string]string, error) {
3232
env := map[string]string{
3333
"CI": "true",
3434
}
35+
// pass ALLOW_EOL_SHIMMED_BUILDER to pack if it is in the environment
36+
// this facilitates testing of the eol shimmed builder
37+
if val, ok := os.LookupEnv("ALLOW_EOL_SHIMMED_BUILDER"); ok {
38+
env["ALLOW_EOL_SHIMMED_BUILDER"] = val
39+
}
3540
params, err := b.aws.GetParametersByPath(paths[0])
3641
stripParamPrefix(params, paths[0], &env)
3742
if err != nil {

builder/build/metadatatoml.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
type BuildpackMetadataTomlProcess struct {
1313
Command []string `toml:"command"`
14+
Args []string `toml:"args"`
1415
Type string `toml:"type"`
1516
BuildpackID string `toml:"buildpack_id"`
1617
}
@@ -37,7 +38,7 @@ func (m *BuildpackMetadataToml) UpdateAppPackToml(a *AppPackToml) {
3738
if process.BuildpackID == "heroku/ruby" && (process.Type == "rake" || process.Type == "console") {
3839
continue
3940
}
40-
a.Services[process.Type] = AppPackTomlService{Command: commandSliceToString(process.Command)}
41+
a.Services[process.Type] = AppPackTomlService{Command: commandSliceToString(append(process.Command, process.Args...))}
4142
}
4243
}
4344

0 commit comments

Comments
 (0)