Skip to content
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
12 changes: 6 additions & 6 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: Pull Requests

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pull-request:
name: PR
uses: canonical/observability/.github/workflows/rock-pull-request.yaml@v1
name: Pull Requests
uses: canonical/observability/.github/workflows/rock-pull-request.yaml@224c92a71bb24f4c67969c331c29b46876178a81
secrets: inherit
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
name: "Publish rock to GHCR:dev"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
workflow_dispatch: {}
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
uses: canonical/observability/.github/workflows/rock-release-dev.yaml@v1
release-dev:
name: Release to GHCR
uses: canonical/observability/.github/workflows/rock-release-dev.yaml@224c92a71bb24f4c67969c331c29b46876178a81
secrets: inherit
with:
rock-name: git-sync
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ on:
- main

jobs:
build:
uses: canonical/observability/.github/workflows/rock-release-oci-factory.yaml@v1
release-oci-factory:
name: Release to OCI Factory
uses: canonical/observability/.github/workflows/rock-release-oci-factory.yaml@224c92a71bb24f4c67969c331c29b46876178a81
secrets: inherit
with:
rock-name: git-sync
21 changes: 0 additions & 21 deletions .github/workflows/rock-update.yaml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Update rock

on:
workflow_dispatch: {}
schedule:
- cron: '0 0 * * 1'

jobs:
update:
name: Update rock
uses: canonical/observability/.github/workflows/rock-update.yaml@224c92a71bb24f4c67969c331c29b46876178a81
secrets: inherit
with:
source-repo: kubernetes/git-sync
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Ignore all spread.yaml files
*/*/spread.yaml

# Except the one in the top-level directory
!/spread.yaml

# Ignore copied goss.yaml files in component version directories
*/*/goss.yaml

# Ignore rocks
*.rock

# Ignore sboms
*.sbom.json
195 changes: 195 additions & 0 deletions 4.6.0/spread/.extension
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
#!/bin/bash

usage() {
echo "usage: $(basename "$0") [command]"
echo "valid commands:"
echo " allocate Create a backend instance to run tests on"
echo " discard Destroy a backend instance used to run tests"
echo " backend-prepare Set up the system to run tests"
echo " backend-restore Restore the system after the tests ran"
echo " backend-prepare-each Prepare the system before each test"
echo " backend-restore-each Restore the system after each test run"
}

prepare() {
case "$SPREAD_SYSTEM" in
fedora*)
dnf update -y
dnf install -y snapd
while ! snap install snapd; do
echo "waiting for snapd..."
sleep 2
done
;;
debian*)
apt update
apt install -y snapd
while ! snap install snapd; do
echo "waiting for snapd..."
sleep 2
done
;;
ubuntu*)
apt update
;;
esac

snap wait system seed.loaded
snap refresh --hold

if systemctl is-enabled unattended-upgrades.service; then
systemctl stop unattended-upgrades.service
systemctl mask unattended-upgrades.service
fi
}

restore() {
case "$SPREAD_SYSTEM" in
ubuntu* | debian*)
apt autoremove -y --purge
;;
esac

rm -Rf "$PROJECT_PATH"
mkdir -p "$PROJECT_PATH"
}

prepare_each() {
true
}

restore_each() {
true
}

allocate_lxdvm() {
name=$(echo "$SPREAD_SYSTEM" | tr '[:punct:]' -)
system=$(echo "$SPREAD_SYSTEM" | tr / -)
if [[ "$system" =~ ^ubuntu- ]]; then
image="ubuntu:${system#ubuntu-}"
else
image="images:$(echo "$system" | tr - /)"
fi

VM_NAME="${VM_NAME:-spread-${name}-${RANDOM}}"
DISK="${DISK:-20}"
CPU="${CPU:-4}"
MEM="${MEM:-8}"

lxc launch --vm \
"${image}" \
"${VM_NAME}" \
-c limits.cpu="${CPU}" \
-c limits.memory="${MEM}GiB" \
-d root,size="${DISK}GiB"

while ! lxc exec "${VM_NAME}" -- true &>/dev/null; do sleep 0.5; done
lxc exec "${VM_NAME}" -- sed -i 's/^\s*#\?\s*\(PermitRootLogin\|PasswordAuthentication\)\>.*/\1 yes/' /etc/ssh/sshd_config
lxc exec "${VM_NAME}" -- bash -c "if [ -d /etc/ssh/sshd_config.d ]; then echo -e 'PermitRootLogin yes\nPasswordAuthentication yes' > /etc/ssh/sshd_config.d/00-spread.conf; fi"
lxc exec "${VM_NAME}" -- bash -c "echo root:${SPREAD_PASSWORD} | sudo chpasswd || true"

# Print the instance address to stdout
ADDR=""
while [ -z "$ADDR" ]; do ADDR=$(lxc ls -f csv | grep "^${VM_NAME}" | cut -d"," -f3 | cut -d" " -f1); done
echo "$ADDR" 1>&3
}

discard_lxdvm() {
instance_name="$(lxc ls -f csv | sed ':a;N;$!ba;s/(docker0)\n/(docker0) /' | grep "$SPREAD_SYSTEM_ADDRESS " | cut -f1 -d",")"
lxc delete -f "$instance_name"
}

allocate_ci() {
if [ -z "$CI" ]; then
echo "This backend is intended to be used only in CI systems."
exit 1
fi
sudo sed -i 's/^\s*#\?\s*\(PermitRootLogin\|PasswordAuthentication\)\>.*/\1 yes/' /etc/ssh/sshd_config
if [ -d /etc/ssh/sshd_config.d ]; then echo -e 'PermitRootLogin yes\nPasswordAuthentication yes' | sudo tee /etc/ssh/sshd_config.d/00-spread.conf; fi
sudo systemctl daemon-reload
sudo systemctl restart ssh

echo "root:${SPREAD_PASSWORD}" | sudo chpasswd || true

# Print the instance address to stdout
echo localhost >&3
}

discard_ci() {
true
}

allocate() {
exec 3>&1
exec 1>&2

case "$1" in
lxd-vm)
allocate_lxdvm
;;
ci)
allocate_ci
;;
*)
echo "unsupported backend $1" 2>&1
;;
esac
}

discard() {
case "$1" in
lxd-vm)
discard_lxdvm
;;
ci)
discard_ci
;;
*)
echo "unsupported backend $1" 2>&1
;;
esac
}

set -e

while getopts "" o; do
case "${o}" in
*)
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))

CMD="$1"
PARM="$2"

if [ -z "$CMD" ]; then
usage
exit 0
fi

case "$CMD" in
allocate)
allocate "$PARM"
;;
discard)
discard "$PARM"
;;
backend-prepare)
prepare
;;
backend-restore)
restore
;;
backend-prepare-each)
prepare_each
;;
backend-restore-each)
restore_each
;;
*)
echo "unknown command $CMD" >&2
;;
esac
7 changes: 7 additions & 0 deletions 4.6.0/spread/general/ready/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
summary: Run goss tests

environment:
GOSS_FILE: "../../../goss.yaml"

execute: |
dgoss run rockcraft-test:latest
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# git-sync-rock

[![Open a PR to OCI Factory](https://github.com/canonical/git-sync-rock/actions/workflows/rock-release-oci-factory.yaml/badge.svg)](https://github.com/canonical/git-sync-rock/actions/workflows/rock-release-oci-factory.yaml)
[![Publish to GHCR:dev](https://github.com/canonical/git-sync-rock/actions/workflows/rock-release-dev.yaml/badge.svg)](https://github.com/canonical/git-sync-rock/actions/workflows/rock-release-dev.yaml)
[![Update Rock](https://github.com/canonical/git-sync-rock/actions/workflows/rock-update.yaml/badge.svg)](https://github.com/canonical/git-sync-rock/actions/workflows/rock-update.yaml)
[![Open a PR to OCI Factory](https://github.com/canonical/git-sync-rock/actions/workflows/release-oci-factory.yaml/badge.svg)](https://github.com/canonical/git-sync-rock/actions/workflows/release-oci-factory.yaml)
[![Publish to GHCR:dev](https://github.com/canonical/git-sync-rock/actions/workflows/release-dev.yaml/badge.svg)](https://github.com/canonical/git-sync-rock/actions/workflows/release-dev.yaml)
[![Update Rock](https://github.com/canonical/git-sync-rock/actions/workflows/update.yaml/badge.svg)](https://github.com/canonical/git-sync-rock/actions/workflows/update.yaml)

[Rocks](https://canonical-rockcraft.readthedocs-hosted.com/en/latest/) for [git-sync](https://github.com/kubernetes/git-sync).
This repository holds all the necessary files to build rocks for the upstream versions we support. The git-sync rock can
Expand Down
50 changes: 21 additions & 29 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
# set quiet # Recipes are silent by default
set export # Just variables are exported to environment variables

rock_name := `echo ${PWD##*/} | sed 's/-rock//'`
latest_version := `find . -maxdepth 1 -type d | sort -V | tail -n1 | sed 's@./@@'`
set allow-duplicate-recipes
set allow-duplicate-variables
import? 'rocks.just'

[private]
default:
@default:
just --list
echo ""
echo "For help with a specific recipe, run: just --usage <recipe>"

# Push an OCI image to a local registry
[private]
push-to-registry version:
echo "Pushing $rock_name $version to local registry"
rockcraft.skopeo --insecure-policy copy --dest-tls-verify=false \
"oci-archive:${version}/${rock_name}_${version}_amd64.rock" \
"docker://localhost:32000/${rock_name}-dev:${version}"

# Pack a rock of a specific version
pack version:
cd "$version" && rockcraft pack

# `rockcraft clean` for a specific version
clean version:
cd "$version" && rockcraft clean

# Run a rock and open a shell into it with `kgoss`
run version=latest_version: (push-to-registry version)
kgoss edit -i localhost:32000/${rock_name}-dev:${version}

# Test the rock with `kgoss`
test version=latest_version: (push-to-registry version)
GOSS_OPTS="--retry-timeout 60s" kgoss run -i localhost:32000/${rock_name}-dev:${version}
# Generate a rock for the latest version of the upstream project
[arg("source_repo", help="Repository of the upstream project in 'org/repo' form")]
[group("maintenance")]
update source_repo:
#!/usr/bin/env bash
just --justfile rocks.just update {{source_repo}}
# Additional update steps
latest_release="$(gh release list --repo {{source_repo}} --exclude-pre-releases --limit=1 --json tagName --jq '.[0].tagName')"
# Explicitly filter out prefixes for known rocks, so we can notice if a new rock has a different schema
version="${latest_release}"
version="${version#mimir-}" # mimir
version="${version#cmd/builder/v}" # opentelemetry-collector
version="${version#v}" # Generic v- prefix
# Substitute the additional version reference
sed -i "s|version.VERSION=[^']*|version.VERSION=${version}|g" "${version}/rockcraft.yaml"
Loading