Skip to content

Commit

Permalink
Build & release arm64 (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlcsaposs-canonical authored Jul 1, 2024
1 parent 535e1b6 commit 46b58e5
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 84 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- run: |
# Workaround for https://github.com/canonical/charmcraft/issues/1389#issuecomment-1880921728
touch requirements.txt
- name: Check libs
uses: canonical/charming-actions/[email protected]
with:
Expand All @@ -62,10 +65,12 @@ jobs:
fail-build: ${{ github.event_name == 'pull_request' }}

build:
name: Build charms
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
permissions:
actions: write # Needed to manage GitHub Actions cache
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
with:
# Use of cache blocked by https://github.com/canonical/charmcraft/issues/1456
# Details: https://github.com/canonical/charmcraftcache/issues/3
cache: false

gh-hosted-collect-integration-tests:
name: (GH hosted) Collect integration test groups
Expand Down Expand Up @@ -144,9 +149,10 @@ jobs:
if: ${{ matrix.libjuju-version == '2.9.44.1' }}
run: poetry add --lock --group integration juju@'${{ matrix.libjuju-version }}'
- name: Download packed charm(s)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.artifact-name }}
pattern: ${{ needs.build.outputs.artifact-prefix }}-*
merge-multiple: true
- name: Select test stability level
id: select-test-stability
run: |
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@ jobs:
name: Tests
uses: ./.github/workflows/ci.yaml
secrets: inherit
permissions:
actions: write # Needed to manage GitHub Actions cache

build:
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/build_charm_without_cache.yaml@v7.0.0
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v16.3.0

release:
name: Release charm
needs:
- ci-tests
- build
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v7.0.0
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v16.3.0
with:
channel: dpe/edge
artifact-name: ${{ needs.build.outputs.artifact-name }}
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
secrets:
charmhub-token: ${{ secrets.CHARMHUB_TOKEN }}
permissions:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync_issue_to_jira.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
sync:
name: Sync GitHub issue to Jira
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v7.0.0
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v16.3.0
with:
jira-base-url: https://warthogs.atlassian.net
jira-project-key: DPE
Expand Down
9 changes: 5 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ git clone https://github.com/canonical/mysql-router-operator.git
cd mysql-router-operator
```

Install `tox` and `poetry`
Install `tox`, `poetry`, and `charmcraftcache`

Install pipx: https://pipx.pypa.io/stable/installation/
```shell
python3 -m pip install --user pipx
python3 -m pipx ensurepath
pipx install tox
pipx install poetry
pipx install charmcraftcache
```

You can create an environment for development:
Expand All @@ -85,7 +86,7 @@ tox # runs 'lint' and 'unit' environments
Build the charm in this git repository using:

```shell
tox run -e build
tox run -e build-dev
```

### Deploy
Expand Down
35 changes: 17 additions & 18 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,35 @@
type: charm
bases:
# Whenever "bases" is changed:
# - Update tests/integration/conftest.py::pytest_configure()
# - Update tests/conftest.py::pytest_configure()
# - Update .github/workflow/ci.yaml integration-test matrix
- build-on:
- name: "ubuntu"
channel: "20.04"
run-on:
- name: "ubuntu"
channel: "20.04"
- build-on:
- name: "ubuntu"
channel: "22.04"
run-on:
- name: "ubuntu"
channel: "22.04"
- name: ubuntu
channel: "20.04"
architectures: [amd64]
- name: ubuntu
channel: "22.04"
architectures: [amd64]
- name: ubuntu
channel: "22.04"
architectures: [arm64]
parts:
charm:
override-pull: |
craftctl default
if [[ ! -f requirements.txt ]]
then
echo 'ERROR: Use "tox run -e build" instead of calling "charmcraft pack" directly' >&2
echo 'ERROR: Use "tox run -e build-dev" instead of calling "charmcraft pack" directly' >&2
exit 1
fi
# TODO: enable after https://github.com/canonical/charmcraft/issues/1456 fixed
charm-strict-dependencies: false
charm-entrypoint: src/machine_charm.py
prime:
- charm_version
- workload_version
build-packages:
- libffi-dev
- libssl-dev
- pkg-config
- rustc
- cargo
charm-entrypoint: src/machine_charm.py
prime:
- charm_version
- workload_version
36 changes: 8 additions & 28 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ pytest-mock = "^3.11.1"
[tool.poetry.group.integration.dependencies]
pytest = "^7.4.0"
pytest-operator = "^0.28.0"
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v7.0.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v7.0.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v7.0.0", subdirectory = "python/pytest_plugins/github_secrets"}
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v16.3.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v16.3.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v16.3.0", subdirectory = "python/pytest_plugins/github_secrets"}
juju = "3.4.0.0"
mysql-connector-python = "~8.0.33"
tenacity = "^8.2.2"
Expand Down
10 changes: 5 additions & 5 deletions src/machine_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def unit_state(self) -> typing.Optional[upgrade.UnitState]:
def unit_state(self, value: upgrade.UnitState) -> None:
if value is upgrade.UnitState.HEALTHY:
# Set snap revision on first install
self._unit_workload_container_version = snap.REVISION
self._unit_workload_container_version = snap.revision
self._unit_workload_version = self._current_versions["workload"]
logger.debug(
f'Saved {snap.REVISION=} and {self._current_versions["workload"]=} in unit databag while setting state healthy'
f'Saved {snap.revision=} and {self._current_versions["workload"]=} in unit databag while setting state healthy'
)
# Super call
upgrade.Upgrade.unit_state.fset(self, value)
Expand Down Expand Up @@ -103,7 +103,7 @@ def _unit_workload_container_version(self, value: str):
@property
def _app_workload_container_version(self) -> str:
"""Snap revision for current charm code"""
return snap.REVISION
return snap.revision

@property
def _unit_workload_version(self) -> typing.Optional[str]:
Expand Down Expand Up @@ -190,8 +190,8 @@ def upgrade_unit(
logger.debug(f"Upgrading {self.authorized=}")
self.unit_state = upgrade.UnitState.UPGRADING
workload_.upgrade(event=event, unit=self._unit, tls=tls, exporter_config=exporter_config)
self._unit_workload_container_version = snap.REVISION
self._unit_workload_container_version = snap.revision
self._unit_workload_version = self._current_versions["workload"]
logger.debug(
f'Saved {snap.REVISION=} and {self._current_versions["workload"]=} in unit databag after upgrade'
f'Saved {snap.revision=} and {self._current_versions["workload"]=} in unit databag after upgrade'
)
14 changes: 10 additions & 4 deletions src/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import enum
import logging
import pathlib
import platform
import shutil
import subprocess
import typing
Expand All @@ -22,7 +23,12 @@
logger = logging.getLogger(__name__)

_SNAP_NAME = "charmed-mysql"
REVISION = "103" # Keep in sync with `workload_version` file
REVISIONS: typing.Dict[str, str] = {
# Keep in sync with `workload_version` file
"x86_64": "106",
"aarch64": "107",
}
revision = REVISIONS[platform.machine()]
_snap = snap_lib.SnapCache()[_SNAP_NAME]
_UNIX_USERNAME = "snap_daemon"

Expand All @@ -34,7 +40,7 @@ class _RefreshVerb(str, enum.Enum):

def _refresh(*, unit: ops.Unit, verb: _RefreshVerb) -> None:
# TODO python3.10 min version: use `removesuffix` instead of `rstrip`
logger.debug(f'{verb.capitalize().rstrip("e")}ing {_SNAP_NAME=}, {REVISION=}')
logger.debug(f'{verb.capitalize().rstrip("e")}ing {_SNAP_NAME=}, {revision=}')
unit.status = ops.MaintenanceStatus(f'{verb.capitalize().rstrip("e")}ing snap')

def _set_retry_status(_) -> None:
Expand All @@ -50,9 +56,9 @@ def _set_retry_status(_) -> None:
reraise=True,
):
with attempt:
_snap.ensure(state=snap_lib.SnapState.Present, revision=REVISION)
_snap.ensure(state=snap_lib.SnapState.Present, revision=revision)
_snap.hold()
logger.debug(f'{verb.capitalize().rstrip("e")}ed {_SNAP_NAME=}, {REVISION=}')
logger.debug(f'{verb.capitalize().rstrip("e")}ed {_SNAP_NAME=}, {revision=}')


def install(*, unit: ops.Unit, model_uuid: str):
Expand Down
Loading

0 comments on commit 46b58e5

Please sign in to comment.