Skip to content

Commit cd5c8ce

Browse files
committed
Updating github-config
1 parent 6f52277 commit cd5c8ce

File tree

7 files changed

+509
-142
lines changed

7 files changed

+509
-142
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: 'Compile Dependency on Target - Reusable Workflow'
2+
3+
description: |
4+
Compiles Dependency on given target, os, and arch
5+
6+
on:
7+
workflow_call:
8+
inputs:
9+
version:
10+
description: 'dependency version'
11+
required: true
12+
type: string
13+
target:
14+
description: 'dependency OS target variant'
15+
required: true
16+
type: string
17+
os:
18+
description: 'platform OS (e.g., linux)'
19+
required: true
20+
type: string
21+
arch:
22+
description: 'platform architecture (e.g., amd64)'
23+
required: true
24+
type: string
25+
shouldCompile:
26+
description: 'whether to compile the dependency'
27+
required: true
28+
type: boolean
29+
shouldTest:
30+
description: 'whether to test the dependency after compilation'
31+
required: true
32+
type: boolean
33+
uploadArtifactName:
34+
description: 'name of the artifact to upload'
35+
required: true
36+
type: string
37+
38+
jobs:
39+
compile:
40+
# Speed up compilation by using runners that match os and arch when they are set, otherwise fall back to emulation.
41+
runs-on: ${{ (inputs.os == 'linux' && inputs.arch == 'arm64') && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
42+
43+
steps:
44+
- name: Check out code
45+
uses: actions/checkout@v4
46+
47+
- name: Enable experimental features for Docker daemon and CLI
48+
run: |
49+
echo '{"experimental": true}' | sudo tee /etc/docker/daemon.json
50+
sudo systemctl restart docker
51+
mkdir -p ~/.docker
52+
echo '{"experimental": "enabled"}' | sudo tee ~/.docker/config.json
53+
54+
- name: Set up QEMU
55+
uses: docker/setup-qemu-action@v3
56+
57+
- name: Set up Docker Buildx
58+
uses: docker/setup-buildx-action@v3
59+
60+
- name: Setup before compilation
61+
id: compile-setup
62+
run: |
63+
echo "outputdir=$(mktemp -d)" >> "$GITHUB_OUTPUT"
64+
65+
- name: docker build
66+
id: docker-build
67+
env:
68+
SKIP_LOGIN: true
69+
if: ${{ inputs.shouldCompile == true || inputs.shouldCompile == 'true' }}
70+
uses: actions-hub/docker/cli@master
71+
with:
72+
args: "build ${{ (inputs.os != '' && inputs.arch != '') && format('--platform {0}/{1}', inputs.os, inputs.arch) || '' }} -t compilation -f dependency/actions/compile/${{ inputs.target }}.Dockerfile dependency/actions/compile"
73+
74+
- name: docker run
75+
id: docker-run
76+
uses: actions-hub/docker/cli@master
77+
env:
78+
SKIP_LOGIN: true
79+
if: ${{ inputs.shouldCompile == true || inputs.shouldCompile == 'true' }}
80+
with:
81+
args: "run ${{ (inputs.os != '' && inputs.arch != '') && format('--platform {0}/{1}', inputs.os, inputs.arch) || '' }} -v ${{ steps.compile-setup.outputs.outputdir }}:/home compilation --outputDir /home --target ${{ inputs.target }} --version ${{ inputs.version }} ${{ inputs.os != '' && format('--os {0}', inputs.os) || '' }} ${{ inputs.arch != '' && format('--arch {0}', inputs.arch) || '' }}"
82+
83+
- name: Print contents of output dir
84+
shell: bash
85+
run: ls -lah ${{ steps.compile-setup.outputs.outputdir }}
86+
87+
- name: Test Dependency
88+
working-directory: dependency
89+
if: ${{ (inputs.shouldCompile == true || inputs.shouldCompile == 'true') && (inputs.shouldTest == true || inputs.shouldTest == 'true') }}
90+
run: |
91+
#!/usr/bin/env bash
92+
set -euo pipefail
93+
shopt -s inherit_errexit
94+
95+
make test \
96+
version="${{ inputs.version }}" \
97+
tarballPath="${{ steps.compile-setup.outputs.outputdir }}/*.tgz" \
98+
os="${{ inputs.os }}" \
99+
arch="${{ inputs.arch }}"
100+
101+
- name: Upload compiled artifact
102+
uses: actions/upload-artifact@v4
103+
if: ${{ inputs.shouldCompile == true || inputs.shouldCompile == 'true' }}
104+
with:
105+
name: '${{ inputs.uploadArtifactName }}'
106+
path: '${{ steps.compile-setup.outputs.outputdir }}/*'

.github/workflows/create-draft-release.yml

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ jobs:
6161
name: Release
6262
runs-on: ubuntu-24.04
6363
needs: integration
64+
services:
65+
registry:
66+
image: registry:2
67+
ports:
68+
- 5000:5000
69+
6470
steps:
6571
- name: Checkout
6672
uses: actions/checkout@v4
@@ -110,13 +116,86 @@ jobs:
110116
echo "buildpack_type=buildpack" >> "$GITHUB_OUTPUT"
111117
fi
112118
119+
- name: Get buildpack path
120+
id: get_buildpack_path
121+
run: |
122+
123+
if [ -f "build/buildpackage.cnb" ]; then
124+
echo "path=build/buildpackage.cnb" >> "$GITHUB_OUTPUT"
125+
else
126+
echo "path=build/buildpackage-linux-amd64.cnb" >> "$GITHUB_OUTPUT"
127+
fi
128+
113129
- name: Create Release Notes
114130
id: create-release-notes
115131
uses: paketo-buildpacks/github-config/actions/release/notes@main
116132
with:
117133
repo: ${{ github.repository }}
118134
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
119135
buildpack_type: ${{ steps.get_buildpack_type.outputs.buildpack_type }}
136+
buildpackage_path: ${{ steps.get_buildpack_path.outputs.path }}
137+
138+
- name: Get Image Digest
139+
id: image_digest
140+
run: |
141+
image_name="localhost:5000/npm-install:latest"
142+
143+
./scripts/publish.sh \
144+
--buildpack-type ${{ steps.get_buildpack_type.outputs.buildpack_type }} \
145+
--image-ref $image_name
146+
147+
echo "digest=$(sudo skopeo inspect "docker://${image_name}" --tls-verify=false | jq -r .Digest)" >> "$GITHUB_OUTPUT"
148+
149+
- name: Set Correct Image Digest on the Release notes
150+
run: |
151+
printf '${{ steps.create-release-notes.outputs.release_body }}' \
152+
| sed -E \
153+
"s/\*\*Digest:\*\* \`sha256:[a-f0-9]{64}\`/\*\*Digest:\*\* \`${{ steps.image_digest.outputs.digest }}\`/" \
154+
> ./release_notes
155+
156+
printf '${{ steps.image_digest.outputs.digest }}' > ./index-digest.sha256
157+
158+
- name: Create release assets
159+
id: create_release_assets
160+
run: |
161+
release_assets=$(jq -n --arg repo_name "${{ github.event.repository.name }}" --arg tag "${{ steps.tag.outputs.tag }}" '
162+
[
163+
{
164+
"path": "build/buildpack.tgz",
165+
"name": ($repo_name + "-" + $tag + ".tgz"),
166+
"content_type": "application/gzip"
167+
},
168+
{
169+
"path": "./index-digest.sha256",
170+
"name": ($repo_name + "-" + $tag + "-" + "index-digest.sha256"),
171+
"content_type": "text/plain"
172+
}
173+
]')
174+
175+
for filepath in build/*.cnb; do
176+
filename=$(basename "$filepath")
177+
asset_name=""
178+
if [[ "$filename" == "buildpackage-linux-amd64.cnb" ]]; then
179+
asset_name="${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.cnb"
180+
elif [[ "$filename" == "buildpackage.cnb" ]]; then
181+
asset_name="${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.cnb"
182+
else
183+
formatted_filename="${filename#buildpackage-}"
184+
asset_name="${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}-${formatted_filename}"
185+
fi
186+
187+
release_assets=$(echo "$release_assets" | jq --arg asset_name "${asset_name}" --arg filepath "$filepath" '
188+
. + [
189+
{
190+
"path": $filepath,
191+
"name": $asset_name,
192+
"content_type": "application/gzip"
193+
}
194+
]')
195+
done
196+
197+
release_assets=$(jq -c <<< "$release_assets" )
198+
printf "release_assets=%s\n" "${release_assets}" >> "$GITHUB_OUTPUT"
120199
121200
- name: Create Release
122201
uses: paketo-buildpacks/github-config/actions/release/create@main
@@ -126,21 +205,9 @@ jobs:
126205
tag_name: v${{ steps.tag.outputs.tag }}
127206
target_commitish: ${{ github.sha }}
128207
name: v${{ steps.tag.outputs.tag }}
129-
body: ${{ steps.create-release-notes.outputs.release_body }}
208+
body_filepath: "./release_notes"
130209
draft: true
131-
assets: |
132-
[
133-
{
134-
"path": "build/buildpack.tgz",
135-
"name": "${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.tgz",
136-
"content_type": "application/gzip"
137-
},
138-
{
139-
"path": "build/buildpackage.cnb",
140-
"name": "${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.cnb",
141-
"content_type": "application/gzip"
142-
}
143-
]
210+
assets: ${{ steps.create_release_assets.outputs.release_assets }}
144211

145212
failure:
146213
name: Alert on Failure

.github/workflows/push-buildpackage.yml

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ on:
44
release:
55
types:
66
- published
7+
78
env:
89
REGISTRIES_FILENAME: "registries.json"
910

1011
jobs:
1112
push:
1213
name: Push
1314
runs-on: ubuntu-24.04
15+
env:
16+
GCR_REGISTRY: "gcr.io"
17+
GCR_PASSWORD: ${{ secrets.GCR_PUSH_BOT_JSON_KEY }}
18+
GCR_USERNAME: "_json_key"
19+
DOCKERHUB_REGISTRY: docker.io
20+
DOCKERHUB_USERNAME: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_USERNAME }}
21+
DOCKERHUB_PASSWORD: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_PASSWORD }}
22+
1423
steps:
1524

1625
- name: Checkout
@@ -25,16 +34,31 @@ jobs:
2534
echo "tag_full=${FULL_VERSION}" >> "$GITHUB_OUTPUT"
2635
echo "tag_minor=${MINOR_VERSION}" >> "$GITHUB_OUTPUT"
2736
echo "tag_major=${MAJOR_VERSION}" >> "$GITHUB_OUTPUT"
28-
echo "download_url=$(jq -r '.release.assets[] | select(.name | endswith(".cnb")) | .url' "${GITHUB_EVENT_PATH}")" >> "$GITHUB_OUTPUT"
37+
echo "download_tgz_file_url=$(jq -r '.release.assets[] | select(.name | endswith(".tgz")) | .url' "${GITHUB_EVENT_PATH}")" >> "$GITHUB_OUTPUT"
38+
echo "download_cnb_file_url=$(jq -r --arg tag_full "$FULL_VERSION" '.release.assets[] | select(.name | endswith($tag_full + ".cnb")) | .url' "${GITHUB_EVENT_PATH}")" >> "$GITHUB_OUTPUT"
39+
echo "download_sha256_file_url=$(jq -r '.release.assets[] | select(.name | endswith("index-digest.sha256")) | .url' "${GITHUB_EVENT_PATH}")" >> "$GITHUB_OUTPUT"
2940
30-
- name: Download
31-
id: download
41+
- name: Download .cnb buildpack
3242
uses: paketo-buildpacks/github-config/actions/release/download-asset@main
3343
with:
34-
url: ${{ steps.event.outputs.download_url }}
44+
url: ${{ steps.event.outputs.download_cnb_file_url }}
3545
output: "/github/workspace/buildpackage.cnb"
3646
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
3747

48+
- name: Download .tgz buildpack
49+
uses: paketo-buildpacks/github-config/actions/release/download-asset@main
50+
with:
51+
url: ${{ steps.event.outputs.download_tgz_file_url }}
52+
output: "/github/workspace/buildpack.tgz"
53+
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
54+
55+
- name: Download .sha digest
56+
uses: paketo-buildpacks/github-config/actions/release/download-asset@main
57+
with:
58+
url: ${{ steps.event.outputs.download_sha256_file_url }}
59+
output: "/github/workspace/index-digest.sha256"
60+
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
61+
3862
- name: Parse Configs
3963
id: parse_configs
4064
run: |
@@ -64,41 +88,74 @@ jobs:
6488
exit 1
6589
fi
6690
67-
- name: Push to GCR
68-
if: ${{ steps.parse_configs.outputs.push_to_gcr == 'true' }}
69-
env:
70-
GCR_PUSH_BOT_JSON_KEY: ${{ secrets.GCR_PUSH_BOT_JSON_KEY }}
91+
- name: Get buildpack type
92+
id: get_buildpack_type
7193
run: |
72-
echo "${GCR_PUSH_BOT_JSON_KEY}" | sudo skopeo login --username _json_key --password-stdin gcr.io
73-
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://gcr.io/${{ github.repository }}:${{ steps.event.outputs.tag_full }}"
74-
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://gcr.io/${{ github.repository }}:${{ steps.event.outputs.tag_minor }}"
75-
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://gcr.io/${{ github.repository }}:${{ steps.event.outputs.tag_major }}"
76-
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://gcr.io/${{ github.repository }}:latest"
94+
if [ -f "extension.toml" ]; then
95+
echo "buildpack_type=extension" >> "$GITHUB_OUTPUT"
96+
else
97+
echo "buildpack_type=buildpack" >> "$GITHUB_OUTPUT"
98+
fi
99+
100+
- name: Docker login docker.io
101+
uses: docker/login-action@v3
102+
with:
103+
username: ${{ env.DOCKERHUB_USERNAME }}
104+
password: ${{ env.DOCKERHUB_PASSWORD }}
105+
registry: ${{ env.DOCKERHUB_REGISTRY }}
106+
107+
- name: Docker login gcr.io
108+
uses: docker/login-action@v3
109+
if: ${{ steps.parse_configs.outputs.push_to_gcr == 'true' }}
110+
with:
111+
username: ${{ env.GCR_USERNAME }}
112+
password: ${{ env.GCR_PASSWORD }}
113+
registry: ${{ env.GCR_REGISTRY }}
77114

78115
- name: Push to DockerHub
79116
if: ${{ steps.parse_configs.outputs.push_to_dockerhub == 'true' }}
80117
id: push
81118
env:
82-
DOCKERHUB_USERNAME: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_USERNAME }}
83-
DOCKERHUB_PASSWORD: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_PASSWORD }}
84119
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
85120
run: |
86-
REPOSITORY="${GITHUB_REPOSITORY_OWNER/-/}/${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}" # translates 'paketo-buildpacks/bundle-install' to 'paketobuildpacks/bundle-install'
87-
IMAGE="index.docker.io/${REPOSITORY}"
88-
echo "${DOCKERHUB_PASSWORD}" | sudo skopeo login --username "${DOCKERHUB_USERNAME}" --password-stdin index.docker.io
89-
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://${IMAGE}:${{ steps.event.outputs.tag_full }}"
90-
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://${IMAGE}:${{ steps.event.outputs.tag_minor }}"
91-
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://${IMAGE}:${{ steps.event.outputs.tag_major }}"
92-
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://${IMAGE}:latest"
121+
IMAGE="${GITHUB_REPOSITORY_OWNER/-/}/${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}" # translates 'paketo-buildpacks/bundle-install' to 'paketobuildpacks/bundle-install'
122+
echo "${DOCKERHUB_PASSWORD}" | sudo skopeo login --username "${DOCKERHUB_USERNAME}" --password-stdin ${DOCKERHUB_REGISTRY}
123+
124+
./scripts/publish.sh \
125+
--archive-path ./buildpack.tgz \
126+
--buildpack-type ${{ steps.get_buildpack_type.outputs.buildpack_type }} \
127+
--image-ref "${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}"
128+
129+
## Validate that the digest pushed to registry matches with the one mentioned on the readme file
130+
pushed_image_index_digest=$(sudo skopeo inspect "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}" | jq -r .Digest)
131+
132+
if [ "$(cat ./index-digest.sha256)" != "$pushed_image_index_digest" ]; then
133+
echo "Image index digest pushed to registry does not match with the one mentioned on the readme file"
134+
exit 1;
135+
fi
136+
137+
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}" "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_minor }}" --multi-arch all
138+
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}" "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_major }}" --multi-arch all
139+
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}" "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:latest" --multi-arch all
93140
echo "image=${IMAGE}" >> "$GITHUB_OUTPUT"
94-
echo "digest=$(sudo skopeo inspect "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" | jq -r .Digest)" >> "$GITHUB_OUTPUT"
141+
echo "digest=$pushed_image_index_digest" >> "$GITHUB_OUTPUT"
142+
143+
- name: Push to GCR
144+
if: ${{ steps.parse_configs.outputs.push_to_gcr == 'true' }}
145+
run: |
146+
echo "${GCR_PASSWORD}" | sudo skopeo login --username "${GCR_USERNAME}" --password-stdin "${GCR_REGISTRY}"
147+
148+
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${{ steps.push.outputs.image }}" "docker://${GCR_REGISTRY}/${{ github.repository }}:${{ steps.event.outputs.tag_full }}" --multi-arch all
149+
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${{ steps.push.outputs.image }}" "docker://${GCR_REGISTRY}/${{ github.repository }}:${{ steps.event.outputs.tag_minor }}" --multi-arch all
150+
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${{ steps.push.outputs.image }}" "docker://${GCR_REGISTRY}/${{ github.repository }}:${{ steps.event.outputs.tag_major }}" --multi-arch all
151+
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${{ steps.push.outputs.image }}" "docker://${GCR_REGISTRY}/${{ github.repository }}:latest" --multi-arch all
95152
96153
- name: Register with CNB Registry
97154
uses: docker://ghcr.io/buildpacks/actions/registry/request-add-entry:main
98155
with:
99156
id: ${{ github.repository }}
100157
version: ${{ steps.event.outputs.tag_full }}
101-
address: ${{ steps.push.outputs.image }}@${{ steps.push.outputs.digest }}
158+
address: index.docker.io/${{ steps.push.outputs.image }}@${{ steps.push.outputs.digest }}
102159
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
103160

104161
failure:

0 commit comments

Comments
 (0)