Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add image build to ghcr.io #22

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .alpine.pkgs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tar crane hugo git cosign bash openssl jq yq
25 changes: 25 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ on:
branches:
- main
workflow_dispatch: {}
permissions:
id-token: write
contents: write
packages: write
jobs:
push-to-balena-cloud:
runs-on: ubuntu-latest
Expand All @@ -29,3 +33,24 @@ jobs:
if: ${{ always() }}
run: |
rm -rfv .balena-key
publish-to-ghcr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- id: run-info
name: collect job run info
env:
CONTAINER_REPO: ghcr.io/${{ github.repository }}
run: |
echo "container-repo=${CONTAINER_REPO,,}" >> $GITHUB_OUTPUT
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: 'latest'
extended: true
- uses: sigstore/cosign-installer@11086d25041f77fe8fe7b9ea4e48e3b9192b8f19 # v3.1.2
- uses: imjasonh/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # v0.3
- name: build
env:
CONTAINER_REPO: ${{ steps.run-info.outputs.container-repo }}
run: ./hack/publish.sh --sign
1 change: 1 addition & 0 deletions hack/image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
image: registry.gitlab.com/bobymcbobs/go-http-server:1.11.0 # {"$imagepolicy": "flux-system:registry-gitlab-com-bobymcbobs-go-http-server"}
52 changes: 52 additions & 0 deletions hack/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash -x

set -o errexit
set -o nounset
set -o pipefail

cd "$(git rev-parse --show-toplevel)" || exit 0

LOCAL_REGISTRY="localhost:5001/$(pwd | md5sum | head -c6)"
BASE_IMAGE="$(< ./hack/image.yaml yq e .image -P)"
TAG="${TAG:-v$(git show -s --format=%cd --date=format:'%s')-$(git rev-parse HEAD | head -c8)}"
SIGN=false

# NOTE budget /bin/sh way
if echo "${@:-}" | grep -q '\-\-sign'; then
SIGN=true
fi

cosign verify \
--certificate-identity-regexp 'https://gitlab.com/BobyMCbobs/go-http-server//.gitlab-ci.yml@(refs/heads/main|refs/tags/.*)' \
--certificate-oidc-issuer-regexp 'https://gitlab.com' \
"$BASE_IMAGE" \
-o text

rm -rf public output
hugo

# bit of a hack
# perhaps there's a way to say
# to tar to pack dir into a new dir?
mkdir -p output/var/run
mv public output/var/run/ko
chmod -R 0755 output/

IMAGE_ARM64="$(crane append --platform=linux/arm64 \
--base="$BASE_IMAGE" \
--new_layer=<(cd output && tar --exclude=".DS_Store" -f - -c .) \
--new_tag="${CONTAINER_REPO:-$LOCAL_REGISTRY}")"
IMAGE_AMD64="$(crane append --platform=linux/amd64 \
--base="$BASE_IMAGE" \
--new_layer=<(cd output && tar --exclude=".DS_Store" -f - -c .) \
--new_tag="${CONTAINER_REPO:-$LOCAL_REGISTRY}")"
IMAGE="$(crane index append \
-m "${IMAGE_ARM64}" \
-m "${IMAGE_AMD64}" \
-t "${CONTAINER_REPO:-$LOCAL_REGISTRY}:$TAG")"

if [ "$SIGN" = true ]; then
cosign sign -y --recursive "$IMAGE"
fi

echo "Published image to: $IMAGE"
Loading