Skip to content

Commit

Permalink
feat: build pipeline using jsonnet for re-use
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorwhitney committed Nov 28, 2023
1 parent 2a73b15 commit b6cc287
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 1 deletion.
99 changes: 99 additions & 0 deletions .github/workflows/jsonnet-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"jobs":
"loki-image":
"runs-on": "ubuntu-latest"
"steps":
- "name": "pull loki code"
"uses": "actions/checkout@v3"
"with":
"ref": "prepare-release-please"
"repository": "grafana/loki"
- "name": "Set up QEMU"
"uses": "docker/setup-qemu-action@v3"
"with":
"go-version-file": "go.mod"
- "name": "set up docker buildx"
"uses": "docker/setup-buildx-action@v3"
- "id": "parse-metadata"
"name": "parse image metadata"
"run": |
mkdir -p dist
platform="$(echo "${{ matrix.platform}}" | sed "s/\(.*\)\/\(.*\)/\1-\2/")"
echo "platform=${platform}" >> $GITHUB_OUTPUT
version=$(jq -r '."cmd/loki"' .release-please-manifest.json)
echo "version=${version}" >> $GITHUB_OUTPUT
"shell": "bash"
- "name": "Build and export"
"uses": "docker/build-push-action@v5"
"with":
"context": "."
"file": "cmd/loki/Dockerfile"
"outputs": "type=docker,dest=dist/loki-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar"
"platforms": "${{ matrix.platform }}"
"tags": "grafana/loki:${{ steps.parse-metadata.outputs.version }}"
- "name": "upload artifacts"
"uses": "actions/upload-artifact@v3"
"with":
"name": "loki-image-${{ matrix.platform }}"
"path": "dist/loki-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar"
"strategy":
"fail-fast": true
"matrix":
"platform":
- "linux/amd64"
- "linux/arm64"
- "linux/arm"
"promtail-image":
"runs-on": "ubuntu-latest"
"steps":
- "name": "pull loki code"
"uses": "actions/checkout@v3"
"with":
"ref": "prepare-release-please"
"repository": "grafana/loki"
- "name": "Set up QEMU"
"uses": "docker/setup-qemu-action@v3"
"with":
"go-version-file": "go.mod"
- "name": "set up docker buildx"
"uses": "docker/setup-buildx-action@v3"
- "id": "parse-metadata"
"name": "parse image metadata"
"run": |
mkdir -p dist
platform="$(echo "${{ matrix.platform}}" | sed "s/\(.*\)\/\(.*\)/\1-\2/")"
echo "platform=${platform}" >> $GITHUB_OUTPUT
version=$(jq -r '."cmd/promtail"' .release-please-manifest.json)
echo "version=${version}" >> $GITHUB_OUTPUT
"shell": "bash"
- "name": "Build and export"
"uses": "docker/build-push-action@v5"
"with":
"context": "."
"file": "cmd/promtail/Dockerfile"
"outputs": "type=docker,dest=dist/promtail-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar"
"platforms": "${{ matrix.platform }}"
"tags": "grafana/promtail:${{ steps.parse-metadata.outputs.version }}"
- "name": "upload artifacts"
"uses": "actions/upload-artifact@v3"
"with":
"name": "promtail-image-${{ matrix.platform }}"
"path": "dist/promtail-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar"
"strategy":
"fail-fast": true
"matrix":
"platform":
- "linux/amd64"
- "linux/arm64"
- "linux/arm"
"name": "release (jsonnet version)"
"on":
"push":
"branches":
- "main"
- "release-[0-9].[0-9].x"
- "k[0-9]*"
"workflow_dispatch": {}
17 changes: 17 additions & 0 deletions lib/common.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
fetchLokiRepo: {
name: 'pull loki code',
uses: 'actions/checkout@v3',
with: {
repository: 'grafana/loki',
ref: 'prepare-release-please',
},
},
setupGo: {
uses: 'actions/setup-go@v4',
with: {
'go-version-file': 'go.mod',
},
},
}

62 changes: 62 additions & 0 deletions lib/image.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
local common = import 'common.libsonnet';

{
buildImage: function(name, path) {
'runs-on': 'ubuntu-latest',
strategy: {
'fail-fast': true,
matrix: {
platform: [
'linux/amd64',
'linux/arm64',
'linux/arm',
],
},
},
steps: [
common.fetchLokiRepo,
common.setupGo
{
name: 'Set up QEMU',
uses: 'docker/setup-qemu-action@v3',
},
{
name: 'set up docker buildx',
uses: 'docker/setup-buildx-action@v3',
},
{
name: 'parse image metadata',
id: 'parse-metadata',
shell: 'bash',
run: |||
mkdir -p dist
platform="$(echo "${{ matrix.platform}}" | sed "s/\(.*\)\/\(.*\)/\1-\2/")"
echo "platform=${platform}" >> $GITHUB_OUTPUT
version=$(jq -r '."%s"' .release-please-manifest.json)
echo "version=${version}" >> $GITHUB_OUTPUT
||| % path,
},
{
name: 'Build and export',
uses: 'docker/build-push-action@v5',
with: {
context: '.',
file: '%s/Dockerfile' % path,
platforms: '${{ matrix.platform }}',
tags: 'grafana/%s:${{ steps.parse-metadata.outputs.version }}' % name,
outputs: 'type=docker,dest=dist/%s-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar' % name,
},
},
{
name: 'upload artifacts',
uses: 'actions/upload-artifact@v3',
with: {
name: '%s-image-${{ matrix.platform }}' % name,
path: 'dist/%s-${{ steps.parse-metadata.outputs.version}}-${{ steps.parse-metadata.outputs.platform }}.tar' % name,
},
},
],
},
}
3 changes: 3 additions & 0 deletions lib/lib.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
image: (import 'image.libsonnet'),
}
19 changes: 19 additions & 0 deletions main.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local lib = import 'lib/lib.libsonnet';

std.manifestYamlDoc({
name: 'release (jsonnet version)',
on: {
workflow_dispatch: {},
push: {
branches: [
'main',
'release-[0-9].[0-9].x',
'k[0-9]*',
],
},
},
jobs: {
'loki-image': lib.image.buildImage("loki", "cmd/loki"),
'promtail-image': lib.image.buildImage("promtail", "cmd/promtail"),
},
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "release pipeline for the Loki database",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"build": "jsonnet -S main.jsonnet > .github/workflows/jsonnet-release.yml"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit b6cc287

Please sign in to comment.