mirror of
https://github.com/Sosokker/ku-polls.git
synced 2025-12-18 13:04:05 +01:00
chore: add Dockerfile and compose
This commit is contained in:
parent
00c1f1797b
commit
4e605a8a8d
21
Dockerfile
Normal file
21
Dockerfile
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
FROM ubuntu:latest
|
||||||
|
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y python3 python3-pip
|
||||||
|
|
||||||
|
RUN apt-get install -y python3-venv
|
||||||
|
|
||||||
|
WORKDIR /usr/share/ku-polls
|
||||||
|
|
||||||
|
COPY . /usr/share/ku-polls
|
||||||
|
|
||||||
|
# Create virtual environment, install requirement
|
||||||
|
RUN python3 -m venv venv \
|
||||||
|
&& ./venv/bin/pip install --upgrade pip \
|
||||||
|
&& ./venv/bin/pip install -r requirements.txt
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
RUN chmod +x ./entrypoint.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["./entrypoint.sh"]
|
||||||
@ -6,29 +6,35 @@ There are two ways to install and run this project.
|
|||||||
2. Manually install the project with the Instruction in section 2.
|
2. Manually install the project with the Instruction in section 2.
|
||||||
|
|
||||||
### 1. Use `setup.py` or `setup.ps1`(for windows) to install the project.
|
### 1. Use `setup.py` or `setup.ps1`(for windows) to install the project.
|
||||||
|
|
||||||
1. Install [Python 3.11 or later](https://www.python.org/downloads/)
|
1. Install [Python 3.11 or later](https://www.python.org/downloads/)
|
||||||
2. Clone this repository and Run `setup.py` to install and run the project
|
2. Clone this repository and Run `setup.py` to install and run the project
|
||||||
|
|
||||||
**Don't forget to answer the question from `setup.py` to setup the project**
|
**Don't forget to answer the question from `setup.py` to setup the project**
|
||||||
|
|
||||||
This method will autogenerate Environment Variable for you.
|
This method will autogenerate Environment Variable for you.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/Sosokker/ku-polls
|
git clone https://github.com/Sosokker/ku-polls
|
||||||
cd ku-polls
|
cd ku-polls
|
||||||
python setup.py
|
python setup.py
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to customize the environment variables, name of environment folder then run this command
|
If you want to customize the environment variables, name of environment folder then run this command
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python setup.py -custom
|
python setup.py -custom
|
||||||
```
|
```
|
||||||
|
|
||||||
or run `setup.ps1` (For Windows User)
|
or run `setup.ps1` (For Windows User)
|
||||||
|
|
||||||
----
|
---
|
||||||
|
|
||||||
### 2. Manually install the project with this instruction.
|
### 2. Manually install the project with this instruction.
|
||||||
|
|
||||||
1. Install [Python 3.11 or later](https://www.python.org/downloads/)
|
1. Install [Python 3.11 or later](https://www.python.org/downloads/)
|
||||||
2. Run these commands to clone this repository and enter the directory.
|
2. Run these commands to clone this repository and enter the directory.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/Sosokker/ku-polls
|
git clone https://github.com/Sosokker/ku-polls
|
||||||
cd ku-polls
|
cd ku-polls
|
||||||
@ -39,30 +45,38 @@ cd ku-polls
|
|||||||
```bash
|
```bash
|
||||||
python -m pip install --user virtualenv
|
python -m pip install --user virtualenv
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Create virtual environment with `venv` or `virtualenv`.
|
4. Create virtual environment with `venv` or `virtualenv`.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python -m virtualenv venv
|
python -m virtualenv venv
|
||||||
or
|
or
|
||||||
python -m venv venv
|
python -m venv venv
|
||||||
```
|
```
|
||||||
|
|
||||||
5. Use `virtual environment`
|
5. Use `virtual environment`
|
||||||
|
|
||||||
- Windows
|
- Windows
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
.\venv\Scripts\activate
|
.\venv\Scripts\activate
|
||||||
```
|
```
|
||||||
|
|
||||||
- Linux or MacOS
|
- Linux or MacOS
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
source venv/bin/activate
|
source venv/bin/activate
|
||||||
```
|
```
|
||||||
|
|
||||||
6. Install require module.
|
6. Install require module.
|
||||||
|
|
||||||
```
|
```
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
7. Create file call `.env` in `ku-polls` directory and add this line
|
7. Create file call `.env` in `ku-polls` directory and add this line
|
||||||
**You can look at `sample.env` for more information and others environment variables to set.**
|
**You can look at `sample.env` for more information and others environment variables to set.**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
SECRET_KEY=your_secret_key
|
SECRET_KEY=your_secret_key
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
@ -72,16 +86,20 @@ EMAIL_HOST_PASSWORD = yourpassword
|
|||||||
```
|
```
|
||||||
|
|
||||||
You can generate your own `your_secret_key` by this command
|
You can generate your own `your_secret_key` by this command
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python manage.py shell -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"
|
python manage.py shell -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"
|
||||||
```
|
```
|
||||||
or
|
|
||||||
|
or
|
||||||
|
|
||||||
- [Django Secret Key Generator #1](https://djecrety.ir/)
|
- [Django Secret Key Generator #1](https://djecrety.ir/)
|
||||||
- [Django Secret Key Generator #2](https://miniwebtool.com/django-secret-key-generator/)
|
- [Django Secret Key Generator #2](https://miniwebtool.com/django-secret-key-generator/)
|
||||||
|
|
||||||
**Don't forget to change `your_secret_key` to your secret key (without quote)**
|
**Don't forget to change `your_secret_key` to your secret key (without quote)**
|
||||||
|
|
||||||
8. Migrate database and load data into it then runserver.
|
8. Migrate database and load data into it then runserver.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python manage.py migrate
|
python manage.py migrate
|
||||||
python manage.py loaddata data/users.json
|
python manage.py loaddata data/users.json
|
||||||
@ -90,13 +108,39 @@ python manage.py loaddata data/vote.json
|
|||||||
python manage.py runserver
|
python manage.py runserver
|
||||||
```
|
```
|
||||||
|
|
||||||
***NOTE***
|
**_NOTE_**
|
||||||
|
|
||||||
By Default `DEBUG=False` and Django will not load Static files for you so if you want to apply CSS run this.
|
By Default `DEBUG=False` and Django will not load Static files for you so if you want to apply CSS run this.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python manage.py runserver --insecure
|
python manage.py runserver --insecure
|
||||||
```
|
```
|
||||||
|
|
||||||
or set `DEBUG=True`
|
or set `DEBUG=True`
|
||||||
or do the [collectstatic](https://docs.djangoproject.com/en/4.2/ref/contrib/staticfiles/)
|
or do the [collectstatic](https://docs.djangoproject.com/en/4.2/ref/contrib/staticfiles/)
|
||||||
|
|
||||||
Then connect to [http://127.0.0.1:8000/](http://127.0.0.1:8000/) or [localhost:8000/](localhost:8000/)
|
Then connect to [http://127.0.0.1:8000/](http://127.0.0.1:8000/) or [localhost:8000/](localhost:8000/)
|
||||||
|
|
||||||
|
### 3. Docker compose
|
||||||
|
|
||||||
|
1. Clone the repository then create .env file in the following format
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/Sosokker/ku-polls
|
||||||
|
```
|
||||||
|
|
||||||
|
.env Format
|
||||||
|
|
||||||
|
```file
|
||||||
|
SECRET_KEY=your_secret_key
|
||||||
|
DEBUG=True
|
||||||
|
ALLOWED_HOSTS=localhost
|
||||||
|
TIME_ZONE=Asia/Bangkok
|
||||||
|
EMAIL_HOST_PASSWORD=yourpassword
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Run docker compose
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose up
|
||||||
|
```
|
||||||
|
|||||||
50
README.md
50
README.md
@ -1,4 +1,5 @@
|
|||||||
## KU Polls: Online Survey Questions
|
## KU Polls: Online Survey Questions
|
||||||
|
|
||||||
[](https://github.com/Sosokker/ku-polls/actions/workflows/django.yml)
|
[](https://github.com/Sosokker/ku-polls/actions/workflows/django.yml)
|
||||||
|
|
||||||
An application to conduct online polls and surveys based
|
An application to conduct online polls and surveys based
|
||||||
@ -10,6 +11,30 @@ Here is **[Install Instruction](Installation.md)**.
|
|||||||
|
|
||||||
## How to Run
|
## How to Run
|
||||||
|
|
||||||
|
### Docker compose
|
||||||
|
|
||||||
|
1. Clone the repository then create .env file in the following format
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/Sosokker/ku-polls
|
||||||
|
```
|
||||||
|
|
||||||
|
.env Format
|
||||||
|
|
||||||
|
```file
|
||||||
|
SECRET_KEY=your_secret_key
|
||||||
|
DEBUG=True
|
||||||
|
ALLOWED_HOSTS=localhost
|
||||||
|
TIME_ZONE=Asia/Bangkok
|
||||||
|
EMAIL_HOST_PASSWORD=yourpassword
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Run docker compose
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose up
|
||||||
|
```
|
||||||
|
|
||||||
### Setup.py Method
|
### Setup.py Method
|
||||||
|
|
||||||
Using setup.py method, it will set `.env` for you and runserver automatically with [--insecure](https://docs.djangoproject.com/en/4.2/ref/contrib/staticfiles/#cmdoption-runserver-insecure).
|
Using setup.py method, it will set `.env` for you and runserver automatically with [--insecure](https://docs.djangoproject.com/en/4.2/ref/contrib/staticfiles/#cmdoption-runserver-insecure).
|
||||||
@ -18,7 +43,9 @@ You can set `DEBUG=True` later and then runserver normally to load static files.
|
|||||||
Then, connect to [http://127.0.0.1:8000/](http://127.0.0.1:8000/)
|
Then, connect to [http://127.0.0.1:8000/](http://127.0.0.1:8000/)
|
||||||
|
|
||||||
### Manual Installation
|
### Manual Installation
|
||||||
|
|
||||||
After follow all of instruction.
|
After follow all of instruction.
|
||||||
|
|
||||||
- Set Virtual Environment and Use it.
|
- Set Virtual Environment and Use it.
|
||||||
- Install Dependencies.
|
- Install Dependencies.
|
||||||
- Migrate and then Load fixtures.
|
- Migrate and then Load fixtures.
|
||||||
@ -44,25 +71,26 @@ Then, connect to [http://127.0.0.1:8000/](http://127.0.0.1:8000/)
|
|||||||
**NOTE** : If you have problems with port you can use runserver and specific your own port.
|
**NOTE** : If you have problems with port you can use runserver and specific your own port.
|
||||||
|
|
||||||
For example, If you run this command then you need to connect to [http://127.0.0.1:7000/](http://127.0.0.1:7000/)
|
For example, If you run this command then you need to connect to [http://127.0.0.1:7000/](http://127.0.0.1:7000/)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python manage.py runserver 7000
|
python manage.py runserver 7000
|
||||||
```
|
```
|
||||||
|
|
||||||
## Demo Superuser
|
## Demo Superuser
|
||||||
|
|
||||||
|Username|Password|
|
| Username | Password |
|
||||||
|:--:|:--:|
|
| :------: | :--------------: |
|
||||||
|admin|ineedmorebullets|
|
| admin | ineedmorebullets |
|
||||||
|
|
||||||
## Demo User
|
## Demo User
|
||||||
|
|
||||||
|Username|Password|
|
| Username | Password |
|
||||||
|:--:|:--:|
|
| :------: | :----------: |
|
||||||
|tester1|aa12345678aa|
|
| tester1 | aa12345678aa |
|
||||||
|tester2|aa12345678aa|
|
| tester2 | aa12345678aa |
|
||||||
|tester3|aa12345678aa|
|
| tester3 | aa12345678aa |
|
||||||
|tester4|aa12345678aa|
|
| tester4 | aa12345678aa |
|
||||||
|novote |aa12345678aa|
|
| novote | aa12345678aa |
|
||||||
|
|
||||||
## Project Documents
|
## Project Documents
|
||||||
|
|
||||||
|
|||||||
12
docker-compose.yml
Normal file
12
docker-compose.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
services:
|
||||||
|
ku-polls:
|
||||||
|
build: .
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
volumes:
|
||||||
|
- ku-polls-data:/usr/share/ku-polls
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
ku-polls-data:
|
||||||
20
entrypoint.sh
Normal file
20
entrypoint.sh
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
echo "Running migrations..."
|
||||||
|
./venv/bin/python3 manage.py migrate
|
||||||
|
|
||||||
|
echo "Loading data for users..."
|
||||||
|
./venv/bin/python3 manage.py loaddata data/users.json
|
||||||
|
|
||||||
|
echo "Loading data for polls..."
|
||||||
|
./venv/bin/python3 manage.py loaddata data/polls.json
|
||||||
|
|
||||||
|
echo "Loading data for votes..."
|
||||||
|
./venv/bin/python3 manage.py loaddata data/vote.json
|
||||||
|
|
||||||
|
echo "Starting Django development server..."
|
||||||
|
./venv/bin/python3 manage.py runserver 0.0.0.0:8000 --insecure
|
||||||
Loading…
Reference in New Issue
Block a user