Skip to content

Update Readme and Makefile #162

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
Binary file removed .coverage
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Thumbs.db
# env files
.envrc
.direnv
.env
*.env
!*.sample.env

# Database
db.sqlite3
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions .terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.9.6
245 changes: 146 additions & 99 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,156 +11,198 @@ Photo contest API is an API for the Runtime Revolution photo contest that takes
- [PHOTO CONTEST API 📸](#photo-contest-api-)
- [Description](#description)
- [Table of Contents](#table-of-contents)
- [Guidelines](#guidelines)
- [Branch Naming](#branch-naming)
- [Who do I talk to?](#who-do-i-talk-to)
- [Setup Time](#setup-time)
- [Prerequisites -](#prerequisites--)
- [Configuration - Setting your python version](#configuration---setting-your-python-version)
- [Configuration - Using poetry for package and dependency management](#configuration---using-poetry-for-package-and-dependency-management)
- [Prerequisites](#prerequisites)
- [Python](#install-the-correct-python-version)
- [Poetry](#install-poetry)
- [Poetry Basics](#poetry-basics)
- [Makefile](#makefile)
- [Running the Project](#running-the-project)
- [Running Tests](#running-tests)
- [TLDR;](#tldr)
- [Setting up localstack s3 to fake Aws](#setting-up-localstack-s3-to-fake-aws)
- [Nice to Have](#nice-to-have)
- [Direnv](#direnv)
- [Guidelines](#guidelines)
- [Branch Naming](#branch-naming)
- [Who do I talk to?](#who-do-i-talk-to)
- [Terraform](#terraform)
- [Data model](#data-model)
- [FAQ](#faq)
- [Macos m1](#macos-m1)
- [gdal related error](#gdal-related-error)

## Guidelines

### Branch Naming

Everytime we need to work on a new feature, bug or any type of task, we need to create a new branch.
Below will be a step by step guide on how we can create and start to work on a task:

The nomenclature for someone named "João Gomes" that need to fix a new "Bug" on a ticket with the ID "1234" and name "Update salary" goes like this:

`jg/bug/1234/Update-salary`

- jg - First and last name initials

- bug - Type of task to be performed

- 1234 - Ticket ID

- Update-salary - Ticket name

## Who do I talk to?

- You can always talk to your Team Leader or the repo owner for any question regarding this project.

## Setup Time

### Prerequisites -
### Prerequisites

#### Install the correct Python version

Install [pyenv](https://github.com/pyenv/pyenv) and [poetry](https://python-poetry.org/docs/#installation)
1 - Install pyenv

If you have this one already, you can jump to the next section [(Configuration - Setting your python version)](#configuration---setting-your-python-version).
```bash
brew install pyenv

### Configuration - Setting your python version
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
```

- Now that you have pyenv, install the version we want to use:
2 - Install the project's python version

```bash
pyenv install -v 3.10.4
```
This command will install the python version that is set in `.python-version`

- Check your list for the installed python version:
```bash
pyenv install
```

```bash
ls ~/.pyenv/versions/
```
3 - Verify that you're using the correct Python version

or by using
```bash
pyenv versions
```

```bash
pyenv versions
```
#### Install Poetry

### Configuration - Using poetry for package and dependency management
```bash
curl -sSL https://install.python-poetry.org | python -
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
```

*To use poetry, we will need to have ***python 3.5 or greater***.*
### Poetry Basics

- Now let's start by always activating a virtual environment to work on when we open the project:
If you need to get out of this virtual environment just type **deactivate**
If you need to get out of this virtual environment just type **deactivate**

```bash
poetry shell
```
```bash
poetry shell
```

- You should have a file called pyproject.toml, with it we can install everything that is needed!
Just a second, make sure you are on your project folder! Let's go and install everything now:

```bash
poetry install
```
```bash
poetry install --no-root
```

This is great! Right now, we have our packages installed!
This is great! Right now, we have our packages installed!

- One last thing! We still need to tell our IDE to use this new interpreter!
Alright, and how do we do this? Its easy, really. (This next steps will be for vscode)
Alright, and how do we do this? Its easy, really. (This next steps will be for vscode)

1. Copy the path from the command below:

1. Copy the path from the command below:
```bash
poetry env info --path
```

```bash
poetry env info --path
```
2. In your vscode, go to settings and search for python interpreter

2. In your vscode, go to settings and search for python interpreter
3. Now select to use a specific path and use the one you just copied
Press Enter and you'r done! Now vscode will use this one.

3. Now select to use a specific path and use the one you just copied
Press Enter and you'r done! Now vscode will use this one.
### Makefile

A lot of commands are available in the Makefile to simplify the setup and day to day tasks.
To get some info regarding these commands you can run:

```bash
make
# OR
make help
```

### Running the Project

*Now, how can we run the app?*
To start the docker containers run

```bash
make up
```

To start the docker container run
```bash
make up
```
After that run the migrations if needed
```bash
make migrate
```

```bash
make migrate
```

Finally run the app

```bash
make run
```
```bash
make run
```

Perfect! You are now running the project locally and you can now start coding!

## Running Tests

To run the tests, inside your working environment run:
```bash
make test
```

To add tests remember that the python automatic discover only works properly for files named "test_*.py".
```bash
make test
```

If you want to use the vscode debugger for a particular test you can use the launch.json.example, rename it launch.json
and place it in the .vscode folder in the root of your working directory.
To add tests remember that the python automatic discover only works properly for files named "test\_\*.py".

## Dummy data

To generate dummy data ensure that the localstack is running and all the migrations are aplied and use the command:

```bash
make populate
```

This command should only be used when the database is empty or it will probaly raise integraty errors related to duplicate
primary keys.
make populate
```

### TLDR;

Check what's available in the Makefile.

Python 3.10.13 environment must exist and be active. Use poetry shell for this.
```bash
make up
make migrate
make run
```

```bash
make up
make migrate
make run
```

### Setting up localstack s3 to fake Aws

After you have installed Docker we will need to install AWS CLI. Even though we are simulating
the AWS, we will require this to comunicate with the docker containers:
1. Install [AWS CLI](https://aws.amazon.com/cli/)
2. After it is installed we will need to supply credentials, even if the
credentials are dummies. Localstack requires this details to be present. For that run the command:
```bash
aws configure
```

1. Install [AWS CLI](https://aws.amazon.com/cli/)
2. After it is installed we will need to supply credentials, even if the
credentials are dummies. Localstack requires this details to be present. For that run the command:
```bash
aws configure
```

In order to create a bucket you can just run the tests to verify everithing is working properly and it will be created automatically.

### Nice to Have

Well, hello there! If you are looking for automation, you have come to the right place!

#### Direnv

Looking for a way to start your venv by doing... nothing!?
Expand All @@ -169,44 +211,49 @@ I know i know, it looks almost like magic. Let me tell you about direnv
- direnv will load and unload a virtual environment everytime we enter or leave the folder
How do we install it? Let's take a look.

1. Let's start by creating an empty file called .envrc

2. Now we can download direnv [here](https://direnv.net/docs/installation.html)
1. Let's start by creating an empty file called .envrc

3. Hook it into your shell like [this](https://direnv.net/docs/hook.html)
2. Now we can download direnv [here](https://direnv.net/docs/installation.html)

4. Alright and finally add the following to your .envrc:
3. Hook it into your shell like [this](https://direnv.net/docs/hook.html)

`layout pyenv 3.10.4`
Note: Everytime you edit your .envrc file direnv will ask you to give permission by typing:
`direnv allow`
4. Alright and finally add the following to your .envrc:

5. ***Important: Now that you changed for direnv replicate the python interpreter change that you did in poetry section***
`layout pyenv 3.10.4`
Note: Everytime you edit your .envrc file direnv will ask you to give permission by typing:
`direnv allow`

6. Reload your shell and you'r set! Now you can leave your folder and come back inside to test if .direnv will show up (thats your new venv).
Everytime you go into or out of your project folder .direnv will activate or deactivate!
## Guidelines
5. **_Important: Now that you changed for direnv replicate the python interpreter change that you did in poetry section_**

### Branch Naming
6. Reload your shell and you'r set! Now you can leave your folder and come back inside to test if .direnv will show up (thats your new venv).
Everytime you go into or out of your project folder .direnv will activate or deactivate!

Everytime we need to work on a new feature, bug or any type of task, we need to create a new branch.
Below will be a step by step guide on how we can create and start to work on a task:
## Terraform

The nomenclature for someone named "João Gomes" that need to fix a new "Bug" on a ticket with the ID "1234" and name "Update salary" goes like this:
This is the easiest way to install Terraform in ARM based CPUs. If you install Terraform directly with an ARM based CPU you might get some errors saying that some providers are not available for ARM. For Intel you can just install Terraform directly.

`jg/bug/1234/Update-salary`
### Install TFenv

- jg - First and last name initials
```bash
brew install tfenv
```

- bug - Type of task to be performed
### Install Terraform

- 1234 - Ticket ID
This command will install the Terraform version that is set in `.terraform-version`

- Update-salary - Ticket name
```bash
tfenv use # If Intel CPU
TFENV_ARCH=amd64 tfenv use # If ARM CPU
```

## Who do I talk to?
You can check your architecture by running the following command:

- You can always talk to your Team Leader or the repo owner for any question regarding this project.
```bash
uname -a
# output example for ARM CPU
> Darwin <USERNAME> 23.6.0 Darwin Kernel Version 23.6.0: <DATE>; root:xnu-10063.141.2~1/RELEASE_ARM64_T8103 arm64
```

## Data model

Expand Down Expand Up @@ -270,7 +317,7 @@ classDiagram
+User votes
}

``````
```

## FAQ

Expand Down
19 changes: 19 additions & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*.env*

.git/
.github/
.pytest_cache/
.vscode/
.env-sample/

docs/
nginx/
terraform/

.flake8
.gitignore
.pre-commit-config.yaml
docker-compose.yml
Dockerfile
Makefile
README.md
Loading
Loading