diff --git a/.github/ISSUE_TEMPLATE/--onboarding.yaml b/.github/ISSUE_TEMPLATE/--onboarding.yaml index 181a6a06..d2382f4f 100644 --- a/.github/ISSUE_TEMPLATE/--onboarding.yaml +++ b/.github/ISSUE_TEMPLATE/--onboarding.yaml @@ -48,7 +48,7 @@ body: id: type attributes: label: Image type - description: Is this a ROCK or a Dockerfile-based image? + description: description of the rock image options: - ROCK - Docker image diff --git a/.github/workflows/Image.yaml b/.github/workflows/Image.yaml index ce1d9366..7bec9b07 100644 --- a/.github/workflows/Image.yaml +++ b/.github/workflows/Image.yaml @@ -149,23 +149,15 @@ jobs: - name: Validate image naming and base working-directory: ${{ matrix.directory }} run: | - if [ -z ${{ matrix.dockerfile-build }} ] + rock_name=`cat rockcraft.y*ml | yq -r .name` + if [[ "${{ matrix.path }}" != *"${rock_name}"* ]] then - rock_name=`cat rockcraft.y*ml | yq -r .name` - if [[ "${{ matrix.path }}" != *"${rock_name}"* ]] - then - echo "ERROR: the ROCK's name '${rock_name}' must match the OCI folder name!" - exit 1 - fi - else - grep 'FROM' Dockerfile | tail -1 | grep ubuntu || \ - (echo "ERROR: the image '${rock_name}' must be based on Ubuntu!" \ - && exit 1) + echo "ERROR: the ROCK's name '${rock_name}' must match the OCI folder name!" + exit 1 fi # If this is a ROCK... - name: Build ROCK ${{ matrix.name }} - if: matrix.dockerfile-build == '' id: rockcraft uses: canonical/craft-actions/rockcraft-pack@main with: @@ -173,41 +165,9 @@ jobs: verbosity: debug - name: Rename ROCK OCI archive - if: matrix.dockerfile-build == '' run: | mv ${{ steps.rockcraft.outputs.rock }} ${{ env.OCI_ARCHIVE_NAME }} - # If this is a Dockerfile-based image... - - name: Set up QEMU - if: matrix.dockerfile-build != '' - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - if: matrix.dockerfile-build != '' - id: buildx - uses: docker/setup-buildx-action@v2 - - - name: Form the platforms string - if: matrix.dockerfile-build != '' - id: buildx-platforms - run: | - sudo apt install -y jq - platforms=$(echo linux/$(echo '${{ toJSON(matrix.dockerfile-build.platforms) }}' | jq -r 'join(",linux/")')) - echo "platforms=${platforms}" >> "$GITHUB_OUTPUT" - - - name: Build OCI image ${{ matrix.name }} - if: matrix.dockerfile-build != '' - uses: docker/build-push-action@v4 - with: - context: "${{ matrix.directory }}" - outputs: "type=oci,dest=${{ env.OCI_ARCHIVE_NAME }}" - platforms: ${{ steps.buildx-platforms.outputs.platforms }} - push: false - cache-from: type=gha - cache-to: type=gha,mode=max - provenance: false - sbom: false - - uses: actions/cache/save@v3 with: path: ${{ env.OCI_ARCHIVE_NAME }} @@ -223,7 +183,7 @@ jobs: with: oci-image-name: "${{ matrix.name }}_${{ matrix.commit }}_${{ matrix.revision }}" oci-image-path: "oci/${{ matrix.name }}" - is-a-rock: ${{ matrix.dockerfile-build == '' && true || false }} + is-a-rock: true test-from: "cache" cache-key: "${{ github.run_id }}-${{ matrix.name }}_${{ matrix.commit }}_${{ matrix.revision }}" secrets: inherit @@ -284,8 +244,6 @@ jobs: - name: Infer track name id: get-track - env: - DOCKERFILE_IMAGE_VERSION: ${{ matrix.dockerfile-build.version }} run: | ./src/uploads/infer_image_track.py --recipe-dirname source/${{ matrix.directory }} diff --git a/README.md b/README.md index 8f20b441..48cd3b83 100644 --- a/README.md +++ b/README.md @@ -147,10 +147,7 @@ Having said that this trigger's syntax is as follows: | upload | False | conlist[Dict[str, Any], min_items=1] | List of image builds. Equivalent to `rockcraft pack && rockcraft upload` | | upload[*].source | True | str | Git repository hosting the image's project. | | upload[*].commit | True | str | Specific reference in the source, where to run the build from. | -| upload[*].directory | True | str | Path to the "rockcraft.yaml"/"Dockerfile". Where the build will run from. | -| upload[*].dockerfile-build | False | Dict[str, Any] | In case this is not a ROCK but rather a Dockerfile-based image. | -| upload[*].dockerfile-build.version | True | str | Same meaning as the `version` field in rockcraft.yaml. | -| upload[*].dockerfile-build.platforms | True | conlist[str, min_items=1] | Same meaning as the "platforms" field in rockcraft.yaml. | +| upload[*].directory | True | str | Path to the "rockcraft.yaml". Where the build will run from. | | upload[*].release | False | Dict[Dict[str, Any]] | Immediately release this (yet unknown) revision to the given channels. Same as using `--release ` with `rockcraft upload`. | | upload[*].release.\ | True | Dict[str, Any] | Track to release this revision to. Canonical track `-` MUST be explicit, always! | | upload[*].release.\.end-of-life | True* | str | Same as `release.` above. | diff --git a/src/image/utils/schema/triggers.py b/src/image/utils/schema/triggers.py index 5b378ce9..bbc9005c 100644 --- a/src/image/utils/schema/triggers.py +++ b/src/image/utils/schema/triggers.py @@ -12,16 +12,6 @@ class ImageTriggerValidationError(Exception): """Error validating image trigger file.""" -class ImageUploadDockerfileSchema(pydantic.BaseModel): - """Schema of the optional dockerfile-build section.""" - - version: str - platforms: List[str] - - class Config: - extra = pydantic.Extra.forbid - - class ImageUploadReleaseSchema(pydantic.BaseModel): """Schema of the release option for uploads in the image.yaml trigger""" @@ -40,9 +30,6 @@ class ImageUploadSchema(pydantic.BaseModel): source: str commit: str directory: str - dockerfile_build: Optional[ImageUploadDockerfileSchema] = pydantic.Field( - alias="dockerfile-build" - ) release: Optional[Dict[str, ImageUploadReleaseSchema]] class Config: diff --git a/src/uploads/infer_image_track.py b/src/uploads/infer_image_track.py index d67982e9..46386352 100755 --- a/src/uploads/infer_image_track.py +++ b/src/uploads/infer_image_track.py @@ -8,8 +8,6 @@ logging.basicConfig() -DOCKERFILE_IMAGE_VERSION = os.getenv("DOCKERFILE_IMAGE_VERSION", None) - def get_release_from_codename(codename: str) -> str: """Uses distro-info tools to infer the Ubuntu release from its codename.""" @@ -25,51 +23,33 @@ def get_release_from_codename(codename: str) -> str: parser = argparse.ArgumentParser() parser.add_argument( "--recipe-dirname", - help="Path to the directory where rockcraft.yaml/Dockerfile is", + help="Path to the directory where rockcraft.yaml is", required=True, ) args = parser.parse_args() -if DOCKERFILE_IMAGE_VERSION: - with open( - f"{args.recipe_dirname.rstrip('/')}/Dockerfile", encoding="UTF-8" - ) as dockerfile: - dockerfile_content = dockerfile.read().splitlines() - - base = list(filter(lambda x: "FROM" in x, dockerfile_content))[-1] - - try: - base_release = float(base.split(":")[-1]) - except ValueError: - logging.warning( - f"Could not infer Ubuntu release from {base}. Trying with codename." - ) - base_release = float(get_release_from_codename(base.split(":")[-1])) +with open( + f"{args.recipe_dirname.rstrip('/')}/rockcraft.yaml", encoding="UTF-8" +) as rockcraft_file: + rockcraft_yaml = yaml.safe_load(rockcraft_file) - version = DOCKERFILE_IMAGE_VERSION -else: - with open( - f"{args.recipe_dirname.rstrip('/')}/rockcraft.yaml", encoding="UTF-8" - ) as rockcraft_file: - rockcraft_yaml = yaml.safe_load(rockcraft_file) +rock_base = ( + rockcraft_yaml["base"] + if rockcraft_yaml["base"] != "bare" + else rockcraft_yaml["build-base"] +) - rock_base = ( - rockcraft_yaml["base"] - if rockcraft_yaml["base"] != "bare" - else rockcraft_yaml["build-base"] +try: + base_release = float(rock_base.replace(":", "@").split("@")[-1]) +except ValueError: + logging.warning( + f"Could not infer ROCK's base release from {rock_base}. Trying with codename." + ) + base_release = float( + get_release_from_codename(rock_base.replace(":", "@").split("@")[-1]) ) - try: - base_release = float(rock_base.replace(":", "@").split("@")[-1]) - except ValueError: - logging.warning( - f"Could not infer ROCK's base release from {rock_base}. Trying with codename." - ) - base_release = float( - get_release_from_codename(rock_base.replace(":", "@").split("@")[-1]) - ) - - version = rockcraft_yaml["version"] +version = rockcraft_yaml["version"] track = f"{version}-{base_release}" print(f"ROCK track: {track}")