Skip to content

Commit

Permalink
Implement migrate rock (#18)
Browse files Browse the repository at this point in the history
* Implement migrate rock
  • Loading branch information
misohu authored Dec 9, 2024
1 parent 7fd0c30 commit 62731d8
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 0 deletions.
51 changes: 51 additions & 0 deletions migrate/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# From (ko image): https://github.com/knative/pkg/blob/release-1.12/apiextensions/storageversion/cmd/migrate/main.go
name: migrate
base: ubuntu@22.04
version: 1.12.4
summary: An image for Knative's migrate
description: |
An image for Knative's migrate
license: Apache-2.0
entrypoint-service: migrate
run-user: _daemon_

platforms:
amd64:

environment:
# Environment variables that are set in the base image
KO_DATA_PATH: "/var/run/ko"
SSL_CERT_FILE: "/etc/ssl/certs/ca-certificates.crt"

services:
migrate:
override: replace
command: "/ko-app/migrate [ ]"
startup: enabled

parts:
security-team-requirement:
plugin: nil
override-build: |
mkdir -p ${CRAFT_PART_INSTALL}/usr/share/rocks
(echo "# os-release" && cat /etc/os-release && echo "# dpkg-query" && \
dpkg-query --root=${CRAFT_PROJECT_DIR}/../bundles/ubuntu-22.04/rootfs/ -f '${db:Status-Abbrev},${binary:Package},${Version},${source:Package},${Source:Version}\n' -W) \
> ${CRAFT_PART_INSTALL}/usr/share/rocks/dpkg.query
migrate:
plugin: go
source: https://github.com/knative/pkg.git
source-type: git
source-branch: release-1.12
overlay-packages:
# Install in overlay instead of stage packages due to https://github.com/canonical/rockcraft/issues/334.
- ca-certificates
build-snaps:
- go/1.21/stable
build-environment:
- CGO_ENABLED: 0
- GOOS: linux
override-build: |
cd apiextensions/storageversion/cmd/migrate
mkdir $CRAFT_PART_INSTALL/ko-app
go build -o $CRAFT_PART_INSTALL/ko-app/migrate -a .
44 changes: 44 additions & 0 deletions migrate/tests/test_rock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import pytest
import subprocess

from charmed_kubeflow_chisme.rock import CheckRock


@pytest.mark.abort_on_fail
def test_rock():
"""Test rock."""
check_rock = CheckRock("rockcraft.yaml")
rock_image = check_rock.get_name()
rock_version = check_rock.get_version()
LOCAL_ROCK_IMAGE = f"{rock_image}:{rock_version}"

subprocess.run(
[
"docker",
"run",
"--rm",
"--entrypoint",
"/bin/bash",
LOCAL_ROCK_IMAGE,
"-c",
"ls -la /ko-app/migrate",
],
check=True,
)

subprocess.run(
[
"docker",
"run",
"--rm",
"--entrypoint",
"/bin/bash",
LOCAL_ROCK_IMAGE,
"-c",
"ls -la /etc/ssl/certs/ca-certificates.crt",
],
check=True,
)
51 changes: 51 additions & 0 deletions migrate/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
[tox]
skipsdist = True
skip_missing_interpreters = True
envlist = pack, export-to-docker, sanity, integration

[testenv]
setenv =
PYTHONPATH={toxinidir}
PYTHONBREAKPOINT=ipdb.set_trace

[testenv:pack]
passenv = *
allowlist_externals =
rockcraft
commands =
rockcraft pack

[testenv:export-to-docker]
passenv = *
allowlist_externals =
bash
rockcraft
yq
commands =
# export rock to docker
bash -c 'NAME=$(yq eval .name rockcraft.yaml) && \
VERSION=$(yq eval .version rockcraft.yaml) && \
ARCH=$(yq eval ".platforms | keys | .[0]" rockcraft.yaml) && \
ROCK="$\{NAME\}_$\{VERSION\}_$\{ARCH\}.rock" && \
DOCKER_IMAGE=$NAME:$VERSION && \
echo "Exporting $ROCK to docker as $DOCKER_IMAGE" && \
rockcraft.skopeo --insecure-policy copy oci-archive:$ROCK docker-daemon:$DOCKER_IMAGE'

[testenv:sanity]
passenv = *
deps =
pytest
charmed-kubeflow-chisme
commands =
# run rock tests
pytest -s -v --tb native --show-capture=all --log-cli-level=INFO {posargs} {toxinidir}/tests

[testenv:integration]
passenv = *
allowlist_externals =
echo
commands =
# TODO: Implement integration tests here
echo "WARNING: This is a placeholder test - no test is implemented here."

0 comments on commit 62731d8

Please sign in to comment.