From e3a62ee836367bd652616e902276f6cb7c9a771a Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Thu, 28 Sep 2023 19:11:58 +0530 Subject: [PATCH 1/5] Add script to build docker image and use the same script in CI --- .github/workflows/build_docker.yml | 8 ++++---- scripts/build_docker.sh | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100755 scripts/build_docker.sh diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index a0a7091..dc2754a 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -2,8 +2,7 @@ name: Build Docker Image on: push: branches: - - master - - main + - '*' jobs: build_docker: @@ -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 \ No newline at end of file + if: github.ref_name == 'main' || github.ref_name == 'master' + run: docker push ghcr.io/$GITHUB_REPOSITORY_OWNER/${{ github.event.repository.name }} --all-tags diff --git a/scripts/build_docker.sh b/scripts/build_docker.sh new file mode 100755 index 0000000..93b659c --- /dev/null +++ b/scripts/build_docker.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if [ $# -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +username="$1" + +reponame="$2" + +docker build -t ghcr.io/$username/$reponame:latest . From aa9047c1754ef1efd0ea31befa181e7ab010d6a8 Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Thu, 28 Sep 2023 19:14:32 +0530 Subject: [PATCH 2/5] Debugging --- .github/workflows/build_docker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index dc2754a..018bd19 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -3,6 +3,7 @@ on: push: branches: - '*' + workflow_dispatch: jobs: build_docker: From 9962cfa42beb39a015d6fc14708c09750bfaf980 Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Thu, 28 Sep 2023 19:16:29 +0530 Subject: [PATCH 3/5] Remove debug code --- .github/workflows/build_docker.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index 018bd19..dc2754a 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -3,7 +3,6 @@ on: push: branches: - '*' - workflow_dispatch: jobs: build_docker: From b78376feb4d80340e822c1c56ac16813584b50d5 Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Thu, 28 Sep 2023 19:29:49 +0530 Subject: [PATCH 4/5] Rearrange sections --- README.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 0f95b2a..6efd78d 100644 --- a/README.md +++ b/README.md @@ -31,24 +31,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: @@ -79,6 +61,24 @@ To run the [`FastStream`](https://github.com/airtai/faststream) application loca ./scripts/stop_kafka_broker_locally.sh ``` +## 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: From fb6dc07710b420f64c53ea5437cf72d38262c050 Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Thu, 28 Sep 2023 19:43:55 +0530 Subject: [PATCH 5/5] Add section to build docker image locally --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6efd78d..81346e9 100644 --- a/README.md +++ b/README.md @@ -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//.git + cd ``` + > **_NOTE:_** Replace `` with your GitHub username and `` with the name of your repository. + 2. Install all development requirements using pip: ```bash @@ -61,6 +63,46 @@ 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 + ``` + + 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//: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 `` with your GitHub username and `` 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: