-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# 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 "master" branch | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
# 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, | ||
pwd | ||
ls -alh | ||
- name: Run Docker Build Script | ||
env: | ||
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
DOCKER_REPO: ${{ secrets.DOCKERHUB_REPO }} | ||
run: | | ||
chmod +x docker-build.sh | ||
./docker-build.sh | ||
test: | ||
# 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. | ||
deploy: | ||
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from flask import Flask | ||
from flask_sqlalchemy import SQLAlchemy | ||
from config import Config | ||
|
||
app = Flask(__name__) | ||
app.config.from_object(Config) | ||
db = SQLAlchemy(app) | ||
|
||
from app import routes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from app import db | ||
|
||
class Demo(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
info1 = db.Column(db.String(80), unique=True, nullable=False) | ||
info2 = db.Column(db.String(120), unique=True, nullable=False) | ||
|
||
def __init__(self, info1, info2): | ||
self.info1 = info1 | ||
self.info2 = info2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from flask import request, jsonify | ||
from app import app, db | ||
from app.models import Demo | ||
|
||
# 添加用户 | ||
@app.route('/demos', methods=['POST']) | ||
def add_demo(): | ||
data = request.get_json() | ||
new_demo = Demo(info1=data['info1'], info2=data['info2']) | ||
db.session.add(new_demo) | ||
db.session.commit() | ||
return jsonify({'message': 'Demo added successfully'}) | ||
|
||
# 获取所有用户 | ||
@app.route('/demos', methods=['GET']) | ||
def get_demos(): | ||
demos = Demo.query.all() | ||
demo_list = [] | ||
for demo in demos: | ||
demo_data = {'id': demo.id, 'info1': demo.info1, 'info2': demo.info2} | ||
demo_list.append(demo_data) | ||
return jsonify({'demos': demo_list}) | ||
|
||
# 获取单个用户 | ||
@app.route('/demos/<int:demo_id>', methods=['GET']) | ||
def get_demo(demo_id): | ||
demo = Demo.query.get(demo_id) | ||
if demo: | ||
demo_data = {'id': demo.id, 'info1': demo.info1, 'info2': demo.info2} | ||
return jsonify(demo_data) | ||
return jsonify({'message': 'Demo not found'}), 404 | ||
|
||
# 更新用户信息 | ||
@app.route('/demos/<int:demo_id>', methods=['PUT']) | ||
def update_demo(demo_id): | ||
demo = Demo.query.get(demo_id) | ||
if not demo: | ||
return jsonify({'message': 'Demo not found'}), 404 | ||
|
||
data = request.get_json() | ||
demo.info1 = data['info1'] | ||
demo.info2 = data['info2'] | ||
db.session.commit() | ||
return jsonify({'message': 'Demo updated successfully'}) | ||
|
||
# 删除用户 | ||
@app.route('/demos/<int:demo_id>', methods=['DELETE']) | ||
def delete_demo(demo_id): | ||
demo = Demo.query.get(demo_id) | ||
if not demo: | ||
return jsonify({'message': 'Demo not found'}), 404 | ||
|
||
db.session.delete(demo) | ||
db.session.commit() | ||
return jsonify({'message': 'Demo deleted successfully'}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
|
||
echo "Please complete the compilation script ./build.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo "Please complete the compilation script ./build.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Config: | ||
SQLALCHEMY_DATABASE_URI = 'sqlite:///../data.db' | ||
SQLALCHEMY_TRACK_MODIFICATIONS = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from app import app, db | ||
|
||
if __name__ == '__main__': | ||
with app.app_context(): | ||
db.create_all() | ||
|
||
app.run(debug=True, port=8061) |