Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
olic32 committed Apr 5, 2023
0 parents commit 1615101
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Imagine this file as a recipe for setting up a virtual computer.

# Dockerfiles typically start with a 'base image'. There are loads of these
# and you can find them at hub.docker.com.
# We're going to use a base image for Python veresion 3.11
FROM python:3.11

# This base image contains essentially everything necessary for a 'virtual
# computer'. It has a terminal, certain basic commands, and of course Python.

# We run a command to install `pipenv`
RUN pip install pipenv

# We'll need our app's files in the container in order to be able to run them!
# We copy them in from the current directory to the folder `/app` in
# our virtual computer. Reminder `.` means 'the current directory'
COPY . /app

# We set the working directory for commands from this point on
WORKDIR /app

# We run `pipenv install` to install our project's dependencies. Since we've
# copied in our `Pipfile`, `pipenv` will use that to get a list of dependencies.
# We include a couple of extra options suitable for deployment.
RUN pipenv install --system --deploy

# At this point we've set up our virtual computer, but we've not _yet_ run our
# application. And we're not going to! We're just setting up the container
# so that it's ready to do so when we tell it.

# So we're going to tell Docker here that when we _do_ want to run it, this is
# what it should run:
CMD ["python", "app.py"]
14 changes: 14 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pytest = "*"
flask = "*"

[dev-packages]

[requires]
python_version = "3.11"
python_full_version = "3.11.0"
155 changes: 155 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Simple Server

This is a simple web server that serves a single route.

To set up this project.

```bash
; pipenv install
; pipenv shell
; pytest # Run the tests
; python app.py # Run the server
```


<!-- BEGIN GENERATED SECTION DO NOT EDIT -->

---

**How was this resource?**
[😫](https://airtable.com/shrUJ3t7KLMqVRFKR?prefill_Repository=makersacademy%2Fcloud-deployment&prefill_File=codebases%2Fsimple_server%2FREADME.md&prefill_Sentiment=😫) [😕](https://airtable.com/shrUJ3t7KLMqVRFKR?prefill_Repository=makersacademy%2Fcloud-deployment&prefill_File=codebases%2Fsimple_server%2FREADME.md&prefill_Sentiment=😕) [😐](https://airtable.com/shrUJ3t7KLMqVRFKR?prefill_Repository=makersacademy%2Fcloud-deployment&prefill_File=codebases%2Fsimple_server%2FREADME.md&prefill_Sentiment=😐) [🙂](https://airtable.com/shrUJ3t7KLMqVRFKR?prefill_Repository=makersacademy%2Fcloud-deployment&prefill_File=codebases%2Fsimple_server%2FREADME.md&prefill_Sentiment=🙂) [😀](https://airtable.com/shrUJ3t7KLMqVRFKR?prefill_Repository=makersacademy%2Fcloud-deployment&prefill_File=codebases%2Fsimple_server%2FREADME.md&prefill_Sentiment=😀)
Click an emoji to tell us.

<!-- END GENERATED SECTION DO NOT EDIT -->
14 changes: 14 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
from flask import Flask, request

app = Flask(__name__)

@app.route('/', methods=['GET'])
def get_home():
return "Hello, world!"

if __name__ == '__main__':
app.run(
debug=True,
host="0.0.0.0" # Listen for connections _to_ any server
)
Empty file added lib/__init__.py
Empty file.
Empty file added tests/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest
from app import app

@pytest.fixture
def web_client():
app.config['TESTING'] = True
with app.test_client() as client:
yield client
4 changes: 4 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def test_get_home(web_client):
response = web_client.get("/")
assert response.status_code == 200
assert response.data.decode("utf-8") == "Hello, world!"

0 comments on commit 1615101

Please sign in to comment.