diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9183d51 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git/ +README.md +.vscode/ +.dockerignore +README.md +.git \ No newline at end of file diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..6c947ff --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,72 @@ +name: Docker + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + push: + branches: [ "main" ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Setup buildx + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v1.7.0 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v1.14.1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v4.0.1 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + # set latest tag for default branch + type=raw,value=latest,enable={{is_default_branch}} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v2.10.0 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..10a8e7c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM tiangolo/uwsgi-nginx-flask:python3.11-2024-01-01 + +WORKDIR /app + +COPY . . + +RUN pip3 install --no-cache-dir -r requirements.txt \ No newline at end of file diff --git a/README.md b/README.md index ba8256f..145bb4c 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Before proceeding, ensure you have the following installed on your system. - `pip` + `virtualenv` - `rtl-sdr` package, including `rtl_tcp` and `rtl_power` - `hackrf_sweep` for the [HackRF](https://github.com/greatscottgadgets/hackrf) +- Optionally `docker` ## Installation and Setup @@ -48,6 +49,33 @@ Before starting Rave, make sure that you have the backend tools like rtl_tcp, rt ``` Note: this currently starts the Flask development server. Proper WSGI server support is coming soon. +## Docker + +Dockerfile and docker-compose.yml files have been added to the repo. + +To build and run application run the following command +```bash +./startContainer.sh +``` + +Additionally, the Docker image is built with GitHub actions on the main branch. + +If you open up the docker-compose.yml and modify this line: + +```yml + image: raven +``` + +to be + +```yml + image: ghcr.io/fosatech/raven:latest +``` + +Then run `docker compose run --publish 5000:5000 raven` to start the container + +This bash script will build the docker image from the Docker file and then run the container from the docker compose file. + ## Usage After completing the setup, the Flask application will be running on your local server. You can access it via `localhost:5000/rtl_data`. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4cd0e78 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.9' + +services: + raven: + image: raven + ports: + - "5000:5000" + entrypoint: + - python + - raven.py + - --host=0.0.0.0 \ No newline at end of file diff --git a/startContainer.sh b/startContainer.sh new file mode 100755 index 0000000..0191726 --- /dev/null +++ b/startContainer.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -x + +echo "Building Docker container..." + +docker build -t raven . + +echo "Starting Docker container..." +docker compose run --publish 5000:5000 raven \ No newline at end of file