Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: integration with Tekton #1216

Merged
merged 3 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 92 additions & 3 deletions .github/workflows/integration-tests-with-dockerio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ on:
push:
branches:
- main
pull_request:

jobs:
cache:
Expand Down Expand Up @@ -69,7 +68,7 @@ jobs:
java-version: '8'
distribution: 'adopt'
- name: Dockerhub login
if: ${{secrets.DOCKERIO_USERNAME != null && secerts.DOCKERIO_PASSWORD != null }}
if: ${{ secrets.DOCKERIO_USERNAME != null && secrets.DOCKERIO_PASSWORD != null }}
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERIO_USERNAME }}
Expand Down Expand Up @@ -126,7 +125,7 @@ jobs:
java-version: '8'
distribution: 'adopt'
- name: Dockerhub login
if: ${{secrets.DOCKERIO_USERNAME != null && secerts.DOCKERIO_PASSWORD != null }}
if: ${{ secrets.DOCKERIO_USERNAME != null && secrets.DOCKERIO_PASSWORD != null }}
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERIO_USERNAME }}
Expand All @@ -147,3 +146,93 @@ jobs:
with:
name: ci-manifests
path: manifests-ocp-jvm${{ matrix.java }}.zip

tekton:
name: Tekton Build
needs: cache
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
kubernetes: [ v1.22.2 ]
tekton: [ v0.39.0 ]
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
- name: Get Date
id: get-date
run: |
echo "::set-output name=date::$(/bin/date -u "+%Y-%m")"
shell: bash
- name: Cache .m2 registry
uses: actions/cache@v2.1.6
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ steps.get-date.outputs.date }}
restore-keys: ${{ runner.os }}-maven-
- name: Setup Minikube-Kubernetes
uses: manusa/actions-setup-minikube@v2.7.1
with:
minikube version: v1.23.2
kubernetes version: ${{ matrix.kubernetes }}
github token: ${{ secrets.GITHUB_TOKEN }}
driver: 'docker'
start args: '--force'
- name: Setup Java 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Dockerhub login
if: ${{ secrets.DOCKERIO_USERNAME != null && secrets.DOCKERIO_PASSWORD != null }}
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERIO_USERNAME }}
password: ${{ secrets.DOCKERIO_PASSWORD }}
- name: Install Tekton
run: |
kubectl apply -f https://github.com/tektoncd/pipeline/releases/download/${{ matrix.tekton }}/release.yaml
- name: Build
run: |
./mvnw -B clean install -Dformat.skip=true -DskipTests
- name: Run Tekton Integration Tests
run: |
kubectl create namespace tekton
kubectl config set-context --current --namespace=tekton
cd examples/spring-boot-with-tekton-example
# Build example
mvn clean install -DskipTests -Ddekorate.docker.registry=docker.io -Ddekorate.docker.group=dekorateio -Ddekorate.tekton.use-local-docker-config-json=true -Ddekorate.tekton.projectBuilderArguments=clean,install,-Pwith-examples,-DskipTests,-Dformat.skip=true,-pl,examples/spring-boot-with-tekton-example,-am
# Install Tekton Task manifests
kubectl apply -f target/classes/META-INF/dekorate/tekton-task.yml
# Trigger Task workflow
kubectl apply -f target/classes/META-INF/dekorate/tekton-task-run.yml
# Wait to finish
kubectl wait --for=condition=Succeeded --timeout=800s TaskRun/spring-boot-with-tekton-example-run-now
kubectl wait deployment spring-boot-with-tekton-example --for condition=Available=True --timeout=180s
# Verify application
RESULT=$(kubectl exec $(kubectl get pod -l app.kubernetes.io/name=spring-boot-with-tekton-example -o name) -- wget -qO- http://localhost:9090)
if [[ "$RESULT" = *"Hello world"* ]]
then
exit 0
fi
echo "Application is not working. Result was: $RESULT"
exit 1
- name: Print logs at failures
if: failure()
run: |
kubectl config set-context --current --namespace=tekton
echo "kubectl get pods: "
kubectl get pods
echo "kubectl describe TaskRun/spring-boot-with-tekton-example-run-now: "
kubectl describe TaskRun/spring-boot-with-tekton-example-run-now
echo "kubectl logs spring-boot-with-tekton-example-run-now-pod --all-containers --max-log-requests 10: "
kubectl logs spring-boot-with-tekton-example-run-now-pod --all-containers --max-log-requests 10
- name: Zip Artifacts
if: failure()
run: |
zip -R manifests-tekton-jvm${{ matrix.java }}.zip 'classes/META-INF/dekorate/*'
- uses: actions/upload-artifact@v1
if: failure()
with:
name: ci-manifests
path: manifests-tekton-jvm${{ matrix.java }}.zip
80 changes: 79 additions & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ jobs:
with:
name: ci-manifests
path: manifests-k8s-jvm${{ matrix.java }}.zip

openshift:
name: Openshift Build
needs: cache
Expand Down Expand Up @@ -151,3 +150,82 @@ jobs:
with:
name: ci-manifests
path: manifests-ocp-jvm${{ matrix.java }}.zip
tekton:
name: Tekton Build
needs: cache
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tekton: [ v0.39.0 ]
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
- name: Get Date
id: get-date
run: |
echo "::set-output name=date::$(/bin/date -u "+%Y-%m")"
shell: bash
- name: Cache .m2 registry
uses: actions/cache@v2.1.6
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ steps.get-date.outputs.date }}
restore-keys: ${{ runner.os }}-maven-
- name: Kubernetes KinD Cluster
uses: container-tools/kind-action@v1
with:
version: v0.18.0
registry: true
- name: Setup Java 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Install Tekton
run: |
kubectl apply -f https://github.com/tektoncd/pipeline/releases/download/${{ matrix.tekton }}/release.yaml || true
- name: Build
run: |
./mvnw -B clean install -Dformat.skip=true -DskipTests
- name: Run Tekton Integration Tests
run: |
kubectl create namespace tekton
kubectl config set-context --current --namespace=tekton
cd examples/spring-boot-with-tekton-example
# Build example
mvn clean install -DskipTests -Ddekorate.docker.registry=$KIND_REGISTRY -Ddekorate.tekton.imageRegistryInsecure=true -Ddekorate.tekton.projectBuilderArguments=clean,install,-Pwith-examples,-DskipTests,-Dformat.skip=true,-pl,examples/spring-boot-with-tekton-example,-am
# Install Tekton Task manifests
kubectl apply -f target/classes/META-INF/dekorate/tekton-task.yml
# Trigger Task workflow
kubectl apply -f target/classes/META-INF/dekorate/tekton-task-run.yml
# Wait to finish
kubectl wait --for=condition=Succeeded --timeout=800s TaskRun/spring-boot-with-tekton-example-run-now
kubectl wait deployment spring-boot-with-tekton-example --for condition=Available=True --timeout=180s
# Verify application
RESULT=$(kubectl exec $(kubectl get pod -l app.kubernetes.io/name=spring-boot-with-tekton-example -o name) -- wget -qO- http://localhost:9090)
if [[ "$RESULT" = *"Hello world"* ]]
then
exit 0
fi
echo "Application is not working. Result was: $RESULT"
exit 1
- name: Print logs at failures
if: failure()
run: |
kubectl config set-context --current --namespace=tekton
echo "kubectl get pods: "
kubectl get pods
echo "kubectl describe TaskRun/spring-boot-with-tekton-example-run-now: "
kubectl describe TaskRun/spring-boot-with-tekton-example-run-now
echo "kubectl logs spring-boot-with-tekton-example-run-now-pod --all-containers --max-log-requests 10: "
kubectl logs spring-boot-with-tekton-example-run-now-pod --all-containers --max-log-requests 10
- name: Zip Artifacts
if: failure()
run: |
zip -R manifests-tekton-jvm${{ matrix.java }}.zip 'classes/META-INF/dekorate/*'
- uses: actions/upload-artifact@v1
if: failure()
with:
name: ci-manifests
path: manifests-tekton-jvm${{ matrix.java }}.zip
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.dekorate.WithProject;
import io.dekorate.config.DefaultConfiguration;
import io.dekorate.kubernetes.configurator.ApplyDeployToApplicationConfiguration;
import io.dekorate.kubernetes.configurator.ApplyImagePullSecretConfiguration;
import io.dekorate.project.ApplyProjectInfo;

public class DefaultKnativeConfigGenerator implements KnativeConfigGenerator, WithProject {
Expand All @@ -28,6 +29,7 @@ public class DefaultKnativeConfigGenerator implements KnativeConfigGenerator, Wi
public DefaultKnativeConfigGenerator(ConfigurationRegistry configurationRegistry) {
this.configurationRegistry = configurationRegistry;
on(new DefaultConfiguration<KnativeConfig>(KnativeConfig.newKnativeConfigBuilderFromDefaults()));
this.configurationRegistry.add(new ApplyImagePullSecretConfiguration());
this.configurationRegistry.add(new ApplyProjectInfo(getProject()));
this.configurationRegistry.add(new ApplyDeployToApplicationConfiguration());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.dekorate.ConfigurationRegistry;
import io.dekorate.config.DefaultConfiguration;
import io.dekorate.kubernetes.configurator.ApplyDeployToApplicationConfiguration;
import io.dekorate.kubernetes.configurator.ApplyImagePullSecretConfiguration;
import io.dekorate.kubernetes.configurator.PopulateWebPort;
import io.dekorate.project.ApplyProjectInfo;

Expand All @@ -28,6 +29,7 @@ public class DefaultKubernetesConfigGenerator implements KubernetesConfigGenerat
public DefaultKubernetesConfigGenerator(ConfigurationRegistry configurationRegistry) {
this.configurationRegistry = configurationRegistry;
this.configurationRegistry.add(new ApplyProjectInfo(getProject()));
this.configurationRegistry.add(new ApplyImagePullSecretConfiguration());
this.configurationRegistry.add(new PopulateWebPort());
this.configurationRegistry.add(new ApplyDeployToApplicationConfiguration());
add(new DefaultConfiguration<KubernetesConfig>(KubernetesConfig.newKubernetesConfigBuilderFromDefaults()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.dekorate.WithProject;
import io.dekorate.config.DefaultConfiguration;
import io.dekorate.kubernetes.configurator.ApplyDeployToApplicationConfiguration;
import io.dekorate.kubernetes.configurator.ApplyImagePullSecretConfiguration;
import io.dekorate.kubernetes.configurator.PopulateWebPort;
import io.dekorate.project.ApplyProjectInfo;

Expand All @@ -30,6 +31,7 @@ public DefaultOpenshiftConfigGenerator(ConfigurationRegistry configurationRegist
this.configurationRegistry = configurationRegistry;
on(new DefaultConfiguration<OpenshiftConfig>(OpenshiftConfig.newOpenshiftConfigBuilderFromDefaults()));

this.configurationRegistry.add(new ApplyImagePullSecretConfiguration());
this.configurationRegistry.add(new ApplyProjectInfo(getProject()));
this.configurationRegistry.add(new PopulateWebPort());
this.configurationRegistry.add(new ApplyDeployToApplicationConfiguration());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@
*/
String[] imagePushArguments() default {};

/*
* If to use an unsecure registry or not.
*
* @return The container image will be configured to work with an insecure registry.
*/
boolean imageRegistryInsecure() default false;

/**
* The relative path to the Dockerfile.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package io.dekorate.tekton.decorator;

import java.nio.file.Path;

import io.dekorate.kubernetes.decorator.Decorator;
import io.fabric8.tekton.pipeline.v1beta1.Step;
import io.fabric8.tekton.pipeline.v1beta1.StepBuilder;
Expand All @@ -29,18 +31,18 @@ public class AddDeployStepDecorator extends NamedTaskDecorator implements StepDe
private static final String PATH_TO_YML_PARAM_NAME = "pathToYml";

private final String stepName;
private final String projectName;
private final Path relativePath;
private final String deployerImage;

public AddDeployStepDecorator(String taskName, String stepName, String projectName, String deployerImage) {
public AddDeployStepDecorator(String taskName, String stepName, Path relativePath, String deployerImage) {
super(taskName);
this.stepName = stepName;
this.projectName = projectName;
this.relativePath = relativePath;
this.deployerImage = deployerImage;
}

public AddDeployStepDecorator(String taskName, String projectName, String deployerImage) {
this(taskName, STEP_NAME, projectName, deployerImage);
public AddDeployStepDecorator(String taskName, Path relativePath, String deployerImage) {
this(taskName, STEP_NAME, relativePath, deployerImage);
}

@Override
Expand All @@ -50,7 +52,8 @@ public void andThenVisit(TaskSpecFluent taskSpec) {

public Step createDeployStep() {
return new StepBuilder().withName(stepName).withImage(deployerImage).withCommand(DEPLOY_CMD)
.withArgs(new String[] { "apply", "-f", param(PATH_TO_YML_PARAM_NAME) }).withWorkingDir(sourcePath(projectName))
.withArgs(new String[] { "apply", "-f", param(PATH_TO_YML_PARAM_NAME) })
.withWorkingDir(sourcePath(relativePath.toString()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

import io.dekorate.tekton.step.ImageStep;

public class AddDockerSocketVolumeDecorator extends AddHostPathVolumeDecorator {
public class AddDockerSocketVolumeTaskDecorator extends AddHostPathVolumeTaskDecorator {

public AddDockerSocketVolumeDecorator(String taskName) {
public AddDockerSocketVolumeTaskDecorator(String taskName) {
super(taskName, ImageStep.DOCKER_SOCKET_NAME, ImageStep.DOCKER_SOCKET_PATH, ImageStep.DOCKER_SOCKET_TYPE);
}

public AddDockerSocketVolumeDecorator(String taskName, String name, String path, String type) {
public AddDockerSocketVolumeTaskDecorator(String taskName, String name, String path, String type) {
super(taskName, name, path, type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import io.fabric8.tekton.pipeline.v1beta1.TaskSpecFluent;

@Description("Add a persistent host path volume to the specified task.")
public class AddHostPathVolumeDecorator extends NamedTaskDecorator {
public class AddHostPathVolumeTaskDecorator extends NamedTaskDecorator {

private final String name;
private final String path;
private final String type;

public AddHostPathVolumeDecorator(String taskName, String name, String path, String type) {
public AddHostPathVolumeTaskDecorator(String taskName, String name, String path, String type) {
super(taskName);
this.name = name;
this.path = path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package io.dekorate.tekton.decorator;

import java.nio.file.Path;

import io.dekorate.kubernetes.decorator.Decorator;
import io.dekorate.tekton.step.ImageBuildStep;
import io.dekorate.utils.Strings;
Expand All @@ -33,24 +35,24 @@ public class AddImageBuildStepDecorator extends NamedTaskDecorator implements St
private static final String DOCKER_CONFIG_DEFAULT = "/tekton/home/.docker";

private final String stepName;
private final String projectName;
private final Path relativePath;
private final String image;
private final String command;
private final String[] args;

public AddImageBuildStepDecorator(String taskName, String projectName) {
this(taskName, ImageBuildStep.ID, projectName);
public AddImageBuildStepDecorator(String taskName, Path relativePath) {
this(taskName, ImageBuildStep.ID, relativePath);
}

public AddImageBuildStepDecorator(String taskName, String stepName, String projectName) {
this(taskName, stepName, projectName, BUILDER_IMAGE_REF, BUILDER_COMMAND_REF, BUILDER_ARGS_REF);
public AddImageBuildStepDecorator(String taskName, String stepName, Path relativePath) {
this(taskName, stepName, relativePath, BUILDER_IMAGE_REF, BUILDER_COMMAND_REF, BUILDER_ARGS_REF);
}

public AddImageBuildStepDecorator(String taskName, String stepName, String projectName, String image, String command,
public AddImageBuildStepDecorator(String taskName, String stepName, Path relativePath, String image, String command,
String... args) {
super(taskName);
this.stepName = stepName;
this.projectName = projectName;
this.relativePath = relativePath;
this.image = Strings.isNotNullOrEmpty(image) ? image : BUILDER_IMAGE_REF;
this.command = Strings.isNotNullOrEmpty(command) ? command : BUILDER_COMMAND_REF;
this.args = args != null && args.length != 0 ? args : new String[] { BUILDER_ARGS_REF };
Expand All @@ -64,7 +66,7 @@ public void andThenVisit(TaskSpecFluent<?> taskSpec) {
.addToEnv(new EnvVarBuilder().withName(DOCKER_CONFIG).withValue(DOCKER_CONFIG_DEFAULT).build())
.withCommand(command)
.withArgs(args)
.withWorkingDir(sourcePath(projectName))
.withWorkingDir(sourcePath())
.endStep();
}

Expand Down
Loading