Unified Declarative CI/CD
KubeVela introduced standalone workflow in version v1.6 that can be used independently, which can be used to orchestrate the process between CI steps and application delivery. Different from the workflow in the KubeVela application, it is one-time and does not manage resources. Even if the workflow is deleted, the created resources will not be deleted.
tip
Apply the following workflow:
The workflow has four steps in total:
- Create a secret with Git token, which is used to pull the code from the private repository to build the image. If your repository is public, you can skip this step. You can also skip this step and use the
kubectl create secret generic git-token --from-literal='GIT_TOKEN=<your-token>'
command to create the secret. - Create a secret with the image registry token to push the image to your image registry. You can also skip this step and use
kubectl create secret docker-registry docker-regcred --docker-server=https://index.docker.io/v1/ --docker-username=<your-username> -- docker-password=<your-password>
command to create the secret. - Use the
build-push-image
step type to build and push the image. This step will use the specified Git url and the code in its branch to build the image. You can also directly specify in the context field. The bottom layer of this step will use for image building. During the building, you can usevela workflow logs build-push-image --step build-push
to view the log of the step. Note that this step has an input fromcontext.image
, which will override the image field in properties. As you can see, we currently declareimage: my-registry/test-image:v2
in the context. When we need to reuse this workflow to build a new image version, we only need to update the data in the context to update the entire process. - In the last step, the image version in
context.image
will be used to publish the application. When the application starts, you can usevela port-forward my-app 8080:80
to check the result.
You can also directly build the image in the application, and use the newly built image in the component. Apply the following application:
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: build-push-image
namespace: default
spec:
components:
type: webservice
image: my-registry/test-image:v1
ports:
- port: 80
expose: true
workflow:
steps:
- name: build-push
type: build-push-image
properties:
# use your kaniko executor image like below, if not set, it will use default image oamdev/kaniko-executor:v1.9.1
# kanikoExecutor: gcr.io/kaniko-project/executor:latest
# you can use context with git and branch or directly specify the context, please refer to https://github.com/GoogleContainerTools/kaniko#kaniko-build-contexts
context:
branch: main
# you must align the image value with image field of the component properties
image: my-registry/test-image:v1
# specify your dockerfile, if not set, it will use default dockerfile ./Dockerfile
# dockerfile: ./Dockerfile
credentials:
image:
name: image-secret
# buildArgs:
# - key="value"
# platform: linux/arm
- name: apply-comp
type: apply-component
component: my-web