Skip to content

Commit

Permalink
feat: Carvel Tutorial update for Q4 2023 (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
MAHDTech authored Nov 13, 2023
1 parent 8858951 commit de17889
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 56 deletions.
5 changes: 4 additions & 1 deletion content/tutorials/carvel/tutorial/author/imgpkg.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/
---
apiVersion: imgpkg.carvel.dev/v1alpha1
kind: Bundle
metadata:
name: ${PACKAGE_NAME}
authors:
- name: ${PACKAGE_AUTHOR}
email: ${PACKAGE_AUTHOR_EMAIL}
websites:
- url: ${PACKAGE_WEBSITE}
_EOF_
Expand All @@ -47,7 +50,7 @@ _EOF_
imgpkg push \
--file "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/" \
--bundle ${OCI_REGISTRY}/${OCI_PROJECT}/packages/${PACKAGE_NAME}:${PACKAGE_VERSION} \
--lock-output "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle-lock.yaml" \
--lock-output "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/BundleLock.yaml" \
--registry-ca-cert-path "${HOME}/.docker/certs.d/${OCI_REGISTRY}/ca.crt"
```

Expand Down
20 changes: 6 additions & 14 deletions content/tutorials/carvel/tutorial/author/kbld.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,22 @@ Instead, we can use an image resolver to lock our supply chain making each deplo

The next step is to resolve and record any image references found by scanning the `vendor` directory.

For further documentation on the kbld available options see [carvel.dev/kbld](https://carvel.dev/kbld/docs/develop/).
For further documentation on the kbld available options see [carvel.dev/kbld](https://carvel.dev/kbld/docs/latest/config/).

In order for `kbld` to operate, the tool requires a valid yaml configuration file. _Let's create one now._
In order for `kbld` to operate, the tool requires a valid yaml configuration file. _Let's create an empty one now._

- Create a basic kbld config file
- Create a basic kbld config file.

{{< tabs "kbld-config" >}}

{{< tab "Linux" >}}

```bash
cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/kbld.yaml"
cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/kbld/Config.yaml"
---
apiVersion: kbld.k14s.io/v1alpha1
kind: Config
minimumRequiredVersion: 0.31.0
searchRules:
- keyMatcher:
path:
- spec
- images:
allIndexes: true
- keyMatcher:
name: image
updateStrategy:
entireValue: {}
_EOF_
```

Expand All @@ -73,6 +63,7 @@ helm template kbld \
"${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/vendor/helm" \
| \
kbld \
--file "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/kbld/Config.yaml" \
--file - \
--imgpkg-lock-output "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/.imgpkg/images.yml"
```
Expand All @@ -90,6 +81,7 @@ kbld \
```bash
# NOTE: You don't need to run this for this tutorial!
kbld \
--file "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/kbld/Config.yaml" \
--file "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/vendor/manifests/" \
--imgpkg-lock-output "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/.imgpkg/images.yml"
```
Expand Down
26 changes: 18 additions & 8 deletions content/tutorials/carvel/tutorial/author/package.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ draft: false

At this point in the tutorial, we have a `bundle` on the local file system, but how to we get it into OCI format into a container registry for consumption?

{{< notice info >}}👍 **What's a bundle?** You will learn more about bundles in the `imgpkg` section later, but for now think of a bundle as _"one or more container images and a metadata file"_.
{{< notice info >}}👍 **What's a bundle?** You will learn more about bundles in the `imgpkg` section later, but for now think of a bundle as a configuration file and a list of references to one or more container images.
{{< /notice >}}

Now it's time to create our first custom resource, the `Package`.
Expand All @@ -22,7 +22,7 @@ Now it's time to create our first custom resource, the `Package`.
{{< tab "Linux" >}}

```bash
cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/metadata.yaml"
cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/PackageMetadata.yaml"
---
apiVersion: data.packaging.carvel.dev/v1alpha1
kind: PackageMetadata
Expand Down Expand Up @@ -74,7 +74,7 @@ Below are just a few examples of what you might come across.
# (You don't need to run this for this tutorial)
# NOTE: We place the output from this into a temporary file, as we will use it later.
ytt \
--file "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/values-schema.yaml" \
--file "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/schema.yaml" \
--data-values-schema-inspect \
--output openapi-v3 \
> "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/schema/openapi.yaml"
Expand Down Expand Up @@ -177,9 +177,10 @@ yq \
```bash
# This step varies wildly per-package. This is an example for this tutorial.
# When creating real packages, this file is usually created once, and lasts for the lifetime of the package.
cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/templates/package.yaml"
cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/templates/Package.yaml"
#@ load("@ytt:data", "data")
#@ load("@ytt:yaml", "yaml")
---
apiVersion: data.packaging.carvel.dev/v1alpha1
kind: Package
Expand All @@ -198,28 +199,37 @@ spec:
openAPIv3: #@ yaml.decode(data.values.openapi)["components"]["schemas"]["dataValues"]
template:
spec:
fetch:
- imgpkgBundle:
image: #@ "${OCI_REGISTRY}/${OCI_PROJECT}/packages/${PACKAGE_NAME}:" + data.values.version
image: #@ "${OCI_REGISTRY}/${OCI_PROJECT}/packages/${PACKAGE_NAME}:" + data.values.version
template:
- helmTemplate:
path: "vendor/helm"
name: ${PACKAGE_NAME}
namespace: ${DEPLOY_NAMESPACE}
valuesFrom:
- secretRef:
name: ${PACKAGE_NAME}-values
- ytt:
paths:
- "ytt/overlays"
- "ytt/schema.yaml"
- "ytt/values.yaml"
- "-"
- "ytt"
- kbld:
paths:
- "kbld/Config.yaml"
- "-"
- ".imgpkg/images.yml"
deploy:
- kapp: {}
_EOF_
```

Expand Down
9 changes: 6 additions & 3 deletions content/tutorials/carvel/tutorial/author/repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ This process is made much easier with the CI configuration, but the following is
```bash
# Use YTT to template the file we made previously.
ytt \
--file "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/templates/package.yaml" \
--file "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/templates/Package.yaml" \
--data-value version="${PACKAGE_VERSION}" \
--data-value-file openapi="${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/schema/openapi.yaml" \
> ${ROOT_DIR}/repos/${REPOSITORY_NAME}/packages/${PACKAGE_NAME}.${PACKAGE_FQN}/${PACKAGE_VERSION}.yaml

# Take a copy of the package metadata to add the package to your repository.
# The metadata is how the repository knows what packages are contained within.
cp -f \
"${ROOT_DIR}/packages/${PACKAGE_NAME}/metadata.yaml" \
"${ROOT_DIR}/packages/${PACKAGE_NAME}/PackageMetadata.yaml" \
"${ROOT_DIR}/repos/${REPOSITORY_NAME}/packages/${PACKAGE_NAME}.${PACKAGE_FQN}/"
```

Expand Down Expand Up @@ -75,11 +75,14 @@ cat <<- _EOF_ > "${ROOT_DIR}/repos/${REPOSITORY_NAME}/.imgpkg/bundle.yml"
---
apiVersion: imgpkg.carvel.dev/v1alpha1
kind: Bundle
metadata:
name: ${REPOSITORY_NAME}
authors:
- name: ${PACKAGE_AUTHOR}
email: ${PACKAGE_AUTHOR_EMAIL}
websites:
- url: ${PACKAGE_WEBSITE}
_EOF_
Expand All @@ -100,7 +103,7 @@ _EOF_
imgpkg push \
--file "${ROOT_DIR}/repos/${REPOSITORY_NAME}" \
--bundle ${OCI_REGISTRY}/${OCI_PROJECT}/repos/${REPOSITORY_NAME}:${REPOSITORY_VERSION} \
--lock-output "${ROOT_DIR}/repos/${REPOSITORY_NAME}/bundle-lock.yaml" \
--lock-output "${ROOT_DIR}/repos/${REPOSITORY_NAME}/BundleLock.yaml" \
--registry-ca-cert-path "${HOME}/.docker/certs.d/${OCI_REGISTRY}/ca.crt"
```

Expand Down
34 changes: 19 additions & 15 deletions content/tutorials/carvel/tutorial/author/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Don't worry too much about understanding the layout early on, we will be filling
{{< tab "Linux" >}}

```bash
mkdir tutorial/ && cd $_
mkdir tutorial && cd $_
```

{{< /tab >}}
Expand Down Expand Up @@ -69,8 +69,8 @@ touch ${ROOT_DIR}/repos/${REPOSITORY_NAME}/packages/${PACKAGE_NAME}.${PACKAGE_FQ

mkdir -p \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/{bundle,examples,test,templates} \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/{.imgpkg,vendor,ytt} \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/overlays \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/{.imgpkg,kbld,vendir,vendor,ytt} \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/{config,overlays} \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/schema
```

Expand All @@ -83,11 +83,12 @@ touch \
${ROOT_DIR}/packages/${PACKAGE_NAME}/metadata.yaml \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/examples/{PackageInstall,Secret}.yaml \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/README.md \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/templates/package.yaml \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/{kbld,package}.yaml \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/{vendir,vendir.lock}.yaml \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/templates/Package.yaml \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/kbld/Config.yaml \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/Package.yaml \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/vendir/{Lock,LockConfig}.yaml \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/.imgpkg/{bundle,images}.yml \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/{values-schema,values}.yaml \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/{schema,defaults}.yaml \
${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/schema/{openapi,helm}.yaml
```

Expand All @@ -107,26 +108,29 @@ kapps/packages
│ ├── bundle
│ │ ├── .imgpkg
│ │ │ └── images.yml
│ │ ├── vendir.lock.yaml
│ │ ├── vendir.yaml
│ │ ├── kbld
│ │ └── Config.yaml
│ │ ├── vendir
│ │ ├── LockConfig.yaml
│ │ └── Config.yaml
│ │ ├── vendor
│ │ └── ytt
│ │ ├── config
│ │ ├── overlays
│ │ ├── values-schema.yaml
│ │ └── values.yaml
│ │ ├── schema.yaml
│ │ └── defaults.yaml
│ ├── examples
│ │ ├── PackageInstall.yaml
│ │ └── Secret.yaml
│ ├── kbld.yaml
│ ├── package.yaml
│ ├── Package.yaml
│ ├── README.md
│ ├── schema
│ │ ├── helm.yaml
│ │ └── openapi.yaml
│ ├── templates
│ │ └── package.yaml
│ │ └── Package.yaml
│ └── test
└── metadata.yaml
└── PackageMetadata.yaml

# Repositories
tree -Aa "${ROOT_DIR}/repos"
Expand Down
8 changes: 4 additions & 4 deletions content/tutorials/carvel/tutorial/author/vendir.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ For further documentation on the `vendir` available options see [carvel.dev/vend
{{< tab "Linux" >}}

```bash
cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/vendir.yaml"
cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/vendir/Config.yaml"
---
apiVersion: vendir.k14s.io/v1alpha1
kind: Config
Expand All @@ -36,7 +36,7 @@ directories:
helmVersion: ""
_EOF_

cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/vendir.lock.yaml"
cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/vendir/LockConfig.yaml"
# This file is generated automatically by vendir and will be updated with resolved image references by kbld later.
_EOF_
```
Expand All @@ -53,8 +53,8 @@ _EOF_

```bash
vendir sync \
--file "vendir.yaml" \
--lock-file "vendir.lock.yaml" \
--file "vendir/Config.yaml" \
--lock-file "vendir/LockConfig.yaml" \
--chdir "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle"

# Take a look at the upstream content you just downloaded.
Expand Down
21 changes: 10 additions & 11 deletions content/tutorials/carvel/tutorial/author/ytt.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,24 @@ _EOF_

# Define the ytt values schema with example value types.
# This also acts as fallback default values for the package, if not provided in values.yaml
cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/values-schema.yaml"
#! values-schema.yaml
cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/schema.yaml"
#@data/values-schema
#@schema/desc "OpenAPIv3 Schema for pacman"
#@schema/desc "OpenAPIv3 Schema for ${PACKAGE_NAME}"
---
#@schema/desc "The namespace in which pacman is deployed"
#@schema/desc "The namespace in which ${PACKAGE_NAME} is installed."
#@schema/nullable
namespace: ""
_EOF_

# Define default data values for the package.
# These are values that can be overridden by Package Consumers in the Secret config at install time.
cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/values.yaml"
#! values.yaml
cat <<- _EOF_ > "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/defaults.yaml"
#@data/values
---
namespace: "pacman"
namespace: "${PACKAGE_NAME}"
_EOF_
```

Expand Down Expand Up @@ -146,8 +145,8 @@ helm template ${PACKAGE_NAME} \
| \
ytt \
--file - \
--file "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/values-schema.yaml" \
--file "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/values.yaml" \
--file "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/schema.yaml" \
--file "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/defaults.yaml" \
--file "${ROOT_DIR}/packages/${PACKAGE_NAME}/${PACKAGE_VERSION}/bundle/ytt/overlays" \
| \
grep "namespace:"
Expand Down

0 comments on commit de17889

Please sign in to comment.