Added Jenkinsfile and Dockerfile
parent
ad4ce178a9
commit
940b2e1c03
|
|
@ -0,0 +1,18 @@
|
|||
FROM rust:1.84 AS builder
|
||||
WORKDIR /app
|
||||
|
||||
RUN apt update && apt install -y musl-tools
|
||||
RUN rustup target add x86_64-unknown-linux-musl
|
||||
|
||||
COPY . .
|
||||
RUN cargo test
|
||||
RUN cargo build --release --target=x86_64-unknown-linux-musl
|
||||
|
||||
FROM alpine:latest
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/api-grub /app/api-grub
|
||||
RUN apk add --no-cache ca-certificates
|
||||
|
||||
|
||||
ENTRYPOINT ["/app/api-grub"]
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
pipeline {
|
||||
agent any
|
||||
environment {
|
||||
REGISTRY_NAME = 'registry.entcor/trust-module'
|
||||
IMAGE_NAME = "integration-module"
|
||||
GITEA_REPOSITORY_URL = "http://git.entcor/api/v1/repos/"
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Init variables') {
|
||||
when {
|
||||
expression { env.CHANGE_BRANCH?.startsWith('rc') }
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
env.IMAGE_TAG = sh(script: "git describe --tags --abbrev=0", returnStdout: true).trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Build tagged image and run tests') {
|
||||
when {
|
||||
expression { env.CHANGE_BRANCH?.startsWith('rc') }
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
try {
|
||||
def image = docker.build("${env.IMAGE_NAME}:${env.IMAGE_TAG}")
|
||||
sh "docker tag ${env.IMAGE_NAME}:${env.IMAGE_TAG} ${env.REGISTRY_NAME}/${env.IMAGE_NAME}:${env.IMAGE_TAG}"
|
||||
} catch (Exception e) {
|
||||
error("Tests failed: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stage ('Push docker image to registry') {
|
||||
when {
|
||||
expression { env.CHANGE_BRANCH?.startsWith('rc') }
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
docker.withRegistry('https://registry.entcor/harbor/', 'harbor-credentials-id') {
|
||||
docker.image("${env.REGISTRY_NAME}/${env.IMAGE_NAME}:${env.IMAGE_TAG}").push()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
always {
|
||||
script {
|
||||
echo "Cleaning up workspace..."
|
||||
sh "rm -rf ${env.WORKSPACE}/rc/ || true"
|
||||
}
|
||||
}
|
||||
success {
|
||||
script {
|
||||
if (env.CHANGE_BRANCH?.startsWith('rc')) {
|
||||
echo "Attempting to merge PR ${env.CHANGE_ID} into master..."
|
||||
withCredentials([usernamePassword(credentialsId: 'gitea_creds', usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_PASS')]) {
|
||||
def prId = env.CHANGE_ID
|
||||
sh """
|
||||
curl -X POST \
|
||||
-u "${GITEA_USER}:${GITEA_PASS}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"do":"merge"}' \
|
||||
http://git.entcor/api/v1/repos/deployer3000/integration-module/pulls/${prId}/merge
|
||||
"""
|
||||
echo "PR ${prId} merged successfully into master!"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
failure {
|
||||
echo "Pipeline failed. Check the logs for details."
|
||||
}
|
||||
aborted {
|
||||
echo "Pipeline was aborted."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,3 +19,4 @@ dotenv = "0.15.0"
|
|||
md5 = "0.7.0"
|
||||
rand = "0.9.0"
|
||||
sysinfo = "0.33.1"
|
||||
openssl = { version = "0.10", features = ["vendored"] }
|
||||
|
|
|
|||
Loading…
Reference in New Issue