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/README.md b/README.md index 0f95b2a..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 @@ -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: @@ -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 + ``` + + 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: + +```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: 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 .