Added pipeline clause
This commit is contained in:
		
							
								
								
									
										121
									
								
								.woodpecker.yml
									
									
									
									
									
								
							
							
						
						
									
										121
									
								
								.woodpecker.yml
									
									
									
									
									
								
							@@ -1,67 +1,68 @@
 | 
			
		||||
when:
 | 
			
		||||
  - event: push
 | 
			
		||||
    branch: woodpecker
 | 
			
		||||
pipeline:
 | 
			
		||||
  when:
 | 
			
		||||
    - event: push
 | 
			
		||||
      branch: woodpecker
 | 
			
		||||
 | 
			
		||||
steps:
 | 
			
		||||
  - name: code-tests
 | 
			
		||||
    image: python:3.11.7-alpine
 | 
			
		||||
    commands:
 | 
			
		||||
      - cd api
 | 
			
		||||
      - python3 -m venv env
 | 
			
		||||
      - source env/bin/activate
 | 
			
		||||
      - pip install -r requirements.txt pytest
 | 
			
		||||
      - python3 -m pytest --junit-xml=pytest_junit.xml
 | 
			
		||||
  steps:
 | 
			
		||||
    - name: code-tests
 | 
			
		||||
      image: python:3.11.7-alpine
 | 
			
		||||
      commands:
 | 
			
		||||
        - cd api
 | 
			
		||||
        - python3 -m venv env
 | 
			
		||||
        - source env/bin/activate
 | 
			
		||||
        - pip install -r requirements.txt pytest
 | 
			
		||||
        - python3 -m pytest --junit-xml=pytest_junit.xml
 | 
			
		||||
 | 
			
		||||
  - name: build-and-push
 | 
			
		||||
    image: marcin00.azurecr.io/azure-cli-docker:slim-bookworm
 | 
			
		||||
    environment:
 | 
			
		||||
      ACR_NAME: marcin00
 | 
			
		||||
      CLIENT_ID: c302726f-fafb-4143-94c1-67a70975574a
 | 
			
		||||
      DOCKER_IMAGE: marcin00.azurecr.io/user-microservice:${CI_COMMIT_SHA}
 | 
			
		||||
    commands:
 | 
			
		||||
      - docker build -t ${DOCKER_IMAGE} --build-arg APP_VERSION=${CI_COMMIT_SHA} --build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") .
 | 
			
		||||
      - az login --identity --client-id ${CLIENT_ID}
 | 
			
		||||
      - az acr login --name ${ACR_NAME}
 | 
			
		||||
      - docker push ${DOCKER_IMAGE}
 | 
			
		||||
    backend_options:
 | 
			
		||||
      kubernetes:
 | 
			
		||||
        runtimeClassName: sysbox-runc
 | 
			
		||||
    - name: build-and-push
 | 
			
		||||
      image: marcin00.azurecr.io/azure-cli-docker:slim-bookworm
 | 
			
		||||
      environment:
 | 
			
		||||
        ACR_NAME: marcin00
 | 
			
		||||
        CLIENT_ID: c302726f-fafb-4143-94c1-67a70975574a
 | 
			
		||||
        DOCKER_IMAGE: marcin00.azurecr.io/user-microservice:${CI_COMMIT_SHA}
 | 
			
		||||
      commands:
 | 
			
		||||
        - docker build -t ${DOCKER_IMAGE} --build-arg APP_VERSION=${CI_COMMIT_SHA} --build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") .
 | 
			
		||||
        - az login --identity --client-id ${CLIENT_ID}
 | 
			
		||||
        - az acr login --name ${ACR_NAME}
 | 
			
		||||
        - docker push ${DOCKER_IMAGE}
 | 
			
		||||
      backend_options:
 | 
			
		||||
        kubernetes:
 | 
			
		||||
          runtimeClassName: sysbox-runc
 | 
			
		||||
 | 
			
		||||
  - 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
 | 
			
		||||
    - 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 "${GITEA_KNOWN_HOST}" >> ~/.ssh/known_hosts
 | 
			
		||||
      - chmod 644 ~/.ssh/known_hosts
 | 
			
		||||
        - echo "${GITEA_KNOWN_HOST}" >> ~/.ssh/known_hosts
 | 
			
		||||
        - chmod 644 ~/.ssh/known_hosts
 | 
			
		||||
 | 
			
		||||
      - echo "${GITEA_DEPLOY_KEY}" > ~/.ssh/id_rsa
 | 
			
		||||
      - chmod 600 ~/.ssh/id_rsa
 | 
			
		||||
        - echo "${GITEA_DEPLOY_KEY}" > ~/.ssh/id_rsa
 | 
			
		||||
        - chmod 600 ~/.ssh/id_rsa
 | 
			
		||||
 | 
			
		||||
      - git config --global user.name "woodpecker[bot]"
 | 
			
		||||
      - git config --global user.email "woodpecker@marcin00.pl"
 | 
			
		||||
        - git config --global user.name "woodpecker[bot]"
 | 
			
		||||
        - git config --global user.email "woodpecker@marcin00.pl"
 | 
			
		||||
 | 
			
		||||
      - git clone "${DEPLOY_REPO}" --branch woodpecker-deploy
 | 
			
		||||
      - cd user-microservice-deploy
 | 
			
		||||
      
 | 
			
		||||
      - |
 | 
			
		||||
        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
 | 
			
		||||
      
 | 
			
		||||
      - git add deploy.yaml
 | 
			
		||||
      - 'git diff-index --quiet HEAD || git commit -m "WOODPECKER: Changed deployed version to $CI_COMMIT_SHA"'
 | 
			
		||||
      - git push origin woodpecker-deploy
 | 
			
		||||
        - git clone "${DEPLOY_REPO}" --branch woodpecker-deploy
 | 
			
		||||
        - cd user-microservice-deploy
 | 
			
		||||
        
 | 
			
		||||
        - |
 | 
			
		||||
          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
 | 
			
		||||
        
 | 
			
		||||
        - git add deploy.yaml
 | 
			
		||||
        - 'git diff-index --quiet HEAD || git commit -m "WOODPECKER: Changed deployed version to $CI_COMMIT_SHA"'
 | 
			
		||||
        - git push origin woodpecker-deploy
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user