Skip to content

Commit e47640b

Browse files
committed
WIP
1 parent fdaba26 commit e47640b

File tree

4 files changed

+119
-3
lines changed

4 files changed

+119
-3
lines changed

.github/workflows/ci.yaml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Rust CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
workflow_dispatch:
7+
8+
jobs:
9+
prepare:
10+
name: Determine image tag
11+
#runs-on: ubuntu-latest
12+
runs-on:
13+
group: Azure_runners
14+
#if: |
15+
# github.ref_name == 'main' ||
16+
# startsWith(github.head_ref, 'feature/') ||
17+
# startsWith(github.head_ref, 'bugfix/') ||
18+
# (github.event_name == 'workflow_dispatch' && (startsWith(github.ref_name, 'feature/') || startsWith(github.ref_name, 'bugfix/')))
19+
outputs:
20+
image_tag: ${{ steps.determine-tag.outputs.image_tag }}
21+
jar_path: ${{ steps.jar-path.outputs.jar_path }}
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Setup Java
29+
uses: actions/setup-java@v4
30+
with:
31+
distribution: 'temurin'
32+
java-version: 17
33+
34+
- name: Setup Gradle
35+
uses: gradle/actions/setup-gradle@v5
36+
37+
- name: Determine base tag
38+
id: determine-tag
39+
run: |
40+
if [ "${{ github.event_name }}" = "pull_request" ] ; then
41+
SHORT_SHA=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-8)
42+
else
43+
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-8)
44+
fi
45+
46+
if [ "${{ github.ref_name }}" = "main" ] ; then
47+
echo "Processing main branch"
48+
echo "image_tag=dev-${SHORT_SHA}" | tee -a $GITHUB_OUTPUT
49+
else
50+
# This covers feature/ and bugfix/ branches
51+
echo "Processing feature/bugfix branch ${{ github.head_ref }}"
52+
echo "image_tag=feature-${SHORT_SHA}" | tee -a $GITHUB_OUTPUT
53+
fi
54+
55+
- name: Docker Regis login
56+
uses: docker/login-action@v3
57+
with:
58+
registry: docker-regis.iex.ec
59+
username: ${{ secrets.NEXUS_USERNAME }}
60+
password: ${{ secrets.NEXUS_PASSWORD }}
61+
62+
- name: Build jar
63+
id: jar-path
64+
run: |
65+
./gradlew build
66+
echo "jar_path=$(gradle properties | grep jarPathForOCI | cut -d" " -f2)" | tee -a $GITHUB_OUTPUT
67+
env:
68+
ORG_GRADLE_PROJECT_nexusUser: ${{ secrets.NEXUS_USERNAME }}
69+
ORG_GRADLE_PROJECT_nexusPassword: ${{ secrets.NEXUS_PASSWORD }}
70+
71+
build-oci-image:
72+
name: Build OCI images
73+
needs: prepare
74+
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/docker-build.yml@feature/improve-docker-build
75+
with:
76+
image-name: docker-regis.iex.ec/iexec-blockchain-adpter-api
77+
image-tag: ${{ needs.prepare.outputs.image_tag }}
78+
dockerfile: Dockerfile
79+
context: .
80+
registry: docker-regis.iex.ec
81+
push: false
82+
security-scan: true
83+
security-report: "sarif"
84+
hadolint: true
85+
platforms: linux/amd64
86+
build-args: |
87+
jar=${{ needs.prepare.outputs.jar_path }}
88+
secrets:
89+
username: ${{ secrets.NEXUS_USERNAME }}
90+
password: ${{ secrets.NEXUS_PASSWORD }}

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
buildJavaProject(
33
integrationTestsEnvVars: ['BROKER_PRIVATE_KEY'],
44
shouldPublishJars: true,
5-
shouldPublishDockerImages: true)
5+
shouldPublishDockerImages: false)

build.gradle

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ testing {
9494
dependencies {
9595
implementation "org.testcontainers:mongodb:$testContainersVersion"
9696
}
97+
targets {
98+
all {
99+
testTask.configure {
100+
systemProperty 'registryUsername', project.findProperty('nexusUser') ?: ''
101+
systemProperty 'registryPassword', project.findProperty('nexusPassword') ?: ''
102+
systemProperty 'registryAddress', 'docker-regis.iex.ec'
103+
}
104+
}
105+
}
97106
}
98107
itest(JvmTestSuite) {
99108
dependencies {
@@ -141,11 +150,10 @@ publishing {
141150

142151
ext.jarPathForOCI = relativePath(tasks.bootJar.outputs.files.singleFile)
143152
ext.gitShortCommit = 'git rev-parse --short=8 HEAD'.execute().text.trim()
144-
ext.ociImageName = 'local/' + ['bash', '-c', 'basename $(git config --get remote.origin.url) .git'].execute().text.trim()
145153

146154
tasks.register('buildImage', Exec) {
147155
group 'Build'
148156
description 'Builds an OCI image from a Dockerfile.'
149157
dependsOn bootJar
150-
commandLine 'docker', 'build', '--build-arg', 'jar=' + jarPathForOCI, '-t', ociImageName + ':dev', '.'
158+
commandLine 'docker', 'build', '--build-arg', 'jar=' + jarPathForOCI, '-t', 'local/' + rootProject.name + ':dev', '.'
151159
}

src/test/java/com/iexec/blockchain/chain/BlockchainListenerTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616

1717
package com.iexec.blockchain.chain;
1818

19+
import com.github.dockerjava.api.model.AuthConfig;
1920
import io.micrometer.core.instrument.Gauge;
2021
import io.micrometer.core.instrument.MeterRegistry;
2122
import lombok.extern.slf4j.Slf4j;
23+
import org.junit.jupiter.api.BeforeAll;
2224
import org.junit.jupiter.api.Test;
2325
import org.springframework.beans.factory.annotation.Autowired;
2426
import org.springframework.boot.test.context.SpringBootTest;
2527
import org.springframework.test.context.DynamicPropertyRegistry;
2628
import org.springframework.test.context.DynamicPropertySource;
29+
import org.testcontainers.DockerClientFactory;
2730
import org.testcontainers.containers.ComposeContainer;
2831
import org.testcontainers.containers.wait.strategy.Wait;
2932
import org.testcontainers.junit.jupiter.Container;
@@ -48,6 +51,21 @@ class BlockchainListenerTests {
4851
private static final String MONGO_SVC_NAME = "ibaa-blockchain-adapter-mongo";
4952
private static final int MONGO_SVC_PORT = 27017;
5053

54+
@BeforeAll
55+
static void setupAuth() {
56+
final AuthConfig authConfig = new AuthConfig()
57+
.withUsername(System.getProperty("registryUsername"))
58+
.withPassword(System.getProperty("registryPassword"))
59+
.withRegistryAddress(System.getProperty("registryAddress"));
60+
61+
// Configure Docker client with auth
62+
DockerClientFactory.instance()
63+
.client()
64+
.authCmd()
65+
.withAuthConfig(authConfig)
66+
.exec();
67+
}
68+
5169
@Container
5270
static ComposeContainer environment = new ComposeContainer(new File("docker-compose.yml"))
5371
.withExposedService(CHAIN_SVC_NAME, CHAIN_SVC_PORT, Wait.forListeningPort())

0 commit comments

Comments
 (0)