This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from openmeterio/build
build: add container image build
- Loading branch information
Showing
5 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
name: Artifacts | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
publish: | ||
description: Publish artifacts to the artifact store | ||
default: false | ||
required: false | ||
type: boolean | ||
outputs: | ||
container-image-name: | ||
description: Container image name | ||
value: ${{ jobs.container-image.outputs.name }} | ||
container-image-digest: | ||
description: Container image digest | ||
value: ${{ jobs.container-image.outputs.digest }} | ||
container-image-tag: | ||
description: Container image tag | ||
value: ${{ jobs.container-image.outputs.tag }} | ||
container-image-ref: | ||
description: Container image ref | ||
value: ${{ jobs.container-image.outputs.ref }} | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
container-image: | ||
name: Container image | ||
runs-on: ubuntu-latest-large | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
id-token: write | ||
security-events: write | ||
|
||
outputs: | ||
name: ${{ steps.image-name.outputs.value }} | ||
digest: ${{ steps.build.outputs.digest }} | ||
tag: ${{ steps.meta.outputs.version }} | ||
ref: ${{ steps.image-ref.outputs.value }} | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 | ||
|
||
- name: Set image name | ||
id: image-name | ||
run: echo "value=ghcr.io/${{ github.repository }}" >> "$GITHUB_OUTPUT" | ||
|
||
- name: Gather build metadata | ||
id: meta | ||
uses: docker/metadata-action@9dc751fe249ad99385a2583ee0d084c400eee04e # v5.4.0 | ||
with: | ||
images: ${{ steps.image-name.outputs.value }} | ||
flavor: | | ||
latest = false | ||
tags: | | ||
type=ref,event=branch,suffix=-${{ matrix.target }} | ||
type=ref,event=pr,prefix=pr-,suffix=-${{ matrix.target }} | ||
type=semver,pattern={{raw}},suffix=-${{ matrix.target }} | ||
type=raw,value=latest,suffix=-${{ matrix.target }},enable={{is_default_branch}} | ||
type=ref,event=branch,suffix=-${{ matrix.target }}-{{sha}}-{{date 'X'}},enable={{is_default_branch}} | ||
# Multiple exporters are not supported yet | ||
# See https://github.com/moby/buildkit/pull/2760 | ||
- name: Determine build output | ||
uses: haya14busa/action-cond@1d6e8a12b20cdb4f1954feef9aa475b9c390cab5 # v1.1.1 | ||
id: build-output | ||
with: | ||
cond: ${{ inputs.publish }} | ||
if_true: type=image,push=true | ||
if_false: type=oci,dest=image.tar | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ github.token }} | ||
if: inputs.publish | ||
|
||
- name: Build and push image | ||
id: build | ||
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0 | ||
with: | ||
context: . | ||
target: ${{ matrix.target }} | ||
build-args: | | ||
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} | ||
platforms: linux/amd64,linux/arm64 | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max,ignore-error=true | ||
outputs: ${{ steps.build-output.outputs.value }} | ||
# push: ${{ inputs.publish }} | ||
|
||
- name: Set image ref | ||
id: image-ref | ||
run: echo "value=${{ steps.image-name.outputs.value }}@${{ steps.build.outputs.digest }}" >> "$GITHUB_OUTPUT" | ||
|
||
- name: Fetch image | ||
run: skopeo --insecure-policy copy docker://${{ steps.image-ref.outputs.value }} oci-archive:image.tar | ||
if: inputs.publish | ||
|
||
- name: Extract OCI tarball | ||
run: | | ||
mkdir -p image | ||
tar -xf image.tar -C image | ||
- name: Run Trivy vulnerability scanner | ||
uses: aquasecurity/trivy-action@91713af97dc80187565512baba96e4364e983601 # 0.16.0 | ||
with: | ||
input: image | ||
format: sarif | ||
output: trivy-results.sarif | ||
|
||
- name: Upload Trivy scan results as artifact | ||
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0 | ||
with: | ||
name: "[${{ github.job }}] Trivy scan results" | ||
path: trivy-results.sarif | ||
retention-days: 5 | ||
|
||
- name: Upload Trivy scan results to GitHub Security tab | ||
uses: github/codeql-action/upload-sarif@29b1f65c5e92e24fe6b6647da1eaabe529cec70f # v2.3.3 | ||
with: | ||
sarif_file: trivy-results.sarif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- "v[0-9]+.[0-9]+.[0-9]+" | ||
- "v[0-9]+.[0-9]+.[0-9]+-dev.[0-9]+" | ||
- "v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+" | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
artifacts: | ||
name: Artifacts | ||
uses: ./.github/workflows/artifacts.yaml | ||
with: | ||
publish: true | ||
permissions: | ||
contents: read | ||
packages: write | ||
id-token: write | ||
security-events: write |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
FROM --platform=$BUILDPLATFORM golang:1.21.5-alpine3.18@sha256:d8b99943fb0587b79658af03d4d4e8b57769b21dcf08a8401352a9f2a7228754 AS builder | ||
|
||
RUN apk add --update --no-cache ca-certificates make git curl | ||
|
||
ARG TARGETPLATFORM | ||
|
||
WORKDIR /usr/local/src/benthos-openmeter | ||
|
||
ARG GOPROXY | ||
|
||
ENV CGO_ENABLED=0 | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . . | ||
|
||
ARG VERSION | ||
|
||
RUN go build -ldflags "-X main.version=${VERSION}" -o /usr/local/bin/benthos . | ||
|
||
FROM alpine:3.19.0@sha256:51b67269f354137895d43f3b3d810bfacd3945438e94dc5ac55fdac340352f48 | ||
|
||
RUN apk add --update --no-cache ca-certificates tzdata bash | ||
|
||
SHELL ["/bin/bash", "-c"] | ||
|
||
COPY --from=builder /usr/local/bin/benthos /usr/local/bin/ | ||
COPY ./etc/cloudevents.spec.json /etc/openmeter/ | ||
|
||
CMD benthos |
File renamed without changes.