From c9949635210597673ee716fa595bd3fddc98559c Mon Sep 17 00:00:00 2001 From: Xiangyu John Wu Date: Mon, 25 Nov 2019 13:53:22 +0900 Subject: [PATCH 1/4] Add docker-compose Dockerfile and requirements to run app with docker-compose up only --- Dockerfile | 7 +++++++ docker-compose.yml | 8 ++++++++ requirements.txt | 1 + 3 files changed, 16 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1cc93f4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3 +ENV PYTHONUNBUFFERED 1 +RUN mkdir /code +WORKDIR /code +COPY requirements.txt /code/ +RUN pip install -r requirements.txt +COPY . /code/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0d8e9d8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3' + +services: + web: + build: . + command: python manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..743917e --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Django>=2.0,<3.0 From ad3fe1a96cc90fd9ade820a310ea7f067bc76b4c Mon Sep 17 00:00:00 2001 From: Xiangyu John Wu Date: Mon, 25 Nov 2019 14:15:25 +0900 Subject: [PATCH 2/4] Changed the dependency to Python 2 and Django 1.11. App runs with Python 2 instead of 3 --- Dockerfile | 6 +++--- docker-compose.yml | 15 ++++++++------- requirements.txt | 3 ++- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1cc93f4..58f8be1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ -FROM python:3 +FROM python:2.7 ENV PYTHONUNBUFFERED 1 RUN mkdir /code WORKDIR /code -COPY requirements.txt /code/ +ADD requirements.txt /code/ RUN pip install -r requirements.txt -COPY . /code/ +ADD . /code/ diff --git a/docker-compose.yml b/docker-compose.yml index 0d8e9d8..ee59eff 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,9 @@ -version: '3' - +version: '2' services: - web: - build: . - command: python manage.py runserver 0.0.0.0:8000 - ports: - - "8000:8000" + web: + build: . + command: python manage.py runserver 0.0.0.0:8000 + volumes: + - .:/code + ports: + - "8000:8000" diff --git a/requirements.txt b/requirements.txt index 743917e..a4a0ad6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -Django>=2.0,<3.0 +Django +psycopg2 From e55103f833eeeca771bb22a3811d4dcd321c40ec Mon Sep 17 00:00:00 2001 From: Xiangyu John Wu Date: Wed, 27 Nov 2019 12:07:51 +0900 Subject: [PATCH 3/4] Create README.md --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..d3713a2 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# PythonWebCalculator + +This is a project to demonstrate my abilities in Docker. + +The goal is to be able to access a web-based calculator on your localhost after running docker-compose up in your terminal. + +The skills required to finalise this project are: + +- How to install and setup docker and associated tools +- Use the CLI, Bash on a terminal on macOS +- Write a Dockerfile using DSL +- Understand a third-party app written in Python in such a way that I can map the necessary Docker commands and Dockerfile specifications to run the web server in Django. +- Using git for source control +- Deliver a ready-to-use app and documentation that allows first-time users to quickly setup the app. + +## Prerequisites + +This application is only tested on macOS Mojave Version 10.14.6, but it should work on Linux and Windows (using PowerShell). + +If the app does not run on your client, please issue a ticket or contact me directly. + +Make sure you have the following dependencies installed on your local environment: + +- docker and docker-compose +- python (version 2) +- django +- psycopg2 + +## How to Use the App + +1. Download the repository + +`git clone https://github.com/byteknacker/PythonWebCalculator.git` + +2. Change directory to the project directory + +cd PythonWebCalculator + +3. Run docker-compose + +`docker-compose up` + +4. Open a web browser such as Chrome and go to the site: http://localhost:8000 + +You should be able to see a web calculator. From cb9a6f877c6017458713feb0d3147d624abc79bf Mon Sep 17 00:00:00 2001 From: Xiangyu John Wu Date: Wed, 27 Nov 2019 12:08:15 +0900 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d3713a2..b8609f0 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Make sure you have the following dependencies installed on your local environmen 2. Change directory to the project directory -cd PythonWebCalculator +`cd PythonWebCalculator` 3. Run docker-compose