Skip to content

Commit

Permalink
feat(makefile): update makefile for long commands
Browse files Browse the repository at this point in the history
  • Loading branch information
iknowright committed Jun 15, 2024
1 parent 9f4e7fb commit eff93a6
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 23 deletions.
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,23 @@ init:
yarn install --dev
poetry env use 3.10
poetry install

run_db:
docker compose -f docker-compose-dev.yml up db -d

run_local: init run_db
export DATABASE_URL=postgresql://postgres:[email protected]:5432/pycontw2016
poetry run python src/manage.py runserver 0.0.0.0:8000

run_dev:
docker compose -f docker-compose-dev.yml up -d
bash -c "trap '' INT; docker compose -f docker-compose-dev.yml logs -f pycontw"

stop_dev:
docker compose -f docker-compose-dev.yml stop

remove_dev:
docker compose -f docker-compose-dev.yml down

shell_dev:
docker compose -f docker-compose-dev.yml exec -it pycontw /bin/sh
6 changes: 3 additions & 3 deletions document/deploy_docker_dev.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
### Requirements
- Docker Engine 1.13.1+
- Docker Compose 1.10.0+
- Docker Compose v2

# Containerized Development Environment

1. Simply run the following command to start containerized services, this will run both the database and django service for you:
```
docker compose -f docker-compose-dev.yml up -d
make run_dev
```

2. If the services are up and running in the first time, you may need to run the following in `pycontw` service in docker shell.

To get into the docker shell for `pycontw`

```
docker compose -f docker-compose-dev.yml exec -it pycontw /bin/sh
make shell_dev
```

In the shell, you can run any commands as if you are in a local development environment. Here are some common Django commands:
Expand Down
56 changes: 37 additions & 19 deletions document/deploy_local_env_dev.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
## Getting Started
### Set up a Virtual Environment
## Local Environment Setup

#### Database - Docker (Optional)
### Requirements
- Docker Engine 1.13.1+
- Docker Compose v2
- nvm
- poetry

### 0 - Database - Docker (Optional)
Create and start the database for development:

docker-compose -f docker-compose-dev.yml db up -d
make run_db

This will create a postgres database with the following existed:
```
Expand All @@ -15,46 +20,59 @@ port=5432
```
And the database connection url will be `postgres://postgres:secretpostgres@localhost:5432/pycontw2016`

#### Install environment using Makefile (Python and Node Modules)
Init environment, including installing dependencies

make init
If you plan to serve your own database server, you will need to modify `DATABASE_URL` in the next section.

Activate the python environment in your terminal

poetry shell

### Set up Local Environment Variables for Database
### 1- Set up Local Environment Variables

Settings are stored in environment variables via [django-environ](http://django-environ.readthedocs.org/en/latest/). The quickest way to start is to copy `local.sample.env` into `local.env`:

cp src/pycontw2016/settings/local.sample.env src/pycontw2016/settings/local.env

Default is sqlite3, you can change to connect `postgres`. Copy `local.sample.env` and change its parameters to your personal setting.
Then edit the `SECRET_KEY` line in `local.env`, replacing `{{ secret_key }}` into any [Django Secret Key](http://www.miniwebtool.com/django-secret-key-generator/) value. An example:

SECRET_KEY=twvg)o_=u&@6^*cbi9nfswwh=(&hd$bhxh9iq&h-kn-pff0&&3

### Get Ready for Development

#### 2 - Install environment (Python and Node Modules)
Init environment, including installing dependencies

make init

Activate the python environment in your terminal

poetry shell

### 3 - Get Ready for Development

`cd` into the `src` directory:

cd src

#### Migrate the database:
#### 4 - Migrate the database:

python manage.py migrate

#### Create Super User
#### 5 - Create Super User

python manage.py createsuperuser

#### Compile localized translation
#### 6 - Compile localized translation

python manage.py compilemessages

Now you’re all set!

## Run the Development Server
#### 7 - Run the Development Server

python manage.py runserver

## Subsequent Development

Step 1 ~ 6 are (mostly) one-time thing, in subsequent development, you may want to
speed up the process of running your application. Use

make run_local

to quick launch your local server. Then develop your logic as it may.

If you missed out the steps in above section, just run `poetry shell` and `cd src` then execute those commands when needed.
5 changes: 4 additions & 1 deletion src/pycontw2016/settings/local.sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
# Note: No spaces around '=' sign and no quotes for righthand values.

DEBUG=True
# You have to set the DATABASE_URL if you are dealing with your own database server other than one we provide in `docker-compose-dev.yml`,
# otherwise you may leave the DATABASE_URL variable unset.
# DATABASE_URL=

# syntax: DATABASE_URL=postgres://username:[email protected]:5432/database
DATABASE_URL=sqlite:///db.sqlite3
# Command to create a new secret key:
# $ python -c 'import random; import string; print("".join([random.SystemRandom().choice(string.digits + string.ascii_letters + string.punctuation) for i in range(100)]))'
SECRET_KEY={{ secret_key }}

0 comments on commit eff93a6

Please sign in to comment.