From 46b58e5c9d78ce0ee0e328ad721a7ad38fd2dc3a Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Mon, 1 Jul 2024 07:25:01 +0000 Subject: [PATCH] Build & release arm64 (#152) --- .github/workflows/ci.yaml | 18 ++++++++---- .github/workflows/release.yaml | 8 ++--- .github/workflows/sync_issue_to_jira.yaml | 2 +- CONTRIBUTING.md | 9 +++--- charmcraft.yaml | 35 +++++++++++----------- poetry.lock | 36 +++++------------------ pyproject.toml | 6 ++-- src/machine_upgrade.py | 10 +++---- src/snap.py | 14 ++++++--- tests/integration/test_upgrade.py | 5 +++- tox.ini | 18 +++++++----- workload_version | 2 +- 12 files changed, 79 insertions(+), 84 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 019bbf9d..9f19fa11 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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/check-libraries@2.6.0 with: @@ -62,10 +65,12 @@ jobs: fail-build: ${{ github.event_name == 'pull_request' }} build: - name: Build charms - uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v7.0.0 - permissions: - actions: write # Needed to manage GitHub Actions cache + name: Build charm + uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v16.3.0 + 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 @@ -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: | diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 60389d75..b0c2e03d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -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: diff --git a/.github/workflows/sync_issue_to_jira.yaml b/.github/workflows/sync_issue_to_jira.yaml index 3c3bb71c..6ebfb6d7 100644 --- a/.github/workflows/sync_issue_to_jira.yaml +++ b/.github/workflows/sync_issue_to_jira.yaml @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7626d9f8..5fb86b6c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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: @@ -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 diff --git a/charmcraft.yaml b/charmcraft.yaml index 47fab5e7..08fdbf56 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -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 diff --git a/poetry.lock b/poetry.lock index 22c97706..23cb1f51 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "appnope" @@ -1000,16 +1000,6 @@ files = [ {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:5bbe06f8eeafd38e5d0a4894ffec89378b6c6a625ff57e3028921f8ff59318ac"}, {file = "MarkupSafe-2.1.3-cp311-cp311-win32.whl", hash = "sha256:dd15ff04ffd7e05ffcb7fe79f1b98041b8ea30ae9234aed2a9168b5797c3effb"}, {file = "MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl", hash = "sha256:134da1eca9ec0ae528110ccc9e48041e0828d79f24121a1a146161103c76e686"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f698de3fd0c4e6972b92290a45bd9b1536bffe8c6759c62471efaa8acb4c37bc"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aa57bd9cf8ae831a362185ee444e15a93ecb2e344c8e52e4d721ea3ab6ef1823"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:47d4f1c5f80fc62fdd7777d0d40a2e9dda0a05883ab11374334f6c4de38adffd"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1f67c7038d560d92149c060157d623c542173016c4babc0c1913cca0564b9939"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9aad3c1755095ce347e26488214ef77e0485a3c34a50c5a5e2471dff60b9dd9c"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:14ff806850827afd6b07a5f32bd917fb7f45b046ba40c57abdb636674a8b559c"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8f9293864fe09b8149f0cc42ce56e3f0e54de883a9de90cd427f191c346eb2e1"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-win32.whl", hash = "sha256:715d3562f79d540f251b99ebd6d8baa547118974341db04f5ad06d5ea3eb8007"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-win_amd64.whl", hash = "sha256:1b8dd8c3fd14349433c79fa8abeb573a55fc0fdd769133baac1f5e07abf54aeb"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8e254ae696c88d98da6555f5ace2279cf7cd5b3f52be2b5cf97feafe883b58d2"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cb0932dc158471523c9637e807d9bfb93e06a95cbf010f1a38b98623b929ef2b"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9402b03f1a1b4dc4c19845e5c749e3ab82d5078d16a2a4c2cd2df62d57bb0707"}, @@ -1764,8 +1754,8 @@ develop = false [package.source] type = "git" url = "https://github.com/canonical/data-platform-workflows" -reference = "v7.0.0" -resolved_reference = "450cba38a436b97f90441ef1586411f749ef1d4e" +reference = "v16.3.0" +resolved_reference = "58f047f7eebbde23770e7058d3f62f88ce7fe0dd" subdirectory = "python/pytest_plugins/github_secrets" [[package]] @@ -1819,8 +1809,8 @@ pyyaml = "*" [package.source] type = "git" url = "https://github.com/canonical/data-platform-workflows" -reference = "v7.0.0" -resolved_reference = "450cba38a436b97f90441ef1586411f749ef1d4e" +reference = "v16.3.0" +resolved_reference = "58f047f7eebbde23770e7058d3f62f88ce7fe0dd" subdirectory = "python/pytest_plugins/pytest_operator_cache" [[package]] @@ -1838,8 +1828,8 @@ pytest = "*" [package.source] type = "git" url = "https://github.com/canonical/data-platform-workflows" -reference = "v7.0.0" -resolved_reference = "450cba38a436b97f90441ef1586411f749ef1d4e" +reference = "v16.3.0" +resolved_reference = "58f047f7eebbde23770e7058d3f62f88ce7fe0dd" subdirectory = "python/pytest_plugins/pytest_operator_groups" [[package]] @@ -1899,7 +1889,6 @@ files = [ {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, - {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, @@ -1907,15 +1896,8 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, - {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, - {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, - {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, - {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, @@ -1932,7 +1914,6 @@ files = [ {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, - {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, @@ -1940,7 +1921,6 @@ files = [ {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, - {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, @@ -2495,4 +2475,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "c53d73341d26f142c4bbac7ea7e9bdfdba453121d21d038688604668e4024b5b" +content-hash = "18a98aba19c7c962b3430a2f9c7eb763a7bbba5c61fc266b8130b8606d47ed8f" diff --git a/pyproject.toml b/pyproject.toml index 1687082f..30561a22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/machine_upgrade.py b/src/machine_upgrade.py index f3574077..e258a731 100644 --- a/src/machine_upgrade.py +++ b/src/machine_upgrade.py @@ -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) @@ -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]: @@ -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' ) diff --git a/src/snap.py b/src/snap.py index be043939..8670b7e5 100644 --- a/src/snap.py +++ b/src/snap.py @@ -6,6 +6,7 @@ import enum import logging import pathlib +import platform import shutil import subprocess import typing @@ -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" @@ -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: @@ -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): diff --git a/tests/integration/test_upgrade.py b/tests/integration/test_upgrade.py index bb7dcba7..07f502d2 100644 --- a/tests/integration/test_upgrade.py +++ b/tests/integration/test_upgrade.py @@ -14,6 +14,8 @@ import tenacity from pytest_operator.plugin import OpsTest +import snap + from .helpers import ( APPLICATION_DEFAULT_APP_NAME, MYSQL_DEFAULT_APP_NAME, @@ -224,7 +226,8 @@ def create_valid_upgrade_charm(charm_file: typing.Union[str, pathlib.Path]) -> N # set rev 102 (an old edge version of the snap) snap_file = pathlib.Path("src/snap.py") content = snap_file.read_text() - new_snap_content = re.sub(r'REVISION = "\d+"', 'REVISION = "102"', str(content)) + # TODO: add arm64 support or mark as amd64 only + new_snap_content = re.sub(f'"x86_64": "{snap.revision}"', '"x86_64": "102"', str(content)) charm_zip.writestr("src/snap.py", new_snap_content) diff --git a/tox.ini b/tox.ini index 5cb398fa..465fc95f 100644 --- a/tox.ini +++ b/tox.ini @@ -17,13 +17,15 @@ set_env = allowlist_externals = poetry -[testenv:{build,pack-wrapper}] +[testenv:build-{production,dev,wrapper}] # Wrap `charmcraft pack` pass_env = - CRAFT_SHARED_CACHE + CI + GH_TOKEN allowlist_externals = {[testenv]allowlist_externals} charmcraft + charmcraftcache mv commands_pre = # TODO charm versioning: Remove @@ -33,10 +35,10 @@ commands_pre = # is pending review. python -c 'import pathlib; import shutil; import subprocess; git_hash=subprocess.run(["git", "describe", "--always", "--dirty"], capture_output=True, check=True, encoding="utf-8").stdout; file = pathlib.Path("charm_version"); shutil.copy(file, pathlib.Path("charm_version.backup")); version = file.read_text().strip(); file.write_text(f"{version}+{git_hash}")' - # `--without-hashes` workaround for https://github.com/canonical/charmcraft/issues/1179 - poetry export --only main,charm-libs --output requirements.txt --without-hashes + poetry export --only main,charm-libs --output requirements.txt commands = - build: charmcraft pack {posargs} + build-production: charmcraft pack {posargs} + build-dev: charmcraftcache pack {posargs} commands_post = mv requirements.txt requirements-last-build.txt mv charm_version.backup charm_version @@ -84,11 +86,11 @@ pass_env = GITHUB_OUTPUT SECRETS_FROM_GITHUB allowlist_externals = - {[testenv:pack-wrapper]allowlist_externals} + {[testenv:build-wrapper]allowlist_externals} commands_pre = poetry install --only integration - {[testenv:pack-wrapper]commands_pre} + {[testenv:build-wrapper]commands_pre} commands = poetry run pytest -v --tb native --log-cli-level=INFO -s --ignore={[vars]tests_path}/unit/ {posargs} commands_post = - {[testenv:pack-wrapper]commands_post} + {[testenv:build-wrapper]commands_post} diff --git a/workload_version b/workload_version index 41cda36c..3e1939c4 100644 --- a/workload_version +++ b/workload_version @@ -1 +1 @@ -8.0.36 +8.0.37