Added Files
This commit is contained in:
parent
200cc84109
commit
ff1789b3e3
18
appspec.yml
Executable file
18
appspec.yml
Executable file
@ -0,0 +1,18 @@
|
||||
version: 0.0
|
||||
os: linux
|
||||
files:
|
||||
- source: /
|
||||
destination: /web/
|
||||
hooks:
|
||||
AfterInstall:
|
||||
- location: scripts/mkdir.sh
|
||||
timeout: 300
|
||||
runas: root
|
||||
ApplicationStart:
|
||||
- location: scripts/start_flask.sh
|
||||
timeout: 300
|
||||
runas: root
|
||||
ApplicationStop:
|
||||
- location: scripts/stop_flask1.sh
|
||||
timeout: 300
|
||||
runas: root
|
24
buildspec.yml
Executable file
24
buildspec.yml
Executable file
@ -0,0 +1,24 @@
|
||||
version: 0.2
|
||||
|
||||
phases:
|
||||
install:
|
||||
commands:
|
||||
- python -m pip install Flask
|
||||
build:
|
||||
commands:
|
||||
- echo Build started on `date`
|
||||
- echo Compiling the Python code...
|
||||
- python test_app.py
|
||||
post_build:
|
||||
commands:
|
||||
- echo Build completed on `date`
|
||||
artifacts:
|
||||
files:
|
||||
- web.py
|
||||
- appspec.yml
|
||||
- templates/layout.html
|
||||
- templates/test.html
|
||||
- scripts/mkdir.sh
|
||||
- scripts/start_flask.sh
|
||||
- scripts/stop_flask1.sh
|
||||
- scripts/stop_flask.py
|
1
requirements.txt
Executable file
1
requirements.txt
Executable file
@ -0,0 +1 @@
|
||||
Flask
|
5
scripts/mkdir.sh
Executable file
5
scripts/mkdir.sh
Executable file
@ -0,0 +1,5 @@
|
||||
mkdir -p /web
|
||||
curl -O https://bootstrap.pypa.io/get-pip.py
|
||||
python get-pip.py --user
|
||||
python -m pip install Flask
|
||||
#sdssdsds
|
1
scripts/start_flask.sh
Executable file
1
scripts/start_flask.sh
Executable file
@ -0,0 +1 @@
|
||||
python /web/web.py > /dev/null 2>&1 &
|
3
scripts/stop_flask.py
Executable file
3
scripts/stop_flask.py
Executable file
@ -0,0 +1,3 @@
|
||||
import requests
|
||||
|
||||
requests.post("http://127.0.0.1/shutdown")
|
6
scripts/stop_flask.sh
Executable file
6
scripts/stop_flask.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/python
|
||||
import requests
|
||||
|
||||
requests.post("http://127.0.0.1/shutdown")
|
||||
|
||||
|
1
scripts/stop_flask1.sh
Executable file
1
scripts/stop_flask1.sh
Executable file
@ -0,0 +1 @@
|
||||
python /web/scripts/stop_flask.py
|
25
templates/layout.html
Executable file
25
templates/layout.html
Executable file
@ -0,0 +1,25 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>AWS CodeBuild-Jenkins-CodeDeploy</title>
|
||||
<style>
|
||||
body {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
|
||||
font-weight: bold;
|
||||
color: #ff9900;
|
||||
font-size: 2.5em;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% block body %}{% endblock %}
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
13
templates/test.html
Executable file
13
templates/test.html
Executable file
@ -0,0 +1,13 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block body %}
|
||||
|
||||
<div class="block1">
|
||||
<h1 style="text-align: center;">Congratulations!!</h1>
|
||||
<h1>You have successfully deployed your web application using automated CI/CD.</h1>
|
||||
<BR>
|
||||
<h2 style="text-align: center;">Jenkins - AWS CodeBuild - AWS CodeDeploy</h2>
|
||||
|
||||
<img style="display: block; margin-left: auto; margin-right: auto;" src="https://a0.awsstatic.com/libra-css/images/logos/aws_logo_smile_1200x630.png"
|
||||
width="527" height="277" />
|
||||
</div>
|
||||
<p>{% endblock %}</p>
|
27
test_app.py
Normal file
27
test_app.py
Normal file
@ -0,0 +1,27 @@
|
||||
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
# SPDX-License-Identifier: MIT-0
|
||||
|
||||
from web import myapp
|
||||
import unittest
|
||||
|
||||
# python -m unittest test_app
|
||||
|
||||
|
||||
class TestMyApp(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.app = myapp.test_client()
|
||||
|
||||
def test_main(self):
|
||||
rv = self.app.get('/')
|
||||
assert rv.status == '200 OK'
|
||||
assert b'Congratulations' in rv.data
|
||||
#assert False
|
||||
|
||||
def test_404(self):
|
||||
rv = self.app.get('/other')
|
||||
self.assertEqual(rv.status, '404 NOT FOUND')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
32
web.py
Normal file
32
web.py
Normal file
@ -0,0 +1,32 @@
|
||||
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
# SPDX-License-Identifier: MIT-0
|
||||
|
||||
from flask import Flask, flash, redirect, render_template, request, session, abort
|
||||
from random import randint
|
||||
|
||||
|
||||
def shutdown_server():
|
||||
func = request.environ.get('werkzeug.server.shutdown')
|
||||
if func is None:
|
||||
raise RuntimeError('Not running with the Werkzeug Server')
|
||||
func()
|
||||
|
||||
|
||||
myapp = Flask(__name__)
|
||||
|
||||
|
||||
@myapp.route('/shutdown', methods=['POST'])
|
||||
def shutdown():
|
||||
shutdown_server()
|
||||
return 'Server shutting down...'
|
||||
|
||||
|
||||
@myapp.route("/")
|
||||
def hello():
|
||||
# return name
|
||||
return render_template(
|
||||
'test.html', **locals())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
myapp.run(host='0.0.0.0', port=80)
|
Loading…
Reference in New Issue
Block a user