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

Update readme to build docker locally #14

Merged
merged 5 commits into from
Sep 28, 2023
Merged
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
8 changes: 4 additions & 4 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: Build Docker Image
on:
push:
branches:
- master
- main
- '*'

jobs:
build_docker:
Expand All @@ -21,6 +20,7 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- run: docker build -t ghcr.io/$GITHUB_REPOSITORY:latest .
- run: ./scripts/build_docker.sh $GITHUB_REPOSITORY_OWNER ${{ github.event.repository.name }}
- name: Push built image
run: docker push ghcr.io/$GITHUB_REPOSITORY --all-tags
if: github.ref_name == 'main' || github.ref_name == 'master'
run: docker push ghcr.io/$GITHUB_REPOSITORY_OWNER/${{ github.event.repository.name }} --all-tags
82 changes: 62 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ To set up your development environment, follow these steps:
1. Clone this repository to your local machine:

```bash
git clone https://github.com/your-username/faststream-app.git
cd faststream-app
git clone https://github.com/<username>/<repo-name>.git
cd <repo-name>
```

> **_NOTE:_** Replace `<username>` with your GitHub username and `<repo-name>` with the name of your repository.

2. Install all development requirements using pip:

```bash
Expand All @@ -31,24 +33,6 @@ Once you have updated tests, you can execute the tests using [`pytest`](https://
pytest
```

## Code Linting

After making changes to the code, it's essential to ensure it adheres to coding standards. We provide a script to help you with code formatting and linting. Run the following script to automatically fix linting issues:

```bash
./scripts/lint.sh
```

## Static Analysis

Static analysis tools [`mypy`](https://mypy.readthedocs.io/en/stable/) and [`bandit`](https://bandit.readthedocs.io/en/latest/) can help identify potential issues in your code. To run static analysis, use the following script:

```bash
./scripts/static-analysis.sh
```

If there are any static analysis errors, resolve them in your code and rerun the script until it passes successfully.

## Running FastStream Application Locally

To run the [`FastStream`](https://github.com/airtai/faststream) application locally, follow these steps:
Expand Down Expand Up @@ -79,6 +63,64 @@ To run the [`FastStream`](https://github.com/airtai/faststream) application loca
./scripts/stop_kafka_broker_locally.sh
```

## Building and Testing Docker Image Locally

If you'd like to build and test the [`Docker`](https://www.docker.com/) image locally, follow these steps:

1. Run the provided script to build the [`Docker`](https://www.docker.com/) image locally. Use the following command:

```bash
./scripts/build_docker.sh <username> <repo-name>
```

This script will build the [`Docker`](https://www.docker.com/) image locally with the same name as the one built in `CI`.

2. Before starting the [`Docker`](https://www.docker.com/) container, ensure that a Kafka [`Docker`](https://www.docker.com/) container is running locally. You can start it using the provided script:

```bash
./scripts/start_kafka_broker_locally.sh
```

3. Once Kafka is up and running, you can start the local [`Docker`](https://www.docker.com/) container using the following command:

```bash
docker run --rm --name faststream-app --net=host ghcr.io/<username>/<repo-name>:latest
```

* `--rm`: This flag removes the container once it stops running, ensuring that it doesn't clutter your system with unused containers.

* `--name faststream-app`: Assigns a name to the running container, in this case, "faststream-app".

* `--net=host`: This flag allows the [`Docker`](https://www.docker.com/) container to share the host's network namespace.

4. To stop the local [`Docker`](https://www.docker.com/) container, simply press `Ctrl+C` in your terminal.

5. Finally, stop the Kafka [`Docker`](https://www.docker.com/) container by running the provided script:

```bash
./scripts/stop_kafka_broker_locally.sh
```

> **_NOTE:_** Replace `<username>` with your GitHub username and `<repo-name>` with the name of your repository in the above commands.

## Code Linting

After making changes to the code, it's essential to ensure it adheres to coding standards. We provide a script to help you with code formatting and linting. Run the following script to automatically fix linting issues:

```bash
./scripts/lint.sh
```

## Static Analysis

Static analysis tools [`mypy`](https://mypy.readthedocs.io/en/stable/) and [`bandit`](https://bandit.readthedocs.io/en/latest/) can help identify potential issues in your code. To run static analysis, use the following script:

```bash
./scripts/static-analysis.sh
```

If there are any static analysis errors, resolve them in your code and rerun the script until it passes successfully.

## Viewing AsyncAPI Documentation

[`FastStream`](https://github.com/airtai/faststream) framework supports [`AsyncAPI`](https://www.asyncapi.com/) documentation. To ensure that your changes are reflected in the [`AsyncAPI`](https://www.asyncapi.com/) documentation, follow these steps:
Expand Down
12 changes: 12 additions & 0 deletions scripts/build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

if [ $# -ne 2 ]; then
echo "Usage: $0 <username> <repo-name>"
exit 1
fi

username="$1"

reponame="$2"

docker build -t ghcr.io/$username/$reponame:latest .