Skip to content

Commit

Permalink
fix: app installation in sqa; add: docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
vykozlov authored Dec 18, 2024
1 parent 7f84cfe commit 88ddef5
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .sqa/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sqa_criteria:
ai4life:
container: testing
commands:
- mkdir -p /srv/app/bandit
- mkdir -p ./bandit
- bandit -r ai4life api -x tests -o ./bandit/index.html

environment:
Expand Down
9 changes: 5 additions & 4 deletions .sqa/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ version: "3.6"

services:
testing:
image: "ai4oshub/ai4os-ai4life-loader:cicd"
#image: "ai4oshub/ai4os-ai4life-loader:cicd"
container_name: "${BUILD_TAG}"
hostname: "${BUILD_TAG}"
working_dir: /srv/app
command: >
sh -c "pip3 install --no-cache-dir -e . &&
sleep infinity"
build:
context: ./.sqa
args:
branch: ${GIT_BRANCH}
volumes:
- type: bind
source: ./
Expand Down
16 changes: 8 additions & 8 deletions .sqa/dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Docker image for CI testing of the DEEPaaS API
# Note there is probably no gpu in the CI server
#FROM ai4oshub/ai4os-ai4life-loader:cicd
## What user branch to clone [!]
#ARG branch=main
## install user app as python package
#RUN git clone -b $branch --depth 1 https://github.com/ai4os/ai4os-ai4life-loader.git app/ && \
# cd app/ && pip3 install --no-cache-dir -e . && \
# cd ..
#CMD ["sleep", "infinity"]
FROM ai4oshub/ai4os-ai4life-loader:cicd
# What user branch to clone [!]
ARG branch=main
# install user app as python package
RUN git clone -b $branch --depth 1 https://github.com/ai4os/ai4os-ai4life-loader.git app/ && \
cd app/ && pip3 install --no-cache-dir -e . && \
cd ..
CMD ["sleep", "infinity"]
68 changes: 65 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,52 @@
@Library(['github.com/indigo-dc/jenkins-pipeline-library@release/2.1.1']) _

// We choose to describe Docker image build directly in the Jenkinsfile instead of JePL2
// since this gives better control on the building process
// (e.g. which branches are allowed for docker image build)

def projectConfig

// function to remove built images
def docker_clean() {
def dangling_images = sh(
returnStdout: true,
script: "docker images -f 'dangling=true' -q"
)
if (dangling_images) {
sh(script: "docker rmi --force $dangling_images")
}
}

pipeline {
agent {
label 'docker'
agent any

environment {
AI4OS_REGISTRY_CREDENTIALS = credentials('AIOS-registry-credentials')
APP_DOCKERFILE = "Dockerfile"
}

stages {
stage('SQA Model api testing') {
stage("Variable initialization") {
steps {
script {
checkout scm
withFolderProperties{
env.DOCKER_REGISTRY = env.AI4OS_REGISTRY
env.DOCKER_REGISTRY_ORG = env.AI4OS_REGISTRY_REPOSITORY
env.DOCKER_REGISTRY_CREDENTIALS = env.AI4OS_REGISTRY_CREDENTIALS
}
// get docker image name from metadata.json
meta = readJSON file: "metadata.json"
image_name = meta["sources"]["docker_registry_repo"].split("/")[1]
// define tag based on branch
image_tag = "${env.BRANCH_NAME == 'main' ? 'latest' : env.BRANCH_NAME}"
env.DOCKER_REPO = env.DOCKER_REGISTRY_ORG + "/" + image_name + ":" + image_tag
env.DOCKER_REPO = env.DOCKER_REPO.toLowerCase()
println ("[DEBUG] Config for the Docker image build: $env.DOCKER_REPO, push to $env.DOCKER_REGISTRY")
}
}
}
stage('Application testing') {
steps {
script {
projectConfig = pipelineConfig()
Expand All @@ -21,6 +59,30 @@ pipeline {
}
}
}
stage("Docker image building & delivery") {
when {
anyOf {
branch 'main'
branch 'release/*'
buildingTag()
}
}
steps {
script {
checkout scm
docker.withRegistry(env.DOCKER_REGISTRY, env.DOCKER_REGISTRY_CREDENTIALS){
def app_image = docker.build(env.DOCKER_REPO,
"--no-cache --force-rm --build-arg branch=${env.BRANCH_NAME} -f ${env.APP_DOCKERFILE} .")
app_image.push()
}
}
}
post {
failure {
docker_clean()
}
}
}
}
post {
// publish results and clean-up
Expand Down

0 comments on commit 88ddef5

Please sign in to comment.