diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0015c6b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +Dockerfile +README.md +*.pyc +*.pyo +*.pyd +__pycache__ \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b32d8aa --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +.idea \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b32ba81 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.7 + +COPY requirements.txt / +WORKDIR / + +RUN pip install --upgrade pip +RUN pip install -r requirements.txt +RUN pip install gunicorn +RUN pip install --upgrade pytest + +COPY app/ /app/ +COPY tests/ /tests/ + +RUN pytest tests/ + +WORKDIR /app + +ENV FLASK_APP=$WORKDIR/app.py + +CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app \ No newline at end of file diff --git a/README.md b/README.md index 2155e62..a2c81ef 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ Your task should you choose to accept it is to: -* Create a Dockerfile to package this simple python app -* Create a script(s) for deploying the app to some cloud service that uses Docker images -* Submit a pull request with your work +* Create a Dockerfile to package this simple python app. +* Create a script(s) for deploying the app to some cloud service that uses Docker images. +* Submit a pull request with your work. Script(s) should include: -* one or more commands to initialize the cloud service resources needed before first-run -* a command that deploys the app/docker image after verifying the unit tests complete succesfully. +* one or more commands to initialize the cloud service resources needed before first-run. +* a command that deploys the app/docker image after verifying the unit tests complete successfully. -Use any language you like for the scripts (shell, python, or whatever) +Use any language you like for the scripts (shell, python, or whatever). -My recomendation for deployment platform is [Google Cloud Run](https://cloud.google.com/run/). +My recommendation for deployment platform is [Google Cloud Run](https://cloud.google.com/run/). Submit a pull request including all your changes when you are ready. \ No newline at end of file diff --git a/app/app.py b/app/app.py index de96c0c..5612de0 100644 --- a/app/app.py +++ b/app/app.py @@ -4,9 +4,11 @@ app = Flask(__name__) + @app.route('/') def hello_world(): return 'Hello Evite!\n' + if __name__ == "__main__": - app.run(debug=True,host='0.0.0.0',port=int(os.environ.get('PORT', 8080))) + app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080))) diff --git a/ship.sh b/ship.sh new file mode 100755 index 0000000..5c5b14a --- /dev/null +++ b/ship.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +export PROJECT_ID='devops-test1-1420' +export SERVICE_NAME='hello-evite' +export GCLOUD_REGION='us-central1' + +echo "Setting region to ${GCLOUD_REGION}..." +gcloud config set run/region $GCLOUD_REGION + +echo "Setting project ID to ${PROJECT_ID}..." +gcloud config set project $PROJECT_ID + +echo 'Enabling API services...' +gcloud services enable run.googleapis.com +gcloud services enable cloudbuild.googleapis.com + +echo 'Building...' +gcloud builds submit --tag gcr.io/${PROJECT_ID}/${SERVICE_NAME} + +if [ $? -eq 0 ] +then + echo "Image built. Deploying..." + gcloud beta run deploy ${SERVICE_NAME} --image gcr.io/${PROJECT_ID}/${SERVICE_NAME} --platform managed --allow-unauthenticated + exit 0 +else + echo "Image failed to build." >&2 + exit 1 +fi \ No newline at end of file diff --git a/tests/test_true.py b/tests/test_true.py index 40c13cc..722303d 100644 --- a/tests/test_true.py +++ b/tests/test_true.py @@ -1,4 +1,3 @@ def test_true(): - foo = True - assert foo == True, "foo should be true" - + foo = True + assert foo == True, "foo should be true"