Skip to content

Using charmcraft, build for jammy and focal #7

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

Merged
merged 1 commit into from
Apr 14, 2025
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 .charmcraft-channel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.x/stable
52 changes: 52 additions & 0 deletions .github/workflows/charm-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Tests
on:
push:
branches:
- main
pull_request:

jobs:
charmcraft-build:
name: Build Charm
runs-on: ubuntu-22.04
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Read charmcraft version file
id: charmcraft
run: echo "channel=$(cat .charmcraft-channel)" >> $GITHUB_OUTPUT
- name: Install and prepare LXD snap environment
run: |
sudo apt-get remove -qy lxd lxd-client | true
sudo snap list lxd | true
sudo snap install lxd --channel=latest/stable
sudo snap refresh lxd --channel=latest/stable
sudo lxd waitready
sudo lxd init --auto
sudo chmod a+wr /var/snap/lxd/common/lxd/unix.socket
sudo lxc network set lxdbr0 ipv6.address none
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: Why do you explicitly disable IPv6 here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no one likes ipv6. ipv5 was better

also, convention pushed me down a road maybe currently no longer necessary for building a charm
https://github.com/charmed-kubernetes/actions-operator/blob/main/src/bootstrap/index.ts#L301-L306

sudo usermod -a -G lxd $USER
sg lxd -c 'lxc version'
- name: Remove Docker
run: |
# https://github.com/canonical/lxd-cloud/blob/f20a64a8af42485440dcbfd370faf14137d2f349/test/includes/lxd.sh#L13-L23
sudo rm -rf /etc/docker
sudo apt-get purge moby-buildx moby-engine moby-cli moby-compose moby-containerd moby-runc -y
sudo iptables -P FORWARD ACCEPT
- name: Install Charmcraft
run: |
sudo snap install charmcraft --classic --channel=${{ steps.charmcraft.outputs.channel }}
- name: Build Charm
run: |
sg lxd -c 'charmcraft pack -v'
- name: Upload charm artifact
uses: actions/upload-artifact@v4
with:
name: aws-integrator.charm
path: ./aws-integrator*.charm
- name: Upload debug artifacts
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: charmcraft-logs
path: ~/.local/state/charmcraft/log/charmcraft-*.log
7 changes: 5 additions & 2 deletions .github/workflows/tox.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Run tests with Tox

on: [pull_request]
on:
- pull_request

jobs:
call-inclusive-naming-check:
Expand All @@ -13,4 +14,6 @@ jobs:
name: Lint Unit
uses: charmed-kubernetes/workflows/.github/workflows/lint-unit.yaml@main
needs:
- call-inclusive-naming-check
- call-inclusive-naming-check
with:
python: "['3.10', '3.12']"
9 changes: 9 additions & 0 deletions .github/workflows/wheelhouse-validation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Charmed Kubernetes Reactive wheelhouse test
on:
- pull_request

jobs:
validate-wheelhouse:
uses: charmed-kubernetes/workflows/.github/workflows/validate-wheelhouse.yaml@main
with:
python: "['3.10', '3.12']"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.tox/
__pycache__/
*.pyc
.coverage
*.charm
38 changes: 38 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
type: charm

bases:
- build-on:
- name: ubuntu
channel: "22.04"
architectures: ["amd64"]
run-on:
- name: ubuntu
channel: "22.04"
architectures: ["amd64", "arm64", "s390x"]
- name: ubuntu
channel: "24.04"
architectures: ["amd64", "arm64", "s390x"]
parts:
charm:
source: src
plugin: reactive
override-build: |
./download_layers.sh
git -C $CRAFT_PROJECT_DIR rev-parse --short HEAD > $CRAFT_PART_INSTALL/version
craftctl default
reactive-charm-build-arguments:
- --layer-index
- 'http://localhost/' # Fake layer index to force a local build
- --debug
- --force
build-packages:
- git
- wget
- python3-dev
build-snaps:
- charm/3.x/stable
- yq
build-environment:
- CHARM_LAYERS_DIR: $CRAFT_STAGE/tmp/layers/
- CHARM_INTERFACES_DIR: $CRAFT_STAGE/tmp/interfaces/
- RELEASE_BRANCH: main
27 changes: 0 additions & 27 deletions metadata.yaml

This file was deleted.

1 change: 1 addition & 0 deletions metadata.yaml
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions src/download_layers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# This script is used to download reactive layers for the charm build process.
# It pulls the layers from the gh and place them in the tmp directory.
set -eu

# ensure we have environment variables set
: "${RELEASE_BRANCH:?Environment variable RELEASE_BRANCH is not set.}"
: "${CHARM_LAYERS_DIR:?Environment variable CHARM_LAYERS_DIR is not set.}"
: "${CHARM_INTERFACES_DIR:?Environment variable CHARM_INTERFACES_DIR is not set.}"

# Ensure the temporary directory was created successfully
TMP_DIR=$(mktemp -d)
if [ ! -d "$TMP_DIR" ]; then
echo "Failed to create a temporary directory."
exit 1
fi
trap 'rm -rf "$TMP_DIR"' EXIT

# ensure we have the right prerequisites
for cmd in charm wget yq; do
if ! command -v $cmd &> /dev/null; then
echo "$cmd command not found. Please install $cmd."
exit 1
fi
done

rm -rf $CHARM_LAYERS_DIR && mkdir -p $CHARM_LAYERS_DIR
rm -rf $CHARM_INTERFACES_DIR && mkdir -p $CHARM_INTERFACES_DIR
wget "https://raw.githubusercontent.com/charmed-kubernetes/jenkins/refs/heads/main/jobs/includes/charm-layer-list.inc" -O ${TMP_DIR}/layers.yaml
for layer in $(cat ${TMP_DIR}/layers.yaml | yq '.[] | keys | .[]' - ); do
if [[ ! "$layer" =~ ^(interface:|layer:) ]]; then continue; fi
echo "Pulling layer: ${layer}"
charm pull-source \
--layer-index ${LAYER_INDEX:-'https://raw.githubusercontent.com/charmed-kubernetes/layer-index/main/'} \
--branch ${RELEASE_BRANCH} \
${layer} &
done
wait
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions src/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: aws-integrator
display-name: AWS-Integrator
summary: |
Charm to enable AWS integrations via Juju relations.
description: |
This charm can grant select permissions to instances of applications
related to it which enable integration with AWS specific features,
such as ELB, EBS, etc.
docs: https://discourse.charmhub.io/t/aws-integrator-docs-index/6100
maintainers: ['Cory Johns <cory.johns@canonical.com>']
series:
- jammy
- noble
tags: ['aws', 'native', 'integration']
provides:
aws:
interface: aws-integration
rds-mysql:
interface: mysql
resources:
aws-cli:
type: file
filename: aws-cli.snap
description: |
Resource to side-load aws-cli snap in network-restricted deployments.
[DEPRECATED] in favor of using a Snap Store Proxy.
See https://ubuntu.com/kubernetes/docs/proxies for more details.
File renamed without changes.
1 change: 1 addition & 0 deletions src/wheelhouse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setuptools==70.3.0
6 changes: 3 additions & 3 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ variable "base" {
default = "ubuntu@22.04"

validation {
condition = contains(["ubuntu@20.04", "ubuntu@22.04"], var.base)
error_message = "Base must be one of ubuntu@20.04, ubuntu@22.04"
condition = contains(["ubuntu@22.04", "ubuntu@24.04"], var.base)
error_message = "Base must be one of ubuntu@22.04, ubuntu@24.04"
}
}

variable "channel" {
description = "The channel to use when deploying a charm."
type = string
default = "1.31/stable"
default = "latest/stable"
}

variable "config" {
Expand Down
10 changes: 10 additions & 0 deletions tests/validate-wheelhouse.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -eux

build_dir="$(mktemp -d --tmpdir=${TOX_ENV_DIR}/tmp)"
charm="$(egrep '^name\S*:' ./metadata.yaml | awk '{ print $2 }')"
function cleanup { rm -rf "$build_dir"; }
trap cleanup EXIT

charm-build src --build-dir "$build_dir" --debug
pip install -f "$build_dir/$charm/wheelhouse" --no-index --no-cache-dir "$build_dir"/$charm/wheelhouse/*
66 changes: 41 additions & 25 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,48 +1,64 @@
[flake8]
max-line-length = 88
ignore =
# line break before binary operator
W503
# whitespace before ':'
E203

[tox]
envlist = lint,unit
skipsdist = True
minversion = 3.2.0

[pytest]
filterwarnings =
ignore::DeprecationWarning

[testenv]
basepython = python3
setenv =
PYTHONPATH={toxinidir}:{toxinidir}/lib
PYTHONPATH={toxinidir}/src:{toxinidir}/src/lib
PYTHONBREAKPOINT=ipdb.set_trace

[testenv:unit]
deps =
pytest
pyyaml
pytest-cov
ipdb
git+https://github.com/juju-solutions/charms.unit_test/#egg=charms.unit_test
commands = pytest --tb native -s {posargs} {toxinidir}/tests/unit

[testenv:integration]
deps =
pytest
pytest-operator
lightkube
python-openstackclient
-r src/wheelhouse.txt
commands =
pytest --tb native \
--asyncio-mode=auto \
--show-capture=no \
--log-cli-level=INFO \
-s {posargs} \
{toxinidir}/tests/integration

pytest --tb native -s -vv \
--cov-report term-missing --cov=src \
{posargs} {toxinidir}/tests/unit

[testenv:lint]
deps =
flake8
black
commands =
flake8 {toxinidir}/actions {toxinidir}/lib {toxinidir}/reactive {toxinidir}/tests
black --check {toxinidir}/actions {toxinidir}/lib {toxinidir}/reactive {toxinidir}/tests
commands =
black --check {toxinidir}/src {toxinidir}/tests
flake8 {toxinidir}/src {toxinidir}/tests

[testenv:format]
envdir = {toxworkdir}/lint
deps = black
commands = black {toxinidir}/actions {toxinidir}/lib {toxinidir}/reactive {toxinidir}/tests

commands =
black {toxinidir}/src {toxinidir}/tests

[flake8]
max-line-length = 88
extend-ignore = E203
[testenv:integration]
deps =
juju
pytest
pytest-operator
lightkube
ipdb
commands = pytest --tb native --show-capture=no --log-cli-level=INFO -s {posargs} {toxinidir}/tests/integration

[testenv:validate-wheelhouse]
deps =
git+https://github.com/juju/charm-tools.git
path<17
allowlist_externals = {toxinidir}/tests/validate-wheelhouse.sh
commands = {toxinidir}/tests/validate-wheelhouse.sh