Skip to content

Commit

Permalink
close #49
Browse files Browse the repository at this point in the history
Besides untracking the .env files the docker-compose.yml got modified
to rely on .env file only. This way a developer is not required to have
two .env files. This is meant to limit the mental overhead required to
start with the project but it has a downside of causing confilcts/errors
while alternating between deployment types (local vs docker).

Additionally the CONTRIBUTING.md got updated. Finally no more notes left
from the old definition of the project.
  • Loading branch information
Adhalianna committed May 6, 2023
1 parent 0357884 commit 107227c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 121 deletions.
4 changes: 0 additions & 4 deletions .env

This file was deleted.

5 changes: 0 additions & 5 deletions .env.docker

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/trackers-api-server/target
/trackers-models/target
/target
/db_data
/db_data
.env
111 changes: 43 additions & 68 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,43 @@
# Developement Guide

___TODO: warn about some caveats of provided compose file___

Each part, back-end and front-end, may use different tools but the following instructions
apply to both.

## Required Tools

### Docker

The project uses docker to make it simpler to work on it while using different
OSes as a developer. To install docker one should follow the guide applicable
to a given operating system and distribution.
- [Windows installation guide](https://docs.docker.com/desktop/install/windows-install/)
- [RPM or Debian based Linux distributions](https://docs.docker.com/desktop/install/linux-install/)
- [ArchLinux based distributions](https://docs.docker.com/desktop/install/archlinux/)

Besides docker we will be using an extension to it called _docker compose_.
It's a tool which can parse a special configuration file usually called
`docker-compose.yml` and run multiple containers using the file as a recipe for
their parameters. [To use _docker compose_ on Windows or
Mac a desktop application is required](https://docs.docker.com/compose/install/)
or the WSL.

## Using the Tools

### Launching the database

To turn the database up execute:
```sh
sudo docker compose up database
```
The database has it's ports exposed so it can be reached from the host using:
```sh
psql -d trackers -h 0.0.0.0 -p 5432 -U trackers
```
The database may be empty when launched which can cause errors in the back-end
application. In such a case it is recommended to run the migrator docker:
```sh
sudo docker compose up migrator
```
If the migrator docker turns out to be too slow (it should take a while to
build only at the first run) the original cli application for managing
migrations can be installed. Check the [back-end's README](./back-end/README.md)
for more details.

### Launching back-end server

To run back-end server execute:
```sh
sudo docker compose up back-end
```
If you have the Rust toolchain available locally and want to iterate quickly
using just `cargo` to compile the project is recommended.
```sh
cd back-end
cargo dev
```
More information can be found in [the back-end's README](./back-end/README.md).

### Launching all the components
It is a good idea to check occasionally if all the dockers can communicate with
each other as expected. The website they are hosting should be available from
the host. To turn on all the services execute:
```sh
sudo docker compose up
```
# Contributing Guide

<!--toc:start-->
- [Contributing Guide](#contributing-guide)
- [Running the Dockers](#running-the-dockers)
- [Services](#services)
- [`.env` file](#env-file)
- [Project structure](#project-structure)
<!--toc:end-->

## Running the Dockers

The project can be set up and used with docker compose. The compose file is
constructed in such a way that no other than the
`docker compose build; docker compose` actions are needed to run the API. What
is however required is to fill a `.env` file which should be placed at the root
of the repository.

### Services

The compose file runs multiple services. Two of them are provided only to build
correctly other images, those are the `trackers-chef` and `trackers-planner`
services. Along with the `migrator` service they are expected to successfully
exit with __0__ code. The migrator prepares the database if neccessary. Left
running should be the __database__ and the __api__ server.

### `.env` file

The provided compose configuration expects a _.env_ file to be located at the
root of the repository. To fill in that file correctly check the environments
defined for the GitHub repository of the project. Access to those may require
the collaborator role within the GitHub repository.


## Project structure

The code is split into two crates:
- `trackers-models` - defines the schema used by the Diesel ORM as well as any
other models used by the API. The goal is to make it useful for anyone who
would want to provide a client for the API server written in Rust or any other
language that can use Rust source code.
- `trackers-api-server` - the actuall API server and the place defining the
business logic.
19 changes: 6 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,25 @@ services:
hostname: "database"
restart: always
image: "postgres:latest"
expose:
- "5432"
ports:
- 5432:5432
volumes:
- ./db_data/:/var/lib/postgresql/data/
command: postgres -c shared_buffers=512MB -c wal_buffers=64MB -c work_mem=8MB
environment:
POSTGRES_USER: trackers
POSTGRES_PASSWORD: trackers
POSTGRES_DB: trackers
env_file: .env
networks:
- app-net

# Common images used to build api and web-ui
trackers-chef:
image: trackers-chef:${TAG:-latest}
build:
build:
context: .
dockerfile: ./.docker/Dockerfile.chef
env_file: .env.docker
env_file: .env
trackers-planner:
image: trackers-planner
env_file: .env.docker
env_file: .env
build:
context: .
dockerfile: ./.docker/Dockerfile.planner
Expand All @@ -43,11 +38,9 @@ services:
build:
context: .
dockerfile: ./.docker/Dockerfile.api
env_file: .env.docker
env_file: .env
ports:
- "4000:4000"
expose:
- "4000:4000"
networks:
- app-net
depends_on:
Expand All @@ -61,7 +54,7 @@ services:
build:
context: .
dockerfile: ./.docker/Dockerfile.models
env_file: .env.docker
env_file: .env
volumes:
- ./trackers-models:/app
networks:
Expand Down
30 changes: 0 additions & 30 deletions trackers-api-server/README.md

This file was deleted.

0 comments on commit 107227c

Please sign in to comment.