test pipeline 1
This commit is contained in:
parent
97781e3d2a
commit
ad4636e4b8
44
.gitea/workflows/ci.yaml
Normal file
44
.gitea/workflows/ci.yaml
Normal file
@ -0,0 +1,44 @@
|
||||
name: CI Pipeline
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.9'
|
||||
- name: Install dependencies
|
||||
run: pip install flake8
|
||||
- name: Run linting
|
||||
run: flake8 . --max-line-length=120
|
||||
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.9'
|
||||
- name: Install dependencies
|
||||
run: pip install -r requirements.txt
|
||||
- name: Run tests
|
||||
run: pytest test_app.py
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [lint, test]
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Build Docker image
|
||||
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/my-flask-app:${{ github.sha }} .
|
1
README copy.md
Normal file
1
README copy.md
Normal file
@ -0,0 +1 @@
|
||||
# test1
|
37
ansible/inventory.yml
Normal file
37
ansible/inventory.yml
Normal file
@ -0,0 +1,37 @@
|
||||
all:
|
||||
hosts:
|
||||
first_vm:
|
||||
ansible_host: 192.168.0.23
|
||||
second_vm:
|
||||
ansible_host: 192.168.0.27
|
||||
tretiy_vm:
|
||||
ansible_host: 192.168.0.28
|
||||
vars:
|
||||
ansible_user: ansible
|
||||
ansible_password: 123qwe123
|
||||
ansible_connection: ssh
|
||||
ansible_port: 22
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#all:
|
||||
# hosts:
|
||||
# first_vm:
|
||||
# ansible_host: 192.168.0.23
|
||||
# ansible_user: ansible
|
||||
# ansible_password: 123qwe123
|
||||
# ansible_connection: ssh
|
||||
# ansible_port: 22
|
||||
# second_vm:
|
||||
# ansible_host: 192.168.0.27
|
||||
# ansible_user: ansible
|
||||
# ansible_password: 123qwe123
|
||||
# ansible_connection: ssh
|
||||
# ansible_port: 22
|
||||
# tretiy_vm:
|
||||
# ansible_host: 192.168.0.28
|
||||
# ansible_user: ansible
|
||||
# ansible_password: 123qwe123
|
||||
# ansible_connection: ssh
|
||||
# ansible_port: 22
|
14
ansible/playbook.yml
Normal file
14
ansible/playbook.yml
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
- name: install and start nginx
|
||||
hosts: all
|
||||
become: yes
|
||||
tasks:
|
||||
- name: install ngnx
|
||||
apt:
|
||||
name: nginx
|
||||
state: latest
|
||||
- name: start engineX
|
||||
service:
|
||||
name: nginx
|
||||
state: started
|
||||
enabled: yes
|
9
app.py
Normal file
9
app.py
Normal file
@ -0,0 +1,9 @@
|
||||
from flask import Flask
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def hello():
|
||||
return 'Hello, DevOps!'
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000)
|
7
dockerfile
Normal file
7
dockerfile
Normal file
@ -0,0 +1,7 @@
|
||||
FROM python:3.9-slim
|
||||
WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
RUN pip install -r requirements.txt
|
||||
COPY . .
|
||||
EXPOSE 5000
|
||||
CMD ["python", "app.py"]
|
35
jenkinsfile
Normal file
35
jenkinsfile
Normal file
@ -0,0 +1,35 @@
|
||||
pipeline {
|
||||
agent {label 'vm-oracle'}
|
||||
environment{
|
||||
IMAGE_NAME = "test-flask-app2"
|
||||
IMAGE_TAG = "${env.BUILD_NUMBER}"
|
||||
CONTAINER_NAME = "test-app"
|
||||
}
|
||||
stages{
|
||||
stage('Checkout'){
|
||||
steps{
|
||||
git url: 'https://github.com/ScoobyBo/test1.git', branch: 'main'
|
||||
}
|
||||
}
|
||||
stage('Build docker image'){
|
||||
steps{
|
||||
sh 'docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .'
|
||||
}
|
||||
}
|
||||
stage('deploy container'){
|
||||
steps{
|
||||
sh 'docker run -d --name $CONTAINER_NAME -p 5000:5000 ${IMAGE_NAME}:${IMAGE_TAG}'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
post{
|
||||
always {
|
||||
sh "echo 'Cleaning up container ${CONTAINER_NAME} and удали свою жопу дубина ${IMAGE_NAME}:${IMAGE_TAG}'"
|
||||
sh "docker stop ${CONTAINER_NAME} || true"
|
||||
sh "docker rm ${CONTAINER_NAME} || true"
|
||||
sh "docker rmi ${IMAGE_NAME}:${IMAGE_TAG} || true"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
flask==2.0.1
|
||||
pytest==7.4.0
|
||||
Werkzeug==2.0.3
|
8
test_app.py
Normal file
8
test_app.py
Normal file
@ -0,0 +1,8 @@
|
||||
from app import app
|
||||
import pytest
|
||||
|
||||
def test_hello():
|
||||
with app.test_client() as client:
|
||||
response = client.get('/')
|
||||
assert response.data == b'Hello, DevOps!'
|
||||
assert response.status_code == 200
|
Loading…
x
Reference in New Issue
Block a user