+ {% block title %}{% endblock %}Viettel intern list
+
+
+
+
+
+
Intern Members
+
+
+
+
Name
+
Username
+
Birth of Year
+
Gender
+
Major
+
University
+
+
+
+ {% for user in data_student %}
+
+
{{ user.name }}
+
{{ user.username}}
+
{{ user.birth_year }}
+
{{ user.gender }}
+
{{ user.major }}
+
{{ user.university }}
+
+ {% endfor %}
+
+
+
+
+
\ No newline at end of file
diff --git a/Midterm/DoAnhTu/app/requirements.txt b/Midterm/DoAnhTu/app/requirements.txt
new file mode 100644
index 000000000..a5053ceec
--- /dev/null
+++ b/Midterm/DoAnhTu/app/requirements.txt
@@ -0,0 +1,11 @@
+blinker==1.6.2
+click==8.1.3
+dnspython==2.3.0
+Flask==2.3.1
+Flask-PyMongo==2.3.0
+itsdangerous==2.1.2
+Jinja2==3.1.2
+MarkupSafe==2.1.2
+pymongo==4.3.3
+
+Werkzeug==2.3.1
diff --git a/Midterm/DoAnhTu/docker-compose.yml b/Midterm/DoAnhTu/docker-compose.yml
new file mode 100644
index 000000000..1e4981f20
--- /dev/null
+++ b/Midterm/DoAnhTu/docker-compose.yml
@@ -0,0 +1,48 @@
+version: '3'
+services:
+ appuser:
+ build: ./app
+ depends_on:
+ - dbmongo
+ ports:
+ - 5000:5000
+ networks:
+ - db
+ - app
+
+
+ nginx-production:
+ image: nginx:1.22.0-alpine
+ ports:
+ - 8000:80
+ volumes:
+ - ./nginx/conf.d/:/etc/nginx/conf.d/
+ depends_on:
+ - appuser
+ networks:
+ - app
+
+
+ dbmongo:
+ image: mongo:5.0
+
+ environment:
+ - MONGO_INITDB_ROOT_USERNAME=admin
+ - MONGO_INITDB_ROOT_PASSWORD=Admin123
+ - MONGO_INITDB_DATABASE=VDTuser
+
+ ports:
+ - 27017:27017
+ volumes:
+ - db1:/data/db
+ - ./mongo-entrypoint:/docker-entrypoint-initdb.d
+ networks:
+ - db
+volumes:
+ db1:
+
+networks:
+ db:
+ driver: bridge
+ app:
+ driver: bridge
diff --git a/Midterm/DoAnhTu/mongo-entrypoint/init-mongo.js b/Midterm/DoAnhTu/mongo-entrypoint/init-mongo.js
new file mode 100644
index 000000000..a189e1b41
--- /dev/null
+++ b/Midterm/DoAnhTu/mongo-entrypoint/init-mongo.js
@@ -0,0 +1,284 @@
+db = db.getSiblingDB("VDTuser");
+db.user.drop();
+db.user.insertMany([{
+ "name": "Bùi Minh Sơn",
+ "username":"sonbm",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Đào Đại Hiệp",
+ "username":"hiepdd",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Điện tử viễn thông",
+ "university": "Đại học Bách khoa Hà Nội"
+ },
+ {
+ "name": "Đỗ Bảo Hoàng",
+ "username":"hoangdb",
+ "year_of_birth": "1997",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": " Hoàng Quốc Doanh",
+ "username":"doanhhq",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"NULL",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Đỗ Anh Tú",
+ "username":"tuda",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Mạng máy tính và truyền thông dữ liệu",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Lê Minh Đức",
+ "username":"duclm",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin ứng dụng phần mềm",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Lê Phúc Lai",
+ "username":"lailp",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Kỹ thuật điện tử viễn thông",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Lê Quang Anh",
+ "username":"anhlq",
+ "year_of_birth": "1997",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Lê Trọng Minh",
+ "username":"minhlt",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Kỹ thuật điều khiển và tự động hóa",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Lê Tùng Lâm",
+ "username":"lamlt",
+ "year_of_birth": "1999",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Lê Văn Chiến",
+ "username":"chienlv",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Kỹ thuật hàng không vũ trụ",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Nguyễn Thị Linh",
+ "username":"linhnt",
+ "year_of_birth": "2002",
+ "gender":"Nữ",
+ "major":"ICT",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Nguyễn Đại An",
+ "username":"annd",
+ "year_of_birth": "2023",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Nguyễn Đình Hoàng",
+ "username":"hoangdn",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin ứng dụng phần mềm",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": " Nguyễn Đức Vinh",
+ "username":"vinhnd",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"NULL",
+ "university": "Học viện Công nghệ Bưu chính Viễn thông"
+ },
+ {
+ "name": " Nguyễn Dương Long",
+ "username":"longnd",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin ứng dụng phần mềm",
+ "university": " ĐH Thuỷ lợi"
+ },
+ {
+ "name": "Nguyễn Hữu Thắng",
+ "username":"thangnh",
+ "year_of_birth": "2000",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": " Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Nguyễn Mạnh Cường",
+ "username":"cuongnm",
+ "year_of_birth": "1997",
+ "gender":"Nam",
+ "major":"Điện tử",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Nguyễn Mạnh Đức",
+ "username":"ducnm",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Học viện Kỹ thuật mật mã"
+ },
+ {
+ "name": "Nguyễn Ngọc Chung",
+ "username":"chungnn",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"NULL",
+ "university": "Học viên Công nghệ Bưu chính Viễn Thông HCM"
+ },
+ {
+ "name": " Nguyễn Tuấn Anh",
+ "username":"anhnt",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": " Nguyễn Văn Quang",
+ "username":"squangnv",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Ninh Chí Hướng",
+ "username":"huongnc",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Học viện Công nghệ Bưu chính viễn thông"
+ },
+ {
+ "name": "Ninh Văn Nghĩa",
+ "username":"nghianv",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Phạm Anh Đức",
+ "username":"ducpa",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Toán ứng dụng và tin học",
+ "university": "Đại học Bách Khoa Hà Nội"
+ },
+ {
+
+ "name": "Phạm Duy Cương",
+ "username":"cuongpd",
+ "year_of_birth": "1997",
+ "gender":"Nam",
+ "major":"Công nghệ điện tử",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Phạm Hồng Thanh",
+ "username":"thanhph",
+ "year_of_birth": "1998",
+ "gender":"Nam",
+ "major":"Phát triển phần mềm",
+ "university": "Swinburne University"
+ },
+ {
+ "name": " Phạm Thị Khánh Linh",
+ "username":"linhptk",
+ "year_of_birth": "2002",
+ "gender":"Nữ",
+ "major":"Mạng máy tính và truyền thông dữ liệu",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Phạm Văn Tới",
+ "username":"toipv",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin ứng dụng phần mềm",
+ "university": "Học viện Công nghệ Bưu chính viễn thông"
+ },
+ {
+ "name": "Trần Đức Mạnh",
+ "username":"manhdt",
+ "year_of_birth": "1998",
+ "gender":"Nam",
+ "major":"Bảo mật thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Trần Mạnh Dũng",
+ "username":"dungtm",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Điện tử viễn thông",
+ "university": "Học viện Công nghệ Bưu chính Viễn thông"
+ },
+ {
+ "name": " Trần Minh Dương",
+ "username":"duongtm",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Mạng máy tính và truyền thông dữ liệu",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Trần Xuân Phú",
+ "username":"phutx",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Trường Đại học Công nghệ thông tin - ĐHQG Tp.Hồ chí Minh"
+ },
+ {
+ "name": "Vũ Hoàng Long",
+ "username":"longvh",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Đại học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Vũ Minh Hiếu",
+ "username":"hieuvm",
+ "year_of_birth": "2000",
+ "gender":"Nam",
+ "major":"Kỹ thuật phần mềm",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ }]);
+
diff --git a/Midterm/DoAnhTu/nginx/conf.d/default.conf b/Midterm/DoAnhTu/nginx/conf.d/default.conf
new file mode 100644
index 000000000..44cd3dced
--- /dev/null
+++ b/Midterm/DoAnhTu/nginx/conf.d/default.conf
@@ -0,0 +1,17 @@
+upstream appuser {
+ server appuser:5000;
+}
+
+
+server {
+ listen 80;
+ server_name _;
+
+ location / {
+ proxy_pass http://appuser;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_set_header X-Forwarded-Host $host;
+ proxy_set_header X-Forwarded-Prefix /;
+ }
+}
\ No newline at end of file
From 5984c469c66165bea0b92e038aeb29543f44104a Mon Sep 17 00:00:00 2001
From: mr8-ubuntu <20021460@vnu.edu.vn>
Date: Thu, 18 May 2023 10:53:40 +0700
Subject: [PATCH 02/49] create crud
---
10.GK /DoAnhTu/.gitignore | 6 +
10.GK /DoAnhTu/app/.dockerignore | 12 +
10.GK /DoAnhTu/app/Dockerfile | 23 ++
10.GK /DoAnhTu/app/VDT/__init__.py | 128 ++++++++
10.GK /DoAnhTu/app/VDT/templates/VDT.html | 58 ++++
10.GK /DoAnhTu/app/requirements.txt | 11 +
10.GK /DoAnhTu/docker-compose.yml | 48 +++
10.GK /DoAnhTu/mongo-entrypoint/init-mongo.js | 284 ++++++++++++++++++
10.GK /DoAnhTu/nginx/conf.d/default.conf | 17 ++
9 files changed, 587 insertions(+)
create mode 100644 10.GK /DoAnhTu/.gitignore
create mode 100644 10.GK /DoAnhTu/app/.dockerignore
create mode 100644 10.GK /DoAnhTu/app/Dockerfile
create mode 100644 10.GK /DoAnhTu/app/VDT/__init__.py
create mode 100644 10.GK /DoAnhTu/app/VDT/templates/VDT.html
create mode 100644 10.GK /DoAnhTu/app/requirements.txt
create mode 100644 10.GK /DoAnhTu/docker-compose.yml
create mode 100644 10.GK /DoAnhTu/mongo-entrypoint/init-mongo.js
create mode 100644 10.GK /DoAnhTu/nginx/conf.d/default.conf
diff --git a/10.GK /DoAnhTu/.gitignore b/10.GK /DoAnhTu/.gitignore
new file mode 100644
index 000000000..07ddd70d4
--- /dev/null
+++ b/10.GK /DoAnhTu/.gitignore
@@ -0,0 +1,6 @@
+.vscode/
+flask-env/
+instance/
+__pycache__/
+
+flask_app/
diff --git a/10.GK /DoAnhTu/app/.dockerignore b/10.GK /DoAnhTu/app/.dockerignore
new file mode 100644
index 000000000..df8f82c7a
--- /dev/null
+++ b/10.GK /DoAnhTu/app/.dockerignore
@@ -0,0 +1,12 @@
+.git
+Dockerfile
+.DS_Store
+.gitignore
+.dockerignore
+
+.vscode
+
+/__pycache__
+/instance
+
+/flask-env
diff --git a/10.GK /DoAnhTu/app/Dockerfile b/10.GK /DoAnhTu/app/Dockerfile
new file mode 100644
index 000000000..55def8633
--- /dev/null
+++ b/10.GK /DoAnhTu/app/Dockerfile
@@ -0,0 +1,23 @@
+FROM python:3.9
+
+ENV FLASK_APP=VDT/__init__.py
+ENV FLASK_ENV=production
+
+
+
+WORKDIR /app
+
+COPY requirements.txt requirements.txt
+
+RUN pip install -r requirements.txt
+
+
+
+COPY . .
+
+EXPOSE 5000
+
+
+
+CMD [ "flask", "run", "--host=0.0.0.0" ]
+
diff --git a/10.GK /DoAnhTu/app/VDT/__init__.py b/10.GK /DoAnhTu/app/VDT/__init__.py
new file mode 100644
index 000000000..700c49738
--- /dev/null
+++ b/10.GK /DoAnhTu/app/VDT/__init__.py
@@ -0,0 +1,128 @@
+import os
+
+from flask import Flask, render_template, request, jsonify, redirect, url_for
+from flask_pymongo import MongoClient
+
+
+def create_app(test_config=None):
+ # create and configure the app
+ app = Flask(__name__, instance_relative_config=True)
+ # connect to db
+
+ client = MongoClient(
+ "mongodb://admin:Admin123@dbmongo:27017/", connectTimeoutMS=3000
+ )
+ VDT_DB = client.VDTuser
+ db = VDT_DB.user
+
+ @app.route("/")
+ def VDT():
+ students = db.find()
+ student_data = []
+
+ for student in students:
+ person = {
+ "name": student["name"],
+ "year_of_birth": student["year_of_birth"],
+ "university": student["university"],
+ "gender": student["gender"],
+ "username": student["username"],
+ "major": student["major"],
+ }
+ student_data.append(person)
+ return render_template("VDT.html", data_student=student_data)
+
+ @app.route("/members", methods=["GET"])
+ def getlistmember():
+ students = db.find()
+ student_data = []
+
+ for student in students:
+ person = {
+ "name": student["name"],
+ "year_of_birth": student["year_of_birth"],
+ "university": student["university"],
+ "gender": student["gender"],
+ "username": student["username"],
+ "major": student["major"],
+ }
+ student_data.append(person)
+ return jsonify(student_data)
+
+ @app.route("/members/", methods=["GET"])
+ def get_student(username):
+ students = db.find()
+ members = []
+ for student in students:
+ person = {
+ "name": student["name"],
+ "year_of_birth": student["year_of_birth"],
+ "university": student["university"],
+ "gender": student["gender"],
+ "username": student["username"],
+ "major": student["major"],
+ }
+ if student["username"] == username:
+ members.append(person)
+ return jsonify(members)
+
+ @app.route("/postdata", methods=["POST"])
+ def post_student():
+ name = request.json["name"]
+ year_of_birth = request.json["year_of_birth"]
+ university = request.json["university"]
+ gender = request.json["gender"]
+ username = request.json["username"]
+ major = request.json["major"]
+
+ db.insert_one(
+ {
+ "name": name,
+ "year_of_birth": year_of_birth,
+ "university": university,
+ "gender": gender,
+ "username": username,
+ "major": major,
+ }
+ )
+ return jsonify(
+ {
+ "name": name,
+ "year_of_birth": year_of_birth,
+ "university": university,
+ "gender": gender,
+ "username": username,
+ "major": major,
+ }
+ )
+
+ @app.route("/delmember/", methods=["DELETE"])
+ def del_mem(username):
+ db.delete_one({"username": username})
+ return redirect(url_for("getlistmember"))
+
+ @app.route("/updatemember/", methods=["PUT"])
+ def up_mem(username):
+ name = request.json["name"]
+ year_of_birth = request.json["year_of_birth"]
+ university = request.json["university"]
+ gender = request.json["gender"]
+ update_username = request.json["username"]
+ major = request.json["major"]
+
+ myquery = {"username": username}
+ myupdate = {
+ "$set": {
+ "name": name,
+ "year_of_birth": year_of_birth,
+ "university": university,
+ "gender": gender,
+ "username": update_username,
+ "major": major,
+ }
+ }
+ db.update_one(myquery, myupdate)
+
+ return redirect(url_for("getlistmember"))
+
+ return app
diff --git a/10.GK /DoAnhTu/app/VDT/templates/VDT.html b/10.GK /DoAnhTu/app/VDT/templates/VDT.html
new file mode 100644
index 000000000..c00929770
--- /dev/null
+++ b/10.GK /DoAnhTu/app/VDT/templates/VDT.html
@@ -0,0 +1,58 @@
+
+
+
+
+ {% block title %}{% endblock %}Viettel intern list
+
+
+
+
+
+
Intern Members
+
+
+
+
Name
+
Username
+
Birth of Year
+
Gender
+
Major
+
University
+
+
+
+ {% for user in data_student %}
+
+
{{ user.name }}
+
{{ user.username}}
+
{{ user.year_of_birth }}
+
{{ user.gender }}
+
{{ user.major }}
+
{{ user.university }}
+
+ {% endfor %}
+
+
+
+
+
\ No newline at end of file
diff --git a/10.GK /DoAnhTu/app/requirements.txt b/10.GK /DoAnhTu/app/requirements.txt
new file mode 100644
index 000000000..a5053ceec
--- /dev/null
+++ b/10.GK /DoAnhTu/app/requirements.txt
@@ -0,0 +1,11 @@
+blinker==1.6.2
+click==8.1.3
+dnspython==2.3.0
+Flask==2.3.1
+Flask-PyMongo==2.3.0
+itsdangerous==2.1.2
+Jinja2==3.1.2
+MarkupSafe==2.1.2
+pymongo==4.3.3
+
+Werkzeug==2.3.1
diff --git a/10.GK /DoAnhTu/docker-compose.yml b/10.GK /DoAnhTu/docker-compose.yml
new file mode 100644
index 000000000..1e4981f20
--- /dev/null
+++ b/10.GK /DoAnhTu/docker-compose.yml
@@ -0,0 +1,48 @@
+version: '3'
+services:
+ appuser:
+ build: ./app
+ depends_on:
+ - dbmongo
+ ports:
+ - 5000:5000
+ networks:
+ - db
+ - app
+
+
+ nginx-production:
+ image: nginx:1.22.0-alpine
+ ports:
+ - 8000:80
+ volumes:
+ - ./nginx/conf.d/:/etc/nginx/conf.d/
+ depends_on:
+ - appuser
+ networks:
+ - app
+
+
+ dbmongo:
+ image: mongo:5.0
+
+ environment:
+ - MONGO_INITDB_ROOT_USERNAME=admin
+ - MONGO_INITDB_ROOT_PASSWORD=Admin123
+ - MONGO_INITDB_DATABASE=VDTuser
+
+ ports:
+ - 27017:27017
+ volumes:
+ - db1:/data/db
+ - ./mongo-entrypoint:/docker-entrypoint-initdb.d
+ networks:
+ - db
+volumes:
+ db1:
+
+networks:
+ db:
+ driver: bridge
+ app:
+ driver: bridge
diff --git a/10.GK /DoAnhTu/mongo-entrypoint/init-mongo.js b/10.GK /DoAnhTu/mongo-entrypoint/init-mongo.js
new file mode 100644
index 000000000..a189e1b41
--- /dev/null
+++ b/10.GK /DoAnhTu/mongo-entrypoint/init-mongo.js
@@ -0,0 +1,284 @@
+db = db.getSiblingDB("VDTuser");
+db.user.drop();
+db.user.insertMany([{
+ "name": "Bùi Minh Sơn",
+ "username":"sonbm",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Đào Đại Hiệp",
+ "username":"hiepdd",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Điện tử viễn thông",
+ "university": "Đại học Bách khoa Hà Nội"
+ },
+ {
+ "name": "Đỗ Bảo Hoàng",
+ "username":"hoangdb",
+ "year_of_birth": "1997",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": " Hoàng Quốc Doanh",
+ "username":"doanhhq",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"NULL",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Đỗ Anh Tú",
+ "username":"tuda",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Mạng máy tính và truyền thông dữ liệu",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Lê Minh Đức",
+ "username":"duclm",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin ứng dụng phần mềm",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Lê Phúc Lai",
+ "username":"lailp",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Kỹ thuật điện tử viễn thông",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Lê Quang Anh",
+ "username":"anhlq",
+ "year_of_birth": "1997",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Lê Trọng Minh",
+ "username":"minhlt",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Kỹ thuật điều khiển và tự động hóa",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Lê Tùng Lâm",
+ "username":"lamlt",
+ "year_of_birth": "1999",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Lê Văn Chiến",
+ "username":"chienlv",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Kỹ thuật hàng không vũ trụ",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Nguyễn Thị Linh",
+ "username":"linhnt",
+ "year_of_birth": "2002",
+ "gender":"Nữ",
+ "major":"ICT",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Nguyễn Đại An",
+ "username":"annd",
+ "year_of_birth": "2023",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Nguyễn Đình Hoàng",
+ "username":"hoangdn",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin ứng dụng phần mềm",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": " Nguyễn Đức Vinh",
+ "username":"vinhnd",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"NULL",
+ "university": "Học viện Công nghệ Bưu chính Viễn thông"
+ },
+ {
+ "name": " Nguyễn Dương Long",
+ "username":"longnd",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin ứng dụng phần mềm",
+ "university": " ĐH Thuỷ lợi"
+ },
+ {
+ "name": "Nguyễn Hữu Thắng",
+ "username":"thangnh",
+ "year_of_birth": "2000",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": " Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Nguyễn Mạnh Cường",
+ "username":"cuongnm",
+ "year_of_birth": "1997",
+ "gender":"Nam",
+ "major":"Điện tử",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Nguyễn Mạnh Đức",
+ "username":"ducnm",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Học viện Kỹ thuật mật mã"
+ },
+ {
+ "name": "Nguyễn Ngọc Chung",
+ "username":"chungnn",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"NULL",
+ "university": "Học viên Công nghệ Bưu chính Viễn Thông HCM"
+ },
+ {
+ "name": " Nguyễn Tuấn Anh",
+ "username":"anhnt",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": " Nguyễn Văn Quang",
+ "username":"squangnv",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Ninh Chí Hướng",
+ "username":"huongnc",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Học viện Công nghệ Bưu chính viễn thông"
+ },
+ {
+ "name": "Ninh Văn Nghĩa",
+ "username":"nghianv",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Phạm Anh Đức",
+ "username":"ducpa",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Toán ứng dụng và tin học",
+ "university": "Đại học Bách Khoa Hà Nội"
+ },
+ {
+
+ "name": "Phạm Duy Cương",
+ "username":"cuongpd",
+ "year_of_birth": "1997",
+ "gender":"Nam",
+ "major":"Công nghệ điện tử",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Phạm Hồng Thanh",
+ "username":"thanhph",
+ "year_of_birth": "1998",
+ "gender":"Nam",
+ "major":"Phát triển phần mềm",
+ "university": "Swinburne University"
+ },
+ {
+ "name": " Phạm Thị Khánh Linh",
+ "username":"linhptk",
+ "year_of_birth": "2002",
+ "gender":"Nữ",
+ "major":"Mạng máy tính và truyền thông dữ liệu",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Phạm Văn Tới",
+ "username":"toipv",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin ứng dụng phần mềm",
+ "university": "Học viện Công nghệ Bưu chính viễn thông"
+ },
+ {
+ "name": "Trần Đức Mạnh",
+ "username":"manhdt",
+ "year_of_birth": "1998",
+ "gender":"Nam",
+ "major":"Bảo mật thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Trần Mạnh Dũng",
+ "username":"dungtm",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Điện tử viễn thông",
+ "university": "Học viện Công nghệ Bưu chính Viễn thông"
+ },
+ {
+ "name": " Trần Minh Dương",
+ "username":"duongtm",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Mạng máy tính và truyền thông dữ liệu",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Trần Xuân Phú",
+ "username":"phutx",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Trường Đại học Công nghệ thông tin - ĐHQG Tp.Hồ chí Minh"
+ },
+ {
+ "name": "Vũ Hoàng Long",
+ "username":"longvh",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Đại học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Vũ Minh Hiếu",
+ "username":"hieuvm",
+ "year_of_birth": "2000",
+ "gender":"Nam",
+ "major":"Kỹ thuật phần mềm",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ }]);
+
diff --git a/10.GK /DoAnhTu/nginx/conf.d/default.conf b/10.GK /DoAnhTu/nginx/conf.d/default.conf
new file mode 100644
index 000000000..44cd3dced
--- /dev/null
+++ b/10.GK /DoAnhTu/nginx/conf.d/default.conf
@@ -0,0 +1,17 @@
+upstream appuser {
+ server appuser:5000;
+}
+
+
+server {
+ listen 80;
+ server_name _;
+
+ location / {
+ proxy_pass http://appuser;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_set_header X-Forwarded-Host $host;
+ proxy_set_header X-Forwarded-Prefix /;
+ }
+}
\ No newline at end of file
From d6c00a19883057cdfa5dd11d05e03853850f19bd Mon Sep 17 00:00:00 2001
From: mr8-ubuntu <20021460@vnu.edu.vn>
Date: Thu, 18 May 2023 10:56:17 +0700
Subject: [PATCH 03/49] rename folder to 10.GK
---
Midterm/DoAnhTu/.gitignore | 5 -
Midterm/DoAnhTu/app/.dockerignore | 12 -
Midterm/DoAnhTu/app/Dockerfile | 23 --
Midterm/DoAnhTu/app/VDT/__init__.py | 42 ---
Midterm/DoAnhTu/app/VDT/templates/VDT.html | 58 ----
Midterm/DoAnhTu/app/requirements.txt | 11 -
Midterm/DoAnhTu/docker-compose.yml | 48 ---
.../DoAnhTu/mongo-entrypoint/init-mongo.js | 284 ------------------
Midterm/DoAnhTu/nginx/conf.d/default.conf | 17 --
9 files changed, 500 deletions(-)
delete mode 100644 Midterm/DoAnhTu/.gitignore
delete mode 100644 Midterm/DoAnhTu/app/.dockerignore
delete mode 100644 Midterm/DoAnhTu/app/Dockerfile
delete mode 100644 Midterm/DoAnhTu/app/VDT/__init__.py
delete mode 100644 Midterm/DoAnhTu/app/VDT/templates/VDT.html
delete mode 100644 Midterm/DoAnhTu/app/requirements.txt
delete mode 100644 Midterm/DoAnhTu/docker-compose.yml
delete mode 100644 Midterm/DoAnhTu/mongo-entrypoint/init-mongo.js
delete mode 100644 Midterm/DoAnhTu/nginx/conf.d/default.conf
diff --git a/Midterm/DoAnhTu/.gitignore b/Midterm/DoAnhTu/.gitignore
deleted file mode 100644
index b6b9bf430..000000000
--- a/Midterm/DoAnhTu/.gitignore
+++ /dev/null
@@ -1,5 +0,0 @@
-.vscode/
-flask-env/
-instance/
-__pycache__/
-
diff --git a/Midterm/DoAnhTu/app/.dockerignore b/Midterm/DoAnhTu/app/.dockerignore
deleted file mode 100644
index df8f82c7a..000000000
--- a/Midterm/DoAnhTu/app/.dockerignore
+++ /dev/null
@@ -1,12 +0,0 @@
-.git
-Dockerfile
-.DS_Store
-.gitignore
-.dockerignore
-
-.vscode
-
-/__pycache__
-/instance
-
-/flask-env
diff --git a/Midterm/DoAnhTu/app/Dockerfile b/Midterm/DoAnhTu/app/Dockerfile
deleted file mode 100644
index 55def8633..000000000
--- a/Midterm/DoAnhTu/app/Dockerfile
+++ /dev/null
@@ -1,23 +0,0 @@
-FROM python:3.9
-
-ENV FLASK_APP=VDT/__init__.py
-ENV FLASK_ENV=production
-
-
-
-WORKDIR /app
-
-COPY requirements.txt requirements.txt
-
-RUN pip install -r requirements.txt
-
-
-
-COPY . .
-
-EXPOSE 5000
-
-
-
-CMD [ "flask", "run", "--host=0.0.0.0" ]
-
diff --git a/Midterm/DoAnhTu/app/VDT/__init__.py b/Midterm/DoAnhTu/app/VDT/__init__.py
deleted file mode 100644
index dceb01bb1..000000000
--- a/Midterm/DoAnhTu/app/VDT/__init__.py
+++ /dev/null
@@ -1,42 +0,0 @@
-import os
-
-from flask import Flask, render_template, request
-from flask_pymongo import MongoClient
-
-
-def create_app(test_config=None):
- # create and configure the app
- app = Flask(__name__, instance_relative_config=True)
- # connect to db
-
- client = MongoClient('mongodb://admin:Admin123@dbmongo:27017/', connectTimeoutMS=3000)
- VDT_DB = client.VDTuser
- db = VDT_DB.user
-
- # a simple page that says hello
- @app.route('/')
- def hello():
-
- student = db.find_one({"name": "Đỗ Anh Tú"})
- print(student)
- return str(student["name"]) + " VDT Hello"
-
- @app.route('/VDT')
- def VDT():
- students = db.find()
- student_data = []
-
- for student in students:
- person = {
- "name": student["name"],
- "birth_year": student["year_of_birth"],
- 'university': student["university"],
- "gender": student["gender"],
- "username": student["username"],
- "major":student["major"]
- }
- student_data.append(person)
- print(student_data)
- return render_template("VDT.html", data_student=student_data)
-
- return app
diff --git a/Midterm/DoAnhTu/app/VDT/templates/VDT.html b/Midterm/DoAnhTu/app/VDT/templates/VDT.html
deleted file mode 100644
index db63462ca..000000000
--- a/Midterm/DoAnhTu/app/VDT/templates/VDT.html
+++ /dev/null
@@ -1,58 +0,0 @@
-
-
-
-
- {% block title %}{% endblock %}Viettel intern list
-
-
-
-
-
-
Intern Members
-
-
-
-
Name
-
Username
-
Birth of Year
-
Gender
-
Major
-
University
-
-
-
- {% for user in data_student %}
-
-
{{ user.name }}
-
{{ user.username}}
-
{{ user.birth_year }}
-
{{ user.gender }}
-
{{ user.major }}
-
{{ user.university }}
-
- {% endfor %}
-
-
-
-
-
\ No newline at end of file
diff --git a/Midterm/DoAnhTu/app/requirements.txt b/Midterm/DoAnhTu/app/requirements.txt
deleted file mode 100644
index a5053ceec..000000000
--- a/Midterm/DoAnhTu/app/requirements.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-blinker==1.6.2
-click==8.1.3
-dnspython==2.3.0
-Flask==2.3.1
-Flask-PyMongo==2.3.0
-itsdangerous==2.1.2
-Jinja2==3.1.2
-MarkupSafe==2.1.2
-pymongo==4.3.3
-
-Werkzeug==2.3.1
diff --git a/Midterm/DoAnhTu/docker-compose.yml b/Midterm/DoAnhTu/docker-compose.yml
deleted file mode 100644
index 1e4981f20..000000000
--- a/Midterm/DoAnhTu/docker-compose.yml
+++ /dev/null
@@ -1,48 +0,0 @@
-version: '3'
-services:
- appuser:
- build: ./app
- depends_on:
- - dbmongo
- ports:
- - 5000:5000
- networks:
- - db
- - app
-
-
- nginx-production:
- image: nginx:1.22.0-alpine
- ports:
- - 8000:80
- volumes:
- - ./nginx/conf.d/:/etc/nginx/conf.d/
- depends_on:
- - appuser
- networks:
- - app
-
-
- dbmongo:
- image: mongo:5.0
-
- environment:
- - MONGO_INITDB_ROOT_USERNAME=admin
- - MONGO_INITDB_ROOT_PASSWORD=Admin123
- - MONGO_INITDB_DATABASE=VDTuser
-
- ports:
- - 27017:27017
- volumes:
- - db1:/data/db
- - ./mongo-entrypoint:/docker-entrypoint-initdb.d
- networks:
- - db
-volumes:
- db1:
-
-networks:
- db:
- driver: bridge
- app:
- driver: bridge
diff --git a/Midterm/DoAnhTu/mongo-entrypoint/init-mongo.js b/Midterm/DoAnhTu/mongo-entrypoint/init-mongo.js
deleted file mode 100644
index a189e1b41..000000000
--- a/Midterm/DoAnhTu/mongo-entrypoint/init-mongo.js
+++ /dev/null
@@ -1,284 +0,0 @@
-db = db.getSiblingDB("VDTuser");
-db.user.drop();
-db.user.insertMany([{
- "name": "Bùi Minh Sơn",
- "username":"sonbm",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Công nghệ thông tin",
- "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
- },
- {
- "name": "Đào Đại Hiệp",
- "username":"hiepdd",
- "year_of_birth": "2001",
- "gender":"Nam",
- "major":"Điện tử viễn thông",
- "university": "Đại học Bách khoa Hà Nội"
- },
- {
- "name": "Đỗ Bảo Hoàng",
- "username":"hoangdb",
- "year_of_birth": "1997",
- "gender":"Nam",
- "major":"An toàn thông tin",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": " Hoàng Quốc Doanh",
- "username":"doanhhq",
- "year_of_birth": "2001",
- "gender":"Nam",
- "major":"NULL",
- "university": "Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Đỗ Anh Tú",
- "username":"tuda",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Mạng máy tính và truyền thông dữ liệu",
- "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
- },
- {
- "name": "Lê Minh Đức",
- "username":"duclm",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Công nghệ thông tin ứng dụng phần mềm",
- "university": "Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Lê Phúc Lai",
- "username":"lailp",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Kỹ thuật điện tử viễn thông",
- "university": "Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Lê Quang Anh",
- "username":"anhlq",
- "year_of_birth": "1997",
- "gender":"Nam",
- "major":"An toàn thông tin",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": "Lê Trọng Minh",
- "username":"minhlt",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Kỹ thuật điều khiển và tự động hóa",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": "Lê Tùng Lâm",
- "username":"lamlt",
- "year_of_birth": "1999",
- "gender":"Nam",
- "major":"Khoa học máy tính",
- "university": "Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Lê Văn Chiến",
- "username":"chienlv",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Kỹ thuật hàng không vũ trụ",
- "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
- },
- {
- "name": "Nguyễn Thị Linh",
- "username":"linhnt",
- "year_of_birth": "2002",
- "gender":"Nữ",
- "major":"ICT",
- "university": "Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Nguyễn Đại An",
- "username":"annd",
- "year_of_birth": "2023",
- "gender":"Nam",
- "major":"Khoa học máy tính",
- "university": "Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Nguyễn Đình Hoàng",
- "username":"hoangdn",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Công nghệ thông tin ứng dụng phần mềm",
- "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
- },
- {
- "name": " Nguyễn Đức Vinh",
- "username":"vinhnd",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"NULL",
- "university": "Học viện Công nghệ Bưu chính Viễn thông"
- },
- {
- "name": " Nguyễn Dương Long",
- "username":"longnd",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Công nghệ thông tin ứng dụng phần mềm",
- "university": " ĐH Thuỷ lợi"
- },
- {
- "name": "Nguyễn Hữu Thắng",
- "username":"thangnh",
- "year_of_birth": "2000",
- "gender":"Nam",
- "major":"Khoa học máy tính",
- "university": " Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Nguyễn Mạnh Cường",
- "username":"cuongnm",
- "year_of_birth": "1997",
- "gender":"Nam",
- "major":"Điện tử",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": "Nguyễn Mạnh Đức",
- "username":"ducnm",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"An toàn thông tin",
- "university": "Học viện Kỹ thuật mật mã"
- },
- {
- "name": "Nguyễn Ngọc Chung",
- "username":"chungnn",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"NULL",
- "university": "Học viên Công nghệ Bưu chính Viễn Thông HCM"
- },
- {
- "name": " Nguyễn Tuấn Anh",
- "username":"anhnt",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"An toàn thông tin",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": " Nguyễn Văn Quang",
- "username":"squangnv",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"An toàn thông tin",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": "Ninh Chí Hướng",
- "username":"huongnc",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"An toàn thông tin",
- "university": "Học viện Công nghệ Bưu chính viễn thông"
- },
- {
- "name": "Ninh Văn Nghĩa",
- "username":"nghianv",
- "year_of_birth": "2001",
- "gender":"Nam",
- "major":"Khoa học máy tính",
- "university": "Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Phạm Anh Đức",
- "username":"ducpa",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Toán ứng dụng và tin học",
- "university": "Đại học Bách Khoa Hà Nội"
- },
- {
-
- "name": "Phạm Duy Cương",
- "username":"cuongpd",
- "year_of_birth": "1997",
- "gender":"Nam",
- "major":"Công nghệ điện tử",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": "Phạm Hồng Thanh",
- "username":"thanhph",
- "year_of_birth": "1998",
- "gender":"Nam",
- "major":"Phát triển phần mềm",
- "university": "Swinburne University"
- },
- {
- "name": " Phạm Thị Khánh Linh",
- "username":"linhptk",
- "year_of_birth": "2002",
- "gender":"Nữ",
- "major":"Mạng máy tính và truyền thông dữ liệu",
- "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
- },
- {
- "name": "Phạm Văn Tới",
- "username":"toipv",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Công nghệ thông tin ứng dụng phần mềm",
- "university": "Học viện Công nghệ Bưu chính viễn thông"
- },
- {
- "name": "Trần Đức Mạnh",
- "username":"manhdt",
- "year_of_birth": "1998",
- "gender":"Nam",
- "major":"Bảo mật thông tin",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": "Trần Mạnh Dũng",
- "username":"dungtm",
- "year_of_birth": "2001",
- "gender":"Nam",
- "major":"Điện tử viễn thông",
- "university": "Học viện Công nghệ Bưu chính Viễn thông"
- },
- {
- "name": " Trần Minh Dương",
- "username":"duongtm",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Mạng máy tính và truyền thông dữ liệu",
- "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
- },
- {
- "name": "Trần Xuân Phú",
- "username":"phutx",
- "year_of_birth": "2001",
- "gender":"Nam",
- "major":"Khoa học máy tính",
- "university": "Trường Đại học Công nghệ thông tin - ĐHQG Tp.Hồ chí Minh"
- },
- {
- "name": "Vũ Hoàng Long",
- "username":"longvh",
- "year_of_birth": "2001",
- "gender":"Nam",
- "major":"Khoa học máy tính",
- "university": "Đại học Bách Khoa Hà Nội"
- },
- {
- "name": "Vũ Minh Hiếu",
- "username":"hieuvm",
- "year_of_birth": "2000",
- "gender":"Nam",
- "major":"Kỹ thuật phần mềm",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- }]);
-
diff --git a/Midterm/DoAnhTu/nginx/conf.d/default.conf b/Midterm/DoAnhTu/nginx/conf.d/default.conf
deleted file mode 100644
index 44cd3dced..000000000
--- a/Midterm/DoAnhTu/nginx/conf.d/default.conf
+++ /dev/null
@@ -1,17 +0,0 @@
-upstream appuser {
- server appuser:5000;
-}
-
-
-server {
- listen 80;
- server_name _;
-
- location / {
- proxy_pass http://appuser;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $scheme;
- proxy_set_header X-Forwarded-Host $host;
- proxy_set_header X-Forwarded-Prefix /;
- }
-}
\ No newline at end of file
From fb8fb8037a96af19ad77b2acfe810eed04fdb7d0 Mon Sep 17 00:00:00 2001
From: mr8-ubuntu <20021460@vnu.edu.vn>
Date: Thu, 18 May 2023 10:58:16 +0700
Subject: [PATCH 04/49] rename folder
---
10.GK /DoAnhTu/.gitignore | 6 -
10.GK /DoAnhTu/app/.dockerignore | 12 -
10.GK /DoAnhTu/app/Dockerfile | 23 --
10.GK /DoAnhTu/app/VDT/__init__.py | 128 --------
10.GK /DoAnhTu/app/VDT/templates/VDT.html | 58 ----
10.GK /DoAnhTu/app/requirements.txt | 11 -
10.GK /DoAnhTu/docker-compose.yml | 48 ---
10.GK /DoAnhTu/mongo-entrypoint/init-mongo.js | 284 ------------------
10.GK /DoAnhTu/nginx/conf.d/default.conf | 17 --
9 files changed, 587 deletions(-)
delete mode 100644 10.GK /DoAnhTu/.gitignore
delete mode 100644 10.GK /DoAnhTu/app/.dockerignore
delete mode 100644 10.GK /DoAnhTu/app/Dockerfile
delete mode 100644 10.GK /DoAnhTu/app/VDT/__init__.py
delete mode 100644 10.GK /DoAnhTu/app/VDT/templates/VDT.html
delete mode 100644 10.GK /DoAnhTu/app/requirements.txt
delete mode 100644 10.GK /DoAnhTu/docker-compose.yml
delete mode 100644 10.GK /DoAnhTu/mongo-entrypoint/init-mongo.js
delete mode 100644 10.GK /DoAnhTu/nginx/conf.d/default.conf
diff --git a/10.GK /DoAnhTu/.gitignore b/10.GK /DoAnhTu/.gitignore
deleted file mode 100644
index 07ddd70d4..000000000
--- a/10.GK /DoAnhTu/.gitignore
+++ /dev/null
@@ -1,6 +0,0 @@
-.vscode/
-flask-env/
-instance/
-__pycache__/
-
-flask_app/
diff --git a/10.GK /DoAnhTu/app/.dockerignore b/10.GK /DoAnhTu/app/.dockerignore
deleted file mode 100644
index df8f82c7a..000000000
--- a/10.GK /DoAnhTu/app/.dockerignore
+++ /dev/null
@@ -1,12 +0,0 @@
-.git
-Dockerfile
-.DS_Store
-.gitignore
-.dockerignore
-
-.vscode
-
-/__pycache__
-/instance
-
-/flask-env
diff --git a/10.GK /DoAnhTu/app/Dockerfile b/10.GK /DoAnhTu/app/Dockerfile
deleted file mode 100644
index 55def8633..000000000
--- a/10.GK /DoAnhTu/app/Dockerfile
+++ /dev/null
@@ -1,23 +0,0 @@
-FROM python:3.9
-
-ENV FLASK_APP=VDT/__init__.py
-ENV FLASK_ENV=production
-
-
-
-WORKDIR /app
-
-COPY requirements.txt requirements.txt
-
-RUN pip install -r requirements.txt
-
-
-
-COPY . .
-
-EXPOSE 5000
-
-
-
-CMD [ "flask", "run", "--host=0.0.0.0" ]
-
diff --git a/10.GK /DoAnhTu/app/VDT/__init__.py b/10.GK /DoAnhTu/app/VDT/__init__.py
deleted file mode 100644
index 700c49738..000000000
--- a/10.GK /DoAnhTu/app/VDT/__init__.py
+++ /dev/null
@@ -1,128 +0,0 @@
-import os
-
-from flask import Flask, render_template, request, jsonify, redirect, url_for
-from flask_pymongo import MongoClient
-
-
-def create_app(test_config=None):
- # create and configure the app
- app = Flask(__name__, instance_relative_config=True)
- # connect to db
-
- client = MongoClient(
- "mongodb://admin:Admin123@dbmongo:27017/", connectTimeoutMS=3000
- )
- VDT_DB = client.VDTuser
- db = VDT_DB.user
-
- @app.route("/")
- def VDT():
- students = db.find()
- student_data = []
-
- for student in students:
- person = {
- "name": student["name"],
- "year_of_birth": student["year_of_birth"],
- "university": student["university"],
- "gender": student["gender"],
- "username": student["username"],
- "major": student["major"],
- }
- student_data.append(person)
- return render_template("VDT.html", data_student=student_data)
-
- @app.route("/members", methods=["GET"])
- def getlistmember():
- students = db.find()
- student_data = []
-
- for student in students:
- person = {
- "name": student["name"],
- "year_of_birth": student["year_of_birth"],
- "university": student["university"],
- "gender": student["gender"],
- "username": student["username"],
- "major": student["major"],
- }
- student_data.append(person)
- return jsonify(student_data)
-
- @app.route("/members/", methods=["GET"])
- def get_student(username):
- students = db.find()
- members = []
- for student in students:
- person = {
- "name": student["name"],
- "year_of_birth": student["year_of_birth"],
- "university": student["university"],
- "gender": student["gender"],
- "username": student["username"],
- "major": student["major"],
- }
- if student["username"] == username:
- members.append(person)
- return jsonify(members)
-
- @app.route("/postdata", methods=["POST"])
- def post_student():
- name = request.json["name"]
- year_of_birth = request.json["year_of_birth"]
- university = request.json["university"]
- gender = request.json["gender"]
- username = request.json["username"]
- major = request.json["major"]
-
- db.insert_one(
- {
- "name": name,
- "year_of_birth": year_of_birth,
- "university": university,
- "gender": gender,
- "username": username,
- "major": major,
- }
- )
- return jsonify(
- {
- "name": name,
- "year_of_birth": year_of_birth,
- "university": university,
- "gender": gender,
- "username": username,
- "major": major,
- }
- )
-
- @app.route("/delmember/", methods=["DELETE"])
- def del_mem(username):
- db.delete_one({"username": username})
- return redirect(url_for("getlistmember"))
-
- @app.route("/updatemember/", methods=["PUT"])
- def up_mem(username):
- name = request.json["name"]
- year_of_birth = request.json["year_of_birth"]
- university = request.json["university"]
- gender = request.json["gender"]
- update_username = request.json["username"]
- major = request.json["major"]
-
- myquery = {"username": username}
- myupdate = {
- "$set": {
- "name": name,
- "year_of_birth": year_of_birth,
- "university": university,
- "gender": gender,
- "username": update_username,
- "major": major,
- }
- }
- db.update_one(myquery, myupdate)
-
- return redirect(url_for("getlistmember"))
-
- return app
diff --git a/10.GK /DoAnhTu/app/VDT/templates/VDT.html b/10.GK /DoAnhTu/app/VDT/templates/VDT.html
deleted file mode 100644
index c00929770..000000000
--- a/10.GK /DoAnhTu/app/VDT/templates/VDT.html
+++ /dev/null
@@ -1,58 +0,0 @@
-
-
-
-
- {% block title %}{% endblock %}Viettel intern list
-
-
-
-
-
-
Intern Members
-
-
-
-
Name
-
Username
-
Birth of Year
-
Gender
-
Major
-
University
-
-
-
- {% for user in data_student %}
-
-
{{ user.name }}
-
{{ user.username}}
-
{{ user.year_of_birth }}
-
{{ user.gender }}
-
{{ user.major }}
-
{{ user.university }}
-
- {% endfor %}
-
-
-
-
-
\ No newline at end of file
diff --git a/10.GK /DoAnhTu/app/requirements.txt b/10.GK /DoAnhTu/app/requirements.txt
deleted file mode 100644
index a5053ceec..000000000
--- a/10.GK /DoAnhTu/app/requirements.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-blinker==1.6.2
-click==8.1.3
-dnspython==2.3.0
-Flask==2.3.1
-Flask-PyMongo==2.3.0
-itsdangerous==2.1.2
-Jinja2==3.1.2
-MarkupSafe==2.1.2
-pymongo==4.3.3
-
-Werkzeug==2.3.1
diff --git a/10.GK /DoAnhTu/docker-compose.yml b/10.GK /DoAnhTu/docker-compose.yml
deleted file mode 100644
index 1e4981f20..000000000
--- a/10.GK /DoAnhTu/docker-compose.yml
+++ /dev/null
@@ -1,48 +0,0 @@
-version: '3'
-services:
- appuser:
- build: ./app
- depends_on:
- - dbmongo
- ports:
- - 5000:5000
- networks:
- - db
- - app
-
-
- nginx-production:
- image: nginx:1.22.0-alpine
- ports:
- - 8000:80
- volumes:
- - ./nginx/conf.d/:/etc/nginx/conf.d/
- depends_on:
- - appuser
- networks:
- - app
-
-
- dbmongo:
- image: mongo:5.0
-
- environment:
- - MONGO_INITDB_ROOT_USERNAME=admin
- - MONGO_INITDB_ROOT_PASSWORD=Admin123
- - MONGO_INITDB_DATABASE=VDTuser
-
- ports:
- - 27017:27017
- volumes:
- - db1:/data/db
- - ./mongo-entrypoint:/docker-entrypoint-initdb.d
- networks:
- - db
-volumes:
- db1:
-
-networks:
- db:
- driver: bridge
- app:
- driver: bridge
diff --git a/10.GK /DoAnhTu/mongo-entrypoint/init-mongo.js b/10.GK /DoAnhTu/mongo-entrypoint/init-mongo.js
deleted file mode 100644
index a189e1b41..000000000
--- a/10.GK /DoAnhTu/mongo-entrypoint/init-mongo.js
+++ /dev/null
@@ -1,284 +0,0 @@
-db = db.getSiblingDB("VDTuser");
-db.user.drop();
-db.user.insertMany([{
- "name": "Bùi Minh Sơn",
- "username":"sonbm",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Công nghệ thông tin",
- "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
- },
- {
- "name": "Đào Đại Hiệp",
- "username":"hiepdd",
- "year_of_birth": "2001",
- "gender":"Nam",
- "major":"Điện tử viễn thông",
- "university": "Đại học Bách khoa Hà Nội"
- },
- {
- "name": "Đỗ Bảo Hoàng",
- "username":"hoangdb",
- "year_of_birth": "1997",
- "gender":"Nam",
- "major":"An toàn thông tin",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": " Hoàng Quốc Doanh",
- "username":"doanhhq",
- "year_of_birth": "2001",
- "gender":"Nam",
- "major":"NULL",
- "university": "Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Đỗ Anh Tú",
- "username":"tuda",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Mạng máy tính và truyền thông dữ liệu",
- "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
- },
- {
- "name": "Lê Minh Đức",
- "username":"duclm",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Công nghệ thông tin ứng dụng phần mềm",
- "university": "Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Lê Phúc Lai",
- "username":"lailp",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Kỹ thuật điện tử viễn thông",
- "university": "Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Lê Quang Anh",
- "username":"anhlq",
- "year_of_birth": "1997",
- "gender":"Nam",
- "major":"An toàn thông tin",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": "Lê Trọng Minh",
- "username":"minhlt",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Kỹ thuật điều khiển và tự động hóa",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": "Lê Tùng Lâm",
- "username":"lamlt",
- "year_of_birth": "1999",
- "gender":"Nam",
- "major":"Khoa học máy tính",
- "university": "Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Lê Văn Chiến",
- "username":"chienlv",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Kỹ thuật hàng không vũ trụ",
- "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
- },
- {
- "name": "Nguyễn Thị Linh",
- "username":"linhnt",
- "year_of_birth": "2002",
- "gender":"Nữ",
- "major":"ICT",
- "university": "Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Nguyễn Đại An",
- "username":"annd",
- "year_of_birth": "2023",
- "gender":"Nam",
- "major":"Khoa học máy tính",
- "university": "Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Nguyễn Đình Hoàng",
- "username":"hoangdn",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Công nghệ thông tin ứng dụng phần mềm",
- "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
- },
- {
- "name": " Nguyễn Đức Vinh",
- "username":"vinhnd",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"NULL",
- "university": "Học viện Công nghệ Bưu chính Viễn thông"
- },
- {
- "name": " Nguyễn Dương Long",
- "username":"longnd",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Công nghệ thông tin ứng dụng phần mềm",
- "university": " ĐH Thuỷ lợi"
- },
- {
- "name": "Nguyễn Hữu Thắng",
- "username":"thangnh",
- "year_of_birth": "2000",
- "gender":"Nam",
- "major":"Khoa học máy tính",
- "university": " Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Nguyễn Mạnh Cường",
- "username":"cuongnm",
- "year_of_birth": "1997",
- "gender":"Nam",
- "major":"Điện tử",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": "Nguyễn Mạnh Đức",
- "username":"ducnm",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"An toàn thông tin",
- "university": "Học viện Kỹ thuật mật mã"
- },
- {
- "name": "Nguyễn Ngọc Chung",
- "username":"chungnn",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"NULL",
- "university": "Học viên Công nghệ Bưu chính Viễn Thông HCM"
- },
- {
- "name": " Nguyễn Tuấn Anh",
- "username":"anhnt",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"An toàn thông tin",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": " Nguyễn Văn Quang",
- "username":"squangnv",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"An toàn thông tin",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": "Ninh Chí Hướng",
- "username":"huongnc",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"An toàn thông tin",
- "university": "Học viện Công nghệ Bưu chính viễn thông"
- },
- {
- "name": "Ninh Văn Nghĩa",
- "username":"nghianv",
- "year_of_birth": "2001",
- "gender":"Nam",
- "major":"Khoa học máy tính",
- "university": "Đại Học Bách Khoa Hà Nội"
- },
- {
- "name": "Phạm Anh Đức",
- "username":"ducpa",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Toán ứng dụng và tin học",
- "university": "Đại học Bách Khoa Hà Nội"
- },
- {
-
- "name": "Phạm Duy Cương",
- "username":"cuongpd",
- "year_of_birth": "1997",
- "gender":"Nam",
- "major":"Công nghệ điện tử",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": "Phạm Hồng Thanh",
- "username":"thanhph",
- "year_of_birth": "1998",
- "gender":"Nam",
- "major":"Phát triển phần mềm",
- "university": "Swinburne University"
- },
- {
- "name": " Phạm Thị Khánh Linh",
- "username":"linhptk",
- "year_of_birth": "2002",
- "gender":"Nữ",
- "major":"Mạng máy tính và truyền thông dữ liệu",
- "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
- },
- {
- "name": "Phạm Văn Tới",
- "username":"toipv",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Công nghệ thông tin ứng dụng phần mềm",
- "university": "Học viện Công nghệ Bưu chính viễn thông"
- },
- {
- "name": "Trần Đức Mạnh",
- "username":"manhdt",
- "year_of_birth": "1998",
- "gender":"Nam",
- "major":"Bảo mật thông tin",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- },
- {
- "name": "Trần Mạnh Dũng",
- "username":"dungtm",
- "year_of_birth": "2001",
- "gender":"Nam",
- "major":"Điện tử viễn thông",
- "university": "Học viện Công nghệ Bưu chính Viễn thông"
- },
- {
- "name": " Trần Minh Dương",
- "username":"duongtm",
- "year_of_birth": "2002",
- "gender":"Nam",
- "major":"Mạng máy tính và truyền thông dữ liệu",
- "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
- },
- {
- "name": "Trần Xuân Phú",
- "username":"phutx",
- "year_of_birth": "2001",
- "gender":"Nam",
- "major":"Khoa học máy tính",
- "university": "Trường Đại học Công nghệ thông tin - ĐHQG Tp.Hồ chí Minh"
- },
- {
- "name": "Vũ Hoàng Long",
- "username":"longvh",
- "year_of_birth": "2001",
- "gender":"Nam",
- "major":"Khoa học máy tính",
- "university": "Đại học Bách Khoa Hà Nội"
- },
- {
- "name": "Vũ Minh Hiếu",
- "username":"hieuvm",
- "year_of_birth": "2000",
- "gender":"Nam",
- "major":"Kỹ thuật phần mềm",
- "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
- }]);
-
diff --git a/10.GK /DoAnhTu/nginx/conf.d/default.conf b/10.GK /DoAnhTu/nginx/conf.d/default.conf
deleted file mode 100644
index 44cd3dced..000000000
--- a/10.GK /DoAnhTu/nginx/conf.d/default.conf
+++ /dev/null
@@ -1,17 +0,0 @@
-upstream appuser {
- server appuser:5000;
-}
-
-
-server {
- listen 80;
- server_name _;
-
- location / {
- proxy_pass http://appuser;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $scheme;
- proxy_set_header X-Forwarded-Host $host;
- proxy_set_header X-Forwarded-Prefix /;
- }
-}
\ No newline at end of file
From cae66d29b845332bc35d7d8be87a2d2782cfad82 Mon Sep 17 00:00:00 2001
From: mr8-ubuntu <20021460@vnu.edu.vn>
Date: Thu, 18 May 2023 10:59:14 +0700
Subject: [PATCH 05/49] create new name folder 10.Gk
---
10.GK/DoAnhTu/.gitignore | 6 +
10.GK/DoAnhTu/app/.dockerignore | 12 +
10.GK/DoAnhTu/app/Dockerfile | 23 ++
10.GK/DoAnhTu/app/VDT/__init__.py | 128 +++++++++
10.GK/DoAnhTu/app/VDT/templates/VDT.html | 58 ++++
10.GK/DoAnhTu/app/requirements.txt | 11 +
10.GK/DoAnhTu/docker-compose.yml | 48 ++++
10.GK/DoAnhTu/mongo-entrypoint/init-mongo.js | 284 +++++++++++++++++++
10.GK/DoAnhTu/nginx/conf.d/default.conf | 17 ++
9 files changed, 587 insertions(+)
create mode 100644 10.GK/DoAnhTu/.gitignore
create mode 100644 10.GK/DoAnhTu/app/.dockerignore
create mode 100644 10.GK/DoAnhTu/app/Dockerfile
create mode 100644 10.GK/DoAnhTu/app/VDT/__init__.py
create mode 100644 10.GK/DoAnhTu/app/VDT/templates/VDT.html
create mode 100644 10.GK/DoAnhTu/app/requirements.txt
create mode 100644 10.GK/DoAnhTu/docker-compose.yml
create mode 100644 10.GK/DoAnhTu/mongo-entrypoint/init-mongo.js
create mode 100644 10.GK/DoAnhTu/nginx/conf.d/default.conf
diff --git a/10.GK/DoAnhTu/.gitignore b/10.GK/DoAnhTu/.gitignore
new file mode 100644
index 000000000..07ddd70d4
--- /dev/null
+++ b/10.GK/DoAnhTu/.gitignore
@@ -0,0 +1,6 @@
+.vscode/
+flask-env/
+instance/
+__pycache__/
+
+flask_app/
diff --git a/10.GK/DoAnhTu/app/.dockerignore b/10.GK/DoAnhTu/app/.dockerignore
new file mode 100644
index 000000000..df8f82c7a
--- /dev/null
+++ b/10.GK/DoAnhTu/app/.dockerignore
@@ -0,0 +1,12 @@
+.git
+Dockerfile
+.DS_Store
+.gitignore
+.dockerignore
+
+.vscode
+
+/__pycache__
+/instance
+
+/flask-env
diff --git a/10.GK/DoAnhTu/app/Dockerfile b/10.GK/DoAnhTu/app/Dockerfile
new file mode 100644
index 000000000..55def8633
--- /dev/null
+++ b/10.GK/DoAnhTu/app/Dockerfile
@@ -0,0 +1,23 @@
+FROM python:3.9
+
+ENV FLASK_APP=VDT/__init__.py
+ENV FLASK_ENV=production
+
+
+
+WORKDIR /app
+
+COPY requirements.txt requirements.txt
+
+RUN pip install -r requirements.txt
+
+
+
+COPY . .
+
+EXPOSE 5000
+
+
+
+CMD [ "flask", "run", "--host=0.0.0.0" ]
+
diff --git a/10.GK/DoAnhTu/app/VDT/__init__.py b/10.GK/DoAnhTu/app/VDT/__init__.py
new file mode 100644
index 000000000..700c49738
--- /dev/null
+++ b/10.GK/DoAnhTu/app/VDT/__init__.py
@@ -0,0 +1,128 @@
+import os
+
+from flask import Flask, render_template, request, jsonify, redirect, url_for
+from flask_pymongo import MongoClient
+
+
+def create_app(test_config=None):
+ # create and configure the app
+ app = Flask(__name__, instance_relative_config=True)
+ # connect to db
+
+ client = MongoClient(
+ "mongodb://admin:Admin123@dbmongo:27017/", connectTimeoutMS=3000
+ )
+ VDT_DB = client.VDTuser
+ db = VDT_DB.user
+
+ @app.route("/")
+ def VDT():
+ students = db.find()
+ student_data = []
+
+ for student in students:
+ person = {
+ "name": student["name"],
+ "year_of_birth": student["year_of_birth"],
+ "university": student["university"],
+ "gender": student["gender"],
+ "username": student["username"],
+ "major": student["major"],
+ }
+ student_data.append(person)
+ return render_template("VDT.html", data_student=student_data)
+
+ @app.route("/members", methods=["GET"])
+ def getlistmember():
+ students = db.find()
+ student_data = []
+
+ for student in students:
+ person = {
+ "name": student["name"],
+ "year_of_birth": student["year_of_birth"],
+ "university": student["university"],
+ "gender": student["gender"],
+ "username": student["username"],
+ "major": student["major"],
+ }
+ student_data.append(person)
+ return jsonify(student_data)
+
+ @app.route("/members/", methods=["GET"])
+ def get_student(username):
+ students = db.find()
+ members = []
+ for student in students:
+ person = {
+ "name": student["name"],
+ "year_of_birth": student["year_of_birth"],
+ "university": student["university"],
+ "gender": student["gender"],
+ "username": student["username"],
+ "major": student["major"],
+ }
+ if student["username"] == username:
+ members.append(person)
+ return jsonify(members)
+
+ @app.route("/postdata", methods=["POST"])
+ def post_student():
+ name = request.json["name"]
+ year_of_birth = request.json["year_of_birth"]
+ university = request.json["university"]
+ gender = request.json["gender"]
+ username = request.json["username"]
+ major = request.json["major"]
+
+ db.insert_one(
+ {
+ "name": name,
+ "year_of_birth": year_of_birth,
+ "university": university,
+ "gender": gender,
+ "username": username,
+ "major": major,
+ }
+ )
+ return jsonify(
+ {
+ "name": name,
+ "year_of_birth": year_of_birth,
+ "university": university,
+ "gender": gender,
+ "username": username,
+ "major": major,
+ }
+ )
+
+ @app.route("/delmember/", methods=["DELETE"])
+ def del_mem(username):
+ db.delete_one({"username": username})
+ return redirect(url_for("getlistmember"))
+
+ @app.route("/updatemember/", methods=["PUT"])
+ def up_mem(username):
+ name = request.json["name"]
+ year_of_birth = request.json["year_of_birth"]
+ university = request.json["university"]
+ gender = request.json["gender"]
+ update_username = request.json["username"]
+ major = request.json["major"]
+
+ myquery = {"username": username}
+ myupdate = {
+ "$set": {
+ "name": name,
+ "year_of_birth": year_of_birth,
+ "university": university,
+ "gender": gender,
+ "username": update_username,
+ "major": major,
+ }
+ }
+ db.update_one(myquery, myupdate)
+
+ return redirect(url_for("getlistmember"))
+
+ return app
diff --git a/10.GK/DoAnhTu/app/VDT/templates/VDT.html b/10.GK/DoAnhTu/app/VDT/templates/VDT.html
new file mode 100644
index 000000000..c00929770
--- /dev/null
+++ b/10.GK/DoAnhTu/app/VDT/templates/VDT.html
@@ -0,0 +1,58 @@
+
+
+
+
+ {% block title %}{% endblock %}Viettel intern list
+
+
+
+
+
+
Intern Members
+
+
+
+
Name
+
Username
+
Birth of Year
+
Gender
+
Major
+
University
+
+
+
+ {% for user in data_student %}
+
+
{{ user.name }}
+
{{ user.username}}
+
{{ user.year_of_birth }}
+
{{ user.gender }}
+
{{ user.major }}
+
{{ user.university }}
+
+ {% endfor %}
+
+
+
+
+
\ No newline at end of file
diff --git a/10.GK/DoAnhTu/app/requirements.txt b/10.GK/DoAnhTu/app/requirements.txt
new file mode 100644
index 000000000..a5053ceec
--- /dev/null
+++ b/10.GK/DoAnhTu/app/requirements.txt
@@ -0,0 +1,11 @@
+blinker==1.6.2
+click==8.1.3
+dnspython==2.3.0
+Flask==2.3.1
+Flask-PyMongo==2.3.0
+itsdangerous==2.1.2
+Jinja2==3.1.2
+MarkupSafe==2.1.2
+pymongo==4.3.3
+
+Werkzeug==2.3.1
diff --git a/10.GK/DoAnhTu/docker-compose.yml b/10.GK/DoAnhTu/docker-compose.yml
new file mode 100644
index 000000000..1e4981f20
--- /dev/null
+++ b/10.GK/DoAnhTu/docker-compose.yml
@@ -0,0 +1,48 @@
+version: '3'
+services:
+ appuser:
+ build: ./app
+ depends_on:
+ - dbmongo
+ ports:
+ - 5000:5000
+ networks:
+ - db
+ - app
+
+
+ nginx-production:
+ image: nginx:1.22.0-alpine
+ ports:
+ - 8000:80
+ volumes:
+ - ./nginx/conf.d/:/etc/nginx/conf.d/
+ depends_on:
+ - appuser
+ networks:
+ - app
+
+
+ dbmongo:
+ image: mongo:5.0
+
+ environment:
+ - MONGO_INITDB_ROOT_USERNAME=admin
+ - MONGO_INITDB_ROOT_PASSWORD=Admin123
+ - MONGO_INITDB_DATABASE=VDTuser
+
+ ports:
+ - 27017:27017
+ volumes:
+ - db1:/data/db
+ - ./mongo-entrypoint:/docker-entrypoint-initdb.d
+ networks:
+ - db
+volumes:
+ db1:
+
+networks:
+ db:
+ driver: bridge
+ app:
+ driver: bridge
diff --git a/10.GK/DoAnhTu/mongo-entrypoint/init-mongo.js b/10.GK/DoAnhTu/mongo-entrypoint/init-mongo.js
new file mode 100644
index 000000000..a189e1b41
--- /dev/null
+++ b/10.GK/DoAnhTu/mongo-entrypoint/init-mongo.js
@@ -0,0 +1,284 @@
+db = db.getSiblingDB("VDTuser");
+db.user.drop();
+db.user.insertMany([{
+ "name": "Bùi Minh Sơn",
+ "username":"sonbm",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Đào Đại Hiệp",
+ "username":"hiepdd",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Điện tử viễn thông",
+ "university": "Đại học Bách khoa Hà Nội"
+ },
+ {
+ "name": "Đỗ Bảo Hoàng",
+ "username":"hoangdb",
+ "year_of_birth": "1997",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": " Hoàng Quốc Doanh",
+ "username":"doanhhq",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"NULL",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Đỗ Anh Tú",
+ "username":"tuda",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Mạng máy tính và truyền thông dữ liệu",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Lê Minh Đức",
+ "username":"duclm",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin ứng dụng phần mềm",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Lê Phúc Lai",
+ "username":"lailp",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Kỹ thuật điện tử viễn thông",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Lê Quang Anh",
+ "username":"anhlq",
+ "year_of_birth": "1997",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Lê Trọng Minh",
+ "username":"minhlt",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Kỹ thuật điều khiển và tự động hóa",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Lê Tùng Lâm",
+ "username":"lamlt",
+ "year_of_birth": "1999",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Lê Văn Chiến",
+ "username":"chienlv",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Kỹ thuật hàng không vũ trụ",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Nguyễn Thị Linh",
+ "username":"linhnt",
+ "year_of_birth": "2002",
+ "gender":"Nữ",
+ "major":"ICT",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Nguyễn Đại An",
+ "username":"annd",
+ "year_of_birth": "2023",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Nguyễn Đình Hoàng",
+ "username":"hoangdn",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin ứng dụng phần mềm",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": " Nguyễn Đức Vinh",
+ "username":"vinhnd",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"NULL",
+ "university": "Học viện Công nghệ Bưu chính Viễn thông"
+ },
+ {
+ "name": " Nguyễn Dương Long",
+ "username":"longnd",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin ứng dụng phần mềm",
+ "university": " ĐH Thuỷ lợi"
+ },
+ {
+ "name": "Nguyễn Hữu Thắng",
+ "username":"thangnh",
+ "year_of_birth": "2000",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": " Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Nguyễn Mạnh Cường",
+ "username":"cuongnm",
+ "year_of_birth": "1997",
+ "gender":"Nam",
+ "major":"Điện tử",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Nguyễn Mạnh Đức",
+ "username":"ducnm",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Học viện Kỹ thuật mật mã"
+ },
+ {
+ "name": "Nguyễn Ngọc Chung",
+ "username":"chungnn",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"NULL",
+ "university": "Học viên Công nghệ Bưu chính Viễn Thông HCM"
+ },
+ {
+ "name": " Nguyễn Tuấn Anh",
+ "username":"anhnt",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": " Nguyễn Văn Quang",
+ "username":"squangnv",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Ninh Chí Hướng",
+ "username":"huongnc",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"An toàn thông tin",
+ "university": "Học viện Công nghệ Bưu chính viễn thông"
+ },
+ {
+ "name": "Ninh Văn Nghĩa",
+ "username":"nghianv",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Đại Học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Phạm Anh Đức",
+ "username":"ducpa",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Toán ứng dụng và tin học",
+ "university": "Đại học Bách Khoa Hà Nội"
+ },
+ {
+
+ "name": "Phạm Duy Cương",
+ "username":"cuongpd",
+ "year_of_birth": "1997",
+ "gender":"Nam",
+ "major":"Công nghệ điện tử",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Phạm Hồng Thanh",
+ "username":"thanhph",
+ "year_of_birth": "1998",
+ "gender":"Nam",
+ "major":"Phát triển phần mềm",
+ "university": "Swinburne University"
+ },
+ {
+ "name": " Phạm Thị Khánh Linh",
+ "username":"linhptk",
+ "year_of_birth": "2002",
+ "gender":"Nữ",
+ "major":"Mạng máy tính và truyền thông dữ liệu",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Phạm Văn Tới",
+ "username":"toipv",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Công nghệ thông tin ứng dụng phần mềm",
+ "university": "Học viện Công nghệ Bưu chính viễn thông"
+ },
+ {
+ "name": "Trần Đức Mạnh",
+ "username":"manhdt",
+ "year_of_birth": "1998",
+ "gender":"Nam",
+ "major":"Bảo mật thông tin",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ },
+ {
+ "name": "Trần Mạnh Dũng",
+ "username":"dungtm",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Điện tử viễn thông",
+ "university": "Học viện Công nghệ Bưu chính Viễn thông"
+ },
+ {
+ "name": " Trần Minh Dương",
+ "username":"duongtm",
+ "year_of_birth": "2002",
+ "gender":"Nam",
+ "major":"Mạng máy tính và truyền thông dữ liệu",
+ "university": "Đại học Công nghệ - Đại học Quốc gia Hà Nội"
+ },
+ {
+ "name": "Trần Xuân Phú",
+ "username":"phutx",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Trường Đại học Công nghệ thông tin - ĐHQG Tp.Hồ chí Minh"
+ },
+ {
+ "name": "Vũ Hoàng Long",
+ "username":"longvh",
+ "year_of_birth": "2001",
+ "gender":"Nam",
+ "major":"Khoa học máy tính",
+ "university": "Đại học Bách Khoa Hà Nội"
+ },
+ {
+ "name": "Vũ Minh Hiếu",
+ "username":"hieuvm",
+ "year_of_birth": "2000",
+ "gender":"Nam",
+ "major":"Kỹ thuật phần mềm",
+ "university": "Đại học CNTT, cơ khí & quang học St.Petersburg LB Nga"
+ }]);
+
diff --git a/10.GK/DoAnhTu/nginx/conf.d/default.conf b/10.GK/DoAnhTu/nginx/conf.d/default.conf
new file mode 100644
index 000000000..44cd3dced
--- /dev/null
+++ b/10.GK/DoAnhTu/nginx/conf.d/default.conf
@@ -0,0 +1,17 @@
+upstream appuser {
+ server appuser:5000;
+}
+
+
+server {
+ listen 80;
+ server_name _;
+
+ location / {
+ proxy_pass http://appuser;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_set_header X-Forwarded-Host $host;
+ proxy_set_header X-Forwarded-Prefix /;
+ }
+}
\ No newline at end of file
From 980ec0e9f24f9f6c63a675850282a2e8464b888e Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 02:07:14 +0700
Subject: [PATCH 06/49] test api
---
10.GK/DoAnhTu/app/test/test_app_api.py | 69 ++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
create mode 100644 10.GK/DoAnhTu/app/test/test_app_api.py
diff --git a/10.GK/DoAnhTu/app/test/test_app_api.py b/10.GK/DoAnhTu/app/test/test_app_api.py
new file mode 100644
index 000000000..43a4b7ca3
--- /dev/null
+++ b/10.GK/DoAnhTu/app/test/test_app_api.py
@@ -0,0 +1,69 @@
+import requests
+from flask_pymongo import MongoClient
+
+ENDPOINT = "http://127.0.0.1:5000/"
+client = MongoClient("mongodb://admin:Admin123@127.0.0.1:27017/", connectTimeoutMS=3000)
+VDT_DB = client.VDTuser
+db = VDT_DB.user
+
+
+def test_can_access_homepage():
+ respone = requests.get(ENDPOINT)
+ assert respone.status_code == 200
+
+
+def test_can_call_endpoint():
+ respone = requests.get(ENDPOINT + "members")
+ assert respone.status_code == 200
+ data = respone.json()
+ print(data)
+
+
+def test_user_api():
+ students = db.find()
+ for student in students:
+ username = student["username"]
+ respone = requests.get(ENDPOINT + f"members/{username}")
+ assert respone.status_code == 200
+
+
+def test_can_create_mem():
+ payload = {
+ "name": "Nguyen Thi Thuy Quynh",
+ "year_of_birth": "2001",
+ "university": "UET",
+ "gender": "Female",
+ "username": "quynhntt1",
+ "major": "computer science",
+ }
+ respone = requests.post(ENDPOINT + "postdata", json=payload)
+
+ assert respone.status_code == 200
+ data = respone.json()
+ print(data)
+
+
+def test_can_del_mem():
+ username = "quynhntt1"
+
+ respone = requests.delete(ENDPOINT + f"delmember/{username}")
+ assert respone.status_code == 200
+ print(respone.status_code)
+
+
+def test_can_update_mem():
+ payload = {
+ "name": "Nguyen Thi Thuy Quynh",
+ "year_of_birth": "2002",
+ "university": "UET",
+ "gender": "Female",
+ "username": "quynhntt",
+ "major": "network and communication",
+ }
+
+ username = payload["username"]
+ respone = requests.put(ENDPOINT + f"/updatemember/{username}", json=payload)
+ assert respone.status_code == 200
+
+ data = respone.json()
+ print(data)
From ae36e8a36ab74faf1b9b25d0c42dc420125677ee Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 02:38:58 +0700
Subject: [PATCH 07/49] learn github action
---
.../.github/workflows/learn-github-actions.yml | 13 +++++++++++++
1 file changed, 13 insertions(+)
create mode 100644 10.GK/DoAnhTu/.github/workflows/learn-github-actions.yml
diff --git a/10.GK/DoAnhTu/.github/workflows/learn-github-actions.yml b/10.GK/DoAnhTu/.github/workflows/learn-github-actions.yml
new file mode 100644
index 000000000..86224bdab
--- /dev/null
+++ b/10.GK/DoAnhTu/.github/workflows/learn-github-actions.yml
@@ -0,0 +1,13 @@
+name: learn-github-actions
+run-name: ${{ github.actor }} is learning GitHub Actions
+on: [push]
+jobs:
+ check-bats-version:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: "14"
+ - run: npm install -g bats
+ - run: bats -v
From a03112c01482a6dc49b480d85dee6fdbb38ec244 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 02:41:30 +0700
Subject: [PATCH 08/49] test github action
---
10.GK/DoAnhTu/app/test/test_app_api.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/10.GK/DoAnhTu/app/test/test_app_api.py b/10.GK/DoAnhTu/app/test/test_app_api.py
index 43a4b7ca3..e480e1496 100644
--- a/10.GK/DoAnhTu/app/test/test_app_api.py
+++ b/10.GK/DoAnhTu/app/test/test_app_api.py
@@ -6,6 +6,8 @@
VDT_DB = client.VDTuser
db = VDT_DB.user
+test_a = "sadsd"
+
def test_can_access_homepage():
respone = requests.get(ENDPOINT)
From 920c9bb967256a158f8e86571501802b8a5e620d Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 02:44:13 +0700
Subject: [PATCH 09/49] del wrong folder
---
.../.github/workflows/learn-github-actions.yml | 13 -------------
1 file changed, 13 deletions(-)
delete mode 100644 10.GK/DoAnhTu/.github/workflows/learn-github-actions.yml
diff --git a/10.GK/DoAnhTu/.github/workflows/learn-github-actions.yml b/10.GK/DoAnhTu/.github/workflows/learn-github-actions.yml
deleted file mode 100644
index 86224bdab..000000000
--- a/10.GK/DoAnhTu/.github/workflows/learn-github-actions.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-name: learn-github-actions
-run-name: ${{ github.actor }} is learning GitHub Actions
-on: [push]
-jobs:
- check-bats-version:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v3
- - uses: actions/setup-node@v3
- with:
- node-version: "14"
- - run: npm install -g bats
- - run: bats -v
From 821b72c04d6400eb2acecaa2fbb6069b026c1b66 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 02:48:23 +0700
Subject: [PATCH 10/49] learning github workflow
---
.../DoAnhTu/workflows/github-actions-demo.yml | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
create mode 100644 10.GK/DoAnhTu/workflows/github-actions-demo.yml
diff --git a/10.GK/DoAnhTu/workflows/github-actions-demo.yml b/10.GK/DoAnhTu/workflows/github-actions-demo.yml
new file mode 100644
index 000000000..e007988b3
--- /dev/null
+++ b/10.GK/DoAnhTu/workflows/github-actions-demo.yml
@@ -0,0 +1,18 @@
+name: GitHub Actions Demo
+run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
+on: [push]
+jobs:
+ Explore-GitHub-Actions:
+ runs-on: ubuntu-latest
+ steps:
+ - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
+ - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
+ - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
+ - name: Check out repository code
+ uses: actions/checkout@v3
+ - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
+ - run: echo "🖥️ The workflow is now ready to test your code on the runner."
+ - name: List files in the repository
+ run: |
+ ls ${{ github.workspace }}
+ - run: echo "🍏 This job's status is ${{ job.status }}."
From d614c5c0526c34fbe504c4988f53642719465f35 Mon Sep 17 00:00:00 2001
From: Tu Do <80826854+batamsieuhang@users.noreply.github.com>
Date: Fri, 19 May 2023 10:14:51 +0700
Subject: [PATCH 11/49] Delete 10.GK/DoAnhTu/workflows directory
---
.../DoAnhTu/workflows/github-actions-demo.yml | 18 ------------------
1 file changed, 18 deletions(-)
delete mode 100644 10.GK/DoAnhTu/workflows/github-actions-demo.yml
diff --git a/10.GK/DoAnhTu/workflows/github-actions-demo.yml b/10.GK/DoAnhTu/workflows/github-actions-demo.yml
deleted file mode 100644
index e007988b3..000000000
--- a/10.GK/DoAnhTu/workflows/github-actions-demo.yml
+++ /dev/null
@@ -1,18 +0,0 @@
-name: GitHub Actions Demo
-run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
-on: [push]
-jobs:
- Explore-GitHub-Actions:
- runs-on: ubuntu-latest
- steps:
- - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- - name: Check out repository code
- uses: actions/checkout@v3
- - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- - run: echo "🖥️ The workflow is now ready to test your code on the runner."
- - name: List files in the repository
- run: |
- ls ${{ github.workspace }}
- - run: echo "🍏 This job's status is ${{ job.status }}."
From 2aa1aaa5e8d0a226dd1800ef7ec0b41ad79765ba Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 10:18:53 +0700
Subject: [PATCH 12/49] learn github action
---
.github/workflows/ci.yaml | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
create mode 100644 .github/workflows/ci.yaml
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
new file mode 100644
index 000000000..335877635
--- /dev/null
+++ b/.github/workflows/ci.yaml
@@ -0,0 +1,36 @@
+# This is a basic workflow to help you get started with Actions
+
+name: CI
+
+# Controls when the workflow will run
+on:
+ # Triggers the workflow on push or pull request events but only for the "main" branch
+ push:
+ branches: ["*"]
+ pull_request:
+ branches: ["main"]
+
+ # Allows you to run this workflow manually from the Actions tab
+ workflow_dispatch:
+
+# A workflow run is made up of one or more jobs that can run sequentially or in parallel
+jobs:
+ # This workflow contains a single job called "build"
+ build:
+ # The type of runner that the job will run on
+ runs-on: ubuntu-latest
+
+ # Steps represent a sequence of tasks that will be executed as part of the job
+ steps:
+ # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
+ - uses: actions/checkout@v3
+
+ # Runs a single command using the runners shell
+ - name: Run a one-line script
+ run: echo Hello, world!
+
+ # Runs a set of commands using the runners shell
+ - name: Run a multi-line script
+ run: |
+ echo Add other actions to build,
+ echo test, and deploy your project.
From c9576b850745f7e93956b321456be1a50bbdc851 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 10:20:34 +0700
Subject: [PATCH 13/49] test ci
---
10.GK/DoAnhTu/app/test/test_app_api.py | 2 --
1 file changed, 2 deletions(-)
diff --git a/10.GK/DoAnhTu/app/test/test_app_api.py b/10.GK/DoAnhTu/app/test/test_app_api.py
index e480e1496..43a4b7ca3 100644
--- a/10.GK/DoAnhTu/app/test/test_app_api.py
+++ b/10.GK/DoAnhTu/app/test/test_app_api.py
@@ -6,8 +6,6 @@
VDT_DB = client.VDTuser
db = VDT_DB.user
-test_a = "sadsd"
-
def test_can_access_homepage():
respone = requests.get(ENDPOINT)
From 97e31a1d04c675863f931085ac152700cef1adbc Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 11:03:17 +0700
Subject: [PATCH 14/49] learn github action cmd
---
.github/workflows/ci.yaml | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 335877635..965a6d5a6 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -26,11 +26,19 @@ jobs:
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- - name: Run a one-line script
- run: echo Hello, world!
+ - name: Check pwd
+ run: pwd
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
+
+ test:
+ runs-on: ubuntu-latest
+ needs: build
+ # Steps represent a sequence of tasks that will be executed as part of the job
+ steps:
+ # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
+ - uses: actions/checkout@v3
From 9f7aecf30ebabd9e8f7115ce4c83e2c08686be9c Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 11:04:27 +0700
Subject: [PATCH 15/49] check pwd in github action
---
.github/workflows/ci.yaml | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 965a6d5a6..fd92890fd 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -27,7 +27,9 @@ jobs:
# Runs a single command using the runners shell
- name: Check pwd
- run: pwd
+ run: |
+ pwd
+ ls
# Runs a set of commands using the runners shell
- name: Run a multi-line script
From 245d5165d2afa03465ec9a3747ddf3798ed494cb Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 11:17:23 +0700
Subject: [PATCH 16/49] test run docker in github action
---
.github/workflows/ci.yaml | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index fd92890fd..a5eddcd28 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -25,17 +25,25 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- # Runs a single command using the runners shell
+ # check working directory
- name: Check pwd
run: |
pwd
ls
+ cd 10.GK/DoAnhTu
+ pwd
+ - name: Docker Compose Action
+ uses: isbang/compose-action@v1.4.1
+ with:
+ compose-file: ".docker-compose.yml"
+ down-flags: "--volumes"
+ services: |
+ appuser
+ dbmongo
# Runs a set of commands using the runners shell
- - name: Run a multi-line script
- run: |
- echo Add other actions to build,
- echo test, and deploy your project.
+ - name: Test docker
+ run: curl 127.0.0.1:8000
test:
runs-on: ubuntu-latest
From 413445e9dffc38b34b1fc22ac45dbf218420ea0f Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 11:20:20 +0700
Subject: [PATCH 17/49] fix error directory
---
.github/workflows/ci.yaml | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index a5eddcd28..a8608ab89 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -35,11 +35,8 @@ jobs:
- name: Docker Compose Action
uses: isbang/compose-action@v1.4.1
with:
- compose-file: ".docker-compose.yml"
+ compose-file: "./docker-compose.yml"
down-flags: "--volumes"
- services: |
- appuser
- dbmongo
# Runs a set of commands using the runners shell
- name: Test docker
From 0d578e448810832259fcdab2f59a8010a366840e Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 11:23:28 +0700
Subject: [PATCH 18/49] check pwd 2
---
.github/workflows/ci.yaml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index a8608ab89..6f8460114 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -32,6 +32,8 @@ jobs:
ls
cd 10.GK/DoAnhTu
pwd
+ - name: check pwd 2
+ run: pwd
- name: Docker Compose Action
uses: isbang/compose-action@v1.4.1
with:
From ac19a67c220a00b6afa2f555665a17f5a577d3cd Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 11:25:37 +0700
Subject: [PATCH 19/49] test run docker in github action
---
.github/workflows/ci.yaml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 6f8460114..db3b6b048 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -37,12 +37,12 @@ jobs:
- name: Docker Compose Action
uses: isbang/compose-action@v1.4.1
with:
- compose-file: "./docker-compose.yml"
+ compose-file: "./10.GK/DoAnhTu/docker-compose.yml"
down-flags: "--volumes"
# Runs a set of commands using the runners shell
- name: Test docker
- run: curl 127.0.0.1:8000
+ run: curl 127.0.0.1:5000
test:
runs-on: ubuntu-latest
From d7b42488bd56815623cbbdc3f65f21dac83e626f Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 11:32:32 +0700
Subject: [PATCH 20/49] run test in ci
---
.github/workflows/ci.yaml | 14 +++++++-------
10.GK/DoAnhTu/app/test/test_requirements.txt | 5 +++++
2 files changed, 12 insertions(+), 7 deletions(-)
create mode 100644 10.GK/DoAnhTu/app/test/test_requirements.txt
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index db3b6b048..3ca44b5d5 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -44,10 +44,10 @@ jobs:
- name: Test docker
run: curl 127.0.0.1:5000
- test:
- runs-on: ubuntu-latest
- needs: build
- # Steps represent a sequence of tasks that will be executed as part of the job
- steps:
- # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- - uses: actions/checkout@v3
+ - name: run test
+ run: |
+ cd 10.GK/DoAnhTu/app/test
+ python3 --version
+ pip install pytest
+ pip install -r test_requirements.txt
+ pytest
diff --git a/10.GK/DoAnhTu/app/test/test_requirements.txt b/10.GK/DoAnhTu/app/test/test_requirements.txt
new file mode 100644
index 000000000..7db46087e
--- /dev/null
+++ b/10.GK/DoAnhTu/app/test/test_requirements.txt
@@ -0,0 +1,5 @@
+pymongo==4.3.3
+pytest==7.3.1
+requests==2.30.0
+Flask==2.3.1
+Flask-PyMongo==2.3.0
\ No newline at end of file
From b2ed87a9030a8d862c96ee86a419550144bb2eb4 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 11:32:53 +0700
Subject: [PATCH 21/49] add pip list
---
10.GK/DoAnhTu/app/requirements.txt | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/10.GK/DoAnhTu/app/requirements.txt b/10.GK/DoAnhTu/app/requirements.txt
index a5053ceec..162503354 100644
--- a/10.GK/DoAnhTu/app/requirements.txt
+++ b/10.GK/DoAnhTu/app/requirements.txt
@@ -1,11 +1,21 @@
blinker==1.6.2
+certifi==2023.5.7
+charset-normalizer==3.1.0
click==8.1.3
dnspython==2.3.0
+exceptiongroup==1.1.1
Flask==2.3.1
Flask-PyMongo==2.3.0
+idna==3.4
+iniconfig==2.0.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.2
+packaging==23.1
+pluggy==1.0.0
pymongo==4.3.3
-
+pytest==7.3.1
+requests==2.30.0
+tomli==2.0.1
+urllib3==2.0.2
Werkzeug==2.3.1
From 8d6f409ccd3cfe4b98a65b8cebf74628c4ffe290 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 11:35:49 +0700
Subject: [PATCH 22/49] done Ci
---
.github/workflows/ci.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 3ca44b5d5..3ca63aeac 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -50,4 +50,4 @@ jobs:
python3 --version
pip install pytest
pip install -r test_requirements.txt
- pytest
+ pytest -s
From db45ee371f00f354e72131ecd7525d1ca1020a3a Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 11:41:28 +0700
Subject: [PATCH 23/49] complete CI
---
.github/workflows/ci.yaml | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 3ca63aeac..337fdee09 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -25,26 +25,18 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- # check working directory
- - name: Check pwd
- run: |
- pwd
- ls
- cd 10.GK/DoAnhTu
- pwd
- - name: check pwd 2
- run: pwd
+ # deploy apllication by docker compose to test
- name: Docker Compose Action
uses: isbang/compose-action@v1.4.1
with:
compose-file: "./10.GK/DoAnhTu/docker-compose.yml"
down-flags: "--volumes"
- # Runs a set of commands using the runners shell
- - name: Test docker
+ # Test application run or die
+ - name: Test application run or die
run: curl 127.0.0.1:5000
- - name: run test
+ - name: Run test by pytest
run: |
cd 10.GK/DoAnhTu/app/test
python3 --version
From 61ba48f9c4174545147725d99dfc045113d19a6e Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 14:48:23 +0700
Subject: [PATCH 24/49] auto push image when release
---
.github/workflows/release.yaml | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 .github/workflows/release.yaml
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
new file mode 100644
index 000000000..9e425d1c3
--- /dev/null
+++ b/.github/workflows/release.yaml
@@ -0,0 +1,27 @@
+name: Release Workflow
+
+on:
+ push:
+ tags:
+ - "*"
+
+jobs:
+ build-and-push:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Login to Docker Hub
+ run: |
+ echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
+ env:
+ DOCKER_USERNAME: ${{ secrets.DOCKER_USER}}
+ DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
+
+ - name: Build and push Docker images
+ run: |
+ cd 10.GK/DoAnhTu/
+ docker-compose build
+ docker-compose push
+ env:
+ DOCKER_USERNAME: ${{ secrets.DOCKER_USER }}
+ DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
From 79c17d8f20d500acf58cc7b8af7769964349a189 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 14:53:44 +0700
Subject: [PATCH 25/49] add checkout in github action
---
.github/workflows/release.yaml | 3 +++
1 file changed, 3 insertions(+)
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index 9e425d1c3..1d1000e51 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -17,6 +17,9 @@ jobs:
DOCKER_USERNAME: ${{ secrets.DOCKER_USER}}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
+ # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
+ - uses: actions/checkout@v3
+
- name: Build and push Docker images
run: |
cd 10.GK/DoAnhTu/
From 0a4d277ac42508054e02229b3ea0535fdcc24286 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 14:58:11 +0700
Subject: [PATCH 26/49] add push to dockerhub
---
.github/workflows/release.yaml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index 1d1000e51..c8edd6cd7 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -25,6 +25,8 @@ jobs:
cd 10.GK/DoAnhTu/
docker-compose build
docker-compose push
+ docker tag doanhtu-appuser mr4x2/doanhtu-appuser
+ docker push mr4x2/doanhtu-appuser
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
From 3dc896f1e50636a8fa381d81ed56da2a4c2a19c6 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 15:01:14 +0700
Subject: [PATCH 27/49] edit image name in release.yaml
---
.github/workflows/release.yaml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index c8edd6cd7..99d6712bf 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -25,8 +25,8 @@ jobs:
cd 10.GK/DoAnhTu/
docker-compose build
docker-compose push
- docker tag doanhtu-appuser mr4x2/doanhtu-appuser
- docker push mr4x2/doanhtu-appuser
+ docker tag appuser mr4x2/appuser
+ docker push mr4x2/appuser
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
From 8e597622ce25ed7e488c3ca4d2e5db7dbb0bc5df Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 15:07:57 +0700
Subject: [PATCH 28/49] show images in github action
---
.github/workflows/release.yaml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index 99d6712bf..2d7b71240 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -24,9 +24,9 @@ jobs:
run: |
cd 10.GK/DoAnhTu/
docker-compose build
- docker-compose push
- docker tag appuser mr4x2/appuser
- docker push mr4x2/appuser
+ docker images
+ docker tag appuser ${{ secrets.DOCKER_USER}}/appuser
+ docker push ${{ secrets.DOCKER_USER}}/appuser
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
From f964e02c6ca5b87d4e9473b9cdb6e513e934e848 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 15:12:14 +0700
Subject: [PATCH 29/49] fix image
---
.github/workflows/release.yaml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index 2d7b71240..504d0e02e 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -25,8 +25,8 @@ jobs:
cd 10.GK/DoAnhTu/
docker-compose build
docker images
- docker tag appuser ${{ secrets.DOCKER_USER}}/appuser
- docker push ${{ secrets.DOCKER_USER}}/appuser
+ docker tag doanhtu_appuser ${{ secrets.DOCKER_USER}}/doanhtu_appuser
+ docker push ${{ secrets.DOCKER_USER}}/doanhtu_appuser
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
From 995f14a29c0d3b8617f2c88ec962f6f7b9fe3626 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Fri, 19 May 2023 15:32:49 +0700
Subject: [PATCH 30/49] add github.ref_name
---
.github/workflows/release.yaml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index 504d0e02e..e84cd7ff9 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -25,8 +25,8 @@ jobs:
cd 10.GK/DoAnhTu/
docker-compose build
docker images
- docker tag doanhtu_appuser ${{ secrets.DOCKER_USER}}/doanhtu_appuser
- docker push ${{ secrets.DOCKER_USER}}/doanhtu_appuser
+ docker tag doanhtu_appuser ${{ secrets.DOCKER_USER}}/doanhtu_appuser:${{ github.ref_name }}
+ docker push ${{ secrets.DOCKER_USER}}/doanhtu_appuser:${{ github.ref_name }}
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
From a7659ba82190ec58f00f25709b64aa92324fc67a Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Sun, 21 May 2023 20:13:36 +0700
Subject: [PATCH 31/49] loadbalancer
---
10.GK/DoAnhTu/docker-compose.yml | 15 +++++++++++++--
10.GK/DoAnhTu/nginx/conf.d/default.conf | 16 ++++++++--------
2 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/10.GK/DoAnhTu/docker-compose.yml b/10.GK/DoAnhTu/docker-compose.yml
index 1e4981f20..71af16aab 100644
--- a/10.GK/DoAnhTu/docker-compose.yml
+++ b/10.GK/DoAnhTu/docker-compose.yml
@@ -1,6 +1,6 @@
version: '3'
services:
- appuser:
+ appuser1:
build: ./app
depends_on:
- dbmongo
@@ -9,6 +9,16 @@ services:
networks:
- db
- app
+
+ appuser2:
+ build: ./app
+ depends_on:
+ - dbmongo
+ ports:
+ - 5001:5000
+ networks:
+ - db
+ - app
nginx-production:
@@ -18,7 +28,8 @@ services:
volumes:
- ./nginx/conf.d/:/etc/nginx/conf.d/
depends_on:
- - appuser
+ - appuser1
+ - appuser2
networks:
- app
diff --git a/10.GK/DoAnhTu/nginx/conf.d/default.conf b/10.GK/DoAnhTu/nginx/conf.d/default.conf
index 44cd3dced..4f1916b1a 100644
--- a/10.GK/DoAnhTu/nginx/conf.d/default.conf
+++ b/10.GK/DoAnhTu/nginx/conf.d/default.conf
@@ -1,5 +1,6 @@
-upstream appuser {
- server appuser:5000;
+upstream localhost {
+ server appuser1:5000;
+ server appuser2:5000;
}
@@ -8,10 +9,9 @@ server {
server_name _;
location / {
- proxy_pass http://appuser;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $scheme;
- proxy_set_header X-Forwarded-Host $host;
- proxy_set_header X-Forwarded-Prefix /;
+ proxy_pass http://localhost;
+
}
-}
\ No newline at end of file
+}
+
+
From a7c5ae759c3683b2fa81818565143c15624dcf6b Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Sun, 21 May 2023 20:13:58 +0700
Subject: [PATCH 32/49] test change port to test in host
---
10.GK/DoAnhTu/app/test/test_app_api.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/10.GK/DoAnhTu/app/test/test_app_api.py b/10.GK/DoAnhTu/app/test/test_app_api.py
index 43a4b7ca3..4c5f0ba46 100644
--- a/10.GK/DoAnhTu/app/test/test_app_api.py
+++ b/10.GK/DoAnhTu/app/test/test_app_api.py
@@ -1,7 +1,7 @@
import requests
from flask_pymongo import MongoClient
-ENDPOINT = "http://127.0.0.1:5000/"
+ENDPOINT = "http://127.0.0.1:8000/"
client = MongoClient("mongodb://admin:Admin123@127.0.0.1:27017/", connectTimeoutMS=3000)
VDT_DB = client.VDTuser
db = VDT_DB.user
From 244c4e688f5e69a9fbb9561e25a6070af73afa79 Mon Sep 17 00:00:00 2001
From: Tu Do <80826854+batamsieuhang@users.noreply.github.com>
Date: Sun, 21 May 2023 20:18:59 +0700
Subject: [PATCH 33/49] Update test host run or die ci.yaml
---
.github/workflows/ci.yaml | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 337fdee09..f5f987b30 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -34,7 +34,10 @@ jobs:
# Test application run or die
- name: Test application run or die
- run: curl 127.0.0.1:5000
+ run: |
+ curl 127.0.0.1:5000
+ curl 127.0.0.1:5001
+ curl 127.0.0.1:8000
- name: Run test by pytest
run: |
From a3680fc3067d57533d9b9a5a88972d087f5a710c Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Sun, 21 May 2023 20:21:38 +0700
Subject: [PATCH 34/49] test port
---
10.GK/DoAnhTu/app/Dockerfile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/10.GK/DoAnhTu/app/Dockerfile b/10.GK/DoAnhTu/app/Dockerfile
index 55def8633..c9fcae1f9 100644
--- a/10.GK/DoAnhTu/app/Dockerfile
+++ b/10.GK/DoAnhTu/app/Dockerfile
@@ -15,7 +15,7 @@ RUN pip install -r requirements.txt
COPY . .
-EXPOSE 5000
+
From 6bbf5afcf1e0d16113a8e47dca1a3b13ff06cd21 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Sun, 21 May 2023 23:30:22 +0700
Subject: [PATCH 35/49] ansible
---
10.GK/DoAnhTu/ansible-roles/ansible.cfg | 6 +++
10.GK/DoAnhTu/ansible-roles/hosts-dev | 14 +++++
.../ansible-roles/roles/common/tasks/main.yml | 46 ++++++++++++++++
.../roles/loadbalancer/tasks/main.yml | 23 ++++++++
.../roles/loadbalancer/templates/default.conf | 18 +++++++
.../ansible-roles/roles/mongo/tasks/main.yml | 37 +++++++++++++
.../roles/webservers/tasks/main.yml | 54 +++++++++++++++++++
10.GK/DoAnhTu/ansible-roles/run.yml | 10 ++++
8 files changed, 208 insertions(+)
create mode 100644 10.GK/DoAnhTu/ansible-roles/ansible.cfg
create mode 100644 10.GK/DoAnhTu/ansible-roles/hosts-dev
create mode 100644 10.GK/DoAnhTu/ansible-roles/roles/common/tasks/main.yml
create mode 100644 10.GK/DoAnhTu/ansible-roles/roles/loadbalancer/tasks/main.yml
create mode 100644 10.GK/DoAnhTu/ansible-roles/roles/loadbalancer/templates/default.conf
create mode 100644 10.GK/DoAnhTu/ansible-roles/roles/mongo/tasks/main.yml
create mode 100644 10.GK/DoAnhTu/ansible-roles/roles/webservers/tasks/main.yml
create mode 100644 10.GK/DoAnhTu/ansible-roles/run.yml
diff --git a/10.GK/DoAnhTu/ansible-roles/ansible.cfg b/10.GK/DoAnhTu/ansible-roles/ansible.cfg
new file mode 100644
index 000000000..36903c918
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/ansible.cfg
@@ -0,0 +1,6 @@
+# ansible.cfg
+
+[defaults]
+inventory = ./hosts-dev
+host_key_checking = False
+retry_files_enabled = False
diff --git a/10.GK/DoAnhTu/ansible-roles/hosts-dev b/10.GK/DoAnhTu/ansible-roles/hosts-dev
new file mode 100644
index 000000000..aa8d1ede7
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/hosts-dev
@@ -0,0 +1,14 @@
+# hosts-dev
+
+[local]
+node1 ansible_host=192.168.60.134
+node1 ansible_ssh_pass=2288
+node1 ansible_user=vm1
+node1 ansible_sudo_pass=2288
+
+
+[VPS]
+vps1 ansible_host=35.84.3.157
+vps1 ansible_ssh_pass=vdt2023
+vps1 ansible_user=cloud_user
+vps1 ansible_sudo_pass=vdt2023
\ No newline at end of file
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/common/tasks/main.yml b/10.GK/DoAnhTu/ansible-roles/roles/common/tasks/main.yml
new file mode 100644
index 000000000..d1b36815e
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/roles/common/tasks/main.yml
@@ -0,0 +1,46 @@
+---
+# tasks file for roles/common
+- name: updating apt packages
+ apt:
+ name: "*"
+ state: latest
+ update_cache: true
+
+- name: instal require packages for docker
+ apt:
+ pkg:
+ - apt-transport-https
+ - ca-certificates
+ - curl
+ - software-properties-common
+ - python3-pip
+ - python3-setuptools
+ state: latest
+ update_cache: true
+
+- name: Add Docker GPG apt Key
+ apt_key:
+ url: https://download.docker.com/linux/ubuntu/gpg
+ state: present
+
+- name: Add Docker Repository
+ apt_repository:
+ repo: deb https://download.docker.com/linux/ubuntu focal stable
+ state: present
+
+- name: Update apt and install docker-ce
+ apt:
+ name: docker-ce
+ state: latest
+ update_cache: true
+
+- name: Install Docker Module for Python
+ pip:
+ name:
+ - docker
+ - docker-compose
+- name: add user to Docker group
+ shell: "usermod -aG docker cloud_user"
+
+- name: allow ports 8000, 5000, 5001
+ ansible.builtin.shell: ufw allow 8000 && ufw allow 5000 && ufw allow 5001
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/loadbalancer/tasks/main.yml b/10.GK/DoAnhTu/ansible-roles/roles/loadbalancer/tasks/main.yml
new file mode 100644
index 000000000..cd3136c73
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/roles/loadbalancer/tasks/main.yml
@@ -0,0 +1,23 @@
+---
+# tasks file for roles/loadbalancer
+- name: Creates src directory
+ file:
+ path: /home/nginx
+ state: directory
+ mode: "0775"
+
+- name: copy config nginx file to host
+ ansible.builtin.copy:
+ src: ../templates/default.conf
+ dest: /home/nginx/conf.d/
+
+- name: deploy nginx
+ community.docker.docker_container:
+ name: nginx
+ image: nginx:1.22.0-alpine
+ ports:
+ - "8000:80"
+ volumes:
+ - /home/nginx/conf.d/:/etc/nginx/conf.d/
+ networks:
+ - name: network_app
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/loadbalancer/templates/default.conf b/10.GK/DoAnhTu/ansible-roles/roles/loadbalancer/templates/default.conf
new file mode 100644
index 000000000..7a2754c34
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/roles/loadbalancer/templates/default.conf
@@ -0,0 +1,18 @@
+upstream flask {
+ server flask1:5000;
+ server flask2:5000;
+}
+
+
+server {
+ listen 80;
+ server_name _;
+
+ location / {
+ proxy_pass http://flask;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_set_header X-Forwarded-Host $host;
+ proxy_set_header X-Forwarded-Prefix /;
+ }
+}
\ No newline at end of file
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/mongo/tasks/main.yml b/10.GK/DoAnhTu/ansible-roles/roles/mongo/tasks/main.yml
new file mode 100644
index 000000000..b6ffb10d0
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/roles/mongo/tasks/main.yml
@@ -0,0 +1,37 @@
+---
+# tasks file for roles/mongo
+- name: Creates src directory
+ file:
+ path: /home/data
+ state: directory
+ mode: "0775"
+
+- name: Copy file with owner and permissions
+ ansible.builtin.copy:
+ src: ../../../../mongo-entrypoint/init-mongo.js
+ dest: /home/data
+ mode: "0777"
+
+- name: Create a volume
+ community.docker.docker_volume:
+ name: db1
+
+- name: Create a network
+ docker_network:
+ name: network_db
+
+- name: deploy mongo db
+ community.docker.docker_container:
+ name: mongodb
+ image: mongo:5.0
+ env:
+ MONGO_INITDB_ROOT_USERNAME: "admin"
+ MONGO_INITDB_ROOT_PASSWORD: "Admin123"
+ MONGO_INITDB_DATABASE: "VDTuser"
+ ports:
+ - "27017:27017"
+ volumes:
+ - db1:/data/db
+ - /home/data/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
+ networks:
+ - name: network_db
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/webservers/tasks/main.yml b/10.GK/DoAnhTu/ansible-roles/roles/webservers/tasks/main.yml
new file mode 100644
index 000000000..4a504b774
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/roles/webservers/tasks/main.yml
@@ -0,0 +1,54 @@
+---
+- name: Creates src directory
+ file:
+ path: /home/src
+ state: directory
+ mode: "0775"
+
+- name: copy src to folder remote
+ ansible.builtin.copy:
+ src: ../../../../app/VDT
+ dest: /home/src
+- name: copy test to folder remote
+ ansible.builtin.copy:
+ src: ../../../../app/test
+ dest: /home/src
+- name: copy dockerfile to folder remote
+ ansible.builtin.copy:
+ src: ../../../../app/Dockerfile
+ dest: /home/src
+- name: copy requirements.txt to folder remote
+ ansible.builtin.copy:
+ src: ../../../../app/requirements.txt
+ dest: /home/src
+
+- name: Create a network
+ docker_network:
+ name: network_app
+
+- name: create docker image flask app
+ shell: docker build -t flask_python .
+ args:
+ chdir: /home/src
+
+- name: create docker container flask app
+ docker_container:
+ name: flask1
+ image: flask_python
+ state: started
+ ports:
+ - "5000:5000"
+ networks:
+ - name: network_db
+ - name: network_app
+
+- name: create docker container flask app
+ docker_container:
+ name: flask2
+ image: flask_python
+ state: started
+ ports:
+ - "5001:5000"
+ networks:
+ - name: network_db
+ - name: network_app
diff --git a/10.GK/DoAnhTu/ansible-roles/run.yml b/10.GK/DoAnhTu/ansible-roles/run.yml
new file mode 100644
index 000000000..227a4feff
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/run.yml
@@ -0,0 +1,10 @@
+---
+- name: install webapp
+ hosts: VPS
+ become: true
+ gather_facts: true
+ roles:
+ - common
+ - mongo
+ - webservers
+ - loadbalancer
From 8e14028e013a3b56f72a978d5f58404d7b33b419 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Sun, 21 May 2023 23:30:35 +0700
Subject: [PATCH 36/49] edit code
---
10.GK/DoAnhTu/README.md | 0
10.GK/DoAnhTu/app/VDT/__init__.py | 2 +-
10.GK/DoAnhTu/docker-compose.yml | 2 +-
3 files changed, 2 insertions(+), 2 deletions(-)
create mode 100644 10.GK/DoAnhTu/README.md
diff --git a/10.GK/DoAnhTu/README.md b/10.GK/DoAnhTu/README.md
new file mode 100644
index 000000000..e69de29bb
diff --git a/10.GK/DoAnhTu/app/VDT/__init__.py b/10.GK/DoAnhTu/app/VDT/__init__.py
index 700c49738..820392be3 100644
--- a/10.GK/DoAnhTu/app/VDT/__init__.py
+++ b/10.GK/DoAnhTu/app/VDT/__init__.py
@@ -10,7 +10,7 @@ def create_app(test_config=None):
# connect to db
client = MongoClient(
- "mongodb://admin:Admin123@dbmongo:27017/", connectTimeoutMS=3000
+ "mongodb://admin:Admin123@mongodb:27017/", connectTimeoutMS=3000
)
VDT_DB = client.VDTuser
db = VDT_DB.user
diff --git a/10.GK/DoAnhTu/docker-compose.yml b/10.GK/DoAnhTu/docker-compose.yml
index 71af16aab..17b3d576e 100644
--- a/10.GK/DoAnhTu/docker-compose.yml
+++ b/10.GK/DoAnhTu/docker-compose.yml
@@ -34,7 +34,7 @@ services:
- app
- dbmongo:
+ mongodb:
image: mongo:5.0
environment:
From 0bdedfdaf6a63764bb8af1729e16ae009c356bbd Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Sun, 21 May 2023 23:35:23 +0700
Subject: [PATCH 37/49] fix error name container
---
10.GK/DoAnhTu/docker-compose.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/10.GK/DoAnhTu/docker-compose.yml b/10.GK/DoAnhTu/docker-compose.yml
index 17b3d576e..df433412c 100644
--- a/10.GK/DoAnhTu/docker-compose.yml
+++ b/10.GK/DoAnhTu/docker-compose.yml
@@ -3,7 +3,7 @@ services:
appuser1:
build: ./app
depends_on:
- - dbmongo
+ - mongodb
ports:
- 5000:5000
networks:
@@ -13,7 +13,7 @@ services:
appuser2:
build: ./app
depends_on:
- - dbmongo
+ - mongodb
ports:
- 5001:5000
networks:
From c08091108d88ef7e18ce1aa9267f782e193bdcb3 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Mon, 22 May 2023 04:12:15 +0700
Subject: [PATCH 38/49] config prom by ansible
---
.../roles/monitor/tasks/main.yml | 18 ++++++
.../monitor/templates/docker-compose.yml | 60 +++++++++++++++++++
.../roles/monitor/templates/prometheus.yml | 52 ++++++++++++++++
3 files changed, 130 insertions(+)
create mode 100644 10.GK/DoAnhTu/ansible-roles/roles/monitor/tasks/main.yml
create mode 100644 10.GK/DoAnhTu/ansible-roles/roles/monitor/templates/docker-compose.yml
create mode 100644 10.GK/DoAnhTu/ansible-roles/roles/monitor/templates/prometheus.yml
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/monitor/tasks/main.yml b/10.GK/DoAnhTu/ansible-roles/roles/monitor/tasks/main.yml
new file mode 100644
index 000000000..55a387252
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/roles/monitor/tasks/main.yml
@@ -0,0 +1,18 @@
+---
+# tasks file for roles/monitoring
+- name: Creates src directory
+ file:
+ path: /home/prometheus
+ state: directory
+ mode: "0775"
+
+- name: Copy file with owner and permissions
+ ansible.builtin.copy:
+ src: ../templates/
+ dest: /home/prometheus/
+ mode: "0777"
+- name: Run Docker Compose
+ community.docker.docker_compose:
+ project_src: /home/prometheus/
+ build: no
+ state: present
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/monitor/templates/docker-compose.yml b/10.GK/DoAnhTu/ansible-roles/roles/monitor/templates/docker-compose.yml
new file mode 100644
index 000000000..0df6dcd05
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/roles/monitor/templates/docker-compose.yml
@@ -0,0 +1,60 @@
+version: '3'
+services:
+ prometheus:
+ image: prom/prometheus:v2.43.0
+ container_name: prometheus
+ volumes:
+ - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
+ command:
+ - "--config.file=/etc/prometheus/prometheus.yml"
+ - "--storage.tsdb.path=/prometheus"
+ - "--web.console.libraries=/etc/prometheus/console_libraries"
+ - "--web.console.templates=/etc/prometheus/consoles"
+ - "--storage.tsdb.retention.time=200h"
+ - "--storage.tsdb.max-block-duration=5d"
+ - "--web.enable-lifecycle"
+ - "--web.listen-address=:9090"
+ restart: unless-stopped
+ network_mode: host
+ environment:
+ TZ: "Asia/Ho_Chi_Minh"
+ labels:
+ org.label-schema.group: "monitoring"
+
+ nodeexporter:
+ image: prom/node-exporter:v1.5.0
+ container_name: nodeexporter
+ volumes:
+ - /proc:/host/proc:ro
+ - /sys:/host/sys:ro
+ - /:/rootfs:ro
+ command:
+ - "--path.procfs=/host/proc"
+ - "--path.rootfs=/rootfs"
+ - "--path.sysfs=/host/sys"
+ - "--collector.filesystem.ignored-mount-points=^/(sys|proc|dev|host|etc)($$|/)"
+ restart: unless-stopped
+ network_mode: host
+ environment:
+ TZ: "Asia/Ho_Chi_Minh"
+ labels:
+ org.label-schema.group: "monitoring"
+
+ cadvisor:
+ image: gcr.io/cadvisor/cadvisor:v0.47.1
+ container_name: cadvisor
+ privileged: true
+ devices:
+ - /dev/kmsg:/dev/kmsg
+ volumes:
+ - /:/rootfs:ro
+ - /var/run:/var/run:ro
+ - /sys:/sys:ro
+ - /var/lib/docker:/var/lib/docker:ro
+ #- /cgroup:/cgroup:ro #doesn't work on MacOS only for Linux
+ restart: unless-stopped
+ network_mode: host
+ environment:
+ TZ: "Asia/Ho_Chi_Minh"
+ labels:
+ org.label-schema.group: "monitoring"
\ No newline at end of file
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/monitor/templates/prometheus.yml b/10.GK/DoAnhTu/ansible-roles/roles/monitor/templates/prometheus.yml
new file mode 100644
index 000000000..66b8e9ebc
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/roles/monitor/templates/prometheus.yml
@@ -0,0 +1,52 @@
+---
+global:
+ scrape_interval: 15s
+ evaluation_interval: 15s
+
+ # Attach these labels to any time series or alerts when communicating with
+ # external systems (federation, remote storage, Alertmanager).
+ external_labels:
+ username: tuda
+
+
+alerting:
+ alertmanagers:
+ - scheme: http
+ static_configs:
+ - targets:
+ - 'localhost:9093'
+ - 'localhost:9094'
+
+# Load and evaluate rules in this file every 'evaluation_interval' seconds.
+rule_files:
+ - "alert.rules"
+
+# remote_read:
+# - url: http://localhost:9090/api/v1/read
+
+# A scrape configuration containing exactly one endpoint to scrape.
+scrape_configs:
+ - job_name: 'prometheus'
+ static_configs:
+ - targets: [
+ 'localhost:9090',
+ 'localhost:9091'
+ ]
+
+
+ - job_name: 'node-exporter'
+ static_configs:
+ - targets: [
+ 'localhost:9100',
+ 'demo.do.prometheus.io:9100'
+ ]
+
+ - job_name: 'cadvisor'
+ static_configs:
+ - targets: [
+ 'localhost:8080',
+ ]
+
+remote_write:
+- url: 'http://27.66.108.93:9090/api/v1/write'
+ name: tuda
\ No newline at end of file
From a55639bb3c7080214d27a207c9ba44d7d997139b Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Mon, 22 May 2023 04:38:37 +0700
Subject: [PATCH 39/49] config host
---
10.GK/DoAnhTu/ansible-roles/hosts-dev | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/10.GK/DoAnhTu/ansible-roles/hosts-dev b/10.GK/DoAnhTu/ansible-roles/hosts-dev
index aa8d1ede7..4d1b18e29 100644
--- a/10.GK/DoAnhTu/ansible-roles/hosts-dev
+++ b/10.GK/DoAnhTu/ansible-roles/hosts-dev
@@ -8,7 +8,12 @@ node1 ansible_sudo_pass=2288
[VPS]
-vps1 ansible_host=35.84.3.157
+vps1 ansible_host=35.86.186.124
vps1 ansible_ssh_pass=vdt2023
vps1 ansible_user=cloud_user
-vps1 ansible_sudo_pass=vdt2023
\ No newline at end of file
+vps1 ansible_sudo_pass=vdt2023
+
+vps2 ansible_host=35.86.242.19
+vps2 ansible_ssh_pass=vdt2023
+vps2 ansible_user=cloud_user
+vps2 ansible_sudo_pass=vdt2023
\ No newline at end of file
From b7520e5e7709748c62e12a75bab9b9b49d5deef8 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Mon, 22 May 2023 04:38:52 +0700
Subject: [PATCH 40/49] main roles
---
10.GK/DoAnhTu/ansible-roles/config.yml | 21 +++++++++++++++++++
.../roles/logging/tasks/main.yml | 16 ++++++++++++++
10.GK/DoAnhTu/ansible-roles/run.yml | 15 ++++++++++++-
3 files changed, 51 insertions(+), 1 deletion(-)
create mode 100644 10.GK/DoAnhTu/ansible-roles/config.yml
create mode 100644 10.GK/DoAnhTu/ansible-roles/roles/logging/tasks/main.yml
diff --git a/10.GK/DoAnhTu/ansible-roles/config.yml b/10.GK/DoAnhTu/ansible-roles/config.yml
new file mode 100644
index 000000000..fcdf4f1c6
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/config.yml
@@ -0,0 +1,21 @@
+---
+# - name: install configure package
+# hosts: vps2
+# become: true
+# gather_facts: true
+# roles:
+# - common
+
+# - name: install configure package
+# hosts: VPS
+# become: true
+# gather_facts: true
+# roles:
+# - monitoring
+
+- name: install configure package
+ hosts: local
+ become: true
+ gather_facts: true
+ roles:
+ - logging
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/logging/tasks/main.yml b/10.GK/DoAnhTu/ansible-roles/roles/logging/tasks/main.yml
new file mode 100644
index 000000000..256708771
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/roles/logging/tasks/main.yml
@@ -0,0 +1,16 @@
+---
+# tasks file for roles/logging
+- name: Creates src directory
+ file:
+ path: /home/fluentd
+ state: directory
+ mode: "0775"
+
+- name: Copy file with owner and permissions
+ ansible.builtin.copy:
+ src: ../templates/
+ dest: /home/fluentd/
+ mode: "0777"
+
+- name: Run docker-compose
+ shell: cd /home/fluentd/ && docker compose up
diff --git a/10.GK/DoAnhTu/ansible-roles/run.yml b/10.GK/DoAnhTu/ansible-roles/run.yml
index 227a4feff..deadd7ea7 100644
--- a/10.GK/DoAnhTu/ansible-roles/run.yml
+++ b/10.GK/DoAnhTu/ansible-roles/run.yml
@@ -1,10 +1,23 @@
---
-- name: install webapp
+- name: install configure package
hosts: VPS
become: true
gather_facts: true
roles:
- common
+
+- name: install webapp
+ hosts: VPS
+ become: true
+ gather_facts: true
+ roles:
- mongo
- webservers
- loadbalancer
+
+- name: install configure package
+ hosts: VPS
+ become: true
+ gather_facts: true
+ roles:
+ - monitoring
From c5d919041266391c26349872c23e2e33c3683289 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Mon, 22 May 2023 04:39:13 +0700
Subject: [PATCH 41/49] ansible logging
---
.../roles/logging/templates/Dockerfile | 5 ++++
.../roles/logging/templates/conf/fluent.conf | 29 +++++++++++++++++++
.../logging/templates/docker-compose.yml | 11 +++++++
3 files changed, 45 insertions(+)
create mode 100644 10.GK/DoAnhTu/ansible-roles/roles/logging/templates/Dockerfile
create mode 100644 10.GK/DoAnhTu/ansible-roles/roles/logging/templates/conf/fluent.conf
create mode 100644 10.GK/DoAnhTu/ansible-roles/roles/logging/templates/docker-compose.yml
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/Dockerfile b/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/Dockerfile
new file mode 100644
index 000000000..301d3ff43
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/Dockerfile
@@ -0,0 +1,5 @@
+FROM fluent/fluentd:v1.12.0-debian-1.0
+USER root
+RUN ["gem", "install", "elasticsearch", "--no-document", "--version", "< 8"]
+RUN ["gem", "install", "fluent-plugin-elasticsearch", "--no-document", "--version", "5.2.2"]
+USER fluent
\ No newline at end of file
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/conf/fluent.conf b/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/conf/fluent.conf
new file mode 100644
index 000000000..23bab7648
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/conf/fluent.conf
@@ -0,0 +1,29 @@
+
+ @type forward
+ port 24224
+ bind 0.0.0.0
+
+
+ @type record_transformer
+
+ Hostname ${hostname}
+ ip ${record['ip']}
+ time ${record['time']}
+ action ${record['action']}
+ result ${record['result']}
+ username "tuda"
+
+
+
+ @type copy
+
+ @type elasticsearch
+ host 171.236.38.168
+ port 9200
+ logstash_format true
+ logstash_prefix tuda
+ logstash_dateformat %Y%m%d
+ include_tag_key true
+ flush_interval 1s
+
+
\ No newline at end of file
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/docker-compose.yml b/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/docker-compose.yml
new file mode 100644
index 000000000..f8a7a9354
--- /dev/null
+++ b/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/docker-compose.yml
@@ -0,0 +1,11 @@
+version: '3'
+services:
+ fluentd:
+ container_name: fluentd
+ build: /home/fluentd
+ volumes:
+ - ./conf:/fluentd/etc
+ network_mode: "host"
+ ports:
+ - "24224:24224"
+ - "24224:24224/udp"
\ No newline at end of file
From 18bad96f52a8546e6896dcd07851661fbacc6aa4 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Mon, 22 May 2023 18:17:57 +0700
Subject: [PATCH 42/49] add fluentd log driver to docker file
---
.../roles/loadbalancer/tasks/main.yml | 4 ++++
.../roles/webservers/tasks/main.yml | 12 ++++++++++--
10.GK/DoAnhTu/ansible-roles/run.yml | 19 ++++++++++---------
10.GK/DoAnhTu/docker-compose.yml | 19 +++++++++++++++++++
4 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/loadbalancer/tasks/main.yml b/10.GK/DoAnhTu/ansible-roles/roles/loadbalancer/tasks/main.yml
index cd3136c73..15da21770 100644
--- a/10.GK/DoAnhTu/ansible-roles/roles/loadbalancer/tasks/main.yml
+++ b/10.GK/DoAnhTu/ansible-roles/roles/loadbalancer/tasks/main.yml
@@ -21,3 +21,7 @@
- /home/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- name: network_app
+ log_driver: fluentd
+ log_options:
+ fluentd-address: "0.0.0.0:24224"
+ tag: app1
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/webservers/tasks/main.yml b/10.GK/DoAnhTu/ansible-roles/roles/webservers/tasks/main.yml
index 4a504b774..a1473cd89 100644
--- a/10.GK/DoAnhTu/ansible-roles/roles/webservers/tasks/main.yml
+++ b/10.GK/DoAnhTu/ansible-roles/roles/webservers/tasks/main.yml
@@ -31,7 +31,7 @@
args:
chdir: /home/src
-- name: create docker container flask app
+- name: create docker container flask app 1
docker_container:
name: flask1
image: flask_python
@@ -41,8 +41,12 @@
networks:
- name: network_db
- name: network_app
+ log_driver: fluentd
+ log_options:
+ fluentd-address: "0.0.0.0:24224"
+ tag: app1
-- name: create docker container flask app
+- name: create docker container flask app 2
docker_container:
name: flask2
image: flask_python
@@ -52,3 +56,7 @@
networks:
- name: network_db
- name: network_app
+ log_driver: fluentd
+ log_options:
+ fluentd-address: "0.0.0.0:24224"
+ tag: app2
diff --git a/10.GK/DoAnhTu/ansible-roles/run.yml b/10.GK/DoAnhTu/ansible-roles/run.yml
index deadd7ea7..d999d574a 100644
--- a/10.GK/DoAnhTu/ansible-roles/run.yml
+++ b/10.GK/DoAnhTu/ansible-roles/run.yml
@@ -1,23 +1,24 @@
---
- name: install configure package
- hosts: VPS
+ hosts: vm2
become: true
gather_facts: true
roles:
- common
-- name: install webapp
- hosts: VPS
+- name: install logging and monitoring
+ hosts: vm2
become: true
gather_facts: true
roles:
- - mongo
- - webservers
- - loadbalancer
+ - monitor
+ - logging
-- name: install configure package
- hosts: VPS
+- name: install webapp
+ hosts: vm2
become: true
gather_facts: true
roles:
- - monitoring
+ - mongo
+ - webservers
+ - loadbalancer
diff --git a/10.GK/DoAnhTu/docker-compose.yml b/10.GK/DoAnhTu/docker-compose.yml
index df433412c..849ad1902 100644
--- a/10.GK/DoAnhTu/docker-compose.yml
+++ b/10.GK/DoAnhTu/docker-compose.yml
@@ -9,6 +9,12 @@ services:
networks:
- db
- app
+ logging:
+ driver: "fluentd"
+ options:
+ fluentd-address: "0.0.0.0:24224"
+ tag: app1
+
appuser2:
build: ./app
@@ -19,6 +25,13 @@ services:
networks:
- db
- app
+ logging:
+ driver: "fluentd"
+ options:
+ fluentd-address: "0.0.0.0:24224"
+ tag: app2
+
+
nginx-production:
@@ -32,6 +45,11 @@ services:
- appuser2
networks:
- app
+ logging:
+ driver: "fluentd"
+ options:
+ fluentd-address: "0.0.0.0:24224"
+ tag: nginx
mongodb:
@@ -49,6 +67,7 @@ services:
- ./mongo-entrypoint:/docker-entrypoint-initdb.d
networks:
- db
+
volumes:
db1:
From ba46b40129af52ee7707b34a23188f6e97315b02 Mon Sep 17 00:00:00 2001
From: batamsieuhang <20021460@vnu.edu.vn>
Date: Mon, 22 May 2023 18:18:41 +0700
Subject: [PATCH 43/49] update ansible config
---
10.GK/DoAnhTu/.gitignore | 2 ++
10.GK/DoAnhTu/ansible-roles/config.yml | 2 +-
10.GK/DoAnhTu/ansible-roles/hosts-dev | 25 ++++++++++++++-----
.../ansible-roles/roles/common/tasks/main.yml | 2 +-
.../roles/logging/tasks/main.yml | 3 +--
.../roles/logging/templates/conf/fluent.conf | 13 ++++++----
.../logging/templates/docker-compose.yml | 5 ++--
7 files changed, 35 insertions(+), 17 deletions(-)
diff --git a/10.GK/DoAnhTu/.gitignore b/10.GK/DoAnhTu/.gitignore
index 07ddd70d4..9a42b13fb 100644
--- a/10.GK/DoAnhTu/.gitignore
+++ b/10.GK/DoAnhTu/.gitignore
@@ -4,3 +4,5 @@ instance/
__pycache__/
flask_app/
+.vscode/
+settings.json
diff --git a/10.GK/DoAnhTu/ansible-roles/config.yml b/10.GK/DoAnhTu/ansible-roles/config.yml
index fcdf4f1c6..a21b13c12 100644
--- a/10.GK/DoAnhTu/ansible-roles/config.yml
+++ b/10.GK/DoAnhTu/ansible-roles/config.yml
@@ -14,7 +14,7 @@
# - monitoring
- name: install configure package
- hosts: local
+ hosts: localhost
become: true
gather_facts: true
roles:
diff --git a/10.GK/DoAnhTu/ansible-roles/hosts-dev b/10.GK/DoAnhTu/ansible-roles/hosts-dev
index 4d1b18e29..273577d07 100644
--- a/10.GK/DoAnhTu/ansible-roles/hosts-dev
+++ b/10.GK/DoAnhTu/ansible-roles/hosts-dev
@@ -1,10 +1,15 @@
# hosts-dev
-[local]
-node1 ansible_host=192.168.60.134
-node1 ansible_ssh_pass=2288
-node1 ansible_user=vm1
-node1 ansible_sudo_pass=2288
+[vm]
+vm1 ansible_host=192.168.60.134
+vm1 ansible_ssh_pass=2288
+vm1 ansible_user=vm1
+vm1 ansible_sudo_pass=2288
+
+vm2 ansible_host=192.168.60.135
+vm2 ansible_ssh_pass=2288
+vm2 ansible_user=vm2
+vm2 ansible_sudo_pass=2288
[VPS]
@@ -16,4 +21,12 @@ vps1 ansible_sudo_pass=vdt2023
vps2 ansible_host=35.86.242.19
vps2 ansible_ssh_pass=vdt2023
vps2 ansible_user=cloud_user
-vps2 ansible_sudo_pass=vdt2023
\ No newline at end of file
+vps2 ansible_sudo_pass=vdt2023
+
+
+
+[localhost]
+node1 ansible_host=localhost
+node1 ansible_ssh_pass=Face123@
+node1 ansible_user=mr8
+node1 ansible_sudo_pass=Face123@
\ No newline at end of file
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/common/tasks/main.yml b/10.GK/DoAnhTu/ansible-roles/roles/common/tasks/main.yml
index d1b36815e..b14c67da5 100644
--- a/10.GK/DoAnhTu/ansible-roles/roles/common/tasks/main.yml
+++ b/10.GK/DoAnhTu/ansible-roles/roles/common/tasks/main.yml
@@ -40,7 +40,7 @@
- docker
- docker-compose
- name: add user to Docker group
- shell: "usermod -aG docker cloud_user"
+ shell: "usermod -aG docker vm2"
- name: allow ports 8000, 5000, 5001
ansible.builtin.shell: ufw allow 8000 && ufw allow 5000 && ufw allow 5001
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/logging/tasks/main.yml b/10.GK/DoAnhTu/ansible-roles/roles/logging/tasks/main.yml
index 256708771..41136381b 100644
--- a/10.GK/DoAnhTu/ansible-roles/roles/logging/tasks/main.yml
+++ b/10.GK/DoAnhTu/ansible-roles/roles/logging/tasks/main.yml
@@ -11,6 +11,5 @@
src: ../templates/
dest: /home/fluentd/
mode: "0777"
-
- name: Run docker-compose
- shell: cd /home/fluentd/ && docker compose up
+ shell: cd /home/fluentd/ && docker compose up -d
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/conf/fluent.conf b/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/conf/fluent.conf
index 23bab7648..0874bff72 100644
--- a/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/conf/fluent.conf
+++ b/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/conf/fluent.conf
@@ -3,7 +3,8 @@
port 24224
bind 0.0.0.0
-
+
+
@type record_transformer
Hostname ${hostname}
@@ -11,17 +12,19 @@
time ${record['time']}
action ${record['action']}
result ${record['result']}
- username "tuda"
+ username "tuda"
+
-
+
+
@type copy
@type elasticsearch
- host 171.236.38.168
+ host 171.236.38.100
port 9200
logstash_format true
- logstash_prefix tuda
+ logstash_prefix tuda
logstash_dateformat %Y%m%d
include_tag_key true
flush_interval 1s
diff --git a/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/docker-compose.yml b/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/docker-compose.yml
index f8a7a9354..277c877a2 100644
--- a/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/docker-compose.yml
+++ b/10.GK/DoAnhTu/ansible-roles/roles/logging/templates/docker-compose.yml
@@ -7,5 +7,6 @@ services:
- ./conf:/fluentd/etc
network_mode: "host"
ports:
- - "24224:24224"
- - "24224:24224/udp"
\ No newline at end of file
+ - 24224:24224
+ - 24224:24224/udp
+
\ No newline at end of file
From 840d0725e49fe6e7fc1bada796a91ff993520f44 Mon Sep 17 00:00:00 2001
From: TuDo16 <20021460@vnu.edu.vn>
Date: Mon, 22 May 2023 18:25:45 +0700
Subject: [PATCH 44/49] fix docker can't run
---
10.GK/DoAnhTu/docker-compose.yml | 15 ---------------
1 file changed, 15 deletions(-)
diff --git a/10.GK/DoAnhTu/docker-compose.yml b/10.GK/DoAnhTu/docker-compose.yml
index 849ad1902..b98482d98 100644
--- a/10.GK/DoAnhTu/docker-compose.yml
+++ b/10.GK/DoAnhTu/docker-compose.yml
@@ -9,11 +9,6 @@ services:
networks:
- db
- app
- logging:
- driver: "fluentd"
- options:
- fluentd-address: "0.0.0.0:24224"
- tag: app1
appuser2:
@@ -25,11 +20,6 @@ services:
networks:
- db
- app
- logging:
- driver: "fluentd"
- options:
- fluentd-address: "0.0.0.0:24224"
- tag: app2
@@ -45,11 +35,6 @@ services:
- appuser2
networks:
- app
- logging:
- driver: "fluentd"
- options:
- fluentd-address: "0.0.0.0:24224"
- tag: nginx
mongodb:
From 07d81a3c462a140b7d0c783420d24e0374c37e66 Mon Sep 17 00:00:00 2001
From: TuDo16 <20021460@vnu.edu.vn>
Date: Mon, 22 May 2023 19:26:47 +0700
Subject: [PATCH 45/49] test CI
---
10.GK/DoAnhTu/README.md | 680 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 680 insertions(+)
diff --git a/10.GK/DoAnhTu/README.md b/10.GK/DoAnhTu/README.md
index e69de29bb..eceae9309 100644
--- a/10.GK/DoAnhTu/README.md
+++ b/10.GK/DoAnhTu/README.md
@@ -0,0 +1,680 @@
+# ***Bài tập lớn giữa kì***
+
+## **Phát triển một 3-tier web application đơn giản (2đ)**
+
+### **Viết một CRUD web application đơn giản thực hiện các chức năng**
+Dưới đây là kiến trúc web-application của em
+```tree
+└── DoAnhTu
+ ├── app
+ │ ├── Dockerfile
+ │ ├── requirements.txt
+ │ ├── test
+ │ │ ├── test_app_api.py
+ │ │ └── test_requirements.txt
+ │ └── VDT
+ │ ├── __init__.py
+ │ └── templates
+ │ └── VDT.html
+ ├── docker-compose.yml
+ ├── mongo-entrypoint
+ │ └── init-mongo.js
+ ├── nginx
+ │ └── conf.d
+ │ └── default.conf
+ └── README.md
+```
+
+### 1. Liệt kê danh sách sinh viên tham gia khóa đào tạo chương trình VDT 2023 lĩnh vực cloud dưới dạng bảng
+Trong thư mục app bao gồm
+
+1. VDT là thư mục của chương trình chính
+```python
+
+#VDT/__init__.py
+import os
+
+from flask import Flask, render_template, request, jsonify, redirect, url_for
+from flask_pymongo import MongoClient
+
+
+def create_app(test_config=None):
+ # create and configure the app
+ app = Flask(__name__, instance_relative_config=True)
+ # connect to db
+
+ client = MongoClient(
+ "mongodb://admin:Admin123@mongodb:27017/", connectTimeoutMS=3000
+ )
+ VDT_DB = client.VDTuser
+ db = VDT_DB.user
+
+ @app.route("/")
+ def VDT():
+ students = db.find()
+ student_data = []
+
+ for student in students:
+ person = {
+ "name": student["name"],
+ "year_of_birth": student["year_of_birth"],
+ "university": student["university"],
+ "gender": student["gender"],
+ "username": student["username"],
+ "major": student["major"],
+ }
+ student_data.append(person)
+ return render_template("VDT.html", data_student=student_data)
+
+ @app.route("/members", methods=["GET"])
+ def getlistmember():
+ students = db.find()
+ student_data = []
+
+ for student in students:
+ person = {
+ "name": student["name"],
+ "year_of_birth": student["year_of_birth"],
+ "university": student["university"],
+ "gender": student["gender"],
+ "username": student["username"],
+ "major": student["major"],
+ }
+ student_data.append(person)
+ return jsonify(student_data)
+
+ @app.route("/members/", methods=["GET"])
+ def get_student(username):
+ students = db.find()
+ members = []
+ for student in students:
+ person = {
+ "name": student["name"],
+ "year_of_birth": student["year_of_birth"],
+ "university": student["university"],
+ "gender": student["gender"],
+ "username": student["username"],
+ "major": student["major"],
+ }
+ if student["username"] == username:
+ members.append(person)
+ return jsonify(members)
+
+ @app.route("/postdata", methods=["POST"])
+ def post_student():
+ name = request.json["name"]
+ year_of_birth = request.json["year_of_birth"]
+ university = request.json["university"]
+ gender = request.json["gender"]
+ username = request.json["username"]
+ major = request.json["major"]
+
+ db.insert_one(
+ {
+ "name": name,
+ "year_of_birth": year_of_birth,
+ "university": university,
+ "gender": gender,
+ "username": username,
+ "major": major,
+ }
+ )
+ return jsonify(
+ {
+ "name": name,
+ "year_of_birth": year_of_birth,
+ "university": university,
+ "gender": gender,
+ "username": username,
+ "major": major,
+ }
+ )
+
+ @app.route("/delmember/", methods=["DELETE"])
+ def del_mem(username):
+ db.delete_one({"username": username})
+ return redirect(url_for("getlistmember"))
+
+ @app.route("/updatemember/", methods=["PUT"])
+ def up_mem(username):
+ name = request.json["name"]
+ year_of_birth = request.json["year_of_birth"]
+ university = request.json["university"]
+ gender = request.json["gender"]
+ update_username = request.json["username"]
+ major = request.json["major"]
+
+ myquery = {"username": username}
+ myupdate = {
+ "$set": {
+ "name": name,
+ "year_of_birth": year_of_birth,
+ "university": university,
+ "gender": gender,
+ "username": update_username,
+ "major": major,
+ }
+ }
+ db.update_one(myquery, myupdate)
+
+ return redirect(url_for("getlistmember"))
+
+ return app
+
+```
+
+**kết quả**
+
+1. Trang chính
+
+
+
+
+**`Vì em chưa làm frontend nên các chức năng thêm sửa xóa em xin phép show bằng api của chương trình`**
+
+2. Xem thông tin tất cả member bằng get method
+
+```python
+ @app.route("/members", methods=["GET"])
+ def getlistmember():
+ students = db.find()
+ student_data = []
+
+ for student in students:
+ person = {
+ "name": student["name"],
+ "year_of_birth": student["year_of_birth"],
+ "university": student["university"],
+ "gender": student["gender"],
+ "username": student["username"],
+ "major": student["major"],
+ }
+ student_data.append(person)
+ return jsonify(student_data)
+```
+
+
+
+
+
+
+
+
+
+
+2. Xem thông tin một member bằng username của họ
+
+
+```link
+http://192.168.60.135:8000/members/tuda
+```
+
+```python
+ @app.route("/members/", methods=["GET"])
+ def get_student(username):
+ students = db.find()
+ members = []
+ for student in students:
+ person = {
+ "name": student["name"],
+ "year_of_birth": student["year_of_birth"],
+ "university": student["university"],
+ "gender": student["gender"],
+ "username": student["username"],
+ "major": student["major"],
+ }
+ if student["username"] == username:
+ members.append(person)
+ return jsonify(members)
+```
+
+
+
+
+### 2. Kiến trúc dịch vụ
+
+- API ở đây được sử dụng bởi framework flask
+
+- DB mongodb
+
+- Nginx có tác dụng là loadbalancer
+
+### 3. Unit test
+
+Pytest là tool được sử dụng để test api
+
+Em chia test ra làm 6 phần
+- test truy cập vào homepage
+```python
+def test_can_access_homepage():
+ respone = requests.get(ENDPOINT)
+ assert respone.status_code == 200
+```
+
+- test api members `http://127.0.0.1:8000/members`
+
+```python
+def test_can_call_endpoint():
+ respone = requests.get(ENDPOINT + "members")
+ assert respone.status_code == 200
+ data = respone.json()
+ print(data)
+
+```
+
+- test member trên web có khớp với db không `http://127.0.0.1:8000/members`
+
+```python
+def test_user_api():
+ students = db.find()
+ for student in students:
+ username = student["username"]
+ respone = requests.get(ENDPOINT + f"members/{username}")
+ assert respone.status_code == 200
+
+```
+Trong đó students em config với db user `mongodb` có sẵn trong server
+```python
+ENDPOINT = "http://127.0.0.1:8000/"
+client = MongoClient("mongodb://admin:Admin123@127.0.0.1:27017/", connectTimeoutMS=3000)
+VDT_DB = client.VDTuser
+db = VDT_DB.user
+```
+
+
+- test thêm member
+
+```python
+def test_can_create_mem():
+ payload = {
+ "name": "Nguyen Thi Thuy Quynh",
+ "year_of_birth": "2001",
+ "university": "UET",
+ "gender": "Female",
+ "username": "quynhntt1",
+ "major": "computer science",
+ }
+ respone = requests.post(ENDPOINT + "postdata", json=payload)
+
+ assert respone.status_code == 200
+ data = respone.json()
+ print(data)
+
+
+```
+
+
+- test sửa member
+
+```python
+def test_can_update_mem():
+ payload = {
+ "name": "Nguyen Thi Thuy Quynh",
+ "year_of_birth": "2002",
+ "university": "UET",
+ "gender": "Female",
+ "username": "quynhntt",
+ "major": "network and communication",
+ }
+
+ username = payload["username"]
+ respone = requests.put(ENDPOINT + f"/updatemember/{username}", json=payload)
+ assert respone.status_code == 200
+
+ data = respone.json()
+ print(data)
+```
+
+
+- test xóa member
+```python
+def test_can_del_mem():
+ username = "quynhntt1"
+
+ respone = requests.delete(ENDPOINT + f"delmember/{username}")
+ assert respone.status_code == 200
+ print(respone.status_code)
+```
+
+#### Kết quả khi chạy test
+```cmd
+pip install pytest
+pytest test_app_api.py
+```
+
+
+
+
+ Kết quả pass với 6 test
+
+## **Triển khai web application sử dụng các DevOps tools & practices(8đ)**
+
+### 1. Containerization (1đ)
+
+**Dockerfile for flask app**
+
+```Dockerfile
+# Dockerfile for flask app
+FROM python:3.9
+
+ENV FLASK_APP=VDT/__init__.py
+ENV FLASK_ENV=production
+
+
+
+WORKDIR /app
+
+COPY requirements.txt requirements.txt
+
+RUN pip install -r requirements.txt
+
+
+
+COPY . .
+
+
+
+
+
+CMD [ "flask", "run", "--host=0.0.0.0" ]
+
+
+```
+
+Ở đây em có sử dụng thủ thuật layer caching cho
+```Dockerfile
+COPY requirements.txt requirements.txt
+
+RUN pip install -r requirements.txt
+
+
+
+COPY . .
+
+```
+Điều đó nhằm tránh việc tải lại requirements.txt khi có source code thay đổi
+
+Ngoài ra em có thêm file `.dockerignore` để cho docker biết không copy những file không cần thiết vào trong docker
+
+
+**docker-compose.yml**
+
+```yml
+version: '3'
+services:
+ appuser1:
+ build: ./app
+ depends_on:
+ - mongodb
+ ports:
+ - 5000:5000
+ networks:
+ - db
+ - app
+
+
+ appuser2:
+ build: ./app
+ depends_on:
+ - mongodb
+ ports:
+ - 5001:5000
+ networks:
+ - db
+ - app
+
+
+
+
+ nginx-production:
+ image: nginx:1.22.0-alpine
+ ports:
+ - 8000:80
+ volumes:
+ - ./nginx/conf.d/:/etc/nginx/conf.d/
+ depends_on:
+ - appuser1
+ - appuser2
+ networks:
+ - app
+
+
+ mongodb:
+ image: mongo:5.0
+
+ environment:
+ - MONGO_INITDB_ROOT_USERNAME=admin
+ - MONGO_INITDB_ROOT_PASSWORD=Admin123
+ - MONGO_INITDB_DATABASE=VDTuser
+
+ ports:
+ - 27017:27017
+ volumes:
+ - db1:/data/db
+ - ./mongo-entrypoint:/docker-entrypoint-initdb.d
+ networks:
+ - db
+
+volumes:
+ db1:
+
+networks:
+ db:
+ driver: bridge
+ app:
+ driver: bridge
+
+```
+
+**output**
+
+```cmd
+docker compose up -d
+```
+
+Do nginx và mongo em sử dụng image default nên em sẽ show history của flask app
+
+history flask app
+
+
+
+
+
+
+### 2. Continuous Integration(1đ)
+● Tự động chạy unit test khi tạo PR vào branch main (0.5đ)
+
+● Tự động chạy unit test khi push commit lên một branch (0.5đ)
+```yml
+# This is a basic workflow to help you get started with Actions
+
+name: CI
+
+# Controls when the workflow will run
+on:
+ # Triggers the workflow on push or pull request events but only for the "main" branch
+ push:
+ branches: ["*"]
+ pull_request:
+ branches: ["main"]
+
+ # Allows you to run this workflow manually from the Actions tab
+ workflow_dispatch:
+
+# A workflow run is made up of one or more jobs that can run sequentially or in parallel
+jobs:
+ # This workflow contains a single job called "build"
+ build:
+ # The type of runner that the job will run on
+ runs-on: ubuntu-latest
+
+ # Steps represent a sequence of tasks that will be executed as part of the job
+ steps:
+ # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
+ - uses: actions/checkout@v3
+
+ # deploy apllication by docker compose to test
+ - name: Docker Compose Action
+ uses: isbang/compose-action@v1.4.1
+ with:
+ compose-file: "./10.GK/DoAnhTu/docker-compose.yml"
+ down-flags: "--volumes"
+
+ # Test application run or die
+ - name: Test application run or die
+ run: |
+ curl 127.0.0.1:5000
+ curl 127.0.0.1:5001
+ curl 127.0.0.1:8000
+
+ - name: Run test by pytest
+ run: |
+ cd 10.GK/DoAnhTu/app/test
+ python3 --version
+ pip install pytest
+ pip install -r test_requirements.txt
+ pytest -s
+
+```
+
+
+Ở file Ci có hai phần test là test từng container có hoạt động không và test theo unit được code tại phần 1
+
+Kết quả khi chạy 1 CI bất kỳ khi em commit lên git
+
From 989bff8b7fa7841024dfdd6e6b243104eee70661 Mon Sep 17 00:00:00 2001
From: TuDo16 <20021460@vnu.edu.vn>
Date: Mon, 22 May 2023 20:18:02 +0700
Subject: [PATCH 46/49] add Readme
---
10.GK/DoAnhTu/README.md | 361 ++++++++++++++++++++++++++++++-
10.GK/DoAnhTu/image/CD1.png | Bin 0 -> 45023 bytes
10.GK/DoAnhTu/image/CD2.png | Bin 0 -> 107628 bytes
10.GK/DoAnhTu/image/CI.png | Bin 0 -> 75549 bytes
10.GK/DoAnhTu/image/CI1.png | Bin 0 -> 55188 bytes
10.GK/DoAnhTu/image/CI2.png | Bin 0 -> 96492 bytes
10.GK/DoAnhTu/image/CI3.png | Bin 0 -> 221148 bytes
10.GK/DoAnhTu/image/del1.png | Bin 0 -> 98531 bytes
10.GK/DoAnhTu/image/edit.png | Bin 0 -> 97574 bytes
10.GK/DoAnhTu/image/getmems.png | Bin 0 -> 99304 bytes
10.GK/DoAnhTu/image/hisflask.png | Bin 0 -> 85335 bytes
10.GK/DoAnhTu/image/homepage.png | Bin 0 -> 146403 bytes
10.GK/DoAnhTu/image/onemem.png | Bin 0 -> 52078 bytes
10.GK/DoAnhTu/image/post1.png | Bin 0 -> 71144 bytes
10.GK/DoAnhTu/image/post2.png | Bin 0 -> 19623 bytes
10.GK/DoAnhTu/image/test.png | Bin 0 -> 49492 bytes
16 files changed, 360 insertions(+), 1 deletion(-)
create mode 100644 10.GK/DoAnhTu/image/CD1.png
create mode 100644 10.GK/DoAnhTu/image/CD2.png
create mode 100644 10.GK/DoAnhTu/image/CI.png
create mode 100644 10.GK/DoAnhTu/image/CI1.png
create mode 100644 10.GK/DoAnhTu/image/CI2.png
create mode 100644 10.GK/DoAnhTu/image/CI3.png
create mode 100644 10.GK/DoAnhTu/image/del1.png
create mode 100644 10.GK/DoAnhTu/image/edit.png
create mode 100644 10.GK/DoAnhTu/image/getmems.png
create mode 100644 10.GK/DoAnhTu/image/hisflask.png
create mode 100644 10.GK/DoAnhTu/image/homepage.png
create mode 100644 10.GK/DoAnhTu/image/onemem.png
create mode 100644 10.GK/DoAnhTu/image/post1.png
create mode 100644 10.GK/DoAnhTu/image/post2.png
create mode 100644 10.GK/DoAnhTu/image/test.png
diff --git a/10.GK/DoAnhTu/README.md b/10.GK/DoAnhTu/README.md
index eceae9309..c9153bc25 100644
--- a/10.GK/DoAnhTu/README.md
+++ b/10.GK/DoAnhTu/README.md
@@ -676,5 +676,364 @@ jobs:
Ở file Ci có hai phần test là test từng container có hoạt động không và test theo unit được code tại phần 1
-Kết quả khi chạy 1 CI bất kỳ khi em commit lên git
+**Kết quả khi chạy 1 CI bất kỳ khi em commit lên git**
+
+[Kiểm tra output tại đây](https://github.com/batamsieuhang/Viettel-Digital-Talent-2023/actions/runs/5045752582/jobs/9050418679)
+
+CI
+
+
+
+
+
+- Test ping to web
+
+
+
+
+- Pytest in CI
+
+
+
+
+
+
+
+
+
+
+### 3. Continuous Delivery (4đ)
+
+#### 3.1 Viết luồng release dịch vụ bằng công cụ CI/CD của GitHub/GitLab, thực hiện build docker image và push docker image lên Docker Hub khi có event một tag mới được developer tạo ra trên GitHub
+
+```yml
+# file setup CI
+name: Release Workflow
+
+on:
+ push:
+ tags:
+ - "*"
+
+jobs:
+ build-and-push:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Login to Docker Hub
+ run: |
+ echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
+ env:
+ DOCKER_USERNAME: ${{ secrets.DOCKER_USER}}
+ DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
+
+ # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
+ - uses: actions/checkout@v3
+
+ - name: Build and push Docker images
+ run: |
+ cd 10.GK/DoAnhTu/
+ docker-compose build
+ docker images
+ docker tag doanhtu_appuser ${{ secrets.DOCKER_USER}}/doanhtu_appuser:${{ github.ref_name }}
+ docker push ${{ secrets.DOCKER_USER}}/doanhtu_appuser:${{ github.ref_name }}
+ env:
+ DOCKER_USERNAME: ${{ secrets.DOCKER_USER }}
+ DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
+
+```
+
+
+**Mô tả**
+
+```yml
+on:
+ push:
+ tags:
+ - "*"
+```
+Khi có 1 tag được tạo trên git thì luồng CD này sẽ tự động được triển khai theo hai bước
+- Bước 1 là đăng nhập tài khoản dockerhub
+```yml
+name: Login to Docker Hub
+ run: |
+ echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
+ env:
+ DOCKER_USERNAME: ${{ secrets.DOCKER_USER}}
+ DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
+```
+
+- Bước 2: build image rồi push lên docker hub
+```yml
+- name: Build and push Docker images
+ run: |
+ cd 10.GK/DoAnhTu/
+ docker-compose build
+ docker images
+ docker tag doanhtu_appuser ${{ secrets.DOCKER_USER}}/doanhtu_appuser:${{ github.ref_name }}
+ docker push ${{ secrets.DOCKER_USER}}/doanhtu_appuser:${{ github.ref_name }}
+ env:
+ DOCKER_USERNAME: ${{ secrets.DOCKER_USER }}
+ DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
+```
+
+
+**Output**
+
+Ảnh luồng build and push được chạy trên github action khi tạo 1 tag là v1.1.0
+[Kiểm tra output tại đây](https://github.com/batamsieuhang/Viettel-Digital-Talent-2023/actions/runs/5022462629)
+
+
+
+
+
+
+[Image sau khi build xong được đẩy lên dockerhub](https://hub.docker.com/layers/mr4x2/doanhtu_appuser/v1.1.0/images/sha256-dca2361f5aab59df2d1c248440132de5f15d79d1645cce0e770440d26e41cf15?context=repo)
+
+