Skip to content

Commit 7eef46d

Browse files
committed
Deploy container image
1 parent b192f66 commit 7eef46d

File tree

6 files changed

+128
-64
lines changed

6 files changed

+128
-64
lines changed

.github/workflows/deploy.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
6+
jobs:
7+
deploy:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout Repository
11+
uses: actions/checkout@v4
12+
- name: Java Setup
13+
uses: actions/setup-java@v4
14+
with:
15+
distribution: 'graalvm'
16+
java-version: '21'
17+
- name: Gradle Build
18+
run: ./gradlew build -Dquarkus.package.jar.enabled=false -Dquarkus.native.container-build=true -Dquarkus.native.enabled=true -Dquarkus.container-image.build=true -Dquarkus.container-image.push=true -Dquarkus.container-image.username="${{ secrets.QUAY_UN }}" -Dquarkus.container-image.password="${{ secrets.QUAY_PW }}"

build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ java {
2020
dependencies {
2121
implementation(enforcedPlatform(libs.quarkus.bom))
2222
implementation("io.quarkus:quarkus-arc")
23-
implementation("io.quarkus:quarkus-openshift")
23+
implementation("io.quarkus:quarkus-kubernetes")
24+
implementation("io.quarkus:quarkus-container-image-jib")
2425
implementation("io.quarkus:quarkus-openshift-client")
2526
implementation("io.quarkus:quarkus-scheduler")
2627
implementation("io.quarkus:quarkus-jackson")
27-
implementation("org.eclipse.jgit:org.eclipse.jgit:7.1.0.202411261347-r")
28+
implementation("io.quarkus:quarkus-smallrye-health")
29+
implementation("io.quarkiverse.jgit:quarkus-jgit:3.3.3")
2830

2931
// Lombok
3032
val lombok = "org.projectlombok:lombok:1.18.36"

src/main/java/io/okd/operators/controller/Controller.java

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,18 @@ public class Controller {
3737

3838
private static final Path RECIPE_REPO = Paths.get("/tmp", "okd-build-controller", "repo");
3939
private static final JsonMapper MAPPER = new JsonMapper();
40-
// private final Thread watchThread;
41-
private final AtomicBoolean running = new AtomicBoolean(false);
42-
// private final String recipesDirectory;
43-
44-
@Inject
45-
ManagedExecutor managedExecutor;
4640

4741
@Inject
4842
OpenShiftClient client;
4943

5044
@Inject
51-
@ConfigProperty(name = "controller.build-repo")
45+
@ConfigProperty(name = "controller.build-repo", defaultValue = "https://github.com/okd-project/okd-operator-pipeline.git")
5246
String buildRepo;
5347

48+
@Inject
49+
@ConfigProperty(name = "controller.build-branch", defaultValue = "master")
50+
String buildBranch;
51+
5452
@Inject
5553
@ConfigProperty(name = "controller.recipes.directory", defaultValue = "recipes")
5654
String recipesDirectory;
@@ -71,6 +69,7 @@ void cloneRepo() throws IOException, GitAPIException {
7169
Git.cloneRepository()
7270
.setURI(this.buildRepo)
7371
.setDirectory(RECIPE_REPO.toFile())
72+
.setBranch(this.buildBranch)
7473
.call()
7574
.close();
7675
}
@@ -287,69 +286,75 @@ private boolean processComponent(Git git, String recipe, String version, Compone
287286

288287
Path gitDirectory = dataDirectory.resolve("git");
289288

290-
Git componentGit;
291-
if (!RepositoryCache.FileKey.isGitRepository(gitDirectory.toFile(), FS.DETECTED)) {
292-
if (Files.exists(gitDirectory)) {
289+
Git componentGit = null;
290+
try {
291+
if (!RepositoryCache.FileKey.isGitRepository(gitDirectory.toFile(), FS.DETECTED)) {
292+
if (Files.exists(gitDirectory)) {
293+
try {
294+
Files.delete(gitDirectory);
295+
} catch (IOException e) {
296+
throw new IllegalStateException("Failed to delete git directory", e);
297+
}
298+
}
293299
try {
294-
Files.delete(gitDirectory);
295-
} catch (IOException e) {
296-
throw new IllegalStateException("Failed to delete git directory", e);
300+
componentGit = Git.cloneRepository()
301+
.setURI(component.getGitUrl())
302+
.setDirectory(gitDirectory.toFile())
303+
.setBranch(branch)
304+
.call();
305+
} catch (GitAPIException e) {
306+
throw new IllegalStateException("Failed to clone repository", e);
297307
}
298-
}
299-
try {
300-
componentGit = Git.cloneRepository()
301-
.setURI(component.getGitUrl())
302-
.setDirectory(gitDirectory.toFile())
303-
.setBranch(branch)
304-
.call();
305-
} catch (GitAPIException e) {
306-
throw new IllegalStateException("Failed to clone repository", e);
307-
}
308-
} else {
309-
try {
310-
componentGit = Git.open(gitDirectory.toFile());
308+
} else {
309+
try {
310+
componentGit = Git.open(gitDirectory.toFile());
311311

312-
componentGit.pull().call();
313-
} catch (IOException | GitAPIException e) {
314-
throw new IllegalStateException("Failed to open git directory", e);
312+
componentGit.pull().call();
313+
} catch (IOException | GitAPIException e) {
314+
throw new IllegalStateException("Failed to open git directory", e);
315+
}
315316
}
316-
}
317317

318-
// Check if we need to create a new PipelineRun by polling the git repo
319-
String hash = null;
320-
boolean runPipeline = false;
321-
try {
322-
List<Ref> call = componentGit.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call();
323-
log.info("Branches: {}", call.stream().map(Ref::getName).toList());
324-
for (Ref ref : call) {
325-
if (ref.getName().equals("refs/remotes/origin/" + branch)) {
326-
hash = ref.getObjectId().getName();
327-
break;
318+
// Check if we need to create a new PipelineRun by polling the git repo
319+
String hash = null;
320+
boolean runPipeline = false;
321+
try {
322+
List<Ref> call = componentGit.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call();
323+
log.info("Branches: {}", call.stream().map(Ref::getName).toList());
324+
for (Ref ref : call) {
325+
if (ref.getName().equals("refs/remotes/origin/" + branch)) {
326+
hash = ref.getObjectId().getName();
327+
break;
328+
}
328329
}
329-
}
330330

331-
if (hash == null) {
332-
log.error("Branch {} not found", branch);
333-
throw new IllegalStateException("Branch not found");
334-
}
331+
if (hash == null) {
332+
log.error("Branch {} not found", branch);
333+
throw new IllegalStateException("Branch not found");
334+
}
335335

336-
Path hashFile = dataDirectory.resolve("hash");
336+
Path hashFile = dataDirectory.resolve("hash");
337337

338-
if (Files.notExists(hashFile)) {
339-
Files.writeString(hashFile, hash);
340-
runPipeline = true;
341-
} else {
342-
String existingHash = Files.readString(hashFile);
343-
if (!existingHash.equals(hash)) {
338+
if (Files.notExists(hashFile)) {
344339
Files.writeString(hashFile, hash);
345340
runPipeline = true;
341+
} else {
342+
String existingHash = Files.readString(hashFile);
343+
if (!existingHash.equals(hash)) {
344+
Files.writeString(hashFile, hash);
345+
runPipeline = true;
346+
}
346347
}
348+
} catch (GitAPIException | IOException e) {
349+
throw new IllegalStateException("Failed to get branch list", e);
347350
}
348-
} catch (GitAPIException | IOException e) {
349-
throw new IllegalStateException("Failed to get branch list", e);
350-
}
351351

352-
return runPipeline;
352+
return runPipeline;
353+
} finally {
354+
if (componentGit != null) {
355+
componentGit.close();
356+
}
357+
}
353358
}
354359

355360
private void buildComponent(String recipe, String version, ComponentRecipe component, String buildVersion,

src/main/java/io/okd/operators/controller/crds/dev/tekton/v1/PipelineRun.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.fabric8.kubernetes.api.model.HasMetadata;
88
import io.fabric8.kubernetes.api.model.Namespaced;
99
import io.fabric8.kubernetes.api.model.ObjectMeta;
10+
import io.fabric8.kubernetes.api.model.apps.Deployment;
1011
import io.fabric8.kubernetes.client.CustomResource;
1112
import io.fabric8.kubernetes.model.annotation.Group;
1213
import io.fabric8.kubernetes.model.annotation.Plural;
@@ -25,7 +26,7 @@
2526
@Group("tekton.dev")
2627
@Singular("pipelinerun")
2728
@Plural("pipelineruns")
28-
public class PipelineRun extends CustomResource<Void, Void> implements Namespaced, HasMetadata {
29+
public class PipelineRun implements Namespaced, HasMetadata {
2930

3031
@JsonProperty("apiVersion")
3132
private String apiVersion = "tekton.dev/v1";
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
quarkus.application.name=operator-build-controller
2+
quarkus.application.ui-header=Operator Build Controller
3+
4+
quarkus.analytics.disabled=true
5+
quarkus.log.file.enable=false
6+
quarkus.banner.enabled=false
7+
8+
quarkus.container-image.registry=quay.io
9+
quarkus.container-image.group=okderators
10+
quarkus.container-image.tag=latest
11+
12+
quarkus.kubernetes.idempotent=true
13+
quarkus.kubernetes.vcs-uri.enabled=false
14+
quarkus.kubernetes.deployment-target=openshift
15+
quarkus.kubernetes.part-of=operator-build-controller
16+
17+
quarkus.kubernetes.readiness-probe.initial-delay=20s
18+
quarkus.kubernetes.readiness-probe.period=45s
19+
20+
quarkus.kubernetes.resources.requests.memory=256Mi
21+
quarkus.kubernetes.resources.requests.cpu=250m
22+
quarkus.kubernetes.resources.limits.memory=512Mi
23+
quarkus.kubernetes.resources.limits.cpu=1000m
24+
25+
# Generate Role resource with name "operator-builder"
26+
quarkus.kubernetes.rbac.roles."operator-builder".policy-rules.0.api-groups=extensions,apps,tekton.dev
27+
quarkus.kubernetes.rbac.roles."operator-builder".policy-rules.0.resources=configmaps,pipelineruns
28+
quarkus.kubernetes.rbac.roles."operator-builder".policy-rules.0.verbs=get,watch,list,create,patch,update,delete
29+
30+
# Generate ServiceAccount
31+
quarkus.kubernetes.rbac.service-accounts."operator-build-controller".namespace=okd-operator-build
32+
33+
# Bind Role "operator-builder" with ServiceAccount "operator-build-controller"
34+
quarkus.kubernetes.rbac.role-bindings."operator-builder-binding".subjects."operator-build-controller".kind=ServiceAccount
35+
quarkus.kubernetes.rbac.role-bindings."operator-builder-binding".subjects."operator-build-controller".namespace=okd-operator-build
36+
quarkus.kubernetes.rbac.role-bindings."operator-builder-binding".role-name=operator-builder
37+
38+
controller.name={CONTROLLER_NAME:operator-build-controller}
39+
controller.build-repo={BUILD_REPO:https://github.com/okd-project/okd-operator-pipelines.git}
40+
controller.build-branch={BUILD_BRANCH:master}
41+
controller.recipes.directory={RECIPES_DIR:recipes}
42+
controller.recipes.patches-directory={PATCHES_DIR:patches}
43+
controller.data-directory={DATA_DIR:/opt/okd/recipes}

src/main/resources/applications.properties

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)