This is a simple dice roll app that allows you to roll a dice using a JavaScript front-end and a Python back-end.
You can try out the app at https://diceroll.byst.re/
This application is available as Docker images on Docker Hub. You can run it using Docker Compose. To do so, follow these steps:
- Make sure you have Docker installed and working.
- On Windows open Command Prompt or BusyBox. On Linux or Mac open a terminal.
- Navigate to any folder you choose.
- Run the following command to download the docker-compose.yaml file:
curl -Lo docker-compose.yaml https://github.com/emkaminsk/dice_roll/raw/master/docker-compose.yaml
- To pull the images and run them, just use the following command:
docker-compose up -d
Now in your browser go to this page:
http://localhost:8000/
and roll the dice!
Instead of pulling the images from Docker Hub, you can build them yourself. To do so, follow these steps:
- Clone the Git repository into any folder you choose:
git clone https://github.com/emkaminsk/dice_roll.git
- Run the following command to build the images:
docker build -t my_ver/dice_fe ./appFE
docker build -t my_ver/dice_be ./appBE
- In the docker-compose.yaml file, replace the image names with your own:
image: my_ver/dice_fe
image: my_ver/dice_be
- Run the following command to pull start the containers:
docker-compose up -d
The build.sh script automates the process of shutting the containers, cleaning, rebuilding images and starting the docker-compose again. However you would need to provide credentials to your Docker Hub and modify the address in the code.
The front-end of the application is a simple HTML page that uses JavaScript to make a request to the back-end API. The JavaScript code is in the index.html file, and it uses the fetch API to make a GET request to the back-end API.
The back-end of the application is a Python script that uses the http.server library to serve the API. The Python code is in the dice.py file, and it defines a DiceRollRequestHandler class that extends the BaseHTTPRequestHandler class from the http.server library. The DiceRollRequestHandler class implements a do_GET method that handles incoming GET requests and returns a JSON response with the dice roll result.
Once the container is running, you can access the front-end by visiting http://localhost:8000/ in your web browser. If you wish you can access the back-end API separately by making a GET request to http://localhost:8081/dice-roll/?max=6, where 6 is the maximum value of the dice roll.
Both images are built using slim base - ca 124MB.
This project is licensed under the MIT License.