4 Commits

Author SHA1 Message Date
e6c9675abc Added sysbox as runtimeClass
Some checks failed
ci/woodpecker/push/build Pipeline failed
2025-07-20 11:15:32 +02:00
ebf713f75f Removed Goss from pipeline; added GitOps commit 2025-07-20 11:01:12 +02:00
13f098fc7c Removed Goss 2025-07-20 10:02:27 +02:00
8cf8a92f8d Removed Jenkinsfile 2025-07-20 10:01:57 +02:00
3 changed files with 50 additions and 112 deletions

View File

@ -12,38 +12,56 @@ steps:
- pip install -r requirements.txt pytest - pip install -r requirements.txt pytest
- python3 -m pytest --junit-xml=pytest_junit.xml - python3 -m pytest --junit-xml=pytest_junit.xml
- name: build - name: build-and-push
image: docker:dind image: marcin00.azurecr.io/azure-cli-docker:slim-bookworm
privileged: true
environment: environment:
ACR_USERNAME: marcin00 ACR_NAME: marcin00
ACR_PASSWORD: CLIENT_ID: c302726f-fafb-4143-94c1-67a70975574a
from_secret: acr_password DOCKER_IMAGE: marcin00.azurecr.io/user-microservice:${CI_COMMIT_SHA}
commands: commands:
- dockerd-entrypoint.sh & - docker build -t ${DOCKER_IMAGE} --build-arg APP_VERSION=${CI_COMMIT_SHA} --build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") .
- sleep 10 # czas na uruchomienie usługi Docker - az login --identity --client-id ${CLIENT_ID}
- az acr login --name ${ACR_NAME}
- docker push ${DOCKER_IMAGE}
backend_options:
kubernetes:
runtimeClassName: sysbox-runc
- DOCKER_IMAGE=marcin00.azurecr.io/user-microservice:$CI_COMMIT_SHA - name: gitops-commit
image: alpine/git
environment:
DEPLOY_REPO: ssh://git@srv22.mikr.us:20343/pikram/user-microservice-deploy.git
GITEA_DEPLOY_KEY:
from_secret: gitea-deploy-key
GITEA_KNOWN_HOST:
from_secret: gitea-known-host
commands:
- mkdir -p ~/.ssh
- echo "===> Building Docker image" - echo "${GITEA_KNOWN_HOST}" >> ~/.ssh/known_hosts
- docker build -t $DOCKER_IMAGE . - chmod 644 ~/.ssh/known_hosts
- echo "===> Installing bash" - echo "${GITEA_DEPLOY_KEY}" > ~/.ssh/id_rsa
- apk add --no-cache bash - chmod 600 ~/.ssh/id_rsa
- echo "===> Installing goss" - git config --global user.name "woodpecker[bot]"
- wget https://github.com/aelsabbahy/goss/releases/latest/download/goss-linux-amd64 -O goss - git config --global user.email "woodpecker@marcin00.pl"
- wget https://github.com/aelsabbahy/goss/releases/latest/download/dgoss -O dgoss
- chmod +x *goss
- echo "===> Starting container for test" - git clone "${DEPLOY_REPO}" --branch woodpecker-deploy
- export GOSS_OPTS="-f junit" - cd user-microservice-deploy
- export GOSS_PATH=./goss
- export GOSS_SLEEP=3
- "./dgoss run -e SQLALCHEMY_DATABASE_URI=sqlite:///:memory: $DOCKER_IMAGE > goss_junit.xml"
- echo "===> Logging in to ACR" - |
- echo "$ACR_PASSWORD" | docker login marcin00.azurecr.io -u $ACR_USERNAME --password-stdin awk -v commit="$CI_COMMIT_SHA" '
$0 ~ /name:[[:space:]]*api/ { in_api_container = 1; print; next }
in_api_container && $0 ~ /^[[:space:]]*image:[[:space:]]*/ {
sub(/:[^:[:space:]]+$/, ":" commit)
in_api_container = 0
print
next
}
{ print }
' deploy.yaml > deploy.tmp && mv deploy.tmp deploy.yaml
- echo "===> Pushing image to ACR" - git add deploy.yaml
- docker push $DOCKER_IMAGE - 'git diff-index --quiet HEAD || git commit -m "WOODPECKER: Changed deployed version to $CI_COMMIT_SHA"'
- git push origin woodpecker-deploy

72
Jenkinsfile vendored
View File

@ -1,72 +0,0 @@
pipeline {
agent any
environment {
DOCKER_REGISTRY_URL = 'marcin00.azurecr.io'
DOCKER_IMAGE = "${DOCKER_REGISTRY_URL}/user-microservice:${GIT_COMMIT}"
ACR_NAME = 'marcin00'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Test python app') {
steps {
script {
dir('api') {
sh '''
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt pytest
python3 -m pytest --junit-xml=pytest_junit.xml
'''
}
}
}
post {
always {
junit testResults: '**/*pytest_junit.xml'
}
}
}
stage('Build & test docker image') {
steps {
script {
appImage = docker.build("${DOCKER_IMAGE}")
sh label: 'Install dgoss', script: '''
curl -s -L https://github.com/aelsabbahy/goss/releases/latest/download/goss-linux-amd64 -o goss
curl -s -L https://github.com/aelsabbahy/goss/releases/latest/download/dgoss -o dgoss
chmod +rx *goss
'''
withEnv(['GOSS_OPTS=-f junit', 'GOSS_PATH=./goss', 'GOSS_SLEEP=3', 'SQLALCHEMY_DATABASE_URI=sqlite:///:memory:']) {
sh label: 'run image tests', script: './dgoss run -e SQLALCHEMY_DATABASE_URI=sqlite:///:memory: ${DOCKER_IMAGE} > goss_junit.xml'
}
}
}
post {
always {
junit testResults: '**/*goss_junit.xml'
}
}
}
stage('Deploy') {
steps {
script {
sh '''
az login --identity
az acr login --name ${ACR_NAME}
docker push ${DOCKER_IMAGE}
'''
}
}
}
}
post {
cleanup {
script { cleanWs() }
}
}
}

View File

@ -1,8 +0,0 @@
port:
tcp:80:
listening: true
ip:
- 0.0.0.0
process:
python3:
running: true