Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lê Văn Chiến - k8s homework #137

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2b63d8a
update
lechiennn May 15, 2023
a2c3092
update dockerignore
lechiennn May 16, 2023
63aedd1
restructure
lechiennn May 16, 2023
42d0343
restructure
lechiennn May 16, 2023
6358cf7
add unittest
lechiennn May 16, 2023
b756842
add github actions
lechiennn May 16, 2023
99839b9
check github action
lechiennn May 16, 2023
c1d784d
add github action
lechiennn May 16, 2023
20b286d
update github workflow
lechiennn May 16, 2023
2614d91
update github workflow
lechiennn May 16, 2023
f274959
update github workflow
lechiennn May 16, 2023
a9b140f
update github workflow
lechiennn May 16, 2023
9f7a625
add test requirements
lechiennn May 16, 2023
8ab76ef
add CD
lechiennn May 17, 2023
34d4590
update git ignore
lechiennn May 17, 2023
01296bf
update nginx config
lechiennn May 17, 2023
0cd76c5
fix api
lechiennn May 17, 2023
36279cd
add container name
lechiennn May 17, 2023
5920798
update CD
lechiennn May 17, 2023
7ee2758
update CD
lechiennn May 17, 2023
8086939
update CD
lechiennn May 17, 2023
52421da
update CD
lechiennn May 17, 2023
174e2ea
update CD
lechiennn May 17, 2023
cb487b2
update CD workflow
lechiennn May 17, 2023
27d66ba
move ansible to new folder
lechiennn May 17, 2023
0f14a78
update git ignore
lechiennn May 17, 2023
091e70b
update CD workflow
lechiennn May 17, 2023
71da317
fix python path
lechiennn May 18, 2023
8098085
fix api endpoint
lechiennn May 18, 2023
46ae91d
move ansible to 2.Ansible
lechiennn May 21, 2023
e3db9a5
add loadbalancer role
lechiennn May 21, 2023
0317df7
fix roles
lechiennn May 21, 2023
d480fe0
add lb role
lechiennn May 21, 2023
69a1f49
add log & monitor
lechiennn May 21, 2023
69e8781
add README
lechiennn May 21, 2023
28f6e20
add log & monitor
lechiennn May 21, 2023
ed04130
update README.finalfinal
lechiennn May 21, 2023
44684ed
update for k8s hw
lechiennn Jun 12, 2023
9345c1b
add k8s assignment
lechiennn Jun 15, 2023
f97680f
add k8s assignment
lechiennn Jun 15, 2023
fade3a7
rename folder
lechiennn Jun 15, 2023
8b3f98a
update readme
lechiennn Jun 15, 2023
6a54a44
add yaml
lechiennn Jun 15, 2023
f0184fa
Delete Kubernetes directory
lechiennn Jun 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/cd-chienlv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build Dockerfile and push

on:
push:
tags:
- v*

jobs:
docker:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push app image
uses: docker/build-push-action@v4
with:
context: 1. Containerization/Le Van Chien/app/
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/app:${{ github.ref_name }}

- name: Build and push web image
uses: docker/build-push-action@v4
with:
context: 1. Containerization/Le Van Chien/nginx/
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/web:${{ github.ref_name }}
30 changes: 30 additions & 0 deletions .github/workflows/ci-chienlv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI

on:
push:
branches:
- midterm
pull_request:
branches:
- midterm

jobs:
test:
runs-on: ubuntu-20.04

steps:
- name: checkout code
uses: actions/checkout@v3

- name: setup Python
uses: actions/setup-python@v3
with:
python-version: 3.8

- name: install dependencies
run: |
pip install --upgrade pip
pip install -r 1.\ Containerization/Le\ Van\ Chien/app/tests/test_requirements.txt
- name: run tests
working-directory: 1. Containerization/Le Van Chien/app
run: pytest
3 changes: 1 addition & 2 deletions 1. Containerization/Le Van Chien/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
/env
db/*
!db/.gitkeep
ansible/collections/ansible_collections/*
!ansible/collections/ansible_collections/.gitkeep
/app/*/__pycache__

This file was deleted.

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions 1. Containerization/Le Van Chien/ansible/roles/web/tasks/main.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions 1. Containerization/Le Van Chien/app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/tests
/.pytest_cache
76 changes: 53 additions & 23 deletions 1. Containerization/Le Van Chien/app/app.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,59 @@
from flask import Flask
from pymongo import MongoClient
from flask_cors import CORS, cross_origin
import json
from bson import json_util
from project.api import create_app
from project.database import create_db

app = Flask(__name__)
cors = CORS(app)
db = create_db()
app = create_app(db)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)

client = MongoClient('mongodb://db:27017')
client.drop_database('attendee')
db = client.attendee
if 'attendees' not in db.list_collection_names():
with open('data/attendees.json') as f:
data = json.load(f)
db.attendees.insert_many(data)
# from flask import Flask, request
# from pymongo import MongoClient
# from flask_cors import CORS, cross_origin
# import json
# from bson import json_util

@app.route('/people/', methods = ['GET'])
def getAll():
attendees = json_util.dumps(db.attendees.find({}))
return attendees
# app = Flask(__name__)
# cors = CORS(app, resources={r'/people/*': {'origins': '*'}})

@app.route('/people/<int:num>', methods = ['GET'])
def get(num):
return json_util.dumps(db.attendees.find({"no": num}))
# client = MongoClient('mongodb://db:27017')
# client.drop_database('attendee')
# db = client.attendee
# if 'attendees' not in db.list_collection_names():
# with open('data/attendees.json') as f:
# data = json.load(f)
# db.attendees.insert_many(data)

# @app.route('/people/', methods = ['GET'])
# def getAll():
# attendees = json_util.dumps(db.attendees.find({}))
# return attendees

if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)
# @app.route('/people/<int:num>', methods = ['GET'])
# def getByID(num):
# return json_util.dumps(db.attendees.find({"id": num}))

# @app.route('/people/<string:username>', methods = ['GET'])
# def getByUsername(username):
# return json_util.dumps(db.attendees.find({"username": username}))

# @app.route('/people/delete/<string:username>', methods = ['DELETE'])
# def delete(username):
# db.attendees.delete_one({'username': username})
# return json_util.dumps({'message': f'Resource with username {username} deleted'})


# @app.route('/people/create/', methods = ['PUT'])
# def create():
# data = request.get_json()
# db.attendees.insert_one(data)
# return json_util.dumps({'message': 'Resource with username {} created'.format(data['username'])})

# @app.route('/people/update/<string:username>', methods = ['PUT'])
# def update(username):
# data = request.get_json()
# db.attendees.update_one({'username':username}, data)
# return json_util.dumps({'message': 'Resource with username {} updated'.format(username)})


# if __name__ == '__main__':
# app.run(debug=True, host='0.0.0.0', port=5000)
Loading