Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a new compose setup, leveraged by gotask #43

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .env

This file was deleted.

32 changes: 32 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Docker Compose
PROJECT_DOMAIN_SUFFIX=localhost

COMPOSE_PROJECT_NAME=ninetofiver
COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.traefik.mixin.yaml
#COMPOSE_FILE=compose.yaml,compose.dev.yaml,compose.fixed-ports.mixin.yaml
COMPOSE_PATH_SEPARATOR=,

MYSQL_EXPOSED_PORT=3306
NINETOFIVER_EXPOSED_PORT=8888

MYSQL_VERSION=5.7
MYSQL_DATABASE=ninetofiver-database
MYSQL_USER=ninetofiver-user
MYSQL_PASSWORD=ninetofiver-password

[email protected]
SUPERUSER_USERNAME=admin
SUPERUSER_PASSWORD=admin

API_APPLICATION_NAME=application
API_APPLICATION_CLIENT_ID=application-id
API_APPLICATION_CLIENT_SECRET=application-secret

# Application
DJANGO_SETTINGS_MODULE=ninetofiver.settings
DJANGO_CONFIGURATION=Dev

CFG_FILE_PATH=/etc/925r/config.yml

PYTHONDONTWRITEBYTECODE=1
PYTHONUNBUFFERED=1
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ docs/_build/
!/media/.gitkeep
*.log
.tox/
.env
.coverage
/scripts/docker/mysql-init/
test_results.html

/.env
20 changes: 7 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
# Pull base image
FROM python:3.8-slim-buster as builder
FROM python:3.8-slim-buster AS builder

# install python project dependencies pre-requisites
RUN apt-get update && \
apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev && \
apt-get install -y gcc default-libmysqlclient-dev

# Set environment variables
COPY requirements.txt requirements.txt
RUN apt-get update \
&& apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev \
&& apt-get install -y gcc default-libmysqlclient-dev

# Install pipenv
RUN set -ex && pip install --upgrade pip

# Install dependencies
COPY requirements.txt requirements.txt
RUN set -ex && pip install -r requirements.txt

FROM builder as final
FROM builder AS final
WORKDIR /code
COPY . /app/

RUN set -ex && bash -c "eval $(grep 'PYTHONDONTWRITEBYTECODE' .env)"
RUN set -ex && bash -c "eval $(grep 'PYTHONUNBUFFERED' .env)"
COPY . .
25 changes: 0 additions & 25 deletions Makefile

This file was deleted.

129 changes: 31 additions & 98 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,112 +7,46 @@ ninetofiver
[![License](https://img.shields.io/github/license/kalmanolah/925r.svg)](https://shields.io)

ninetofiver (or 925r) is a free and open source time and leave tracking application.

## Dependencies

## Installation
- [Taskfile](https://taskfile.dev/)
- [Docker Compose plugin](https://docs.docker.com/compose/)

Install build dependencies:

```bash
apt-get install -y python-dev default-libmysqlclient-dev libldap2-dev libsasl2-dev libssl-dev
```
or
```bash
sudo dnf install -y mysql-devel openldap-devel
```

You'll need [pipenv](https://docs.pipenv.org/). Installing it is super simple:

```bash
pip install pipenv
```

After that, installing the application is smooth sailing:

```bash
pipenv install
```

Once your pipenv is set up, you can use `pipenv shell` to get a shell, or
just prefix additional commands with `pipenv run`.
The Taskfile and Docker Compose setup hides a bit of the setup.
If you want to walk the manual path, check the files `.env.dist`, `Taskfile.dist.yml` and `Dockerfile`.

## Usage
**For usage with Docker, see latter section named _Local Development (with Docker)_.**
1. Run `python manage.py migrate` to create the models.
2. Run `python manage.py createsuperuser` to create an admin user

### Running (development)

Running the command below starts a development server at
`http://127.0.0.1:8000`.

```bash
python manage.py runserver
```
1. Run `task prepare` and check if the values in the .env file are correct for your environment
2. Run `task start` to start the application at `http://localhost:8000`.
3. Run `task app:manage -- migrate` to create the models
4. Run `task app:manage -- createsuperuser` to create an admin user (interactively)
5. Run `task app:manage -- create_test_data` to fill the database with test data (see below for more information)

### Running (production)
For more tasks, check `task --list-all`.

## First steps

Running the command below starts a server using the production configuration
at `http://127.0.0.1:8000`.
### Set up an application for YaYata

Note: The `insecure` flag is used to allow the server to serve static files.
Before you can set up YaYata, you need to register an application in ninetofiver.

```bash
python manage.py runserver --configuration=Prod --insecure
```

## Local Development (with Docker)

To build, run and test and more ... use magic of make help to play with this project.
Make sure you have installed docker and docker compose.
```shell
make help
```
and you receive below list:
```text
build Build project with docker compose
clean Clean Reset project containers with docker compose
down Reset project containers with docker compose
help Show this help
test Run project tests and coverage with tox runner
up Run project with docker compose
```
### How to run local environment with test data.
Build and run docker containers.
```shell
make build
make up
```
Exec initial migration. After _exec_ should be your 925r container name.
```shell
docker exec 925r-web python manage.py migrate
```
Interactively create a new superuser.
```shell
docker exec -it 925r-web python manage.py createsuperuser
```

If you are running YaYata too (in debug mode), then you could need to change 925r port from
8888 to something else, because YaYata runs webpack on the port 8888.

### Next steps
If you want to work with YaYata you need to set up an application.
1. Log in.
2. In the right top corner, navigate to **Your Account -> Your applications -> New application**.
3. Fill **Name** and **Client id**.
4. Set **Client type = Public**.
5. Set **Authorization grant type = Resource owner password-based**.

Now you can log in YaYata with root account, or you can create a new test user.
You are all set to work with Admin interface, if you want some test data filled, see next section.
Now you can log in to YaYata with the root account, or you can create a new test user.

## Example/Test data
You can use django command `create_test_data` to fill database with test data.
You can specify the ammount of data to be created by one optional argument
(`small`, `normal` or `extensive`) with `normal` being the default ammount when not specified.
It can run a few minutes depending on resources. For this reason there is a `-t` option, so you
can see what is happening at the moment.
### Add example data

You can run `task app:manage -- create_test_data` to fill the database with test data.
You can specify the amount of data to be created by one optional argument `amount`. Possible values are
(`small`, `normal` or `extensive`) with `normal` being the default.
```shell
docker exec -t 925r-web python manage.py create_test_data extensive
task app:manage -- create_test_data extensive
```

## Configuration
Expand All @@ -135,31 +69,30 @@ could use the following configuration:
SECRET_KEY: mae3fo4dooJaiteth2emeaNga1biey9ia8FaiQuooYoac8phohee7r
```

## Testing
## Test

Run the test suite:

```bash
tox
task test
```

Generate dummy data for testing (only in DEBUG mode):

```bash
python manage.py create_test_data # fills almost all tables
task task app:manage -- create_test_data # fills almost all tables
```

Clean all database:
Clean the complete database:

```bash
python manage.py flush
task app:manage -- flush
# or delete db.sqlite3 file in root directory
```
```

Other commands for testing:
Other possible commands can be found by running:
```bash
python manage.py help
# [ninetofiver]
task app:manage -- help
```

## License
Expand Down
78 changes: 78 additions & 0 deletions Taskfile.dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
version: '3'

env:
COMPOSE: docker compose

dotenv: ['.env'] # first file takes precedence

tasks:
default:
cmds:
- "'{{.TASK_EXE}}' --list"

.env:
desc: Initiate the .env file
cmds:
- cp "{{.TASK}}.dist" "{{.TASK}}"
generates:
- "{{.TASK}}"
status:
- test -f "{{.TASK}}"
silent: true

prepare:
desc: Prepare your setup
deps: [.env]

build:
desc: Build your services
deps: [prepare]
cmds:
- |
{{.COMPOSE}} build --no-cache

start:
desc: Start all services
deps: [prepare]
cmds:
- |
{{.COMPOSE}} up --detach --remove-orphans {{.CLI_ARGS}}

stop:
desc: Stop all services
deps: [prepare]
cmds:
- |
{{.COMPOSE}} down {{.CLI_ARGS}}

compose:service:*:exec:*:
desc: Open a terminal inside a service
deps: [prepare]
vars:
SERVICE: '{{index .MATCH 0}}'
COMMAND: '{{index .MATCH 1 | default "sh"}}'
cmds:
- |
{{.COMPOSE}} exec --interactive --tty "{{.SERVICE}}" {{.COMMAND}} && exit 0

app:manage:
desc: Run a command against manage.py
deps: [prepare]
cmds:
- |
{{.COMPOSE}} exec --interactive --tty ninetofiver python manage.py {{.CLI_ARGS}}

test:
desc: Run the test suite
deps: [prepare]
cmds:
- |
{{.COMPOSE}} run --rm web tox

clean:
desc: Clean up
deps: [prepare]
cmds:
- |
{{.COMPOSE}} down --remove-orphans --volumes {{.CLI_ARGS}}
- rm -f .env
Loading